php - 访问 https://api.sandbox.paypal.com/v1/payments/payouts?sync_mode=true 时得到 Http 响应码 403
问题描述
当我尝试使用 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();
推荐阅读
- javascript - java-script Catch 块在 promise 的 fetch api 响应中不起作用
- javascript - 我想在甜蜜警报中单击我的按钮时加载一些功能
- php - 遇到未捕获的异常 - ParseError
- java - 是否可以使用带有 JPA 的 Spring Boot 创建数据库模式
- proguard - Proguard 的日志去混淆
- c - 为什么设置 LINKOPTS=' ' 抑制错误信息
- java - 如何从资源中导入 .tff 字体并使用 Graphics2D 在屏幕上绘制字符串?
- assembly - 第一行是打印垃圾。无法识别错误
- python - 协助优化将 Python 脚本的输出保存到文本文件
- javascript - 如何测试异步调用以便伊斯坦布尔将覆盖它?