【问题标题】:Show do not refresh message/page while payment details are fetched PayPal Checkout Button显示在获取付款详细信息时不刷新消息/页面 PayPal 结帐按钮
【发布时间】:2020-04-07 23:51:38
【问题描述】:

我正在将 paypal express checkout 与 v2 php checkout sdk 集成。我能够完成交易并将用户重定向到感谢页面并将详细信息保存到数据库,但是当用户通过贝宝安全窗口付款并关闭时,贝宝处理付款并获取我的 getorder 函数,此时有显着延迟,用户坐在结帐页面上,没有任何迹象表明发生了什么,几秒钟后,页面刷新,用户被重定向到感谢页面,付款成功。

现在我的问题是我应该如何向用户显示一条消息,在获取付款详细信息时不要刷新页面或关闭窗口。 或者有什么方法可以将用户发送到另一个页面,告诉他在点击贝宝按钮时等待然后处理它。

谢谢

我的 PayPal 按钮代码:

paypal.Buttons({
        createOrder: function() {
            let formData = new FormData();
            formData.append('amount', document.getElementById("amount_paypal").value);
            formData.append('currency_code', document.getElementById("currency_code_paypal").value);
            formData.append('refrence_id', document.getElementById("refrence_id_paypal").value);
            formData.append('event_id', document.getElementById("event_id_paypal").value);
            formData.append('description', document.getElementById("description_paypal").value);

            return fetch('../paypal/createorder.php', {
                method: 'POST',
                body: formData
            }).then(function(response) {
                return response.json();
            }).then(function(resJson) {
                return resJson.result.id;
            });
        },
        // Wait for the payment to be authorized by the customer
        onApprove: function(data, actions) {
            return actions.order.capture().then(function(details) {
                return fetch('../paypal/getorder.php', {
                    method: 'POST',
                    headers: {
                        'content-type': 'application/json',
                    },
                    body: JSON.stringify({
                        orderID: data.orderID
                    })
                }).then(function(res) {
                    if (!res.ok)
                        throw new Error('Something Went Wrong!');
                    window.location = "../paypal/thankyou.php";
                });
            });
        },
        experience: {
            input_fields: {
                no_shipping: 1
            },
        },
    }).render('#paypal-button-container');

【问题讨论】:

    标签: paypal express-checkout paypal-buttons


    【解决方案1】:

    理想的解决方案是进行服务器端集成。

    https://developer.paypal.com/demo/checkout/#/pattern/server

    这样,买家通过@paypal 批准付款,然后点击您网站上的最终“立即付款”/“下订单”按钮,该按钮调用您的服务器,然后调用贝宝执行/捕获交易,然后您的服务器有已完成交易的即时记录,然后进行响应,以便您的页面向已完成交易的客户显示感谢消息。

    这样,如果您的服务器不知道,并且客户没有看到感谢信息,就不可能完成交易

    【讨论】:

      猜你喜欢
      • 2018-04-05
      • 2014-07-03
      • 2020-10-16
      • 2023-04-06
      • 2018-09-05
      • 2020-01-20
      • 2014-02-23
      • 2015-04-24
      • 2015-07-22
      相关资源
      最近更新 更多