访问https://api.sandbox.paypal.com/v1/payments/payouts?sync_mode=true时收到Http响应代码403

时间:2019-02-02 07:49:34

标签: php paypal paypal-sandbox payout

当我尝试使用Paypal执行付款时,出现此错误。我试图避免sync_mode等方法,但没有帮助。请协助解决这个错误 我的功能

$payouts = new Payout();
    $senderBatchHeader = new PayoutSenderBatchHeader();
    $senderBatchHeader->setSenderBatchId(uniqid())
        ->setEmailSubject("You have a Payout!");
    $senderItem = new PayoutItem();
    $senderItem->setRecipientType('Email')
        ->setNote('Thanks for your patronage!')
        ->setReceiver('paypalemail@gmail.com')
        ->setSenderItemId("2014031400023")
        ->setAmount(new Currency('{
                    "value":"1.0",
                    "currency":"USD"
                }'));
    $payouts->setSenderBatchHeader($senderBatchHeader)
        ->addItem($senderItem);
    $request = clone $payouts;
    $apiContext = new \PayPal\Rest\ApiContext(
        new \PayPal\Auth\OAuthTokenCredential(
            'client_id',
            'client_secrete_id'
        )
    );
    try {
        $output = $payouts>createSynchronous($apiContext);
    } catch (Exception $ex) {
        return $ex;
    }
    return $output;

1 个答案:

答案 0 :(得分:1)

很高兴我找到了对我有用的答案!

将上面的代码更改为

$payouts = new \PayPal\Api\Payout();
            $senderBatchHeader = new \PayPal\Api\PayoutSenderBatchHeader();
            $senderBatchHeader->setSenderBatchId(uniqid().microtime(true))
                ->setEmailSubject("You have a payment");


                    $senderItem = new \PayPal\Api\PayoutItem();
                    $senderItem->setRecipientType('Email')
                        ->setNote('Thanks you.')
                        ->setReceiver('paypal_email@gmail.com')
                        ->setSenderItemId("item_1" . uniqid().microtime('true'))
                        ->setAmount(new \PayPal\Api\Currency('{
                    "value":"1.0",
                    "currency":"USD"
                }'));
                    $payouts->setSenderBatchHeader($senderBatchHeader)->addItem($senderItem);
            $request = clone $payouts;
            $apiContext = new \PayPal\Rest\ApiContext(
                new \PayPal\Auth\OAuthTokenCredential(
                    $paypal->client_id,
                    $paypal->client_secrete
                )
            );
            try {
                $output = $payouts->create(null, $apiContext);
            } catch (Exception $ex) {
            Flash::error(trans('payout.payout_error'));
                return redirect()->back();
            }
            Flash::success(trans('payout.payout_success'));
            return redirect()->back();