当用户取消 paypal 付款时,我试图将用户转到另一个页面。使用下面的脚本,它在没有 onCancel 函数的情况下也能正常工作,但是一旦我将其添加到 JS 中,paypal 按钮就会消失。
谁能看看代码并告诉我如何更正它。
提前致谢。
paypal.Button.render({
// Set your environment
env: 'sandbox', // sandbox | production
// Specify the style of the button
style: {
label: 'checkout',
size: 'medium', // small | medium | large | responsive
shape: 'pill', // pill | rect
color: 'silver' // gold | blue | silver | black
},
// PayPal Client IDs - replace with your own
// Create a PayPal app: https://developer.paypal.com/developer/applications/create
client: {
sandbox: '<insert production client id>',
production: '<insert production client id>'
},
// Show the buyer a 'Pay Now' button in the checkout flow
commit: true,
// Wait for the PayPal button to be clicked
payment: function(data, actions) {
// Make a client-side call to the REST api to create the payment
return actions.payment.create({
payment: {
transactions: [
{
amount: { total: '1.09', currency: 'GBP' }
}
]
},
experience: {
input_fields: {
no_shipping: 1
}
}
});
},
// Wait for the payment to be authorized by the customer
onAuthorize: function(data, actions) {
// Execute the payment
return actions.payment.execute().then(function() {
window.location.href = "<direct to payment success page>";
});
}
onCancel: function(data, actions) {
// Show a cancel page or return to cart
}
}, '#paypal-button-container');
最佳答案
您需要添加一个 ,
来为每个附加项格式化 JSON 对象,例如 onCancel。请注意 onAuthorize 项的右大括号后的逗号。
},
onCancel: function(data, actions) {
// Show a cancel page or return to cart
}
关于javascript - Paypal 取消功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48157678/