I am using PayPal payouts sandbox API. In my sandbox app, payouts are enabled. But when I hit the API endpoint then it gives AUTHORIZATION_ERROR although my client_id & client_secret are correct. Following is the code sample:
function get_paypal_auth_token($client_id, $client_secret) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_USERPWD, $client_id.":".$client_secret);
curl_setopt($curl, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
$result = curl_exec($curl);
curl_close($curl);
return json_decode($result);
}
function create_paypal_payment($data) {
$client_id = "XXXXXX";
$client_secret = "XXXXXXXSECRET";
$auth_data = get_paypal_auth_token($client_id, $client_secret);
$url = "https://api.sandbox.paypal.com/v1/payments/payouts";
$data_json = json_encode($data);
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Bearer '.$auth_data->access_token));
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_json);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$resp = curl_exec($curl);
curl_close($curl);
return json_decode($resp);
}
The expected result of this API should be kind of related to payouts.
Also, I try it with another account's credentials then it gives INSUFFICIENT_FUNDS error.
So can anyone please tell how to add balance to my PayPal account?
Do you get this error only sometimes? I think their sandbox is experiencing issues, as my system also gets this error about 50% of the time since a couple of days ago. You can try sending a direct request to their servers to confirm this.
Follow these steps to add money in your sandbox account
Login to your Paypal sandbox using your sandbox account.
Click My Account –> Add Money
Click the type of account
Enter the amount
Related
I will admit, I have been on this for 3 days, back and forth through documentation, and even learned how to create my own products and plans through Postman.
So I have a complete working subscription button, now I learned I need to save the Subscription ID in order to cancel the subscription so now that is saving and loading perfectly.
To my sad surprise, I need to get an AuthKey every time someone wants to cancel, so I need to run 2 cURL commands, 1 GET Auth Key, and 1 POST cancel a subscription. How would I do this in PHP?
I don't get any errors when these commands run just no data.
Paypal cURL Example:
https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_cancel
////////////////////////////// GET TEMP ACCESS TOKEN/////////////////////////////////
$ch = curl_init();
$clientId = "x";
$secret = "x";
$myIDKEY = "";
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $clientId.":".$secret);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
$result = curl_exec($ch);
if(empty($result))die("Error: No response.");
else
{
$json = json_decode($result);
print_r($json->access_token);
$myIDKEY = $json->access_token;
}
curl_close($ch);
/////////////////////////////// SEND CANCEL POST ////////////////////////////////
$ch = curl_init();
$headers = [
'Authorization: Bearer '.$myIDKEY,
'Content-Type: application/json'
];
$postData = [
'reason' => 'clicked cancel subscription button'
];
curl_setopt($ch, CURLOPT_URL,"https://api.sandbox.paypal.com/v1/billing/subscriptions/".$_SESSION['honeybeesubID']."/cancel");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec ($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo $myIDKEY
Thank you so much!
As documented at https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_cancel , a success response is an HTTP 204 with no data.
So, it will be normal to receive an empty response, along with that status code.
I am trying to connect to the Aliseeks api with CURL but I am not sure where to put my api key.
On the API's doc they say
"Aliseeks expects for the API key to be included in all API requests
in a header that look like the following: X-Api-Client-Id: Your Api
Key"
Now I am doing this :
$url = 'https://api.aliseeks.com/v1/products/details';
$curl = curl_init();
$auth_data = array(
"X-Api-Client-Id" => 'my_api_key_here',
);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HEADER, $auth_data );
curl_setopt($curl, CURLOPT_POSTFIELDS, $auth_data);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$result = curl_exec($curl);
if(!$result){die("Connection Failure");}
curl_close($curl);
echo $result;
But in the return I get :
[{"code":"no_token_found","violation":"aliseeks.authentication.notokenfound"}]
Any idea ?
ps: the $auth_data is here twice because I am trying kind of everything now...
You are using a wrong constant to send the headers.
It should be CURLOPT_HTTPHEADER instead of CURLOPT_HEADER.
I am working on PayPal Payout API.i am not getting what exactly process should be for a complete payout payment method.everything is working fine but still there are so many bugs. what I and mobile application developer is doing.
Mobile API calls to the server with an amount so that server side a PayPal SDK has been integrated where I make a call on PayPal and make a transaction.
The problem is that whether a payer email register or not in Paypal it returns status PENDING without any transaction id.
And I have set up an IPN listener on PayPal which makes a call whenever payout status update. but it returns transaction_id and I am not getting transaction id while payout made.
I don't know what I need to do with it. Please if you did not understand you can drop a comment.
I am using the simple code for Payouts.
$headers = array(
'Content-Type:application/json',
'Authorization:Bearer '.$accsessToken,
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payouts?sync_mode=false");
// curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$result = curl_exec($ch);
$response = json_decode($result, 1);
$payoutBatchId = $response['batch_header']['payout_batch_id'];
$headers = array(
'Content-Type:application/json',
'Authorization:Bearer '.$accsessToken,
);
unset($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payouts/".$payoutBatchId);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'GET' );
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$response = json_decode($result, 1);
dd($response);
I think you should use PHP Paypal SDK.
There is some easy examples.
Hope this help.
I have an issue trying to implement Neteller's REST API. I have created my app in the merchant account (I don't have an SSL certificate in my site), I have a static IP for my web site and it is added to Neteller's allowed IP list, but for some reason I always receive a null response back from them.
This is my code:
$username = 'XXXXXXXXXXXXXXXX';
$password = 'XXxxxxxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_URL, "https://api.neteller.com/v1/oauth2/token?grant_type=client_credentials");
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Cache-Control:no-cache"));
curl_setopt($curl, CURLOPT_POSTFIELDS, array("scope"=>"default"));
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$serverOutput = curl_exec($curl);
$info = curl_getinfo($curl);
echo $serverOutput; // null response
Can anyone help me to solve this issue?
If you are receiving a null response to the curl_exec() method, this could indicate a problem establishing the HTTP connection.
try adding:
print_r(curl_errno($curl));
This will return the curl error code, which you can then check against this list.
Most probably it is a problem establishing the SSL connection - because the certificate issuing authority is not trusted by your cUrl installation. You can fix this by updating the trusted certificate authorities list. More info here.
I am trying to fetch my user's emails with google api & curl, and I am stuck on redeeming access token. I get the key no problem, but when it comes to token, google just returns json
{"error" : "invalid_request"}
below is a snippet which redeems code for token (well at least it supposed to)
$code = urlencode($_GET["code"]);
$secret = "MYSECRET";
$client_id = "MYCLIENTID";
$redirect_uri = urlencode("http://www.mysupersite.com/callback.html");
$grant_type = "authorization_code";
$url = "https://accounts.google.com/o/oauth2/token";
$headers = array("Content-type: application/x-www-form-urlencoded");
$post = "code=".$code."&client_id=".$client_id."&secret=".$secret."&redirect_uri=".$redirect_uri."&grant_type=".$grant_type;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($curl, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
curl_setopt($curl, CURLOPT_VERBOSE, TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$json = curl_exec($curl);
curl_close($curl);
var_dump($json);
I'm really stuck and google api never tells you what exactly is wrong.
UPD I know there's a lib for this kind of calls, but I'm solving one simple task (well according to google api documentation) and simply see no point in including loads of other methods.
okay my bad - $_GET["secret"] needs to be $_GET["client_secret"]