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?
2
Answers
Follow these steps to add money in your
sandbox 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.