I appreciate your advice on this matter. I’ve been looking for a way to send payments to multiple receivers from paypal for a few days, I’m developing a platform in Laravel, and I’ve tried the api-sdk-php, and it works perfectly for individual payments however, I have not got the corresponding method to create an invoice similar to this one.
2 Tennis 25 $
nike@paypal.com
1 Redmi 10 $ 150
xiami@paypal.com
I have reviewed many threads, some mention the adaptive payments of paypal, however when I review the documentation it shows me that this payment format is deprecated and the APP_ID parameter currently I could not obtain it.
I also read and tried some guides but in the end I used deprecated code, I found libraries with tiny documentation, except the official PayPal one, every day I end up more disoriented, I appreciate the help and advice that you can give me to achieve the goal, and leave an answer that I can help others in the future.
Advertisement
Answer
I found my solution for Laravel or PHP, Adaptive payments still work, I used that old method and managed to create an invoice of several receivers and receive in his sandbox accounts.
I will share my finding so that others can also benefit, although I can not give myself any credit, the solution is found in the channel from youtube optikalefx and support me from the paypal api.
Here the solution, I hope it helps other programmers
$createPacket = array( "actionType" => "PAY", // Payment action type "currencyCode" => "USD", // Payment currency code "receiverList" => array( "receiver" => array( array( "amount" => "25", // Payment amount "email" => "nike@paypal.com", // Receiver's email address ), array( "amount" => "150", // Payment amount "email" => "xiaomi@paypal.com", // Receiver's email address ), ), ), "returnUrl" => url("/"), // Redirect URL after approval "cancelUrl" => url("/"), // Redirect URL after cancellation "requestEnvelope" => array( "errorLanguage" => "en_US", // Language used to display errors "detailLevel" => "ReturnAll", // Error detail level ), ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://svcs.sandbox.paypal.com/AdaptivePayments/Pay'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($createPacket)); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "X-PAYPAL-SECURITY-USERID:" . "YOUR_USER_ID", "X-PAYPAL-SECURITY-PASSWORD:" . "YOUR_SECURITY_PASSWORD", "X-PAYPAL-SECURITY-SIGNATURE:" . "YOUR_SIGNATURE", "X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T", //USE THIS Global SANDBOX APP ID "X-PAYPAL-REQUEST-DATA-FORMAT: JSON", "X-PAYPAL-RESPONSE-DATA-FORMAT: JSON", ]); $response = json_decode(curl_exec($ch), true); return redirect("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_ap-payment&paykey=".$response['payKey']));