客户使用 Paypal 付款并立即离开网站导致他没有收到商品

Customer pays with Paypal and immediately leaves the website causes him not to get the item

我通过 react-paypal-button-v2 使用 paypal 在我的网站上收款。 我在我的 Sandbox 帐户上测试了一些东西,发现如果客户付款,window 大约需要 3 秒,直到成功函数触发

           onSuccess={() => {
             this.props.handlePaymentComplete();
           }}

问题是,如果客户付款并在那 3 秒内退出我的网站 window,他将被收取费用但该功能不会启动,因此他的信息不会保存到数据库中.

我很确定这是 react-paypal-button-v2 的问题,但我找不到合适的方式将 paypal 与 react 连接起来。有办法解决这个问题吗?

onSuccess 不好,那是一个不好的例子,不应该是默认值

有一个 commented out example below 应该可以正常工作

                    onApprove={(data, actions) => {
                        // Capture the funds from the transaction
                        return actions.order.capture().then(function(details) {
                            // Show a success message to your buyer
                            alert("Transaction completed by " + details.payer.name.given_name);
                        });
                    }}

但是,这都是客户端的,在保存到数据库之前仍然容易受到潜在的中断。


一个真正的解决方案是将其扩展为服务器端集成,这通常是通过调用 PayPal API 的两个服务器端路由完成的:'Set Up Transaction' 和 'Capture Transaction',如此处记录:https://developer.paypal.com/docs/checkout/reference/server-integration/

与这些路由配对的前端在这里,您可以将其适配为 JSX:https://developer.paypal.com/demo/checkout/#/pattern/server