客户使用 Paypal 付款并立即离开网站导致他没有收到商品 [英] Customer pays with Paypal and immediately leaves the website causes him not to get the item
问题描述
我正在使用带有 react-paypal-button-v2 在我的网站上获得付款.我在我的 Sandbox 帐户上测试了一些东西,并意识到如果客户付款,则在成功功能触发前有大约 3 秒的窗口
I am using paypal with react-paypal-button-v2 to get payments on my website. I was testing a few things on my Sandbox account and realized that if the customer pays, there is a window of about 3 seconds until the success function fires
onSuccess={() => {
this.props.handlePaymentComplete();
}}
问题是,如果客户在这 3 秒窗口内付款并退出我的网站,他将被收取费用但该功能不会触发,因此他的信息不会保存到数据库中.
The problem is, if the customer pays and quits my website in that 3 seconds window, he will be charged the money but the function will not fire and therefore his information will not be saved to the DB.
我很确定这是 react-paypal-button-v2 的问题,但我找不到将 paypal 与 react 连接的体面方法.有没有办法解决这个问题?
I'm pretty sure that it is a problem with the react-paypal-button-v2, but I couldn't find a decent way to connect paypal with react. Is there a way to solve this issue?
推荐答案
onSuccess 不好,这是一个不好的例子,不应该是默认的
onSuccess is no good, that is a bad example and should not be the default
有一个没有引用下面的例子应该可以正常工作
There is a commented out example below that should work fine
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);
});
}}
然而,这都是客户端,在保存到数据库之前仍然容易受到潜在中断的影响.
However, this is all client-side and is still vulnerable to potential interruption before being saved in your database.
真正的解决方案是将其扩展为服务器端集成,这通常通过调用 PayPal API 的两个服务器端路由完成:设置交易"和捕获交易",如此处所述:https://developer.paypal.com/docs/checkout/reference/server-整合/
A real solution is to extend this to be a server-side integration, which is usually done with two server-side routes that call the PayPal API: 'Set Up Transaction', and 'Capture Transaction', as documented here: https://developer.paypal.com/docs/checkout/reference/server-integration/
与这些路由配对的前端在这里,您可以为 JSX 进行调整:https://developer.paypal.com/demo/checkout/#/pattern/server
The front-end to pair with those routes is here, which you can adapt for JSX: https://developer.paypal.com/demo/checkout/#/pattern/server
这篇关于客户使用 Paypal 付款并立即离开网站导致他没有收到商品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!