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.
... View more