调用 RedirectUrls,忽略 onAuthorize 函数

RedirectUrls Being Called, onAuthorize Function Ignored

根据高级服务器集成下的 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 函数被忽略。它甚至会打开一个新的弹出窗口 window,然后在那里打开我的 payment-execute.php 脚本,附加 GET 查询,忽略我的 POSTed 值。

这是我正在使用的 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