Payout API I get Error 422
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I try to execute the payout API with a payout using this code
require __DIR__ . '/PayPal-PHP-SDK/autoload.php'; $apiContext = new \PayPal\Rest\ApiContext( new \PayPal\Auth\OAuthTokenCredential( '123456...', // ClientID '789012...' // ClientSecret ) ); $payouts = new \PayPal\Api\Payout(); $senderBatchHeader = new \PayPal\Api\PayoutSenderBatchHeader(); $senderBatchHeader->setSenderBatchId(uniqid()) ->setEmailSubject("You have a payment from us") ->setRecipientType("Email"); // We try one only payment for now for($i = 0; $i < 1; $i++) { $senderItem = new \PayPal\Api\PayoutItem( array( "receiver" => "existing_paypal_account_email", "note" => "Thank you.", "sender_item_id" => uniqid(), "amount" => array( "value" => (($i+1) * 0.11), "currency" => "EUR" ) ) ); $payouts->setSenderBatchHeader($senderBatchHeader) ->addItem($senderItem); } $request = clone $payouts; try { $output = $payouts->create(null, $apiContext); } catch (Exception $ex) { echo "PayPal Payout Error: ". $ex . "<br><br>"; echo "Batch Payout: ". $request . "<br><br>"; exit(1); }
And I get this error
EX: exception 'PayPal\Exception\PayPalConnectionException' with message 'Got Http response code 422 when accessing https://api.sandbox.paypal.com/v1/payments/payouts?.' in /mysite.com/test/APIs/PayPal/PayPal-PHP-SDK/paypal/rest-api-sdk-php/lib/PayPal/Core/PayPalHttpConnection.php:183 Stack trace: #0 /mysite.com/test/APIs/PayPal/PayPal-PHP-SDK/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php(73): PayPal\Core\PayPalHttpConnection->execute('{"sender_batch_...') #1 /mysite.com/test/APIs/PayPal/PayPal-PHP-SDK/paypal/rest-api-sdk-php/lib/PayPal/Common/PayPalResourceModel.php(102): PayPal\Transport\PayPalRestCall->execute(Array, '/v1/payments/pa...', 'POST', '{"sender_batch_...', NULL) #2 /mysite.com/test/APIs/PayPal/PayPal-PHP-SDK/paypal/rest-api-sdk-php/lib/PayPal/Api/Payout.php(122): PayPal\Common\PayPalResourceModel::executeCall('/v1/payments/pa...', 'POST', '{"sender_batch_...', NULL, Object(PayPal\Rest\ApiContext), NULL) #3 /mysite.com/test/APIs/PayPal/PayPal_BatchPayout.php(148): PayPal\Api\Payout->create(NULL, Object(PayPal\Rest\ApiContext)) #4 {main}
What do I miss in the code? It already worked for about 6 times. Now it won't.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have solved the problem. In the catch paragraph I added this line
echo "PayPal Payout GetData:<br>". $ex->getData() . "<br><br>";
which reported INSUFFICIENT FUNDS. Then I discovered that we can't add funds to a sandobox account. We have to create a new sambox account with large funds, then re-create the App Rest, get new credentials, add the Webhook, the Return URL, change the Credentials in our php code... A mess.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Lunardi wrote:
[…] Then I discovered that we can't add funds to a sandobox account. We have to create a new sambox account with large funds, then re-create the App Rest, get new credentials, add the Webhook, the Return URL, change the Credentials in our php code... A mess.
Hi @Lunardi, you are right that you can't explictly add funds to an existing Sandbox account – but you can create a separate Sandbox account and use the Send Money feature on https://www.sandbox.paypal.com to send a large amount from this to your existing account. The money will go into the old account's balance and you should be able to continue to use your existing setup and credentials.
Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
- Getting errors when integrating standard checkout with my web site. Probably a beginner problem. in SDKs
- Get error message "Someting went wrong" when the sandbox account tap "Agree and Connect" button. in Sandbox Environment
- Connecting with site to take payments in Payflow
- link my PayPal business account with my WordPress website , but it's not work ?! in PayPal Payments Standard
- Problems with accent characters when calling Paypal API (v2/invoicing/invoices). in REST APIs