how to create wallet in mangopay? - php

I want to integrate mangopay using php and i am using following link as ref:
http://docs.mangopay.com/api-references/wallets/
but i can't able to do that because if i am use any options like create wallet or any other then it will try to create new user even i am trying to use any other option.
following is code which i used for create new wallet in mangopay:
<h2>Create User</h2>
<form action="https://api.sandbox.mangopay.com/v2/clients" method="post">
<input name="ClientId" id="ClientId" value="<cust's sandbox id>" /><br>
<input name="Email" id="Email" value="" /><br>
<input name="FirstName" id="FirstName" value="" /><br>
<input name="LastName" id="LastName" value="" /><br>
<input name="Birthday" id="Birthday" value="<?php echo strtotime("1988-03-19");?>" /><br>
<input name="Nationality" id="Nationality" value="DE" /><br>
<input name="CountryOfResidence" id="CountryOfResidence" value="DE" /><br>
<input type="submit" value="submit">
</form>
<h2>Create Wallet</h2>
<form action="https://api.sandbox.mangopay.com/v2/clients" method="post">
<input name="ClientId" id="ClientId" value="<cust's sandbox id>" /><br>
<input name="Owners" id="Owners" value="<cust's sandbox id>" /><br>
<input name="Email" id="Email " value="mddipen" /><br>
<input name="Description" id="Description" value="" /><br>
<input name="Currency" id="Currency" value="EUR" /><br>
<input type="submit" value="submit">
</form>

define('MANGOPAY_REQUEST_URL','https://api.sandbox.mangopay.com/v2/');
define('MANGOPAY_ADMIN_ID','Admin ID');
define('CURL_AUTH_HEADER','Authentication Key');
function processCurlJsonrequest($parseUrl, $fieldString) { //Initiate cURL request and send back the result
$URL=MANGOPAY_REQUEST_URL.$parseUrl;
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Basic ".CURL_AUTH_HEADER, "Content-Type: application/json; charset=utf-8","Accept:application/json, text/javascript, */*; q=0.01"));
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fieldString));
curl_setopt($ch, CURLOPT_POST, 1);
$resulta = curl_exec($ch);
if (curl_errno($ch)) {
print curl_error($ch);
} else {
curl_close($ch);
}
return $resulta;
}
$data = array(
"FirstName" => $first_name,
"LastName" => $last_name,
"Address" => "",
"Birthday" => $birthdatestr,
"Nationality" => $nationality,
"CountryOfResidence" => $CountryOfResidence,
"Occupation" => "",
"IncomeRange" => "",
"ProofOfIdentity" => null,
"ProofOfAddress" => null,
//"PersonType" => "NATURAL",
"Email" => $email,
"Tag" => ""
);
$parseUrl=MANGOPAY_ADMIN_ID.'/users/natural';
$response= processCurlJsonrequest($parseUrl, $data);
$arrResponse=json_decode($response);
$mangopay_userId = $arrResponse->Id;
$data_mangopay = array(
"Owners" => array($mangopay_userId),
"Description" => "A very cool wallet",
"Currency" => "EUR",
"Tag" => ""
);
$parseUrl=MANGOPAY_ADMIN_ID.'/wallets';
$response_mangopay= processCurlJsonrequest($parseUrl, $data_mangopay);
$arrResponse_mangopay=json_decode($response_mangopay);
$mangopay_walletId = $arrResponse_mangopay->Id;

I don't quite understand what the problem is - are you trying to create a new user AND wallet on the same page? If so, that isn't possible - you'll have to get the UserId first to then supply for the wallet creation.
Also, if you're not yet using the new PHP SDK, I suggest you do as it's really comprehensive. However the reference/docs are pretty dire but I found this site which is very useful.
Using the SDK and to solve your problem if I've understood it correctly:
//Create an instance of MangoPayApi SDK
$mangoPayApi = new \MangoPay\MangoPayApi();
$mangoPayApi->Config->ClientId = MangoPayDemo_ClientId;
$mangoPayApi->Config->ClientPassword = MangoPayDemo_ClientPassword;
$mangoPayApi->Config->TemporaryFolder = MangoPayDemo_TemporaryFolder;
//Build the parameters for the request
$User = new MangoPay\User();
$User->PersonType = "NATURAL";
$User->FirstName = "blabla";
$User->LastName = "blabla";
$User->Address = "blabla";
$User->Birthday = 1396886568;
$User->Nationality = "NZ";
$User->CountryOfResidence = "ES";
$User->Email = "hello#example.com";
//Send the request
$createdUser = $mangoPayApi->Users->Create($User);
//Now for the wallet
$Wallet = new MangoPay\Wallet();
$Wallet->Owners = array($createdUser->Id);
$Wallet->Description = "blabla";
$Wallet->Currency = "GBP";
//Send the request
$createdWallet = $mangoPayApi->Wallets->Create($Wallet);
//store this in your DB: $createdWallet->Id

Related

I want to convert a post method form to curl command

I'm making an auto SMS system. But SMS provider gave me post method form but I want it to modify with curl command by my own.
they provided me
<head>
<title>SMS</title>
</head>
<body>
<form name="sms" method="post" >
<input type="text" placeholder="send to number" name="to" /><br />
<input type="textarea" placeholder="sms" name="msg" /><br />
<input type="submit" value=" OK " />
</form>
<?php
$apikey='$2y$10$t..Yr.YDG0kXYiuLwQ78OecDgz6/qh.1xSWx77mXjczkk3AEKvTZe';
if (isset($_POST["msg"]) ) {
$sendto = $_POST["to"];
$fullNumber = '880' . substr(preg_replace('/\D/', '', $sendto), -10);
$msg = urlencode($_POST["msg"]);
// $masking='CITY PORTER';
// $masking=urlencode($masking);
// masking $url='http://example.com/smsapi/masking?api_key='.$apikey.'&smsType=text&maskingID='.$masking.'&mobileNo='.$fullNumber.'&smsContent='.$msg.'';
$url='http://example.com/smsapi/non-masking?api_key='.$apikey.'&smsType=text&mobileNo='.$fullNumber.'&smsContent='.$msg.'';
if ( !empty($_POST["to"]) && !empty($_POST["msg"])) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL =>$url,
CURLOPT_USERAGENT =>'My Browser'
));
$resp = curl_exec($curl);
echo $resp;
curl_close($curl);
}
else
{ echo "Field is empty";}
}
?>
</body>
I converted it to curl command but this is not still working. I just want to input multiple value without is set() 1 value.
$api_key = "$2y$10$mtW.yfKj18i2mTPe/0iCEuKdCfCGh9zOYYEU9AmnMrJyBb.h7fVcG";
$number = $row[mailing_no];
$message = "Dear Guardian, ". $row[name] . " has swiped his card right now";
$type= "text";
$params = array('api_key'=>$api_key, 'smsType'=>$type, 'mobileNo'=>$number, 'smsContent'=>$message);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com/smsapi/non-masking?".http_build_query($params, "", "&"));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Accept:application/json"));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close ($ch);
Try this i hope your problem will be solve
<div id="send_reply"></div>
<form name="sms" method="post" >
<input type="text" placeholder="send to number" name="to" id="phone" /><br />
<input type="textarea" placeholder="sms" name="msg" id="mess" /><br />
<input type="submit" value=" OK " id="send_btn" />
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#send_btn").click(function(){
var txt1=$("#phone").val();
var txt2=$("#mess").val();
$.ajax({
url : 'check.php',
method : 'GET',
data : {txt1:txt1,txt2:txt2},
success:function(dda){
$("#send_reply").html(dda);
}
});
});
});
</script>
I think we were missing double quotes for $row keys, try this:
$api_key = "$2y$10$mtW.yfKj18i2mTPe/0iCEuKdCfCGh9zOYYEU9AmnMrJyBb.h7fVcG";
$number = $row["mailing_no"];
$message = "Dear Guardian, ". $row["name"] . " has swiped his card right now";
$type= "text";
$params = array('api_key'=>$api_key, 'smsType'=>$type, 'mobileNo'=>$number, 'smsContent'=>$message);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com/smsapi/non-masking?".http_build_query($params, "", "&"));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Accept:application/json"));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close ($ch);

How to send post data using CURL POST to third party payment gateway in laravel 5?

I'm trying to integrate a payment gateway for my eCommerce website.How do I send form data to their API ?
This is what they are requesting from us.
<html>
<body>
<form method="post" action="https://sandbox.payhere.lk/pay/checkout">
<input type="hidden" name="merchant_id" value="123456"> <!-- Replace
your Merchant ID -->
<input type="hidden" name="return_url" value="http://sample.com/return">
<input type="hidden" name="cancel_url" value="http://sample.com/cancel">
<input type="hidden" name="notify_url" value="http://sample.com/notify">
<br><br>Item Details<br>
<input type="text" name="order_id" value="ItemNo12345">
<input type="text" name="items" value="Door bell wireless"><br>
<input type="text" name="amount" value="1000">
<br><br>Customer Details<br>
<input type="text" name="first_name" value="Saman">
<input type="text" name="last_name" value="Perera"><br>
<input type="text" name="email" value="samanp#gmail.com">
<input type="text" name="phone" value="0771234567"><br>
<input type="text" name="address" value="No.1, Galle Road">
<input type="text" name="city" value="Colombo">
<input type="hidden" name="country" value="Sri Lanka"><br><br>
<input type="submit" value="Buy Now">
</form>
</body>
</html>
<?php
$merchant_id = $_POST['merchant_id'];
$order_id = $_POST['order_id'];
$payhere_amount = $_POST['payhere_amount'];
$payhere_currency = $_POST['payhere_currency'];
$status_code = $_POST['status_code'];
$md5sig = $_POST['md5sig'];
$merchant_secret = '123456'; // Replace with your Merchant Secret (Can be found on your PayHere account's Settings page)
$local_md5sig = strtoupper (md5 ( $merchant_id . $order_id . $payhere_amount . $payhere_currency . $status_code . strtoupper(md5($merchant_secret)) ) );
if (($local_md5sig === $md5sig) AND ($status_code == 2) ){
//TODO: Update your database as payment success
}
?>
I've tried this on my laravel application using a Payment Controller. Get data from vuejs form and send data to laravel controller.
This is my code inside the paymentController.
public function store(Request $request)
{
$merchant_id = $request->input('merchant_id');
$order_id = $request->input('order_id');
$payhere_amount = $request->input('amount');
$payhere_currency = $request->input('currency');
$merchant_secret =$request->input('merchant_secret');
$status_code ='2';
$md5sig = strtoupper (md5 ( $merchant_id . $order_id . $payhere_amount . $payhere_currency . $status_code . strtoupper(md5($merchant_secret)) ) );
$url="https://sandbox.payhere.lk/pay/checkout";
$method = 'POST';
$data = array([
"merchant_id"=> $merchant_id,
"order_id"=> $order_id,
"payhere_amount" => $payhere_amount,
"payhere_currency" => $payhere_currency,
"merchant_secret" => $merchant_secret,
"status_code" => $status_code,
"md5sig" => $md5sig
]);
$data_string = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,$method);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$result = curl_exec($ch);
curl_close($ch);
//print_r($result);
}
I expected to integrate the given payment gateway, but the output is 'undefined'.
CURL is not a great solution for what you are trying to do - rather create an extra step and post from a form. This worked for me with a merchant:
$ch = curl_init();
// Set cURL options - Use curl_setopt for greater PHP compatibility
// Base settings
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HEADER, false );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 2 );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
// Standard settings
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, count($data_string));
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data_string );
// Execute CURL
$response = curl_exec( $ch );
curl_close( $ch );

MailChimp group options select in php

I tried to find the answer for the last 5 hours but I finally caved in and am reaching out for help.
Basically, this code worked great until I needed to select a group option. I'm not sure if I'm creating my interests array properly, I may have to use 'merge_vars' but really would like some guidance before I spend another 5 hours blindly walking into walls.
Note for my group name I've been using the entire string "group[3117]"
Action.php
<?php
session_start();
if(isset($_POST['submit'])){
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$interest = $_POST['group[3117]'];
if(!empty($email) && !filter_var($email, FILTER_VALIDATE_EMAIL) === false){
// MailChimp API credentials
$apiKey = '+ insert api key here +';
$listID = 'insert list id';
$interest = 'insert group name'; // YOUR INTEREST/GROUP ID
// MailChimp API URL
$memberID = md5(strtolower($email));
$dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
$url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $listID . '/members/' . $memberID;
// member information
$json = json_encode([
'email_address' => $email,
'status' => 'subscribed',
'merge_fields' => [
'FNAME' => $fname,
'LNAME' => $lname
],
'interests' => array(
$interest => true
),
]);
// send a HTTP POST request with curl
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// store the status message based on response code
if ($httpCode == 200) {
$_SESSION['msg'] = '<p style="color: #34A853">You have successfully subscribed to CodexWorld.</p>';
} else {
switch ($httpCode) {
case 214:
$msg = 'You are already subscribed.';
break;
default:
$msg = 'Some problem occurred, please try again.';
break;
}
$_SESSION['msg'] = '<p style="color: #EA4335">'.$msg.'</p>';
}
}else{
$_SESSION['msg'] = '<p style="color: #EA4335">Please enter valid email address.</p>';
}
}
// redirect to homepage
header('location:index.php');
Index.php
<?php session_start(); // place it on the top of the script ?>
<?php
$statusMsg = !empty($_SESSION['msg'])?$_SESSION['msg']:'';
unset($_SESSION['msg']);
echo $statusMsg;
?>
<form method="post" action="action.php">
<p><label>First Name: </label><input type="text" name="fname" /></p>
<p><label>Last Name: </label><input type="text" name="lname" /></p>
<p><label>Email: </label><input type="text" name="email" /></p>
<p><select name="group[3117]" class="REQ_CSS" id="mce-group[3117]">
<option value=""></option>
<option value="1">Los Angeles</option>
<option value="2">Seattle</option>
<option value="4">Portland</option> </p>
<p><input type="submit" name="submit" value="SUBSCRIBE"/></p>
</form>
Here's the solution, there's a lot of manual data entry but it works, if someone has an easier method please let me know.
Enter the MailChimp API playground. Select your list / subresources / interest-categories / interest name / subresources / interests / response . scroll down and there will be a unique "id" for interest. (ignore category id)
Here is the code, credit goes Mukesh Chapegan and CodexWorld
Name this page Action.php
<?php
$email = $_POST['email'];
$memberHash = md5($email);
$first_name = $_POST['fname'];
$last_name = $_POST['lname'];
$interest = $_POST['location'];
$api_key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; // YOUR API KEY
$server = 'us14.'; //last part of ur api key
$list_id = 'XXXXXXX'; // YOUR LIST ID
$auth = base64_encode( 'user:'.$api_key );
$data = array(
'apikey' => $api_key,
'email_address' => $email,
'status' => 'subscribed',
'merge_fields' => array(
'FNAME' => $first_name,
'LNAME' => $last_name
),
'interests' => array(
$interest => true
),
);
$json_data = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://'.$server.'api.mailchimp.com/3.0/lists/'.$list_id.'/members/'.$memberHash);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
'Authorization: Basic '.$auth));
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
$result = curl_exec($ch);
$result_obj = json_decode($result);
echo $result_obj->status;
echo '<br>';
echo '<pre>'; print_r($result_obj); echo '</pre>';
?>
Here is the HTML form. name this index.php
Note I named the select element to location and the option values to the interest id I obtained through the API playground.
<?php session_start(); // place it on the top of the script ?>
<?php
$statusMsg = !empty($_SESSION['msg'])?$_SESSION['msg']:'';
unset($_SESSION['msg']);
echo $statusMsg;
?>
<form method="post" action="action.php">
<p><label>First Name: </label><input type="text" name="fname" /></p>
<p><label>Last Name: </label><input type="text" name="lname" /></p>
<p><label>Email: </label><input type="text" name="email" /></p>
<p> <select name="location" class="REQ_CSS" id="mce-group[3117]">
<option value=""></option>
<option value="f3eb68268d">Los Angeles</option>
<option value="3204c60199">Seattle</option>
<option value="3c5b8d638a">Portland</option> </p>
</select>
<p><input type="submit" name="submit" value="SUBSCRIBE"/></p>
</form>
If this answer helps please upvote so it's easier to find. I looked for this solution for a very very long time and found a lot of questions but few answers.

upload file via curl in controller codeigniter and return result to view

Hi i am new in CI and php i want to upload file to server using curl and return the result back to the view but it's not working
here my controller
$issue_name = $this->input->post('issue_name');
$issue_tagline = $this->input->post('issue_tagline');
$issue_description = $this->input->post('issue_description');
$issue_publish_on = $this->input->post('issue_publish_on');
$issue_file = $this->input->post('issue_file');
$data2=array(
'issue_name' => $issue_name,
'issue_tagline' => $issue_tagline,
'issue_description' => $issue_description,
'issue_file' => $issue_file,
);
$this->load->helper('form');
$this->load->view('issue_detail',$data2);
echo '<pre>' .var_dump($issue_name).'</pre>';
$target_url = 'https://platform.twixlmedia.com/admin-api/1/upload';
$file_name_with_full_path = realpath($issue_file);
$post3 = array(
'admin_api_key' => 'da06751194bc18cc60xxxxxxx',
'app_key' => 'bd7cf04226c58723cxxxxxx',
'issue_identifier' => $productid,
'issue_file' =>'#' . realpath($issue_file),
'issue_name' => $issue_name
);
$ch3 = curl_init();
curl_setopt($ch3, CURLOPT_URL, 'https://platform.twixlmedia.com/admin-api/1/upload');
curl_setopt($ch3, CURLOPT_POST, 1);
curl_setopt($ch3, CURLOPT_POSTFIELDS, $post3);
curl_setopt($ch3, CURLOPT_RETURNTRANSFER, 1);
$result3 = curl_exec($ch3);
curl_close ($ch3);
echo $result3;
and this is my view:
<form class="editissueform" action="home/editissue" method="post" enctype="multipart/form-data">
<label for="name">Name:</label>
<input type="text" name="issue_name"><br>
<label for="tagline">Tagline:</label>
<input type="text" name="issue_tagline"><br>
<label type"description">Description:</label>
<input type="text" name="issue_description"><br>
<label type"publishdate">Publish Date:</label>
<input type="text" name="issue_publish_on"><br>
</div>
<h4>Upload Publication</h4>
<div class="issuedit">
<input type="file" name="issue_file" size="40" />
<h4>Please Upload using pdf file format</h4>
</div>
<br>
<br>
<input type="submit" name="submit" value="Save">
</form>
i don't know what i'm missing in my code
thanks for your help

How to put POST form data in action

I am trying to setup a user creation API for VestaCP. I have these two pages.
The form:
<form action="process.php" method="post">
Username:<br>
<input type="text" name="username">
<br>
Password:<br>
<input type="password" name="password">
<br>
Email Address:<br>
<<input type="email" name="email">
<br><br>
<input type="submit" value="Submit">
</form>
Then the action:
<?php
// Server credentials
$vst_hostname = 'MYSERVERADDRESS';
$vst_username = 'MYSERVERUSERNAME';
$vst_password = 'MYSERVERPASSWORD';
$vst_command = 'v-add-user';
// New Account
$username = 'username';
$password = 'password';
$email = 'email';
$package = 'Free';
$fist_name = 'Null';
$last_name = 'Null';
// Prepare POST query
$postvars = array(
'user' => $vst_username,
'password' => $vst_password,
'returncode' => $vst_returncode,
'cmd' => $vst_command,
'arg1' => $username,
'arg2' => $password,
'arg3' => $email,
'arg4' => $package,
'arg5' => $fist_name,
'arg6' => $last_name
);
$postdata = http_build_query($postvars);
// Send POST query via cURL
$postdata = http_build_query($postvars);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://' . $vst_hostname . ':8083/api/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$answer = curl_exec($curl);
// Check result
if($answer == 0) {
echo "User account has been successfuly created\n";
} else {
echo "Query returned error code: " .$answer. "\n";
}
?>
I think the problem is inputting the form data into the php script but I'm not very experienced so I don't know.
The API is connecting to my server correctly as I tested the same
//Server Credentials
part with a different API and it worked.
When I run this script, it outputs "User account has been successfully created" but when I check my control panel, there is no new user.
Thank you for any help.
EDIT: I only wrote the form, this script was made by VestaCP as shown here: https://vestacp.com/docs/api/. The errors in this script are direct from Vesta.
Try this:
<form action="process.php" method="post">
Username:<br>
<input type="text" name="username">
<br>
Firstname:<br>
<input type="text" name="firstname">
<br>
Name:<br>
<input type="text" name="name">
<br>
Password:<br>
<input type="password" name="password">
<br>
Email Address:<br>
<input type="email" name="email">
<br><br>
<input type="submit" value="Submit">
</form>
process.php
<?php
// Server credentials
$vst_hostname = 'MYSERVERADDRESS';
$vst_username = 'admin';
$vst_password = 'ADMINPASSWORD';
$vst_returncode = 'yes';
$vst_command = 'v-add-user';
// New Account
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$package = 'default'; // $package = 'Free'; //Free package exist on server?
$fist_name = $_POST['firstname'];
$last_name = $_POST['name'];
// Prepare POST query
$postvars = array(
'user' => $vst_username,
'password' => $vst_password,
'returncode' => $vst_returncode,
'cmd' => $vst_command,
'arg1' => $username,
'arg2' => $password,
'arg3' => $email,
'arg4' => $package,
'arg5' => $fist_name,
'arg6' => $last_name
);
$postdata = http_build_query($postvars);
// Send POST query via cURL
$postdata = http_build_query($postvars);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://' . $vst_hostname . ':8083/api/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$answer = curl_exec($curl);
// Check result
if($answer == 0) {
echo "User account has been successfuly created\n";
} else {
echo "Query returned error code: " .$answer. "\n";
}
?>

Categories