1

I am attempting to make a sandboxed PayPal batch payout and I receive the following error:

{
    "debug_id": "c0c02d9a5a9f2",
    "information_link": "https://developer.paypal.com/webapps/developer/docs/api/#SENDER_RESTRICTED",
    "message": "Authorization error occurred",
    "name": "SENDER_RESTRICTED"
}

I am using the PayPal PHP API, which I have slightly refactored. This is my auth function:

private function pp_getApiContext($clientId, $clientSecret)
{
    // ### API CONTEXT
    // USE AN APICONTEXT OBJECT TO AUTHENTICATE API CALLS. THE CLIENTID AND CLIENTSECRET FOR THE
    // OAUTHTOKENCREDENTIAL CLASS CAN BE RETRIEVED FROM DEVELOPER.PAYPAL.COM
    $apiContext = new ApiContext(new OAuthTokenCredential($clientId, $clientSecret));

    // COMMENT THIS LINE OUT AND UNCOMMENT THE PP_CONFIG_PATH
    // 'DEFINE' BLOCK IF YOU WANT TO USE STATIC FILE BASED CONFIGURATION
    $apiContext->setConfig(array('mode' => 'sandbox',
                                'log.LogEnabled' => true,
                                'log.FileName' => './logs/PayPal/PayPal.log',
                                'log.LogLevel' => 'DEBUG', // PLEASE USE `FINE` LEVEL FOR LOGGING IN LIVE ENVIRONMENTS
                                'cache.enabled' => true));

    return $apiContext;
}

And this is my payout function:

private function pp_CreateBatchPayout($apiContext, $payoutId, $orders)
{
    // CREATE A NEW INSTANCE OF PAYOUT OBJECT
    $payouts = new \PayPal\Api\Payout();

    $senderBatchHeader = new \PayPal\Api\PayoutSenderBatchHeader();
    $senderBatchHeader->setSenderBatchId($payoutId);
    $senderBatchHeader->setEmailSubject("You have a payment");
    $payouts->setSenderBatchHeader($senderBatchHeader);

    foreach($orders as $item_order)
    {
        // #### SENDER ITEM
        // PLEASE NOTE THAT IF YOU ARE USING SINGLE PAYOUT WITH SYNC MODE, YOU CAN ONLY PASS ONE ITEM IN THE REQUEST
        $senderItem = new \PayPal\Api\PayoutItem();
        $senderItem->setRecipientType('Email')
                    ->setReceiver($item_order['email'])
                    ->setAmount(new \PayPal\Api\Currency("{ \"value\":\"{$item_order['commissionAmount']}\", \"currency\":\"AUD\" }"))
                    ->setSenderItemId($item_order['commissionId'])
                    ->setNote("Store Name [{$item_order['storeName']}]");

        $payouts->addItem($senderItem);
    }

    // ### CREATE PAYOUT
    $output = $payouts->create(null, $apiContext);
    $this->logger->info("CREATED BATCH PAYOUT ID [{$output->getBatchHeader()->getPayoutBatchId()}] REQUEST [{$payouts}] OUTPUT [{$output}]");

    return $output;
}

Any help is appreciated. Thanks

mils
  • 1,878
  • 2
  • 21
  • 42
  • Well it appears that if I use the sandbox credentials provided with the API my functions work fine. This is still an issue for me though, as I need to be able to test with my own sandbox credentials. – mils Jan 21 '16 at 06:24

0 Answers0