gpt4 book ai didi

javascript - Paypal 智能支付抛出错误但仍在处理付款

转载 作者:行者123 更新时间:2023-12-05 07:10:59 25 4
gpt4 key购买 nike

我有一个客户网站,他们要求在他们的网站上进行借记/贷记付款,我已经设置了智能支付设置,它似乎在网站上运行正常,但是,我只是添加了一个功能来检索来自 URL 的变量(价格) 智能按钮抛出一个错误代码 并且我假设它是因为 javascript 部分从 URL 中获取金额变量 但是无论错误代码。

下面是我的代码示例

function getQueryVariable(variable)
{
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}
var sel = getQueryVariable("price");

paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: sel
}
}]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
alert('Transaction completed by ' + details.payer.name.given_name);
});
}
}).render('#paypal-button-container');

最佳答案

尝试在成功时执行 window.location.href 重定向而不是显示警报,一切都应该很好

或者,您可以在呈现之前保存对按钮的引用,然后在成功时关闭它们并使用任何成功消息更新页面。

类似(未经测试的):

  window.myButtons = paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: sel
}
}]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
alert('Transaction completed by ' + details.payer.name.given_name);
window.myButtons.close();
document.getElementById('paypal-button-container').innerHTML = '<pre>' + JSON.stringify(details, null, 4) + '</pre>';
});
}
});
window.myButtons.render('#paypal-button-container');

关于javascript - Paypal 智能支付抛出错误但仍在处理付款,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60983344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com