1

我正在尝试进行沙盒化 PayPal 批量支付,但收到以下错误:

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

我正在使用 PayPal PHP API,我对它进行了轻微的重构。这是我的身份验证功能:

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;
}

这是我的支付功能:

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;
}

任何帮助表示赞赏。谢谢

4

0 回答 0