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

标签 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;

最佳答案

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

将上面的代码改成,

$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();

关于php - 访问 https ://api. sandbox.paypal.com/v1/payments/payouts?sync_mode=true 时得到 Http 响应代码 403,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54491115/

相关文章:

ssl - 用paypal支付,需要ssl证书吗

Paypal API,它的功能是什么?

php - 您用于进入Pay​​Pal系统的链接无效。请检查链接并重试

php - mysqli_num_rows() 结果不正确

javascript - 等待 Bootbox 确认运行 Ajax

c# - Paypal IPN 监听器不返回值

c# - 付款错误 : PayPal error: Invalid request. 查看详情。 (VALIDATION_ERROR) Paypal

php - 在移动设备上排除部分 CSS

php - 当在Linux Apache服务器上执行php文件时,替换php文件会发生什么?

android - Paypal 对话框向我显示类似 "Android_pay_button PayPal"的按钮如何解决此错误?