[在提取付款明细时不刷新消息/页面,贝宝结帐按钮

问题描述 投票:0回答:1

我正在将Paypal Express Checkout与v2 php checkout sdk集成。我能够完成交易并将用户重定向到thankyou页面,并将详细信息保存到数据库,但是当用户通过贝宝安全窗口付款并关闭时,贝宝会处理付款并获取我的getorder函数,这时延迟,用户坐在结帐页面上,没有任何提示,几秒钟后,页面刷新,用户被重定向到thankyou页面以成功付款。

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

谢谢

我的贝宝按钮代码:

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个回答
0
投票

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

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

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

这样,如果您的服务器不知道这笔交易是不可能完成的交易,而您的客户也不会看到一条感谢消息,那么这是不可能的

© www.soinside.com 2019 - 2024. All rights reserved.