Reputation: 21
I want to integrate paypal's single payout method in my system, as I want to send money to my sellers, when they request for withdrawal. I have generated an "Access token key" for this and making a curl call from PHP script. But the response is a blank string. I have tried curl_error($curl);
but this also doesn`t do anything. Below is my code
// data to be sent
$data = [
'sender_batch_header' => [
'email_subject' => "You have a payment",
'sender_batch_id' => "125458268"
],
'items' => [
[
'recipient_type' => "EMAIL",
'amount' => [
'value' => "12.00",
'currency' => "USD"
],
'receiver' => '[email protected]',
'note' => 'A trial for single payout',
'sender_item_id' => "2014031400456"
],
],
];
//curl link for single payout with sync off
$curl = curl_init("https://api.sandbox.paypal.com/v1/payments/payouts?sync_mode=true");
$header = array(
"Content-Type: application/json",
"Authorization: Bearer ".$access_token ,
);
$options = array(
CURLOPT_HTTPHEADER => $header,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_POSTFIELDS => json_encode($values),
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_TIMEOUT => 10
);
curl_setopt_array($curl, $options);
$rep = curl_exec($curl);
$response = json_decode($rep, true);
curl_close($curl);
But here my $rep is a blank string, tried getting single payout details as well, but this also returns blank string...please help..thanx in advance.
Upvotes: 1
Views: 663
Reputation: 21
After 2 days of search I found an answer, which was very easy. I didn't use paypal's single payout, instead of that I used it's Implicit Payments operation of PAY API. Below is the code for it..
$receiver[] = array(
'amount' => '125.00',//amount to be transferred
'email' => '[email protected]',// paypal email id to which you want to send money
);
$result = $paypal->call(
array(
'actionType' => 'PAY',
'currencyCode' => 'USD',
'feesPayer' => 'EACHRECEIVER',
'memo' => 'Withdrawal request no. 356',
'cancelUrl' => '/cancel.php',
'returnUrl' => '/success.php',
'senderEmail' => '[email protected]', // email id of admin's business account, from which amount will be transferred.
'receiverList' => array(
'receiver'=>$receiver
)
), 'Pay'
);
function call($values,$type)
{
$header = array(
"X-PAYPAL-SECURITY-USERID: ".$config['userid'],
"X-PAYPAL-SECURITY-PASSWORD: ".$config['password'],
"X-PAYPAL-SECURITY-SIGNATURE: ".$config['signature'],
"X-PAYPAL-REQUEST-DATA-FORMAT: JSON",
"X-PAYPAL-RESPONSE-DATA-FORMAT: JSON",
"X-PAYPAL-APPLICATION-ID: ".$config['appid'];
);
$curl = curl_init("https://svcs.sandbox.paypal.com/AdaptivePayments/");
$options = array(
CURLOPT_HTTPHEADER => $header,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_POSTFIELDS => json_encode($values),
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_TIMEOUT => 10
);
curl_setopt_array($curl, $options);
$rep = curl_exec($curl);
$response = json_decode($rep, true);
curl_close($curl);
return $response;
}
If you are the API caller and you specify your email address in the senderEmail field, PayPal sets the payment to be implicitly approved, without redirection to PayPal. (Alternatively, you can use sender.accountId.)
Upvotes: 1