I am trying to implement the Areto API payment gateway, but it returns response with authentication error such as :
Authentication failed - invalid ID/Session/IP combination.
I am try to first time implement (this type) payment gateway.
how to implement Areto API payment gateway.
Just have use the code like this:
<?php
$url = 'https://pay.aretosystems.com/api/sale/v1';
$api_session = 'ZXUKwKG97WCEdyYBZxnBgFOutVj5qdO7yWaYxT5T9CAbPMn4tamzUpH0HgtdIn6b';
$api_id = '6mK+KXQ5dadlu+4qnxpY3jtH/Hg56AgMhhpOMWXP0/TCmbE6OhXZkG/QRjE/dNjQ';
$transaction = array(
"Authentication" => array(
"Id" => $api_id,
"Session" => $api_session
),
"Order" => array(
"OrderId" => "TESTSALE",
"Amount" => "0.01",
"CurrencyCode" => "EUR"
),
"CardDetails" => array(
"CCVC" => "123",
"CCExpiryMonth" => "01",
"CCExpiryYear" => "2017",
"CCName" => "Wdp",
"CCSurname" => "Tech",
"CCNumber" => '4200000000000000',
"CCType" => "VISA",
"CCAdress" => "542, surya nagar",
"ClientCity" => "Jaipur",
"ClientCountryCode" => "US",
"ClientZip" => "302017",
"ClientEmail" => "wdpjaipur#gmail.com",
"ClientExternalIdentifier" => "MytestUserName1",
"ClientIP" => "162.158.50.205",
"ClientPhone" => "1234567890"
)
);
$data_string = json_encode($transaction);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$http_status . PHP_EOL;
$responceData = json_decode($response, TRUE);
echo '<pre>';
print_r($responceData);die;
?>
This part of the API is not very well documented, but after we found this question we were finally able to find a way to solve the problem:
The key is to have all the properties you want to send concatenated into a string divided by & characters and send them as plain text via POST.
If you want to try it out in Postman:
1) enter the properties as url parameters
2) copy the string from the url
3) and paste it in the request body, setting the type to plain text.
error_reporting(1);
$url = 'https://pay.aretosystems.com/api/sale/v1';
$api_session = 'ZXUKwKG97WCEdyYBZxnBgFOutVj5qdO7yWaYxT5T9CAbPMn4tamzUpH0HgtdIn6b';
$api_id = '6mK+KXQ5dadlu+4qnxpY3jtH/Hg56AgMhhpOMWXP0/TCmbE6OhXZkG/QRjE/dNjQ';
$clientIP = $_SERVER['REMOTE_ADDR'];
$request_arr = array(
'Id'=>$api_id,
'Session'=>$api_session,
'OrderId'=>time(),
'Amount'=>'4.0',
'CurrencyCode'=>'EUR',
'CCVC'=>'123',
'CCExpiryMonth'=>'12',
'CCExpiryYear'=>'2017',
'CCName'=>'wdp',
'CCSurname'=>'technologies',
'CCNumber'=>'4200000000000000',
'CCType'=>'VISA',
'CCAddress'=>'surya nagar',
'ClientCity'=>'Ajmer',
'ClientCountryCode'=>'IN',
'ClientZip'=>'302018',
'ClientEmail'=>'wdpjaipur1#gmail.com',
'ClientExternalIdentifier'=>'Wdp tech',
'ClientIP'=>$clientIP,
'ClientPhone'=>'1234567890',
'ClientDOB'=>'1989-11-05'
);
$ch = curl_init();
$post_variables = '';
foreach ($request_arr as $key => $value) {
$post_variables .= "{$key}={$value}&";
}
$post_variables = rtrim($post_variables, '&');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_variables);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
$responceData = json_decode($response, TRUE);
Related
I want to upload the media via Whatsapp cloud API in order to send the media to WhatsApp, I have followed the link below, but having the stated issue.
https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media#get-media-id
Array ( [error] => Array ( [message] => (#100) The parameter messaging_product is required. [type] => OAuthException [code] => 100 [fbtrace_id] => AQPftb9Bf343375gQ_QytxNen ) ) 400
My Code is
// #1640191015925.jpg on my root folder
$post = [
'file' => '#1640191015925.jpg;type=image/jpeg',
'messaging_product' => 'whatsapp'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/v13.0/Phone-Number-ID/media');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$headers = array();
$YOUR_WHATSAPP_ACCESS_TOKEN = '+++++++';
$headers[] = "Authorization: Bearer $YOUR_WHATSAPP_ACCESS_TOKEN";
$headers[] = "Content-Type: image/jpeg";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = json_decode(curl_exec($ch), true);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
//$MEDIA_OBJECT_ID = $result['media'][0]['id']; //MEDIA OBJECT ID
print_r($result);
print_r($httpcode);
?> ```
I had the same issue, after some digging around I wrote this function to upload a file and return the id.
function waFileUploader($token, $file, $senderid){
$mime = mime_content_type($file);
$info = pathinfo($file);
$name = $info['basename'];
$curlfile = new CURLFile($file, $mime, $name);
$filedata = array("messaging_product"=>"whatsapp", "file" => $curlfile);
$url = 'https://graph.facebook.com/v13.0/' . $senderid . '/media';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER,array("Authorization: Bearer $token", "Content-Type: multipart/form-data"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $filedata);
$r = curl_exec($ch);
curl_close($ch);
$id = json_decode($r, true);
return $id["id"];
}
How to update Products inventory from 3rd party POS system in Magento2?
I need to make a button in POS system when I hit that button the products inventory should be update from POS to Magento2 system.
Here is working code for update qty from Rest API
<?php $adminUrl = 'http://localhost/magento2/rest/V1/integration/admin/token/';
$ch = curl_init();
$data = array("username" => "admin", "password" => "admin"); //Admin Login details
$data_string = json_encode($data);
$ch = curl_init($adminUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($data_string)));
$token = curl_exec($ch);
$token= json_decode($token);
$headers = array("Authorization: Bearer $token","Content-Type: application/json");
$skus = array('100001' => 66,'100002' => 99); //Here 100001 and 100002 are SKU and 66 and 99 are Qty
foreach ($skus as $sku => $stock) {
$requestUrl='http://localhost/magento2/rest/V1/products/' . $sku . '/stockItems/1';
$sampleProductData = array("qty" => $stock);
$productData = json_encode(array('stockItem' => $sampleProductData));
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $requestUrl);
curl_setopt($ch,CURLOPT_POSTFIELDS, $productData);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
unset($productData);
unset($sampleProductData);
}
I am trying to create Sales Order attachment in Zoho Books using Sales Order attachment API but it gives me error like "[code] => 33003 [message] => Receipt not attached".
If I try API with postman it works.
Below is my API call copied from postman.
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL =>
"https://books.zoho.com/api/v3/salesorders/**********/attachment?
organization_id=********",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-
Disposition: form-data; name=\"attachment\";
filename=\"D:\\wamp\\www\\*****\\01-30-18 E01301811384413.pdf\"\r\nContent-
Type: application/pdf\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--
",
CURLOPT_HTTPHEADER => array(
"Authorization: *********************",
"Cache-Control: no-cache",
"Content-Type: application/json",
"Postman-Token: e1141774-32e0-09f1-059b-6d2ee0c44095",
"content-type: multipart/form-data; boundary=----
WebKitFormBoundary7MA4YWxkTrZu0gW"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
Any help is appreciated.
The code generated by postman is not working for any file upload API's.
Please try this below php code snippet for uploading file to Zoho Books.
<?php
$file_name_with_full_path = '/Users/Admin/Desktop/1.png';
$request_url = 'https://books.zoho.com/api/v3/salesorders/******/attachment';
if (function_exists('curl_file_create')) { // php 5.6+
$cFile = curl_file_create($file_name_with_full_path);
} else { //
$cFile = '#' . realpath($file_name_with_full_path);
}
$post = array(
'authtoken' => '*******',
'organization_id' => '*******',
'attachment'=> $cFile);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$r = curl_exec($ch);
curl_close ($ch);
print_r($r);
?>
I'm trying to searchRecord using the Zoho CRM API and I sometimes get the following error:
Array ( [response] => Array ( [error] => Array ( [message] => Unable
to process your request. Please verify whether you have entered proper
method name,parameter and parameter values. [code] => 4600 ) [uri] =>
/crm/private/json/Contacts/searchRecords ) )
My problem is that sometimes everything works fine and sometimes I get this error
define("TARGETURL", "https://crm.zoho.com/crm/private/json/Contacts/searchRecords");
$parameter = array(
'scope' => 'crmapi',
'authtoken' => AUTHTOKEN,
'selectColumns' => 'All',
'criteria' => '(Account Name:'.$accountName.')',
'fromIndex' => $fromIndex,
'toIndex' => $toIndex
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, TARGETURL);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameter);
$result = curl_exec($ch);
curl_close($ch);
Try search field with double quotation mark, following is script to search email from lead module.
$xmlData = "(Email:$email)";
$ch = curl_init('https://crm.zoho.com/crm/private/xml/Leads/searchRecords');
curl_setopt($ch, CURLOPT_VERBOSE, 1); //standard i/o streams
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Turn off the server and peer verification
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set to return data to string ($response)
curl_setopt($ch, CURLOPT_POST, 1); //Regular post
$authtoken = "********************************";
$query = "authtoken=" . $authtoken . "&scope=crmapi&criteria=" . $xmlData;
curl_setopt($ch, CURLOPT_POSTFIELDS, $query); // Set the request as a POST FIELD for curl.
$response = curl_exec($ch);
curl_close($ch);
I'm trying to edit Eventbrite event using version 3 of the API but I always returns false.
$request_url = 'https://www.eventbriteapi.com/v3/events/xxxxxx';
$options = array(
'http' => array(
'method' => 'POST',
'header'=> "Authorization: Bearer xxxxxxxxxx"
),
'name' => array(
'text'=>'Hi',
'html'=>'<p>Hi</p>'
));
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $options);
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$json_data = curl_exec($ch);
$resp_info = curl_getinfo($ch);
curl_close($ch);
var_dump($json_data);
This always returns me :
boolean false
What am I doing wrong?
You don't need to create an options array with curl as you are setting those options in curl_setopt. Just make a data array and submit it.
<?php
$request_url = 'https://www.eventbriteapi.com/v3/events/xxxxxx';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
$data = array(
'name' => array(
'text'=>'Hi',
'html'=>'<p>Hi</p>'
)
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$json_data = curl_exec($ch);
$resp_info = curl_getinfo($ch);
curl_close($ch);
var_dump($json_data);
Though according to the docs there is a minimum amount of data to create an event.