使用智能支付按钮,付款弹出窗口关闭后有3-4秒的延迟。事务窗口关闭后需要3-4秒才能触发onApproval事件,该事件获取处理订单所需的事务ID。
这会给带来麻烦,因为在此期间,买方可能会关闭窗口(因为似乎什么都没有发生),而且事件从未收到,因此订单没有处理(尽管已付款)。
以下是代码:
paypal.Buttons({
createOrder: function(data,actions) {
// do some stuff
return fetch('/createOrder', {
method: 'post',
headers: {
'content-type': 'application/json'
}
}).then(function(res) {
return res.json();
}).then(function(data) {
return data.orderID;
});
},
// onApprove will be fired 3-4 second AFTER the popup of transaction closes
onApprove: function(data, actions) {
return fetch('captureOrder', {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
orderID:data.orderID
})
}).then(function(res) {
return res.json();
}).then(function(details) {
});
}
}).render(selector);
有什么办法让弹出窗口在偶数被触发后关闭吗?,否则唯一的解决办法就是用旋转器(或类似的东西)覆盖,一旦接收到onApproval就会消失。但这太麻烦了。弹出式弹出实际上不应该在活动开始前关闭。
发布于 2020-07-14 08:34:17
我本人并没有观察到这么长时间的延误,也不应该引起问题,因为无论如何买方都应该等待他们的确认,但事实是这样的。
如果您认为有必要,可以使用onClick
方法来触发“请等待/旋转”或其他任何操作,并在onApprove的fetch (以及onError和onCancel函数)中对其进行核武器化。但你让事情变得太复杂了。
发布于 2022-01-06 21:20:58
使用这个
// Finalize the transaction after payer approval
onApprove: function(data, actions) {
return actions.order.capture().then(function(orderData) {
// Successful capture! For dev/demo purposes:
console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
var transaction = orderData.purchase_units[0].payments.captures[0];
alert('Transaction '+ transaction.status + ': ' + transaction.id + '\n\nSee console for all available details');
// When ready to go live, remove the alert and show a success message within this page. For example:
// var element = document.getElementById('paypal-button-container');
// element.innerHTML = '';
// element.innerHTML = '<h3>Thank you for your payment!</h3>';
// Or go to another URL: actions.redirect('thank_you.html');
});
}
https://stackoverflow.com/questions/62890806
复制相似问题