根据documentation on PayPal's Developer site在高级服务器集成下,重定向 URL 必须在付款调用中提供,但是:
(…) PayPal does not automatically call these URLs. PayPal invokes your onAuthorize function when the buyer authorizes the payment. that are provided will not be used.
因此,我假设这是真的来开发我的代码,并且在我的本地设置中它工作正常。但是当我将它推送到我的登台服务器时,正在调用 SDK 中传递的重定向 URL,而我的 onAuthorize
函数被忽略。它甚至会打开一个新的弹出窗口,然后在那里打开我的 payment-execute.php
脚本,附加 GET
查询,忽略我的 POST
ed 值.
这是我正在使用的 JS 示例:
paypal.Button.render({
env: 'sandbox',
payment: function(resolve, reject) {
paypal.request.post(
'/path-to-inc/payment.php',
{
action: 'create_paypal_payment',
orderId: order_id,
postId: post_id,
}
)
.then(function(data) {
resolve(data.paymentID);
})
.catch(function(err) {
reject(err);
});
},
onAuthorize: function(data) {
paypal.request.post('/path-to-inc/payment-execute.php',
{
paymentID: data.paymentID,
payerID: data.payerID,
postId: post_id
})
.then(function(data) {
window.location.reload();
})
.catch(function(err) {
console.log('Error');
});
}
}, '#paypal-button');
还有来自 PHP 文件的片段:
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl('http://website.com/payment-execute.php')
->setCancelUrl('http://website.com/checkout');
$payment = new Payment();
$payment->setIntent('sale')
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions(array($transaction));
try {
$payment->create($apiContext);
echo json_encode( ['paymentID' => $payment->id] );
} catch (Exception $e) {
error_log( 'Payment error: ' . $e->getMessage() );
}
最佳答案
我从 1 天前开始遇到同样的问题,我在旧测试中使用 onAuthorize 调用
编辑 1:使用旧脚本版本进行良好测试,我使用这个得到了预期的结果 https://www.paypalobjects.com/api/checkout.4.0.38.js
关于php - 调用 RedirectUrls,忽略 onAuthorize 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42120990/