So after alot of searching around I've finally been able to successfully get my Paypal access token using PHP cURL. Now i'm trying to retrieve transaction details based on transaction id. So far i think I've gotten the call URL correct however i think that my post data formatting may be incorrect. The Code used is found below:
<?php
//this function is for handling post call requests
function make_post_call($url, $postdata) {
global $token;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_SSLVERSION , 6);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer '.$token,
'Accept: application/json',
'Content-Type: application/json'
));
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$response = curl_exec( $curl );
print_r($response); //IM NOW RECEIVING OUTPUT, however symbols are now being replaced by placeholders such as '%40', how can i prevent this?
if (empty($response)) {
die(curl_error($curl)); //close due to error
curl_close($curl);
} else {
$info = curl_getinfo($curl);
echo "Time took: " . $info['total_time']*1000 . "ms\n";
curl_close($curl); // close cURL handler
if($info['http_code'] != 200 && $info['http_code'] != 201 ) {
echo "Received error: " . $info['http_code']. "\n";
echo "Raw response:".$response."\n";
die();
}
}
// Convert the result from JSON format to a PHP array
$jsonResponse = json_decode($response, TRUE);
return $jsonResponse;
}
$token = get_access_token($url,$postArgs); //works and returns a valid access token
//This is the URL for the call
$url = 'https://api-3t.sandbox.paypal.com/nvp';
//This is the data to be sent in the call
$postdata = array(
'USER' => 'peoplesroewrwwsg_api1.outlook.com',
'PWD' => 'KR2TVKHGDSHSNDJ6E2',
'SIGNATURE' => 'AFcWxV21C7fdFHSGGSDGD51G0BJYUWOCSyjUAKPPGs',
'METHOD' => 'GetTransactionDetails',
'VERSION' => '123',
'TransactionID' => '1RE953245246192109'
);
$postdata = http_build_query($postdata);
//$postdata = json_encode($postdata); //Is this the correct way of formatting?
$transactionInfo = make_post_call($url, $postdata); //get transaction details NOT WORKING
print_r($transactionInfo); //does not print anything
?>
im not recieving any cURL errors so i assume that the problem is either the data im sending or how i format it.
A breif Paypal guide on how to do this can be found here-> https://developer.paypal.com/docs/classic/express-checkout/gs_transaction/#tryit However it is written in cURL and not PHP cURL extension so im not sure if im sending the data properly.
Paypal GetTransactionDetails details here-> https://developer.paypal.com/docs/classic/api/merchant/GetTransactionDetails_API_Operation_NVP/
Any guidance regarding data formatting, or any other suggestions are greatly appreciated!
---------------------------------------------------------UPDATE!-----------------------------------------------------------
Now when i'm printing the result as soon as the cURL statement is executed im receiving information like this:
RECEIVERID=GN7SRQEGEREASDV9BQU&EMAIL=peoplesrobotiblabal%40outlook%2ecom&PAYERID=JC5RWUUKWGDFYJYY&PAYERSTATUS=verified&COUNTRYCODE=US&SHIPTONAME=Jane%20Smurf...
As can be seen some symbols such as periods are being replaced by placeholders such as '%40'. Can the sorce of this be identified? is it because i'm expecting a JSON response?