PayPal PayFlow API Error - paypal

We are using PayFlow PayPal API for recurring payments, it gives us an issue.
We are sending amount $29 to the API but on PayPal log it is showing $1 only. When we asked PayPal support for this they said you are sending $1.
Please help us. Below is the code we have setup:
<?php
$payflow_partner = 'PayPal';
$payflow_vender = 'xxxxxxxxxxxxx';
$payflow_user = 'xxxxxxxxxxxx';
$payflow_pwd = 'XXXXXXXXX';
$payflow_url = 'https://pilot-payflowpro.paypal.com';
$first_name = 'First Name';
$last_name = 'Last Name';
$profile_name = $first_name.$last_name;
$plan_amount = 29.00;
$card_number = '4111111111111111';
$expiry_month = '05';
$expiry_year = '21';
$expiry = $expiry_month.$expiry_year;
$user_email = 'test#example.com';
$start_date = '01202017';
$post_list = 'TRXTYPE=R&TENDER=C&PARTNER='.$payflow_partner.'&VENDOR='.$payflow_vender.'&USER='.$payflow_user.'&PWD='.$payflow_pwd.'&ACTION=A&PROFILENAME='.$profile_name.'&AMT='.$plan_amount.'&CURRENCY=USD&ACCT='.$card_number.'&EXPDATE='.$expiry.'&START='.$start_date.'&PAYPERIOD=MONT&TERM=0&EMAIL='.$user_email.'&OPTIONALTRX=A&OPTIONALTRXAMT='.$plan_amount.'&COMMENT1=First-time-customer&STREET=sector-7-malviya-nagar&ZIP=302017&CITY=jaipur&STATE=rajasthan&COUNTRY=india&FIRSTNAME='.$first_name.'&MIDDLENAME='.$last_name.'&LASTNAME='.$last_name;
$headers = array();
$headers[] = "Content-Type: text/namevalue"; //or maybe text/xml
$headers[] = "X-VPS-Timeout: 3000";
$headers[] = "X-VPS-VIT-OS-Name: Linux"; // Name of your OS
$headers[] = "X-VPS-VIT-OS-Version: RHEL 4"; // OS Version
$headers[] = "X-VPS-VIT-Client-Type: PHP/cURL"; // What you are using
$headers[] = "X-VPS-VIT-Client-Version: 0.01"; // For your info
$headers[] = "X-VPS-VIT-Client-Architecture: x86"; // For your info
$headers[] = "X-VPS-VIT-Client-Certification-Id:13fda2433fc2123d8b191d2d011b7fdc";
$headers[] = "X-VPS-VIT-Integration-Product: MyApplication"; // For your info, would populate with application name
$headers[] = "X-VPS-VIT-Integration-Version: 0.01"; // Application version
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $payflow_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 1); // tells curl to include headers in response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 45); // times out after 45 secs
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // this line makes it work under https
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_list); //adding POST data
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); //verifies ssl certificate
curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE); //forces closure of connection when done
curl_setopt($ch, CURLOPT_POST, 1); //data sent as POST
$result = curl_exec($ch);
$headers = curl_getinfo($ch);
curl_close($ch);
echo $result;

In your post data you are sending these two values:
AMT='.$plan_amount
OPTIONALTRXAMT='.$plan_amount
PayPal's documentation states that OPTIONALTRXAMT should only be used when OPTIONALTRX=S, which it is not in your case.
The documentation also states that Amount is ignored when OPTIONALTRX=A, which is what you are doing.
Note: Do not specify an amount when OPTIONALTRX=A. The amount is ignored.
So, remove the Optional parameters.

Related

Paypal transaction to me is verified (by API), but my account balance is $0.00

Paypal transaction yesterday was verified (by API (https://api.paypal.com/v1/payments/payment/)), but my account balance was $0.00.
Today the same API answers me ----> ["name"]=> string(19) "INVALID_RESOURCE_ID" ["message"]=> string(39) "The requested resource ID was not found" ["information_link"]=> string(54) "https://developer.paypal.com/docs/api/payments/#errors" ["debug_id"]=> string(13) "b39d1f444064e"
And balance is $0 again. How to fix it, there in my online store are verified payments, they get "verified" status during payment, by API query.. what to do now? Where to search the problem?
(Before that the Sandbox version worked fine).
Payment execution:
if($test_mode_paypal)
$execute_url = 'https://api.sandbox.paypal.com/v1/payments/payment/'.$pay_key.'/execute';
else
$execute_url = 'https://api.paypal.com/v1/payments/payment/'.$pay_key.'/execute';
$header = array();
$header[] = 'Content-type: application/json';
$header[] = 'Accept: application/json';
$header[] = 'Authorization: Bearer '.$accessToken;
$data ='{
"payer_id":"'.$payer_id.'"
}';
//open connection
$curl = curl_init();
//set connection properties
curl_setopt($curl, CURLOPT_URL, $execute_url);
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
//execute post
$response = curl_exec($curl);
//close connection
curl_close($curl);
$result = json_decode($response);
$response_arr = array();
if($result->state == 'approved')
{
$response_arr['status'] = 'ok';
$response_arr['message'] = $response;
return $response_arr;
}
Sounds like you created the payment but you never executed it.

Getting data from Kobo Toolbox

I want to get my form data back from kobo api (https://kc.kobotoolbox.org/api/v1/). I registered client application from kobo. To authorize client application, i run below url but it results in
http://localhost/kobo/o/authorize?client_id=MY_CLIENT_iD&response_type=code&state=xyz
Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
Apache/2.4.27 (Win32) OpenSSL/1.0.2l PHP/7.1.9
Similarly request for access token also result in same error
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://localhost/o/token/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=authorization_code&\ncode=PSwrMilnJESZVFfFsyEmEukNv0sGZ8&\nclient_id=MY_CLIENT_ID&\nredirect_uri=http://localhost:30000");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, "USERNAME" . ":" . "PASSWORD");
$headers = array();
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
echo $result;
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
Apache/2.4.27 (Win32) OpenSSL/1.0.2l PHP/7.1.9
I am using xampp and curl is enabled.
You have to use https://kc.kobotoolbox.org/api/v1/ not https://kf.kobotoolbox.org/api/v1/
checkout docs here http://help.kobotoolbox.org/managing-your-project-s-data/rest-services
MY WORKING CODE:
$url = 'https://kc.kobotoolbox.org/api/v1/stats';
$data = array (
// 'q' => 'nokia'
);
$params = '';
foreach($data as $key=>$value)
$params .= $key.'='.$value.'&';
$params = trim($params, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url.'?'.$params ); //Url together with parameters
//curl_setopt($ch, CURLOPT_CONNECTTIMEOUT , 7); //Timeout after 7 seconds
//curl_setopt($ch, CURLOPT_HEADER , false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$header = array();
$header[] = 'Content-length: 0';
$header[] = 'Content-type: application/json';
$header[] = 'Authorization: Token xxxxxxxx';
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
//curl_setopt($ch, CURLOPT_USERPWD, "USERNAME" . ":" . "PASSWORD");
$result = curl_exec($ch);
if(curl_errno($ch)) //catch if curl error exists and show it
echo 'Curl error: ' . curl_error($ch);
echo $result;

Upload a file into dropbox folder

I have tried this to upload a file from a folder in my desktop to a folder in dropbox account.
but each time i have uploaded an empty file through this code.
How it is possible?
Below s my code:
$ch = curl_init();
$TOKEN = "asasasa";//token here
$url = 'https://content.dropboxapi.com/2/files/upload';
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers[] = 'Accept: application/json';
$headers[] = 'Content-Type: multipart/form-data';
$headers[] = 'Dropbox-API-Arg:{"path":"/home/new/ofd","mode":{".tag":"add"},"autorename":false,"mute":false}';
$headers[] = "Authorization: Bearer ".$TOKEN;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$droplist = json_decode($response,true);
You don't seem to be adding the file content to the upload call anywhere, so an empty file is expected from your code.
You can find an example of using /2/files/upload with curl in PHP below. That uses CURLOPT_INFILE to add the file content itself.
<?php
$path = 'test_php_upload.txt';
$fp = fopen($path, 'rb');
$size = filesize($path);
$cheaders = array('Authorization: Bearer <ACCESS_TOKEN>',
'Content-Type: application/octet-stream',
'Dropbox-API-Arg: {"path":"/test/'.$path.'", "mode":"add"}');
$ch = curl_init('https://content.dropboxapi.com/2/files/upload');
curl_setopt($ch, CURLOPT_HTTPHEADER, $cheaders);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, $size);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
echo $response;
curl_close($ch);
fclose($fp);
?>
<ACCESS_TOKEN> should be replaced with the OAuth 2 access token.
Upload a file into dropbox folder dropbox api v2
$dropbox_api_url = 'https://content.dropboxapi.com/2/files/upload'; //dropbox api url
$token = 'Access token value put here'; // should be replaced with the OAuth 2 access token
$headers = array('Authorization: Bearer '. $token,
'Content-Type: application/octet-stream',
'Dropbox-API-Arg: '.
json_encode(
array(
"path"=> '/'. basename($filename),
"mode" => "add",
"autorename" => true,
"mute" => false
)
)
);
$ch = curl_init($dropbox_api_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
$path = $filename;
$fp = fopen($path, 'rb');
$filesize = filesize($path);
curl_setopt($ch, CURLOPT_POSTFIELDS, fread($fp, $filesize));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
//For display value as array object starts here
echo "<pre>";
print_r(json_decode($response));
//For display value as array object ends here
echo($response.'<br/>');
echo($http_code.'<br/>');
curl_close($ch);

PUT request to REST api using cURL

I am trying to do a put request to a RESTapi using cURL. I was able to do post request. But PUT is not working
I used following code
public function callTeamworkPutApi($secretApiKey, $apiCallString,$param)
{
//cURL
$password = "xxx";
$channel = curl_init();
//options
curl_setopt($channel, CURLOPT_URL, "http://projects.abounde.com/".$apiCallString); // projects.json?status=LATE gets all late projects
$headers = array();
$headers[] = "Authorization: Basic " . base64_encode($secretApiKey . ":" . $password);
$headers[] = "Content-Type: application/json";
curl_setopt($channel, CURLOPT_HTTPHEADER, $headers);
curl_setopt($channel, CURLOPT_PUT, true);
//curl_setopt($channel, CURLOPT_POSTFIELDS, $comment);
curl_setopt($channel, CURLOPT_PUTFIELDS, $param);
// curl_setopt($channel, CURLOPT_RETURNTRANSFER, true);
$msg = curl_exec($channel);
$tester =var_dump(curl_getinfo($channel));
curl_close($channel);
//var_dump($msg);
return response()->json(['res'=>$tester]);
}
Error:
Any Idea?
Just been doing that myself today. here is example code.
$data = array("a" => $a);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($data));
$response = curl_exec($ch);
if (!$response)
{
return false;
}
src: http://www.lornajane.net/posts/2009/putting-data-fields-with-php-curl

Paypal PDT error

I use this code to process Paypal payment data transfer (PDT):
$pp_hostname = "www.sandbox.paypal.com"; // Change to www.sandbox.paypal.com to test against sandbox
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-synch';
$tx_token = $_GET['tx'];
$auth_token = "my_token";
$req .= "&tx=$tx_token&at=$auth_token";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://$pp_hostname/cgi-bin/webscr");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
//set cacert.pem verisign certificate path in curl using 'CURLOPT_CAINFO' field here,
//if your server does not bundled with default verisign certificates.
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: $pp_hostname"));
$res = curl_exec($ch);
curl_close($ch);
if(!$res){
echo "HTTP ERROR";
}else{ ...
But it does not work, my code tells me that the request fails, and it outputs HTTP ERROR because $res is empty.
Why?