Javascript 贝宝取消功能
我试图在用户取消paypal付款时将其发送到另一个页面。在下面的脚本中,没有onCancel函数也可以很好地工作,但是一旦我将这个脚本添加到JS中,paypal按钮就会消失 有人能看一下代码并告诉我如何更正它吗 提前谢谢Javascript 贝宝取消功能,javascript,paypal,Javascript,Paypal,我试图在用户取消paypal付款时将其发送到另一个页面。在下面的脚本中,没有onCancel函数也可以很好地工作,但是一旦我将这个脚本添加到JS中,paypal按钮就会消失 有人能看一下代码并告诉我如何更正它吗 提前谢谢 paypal.Button.render({ // Set your environment env: 'sandbox', // sandbox | production // Specify the style of the button
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');
paypal.Button.render({
//设置您的环境
env:'沙盒',//沙盒|生产
//指定按钮的样式
风格:{
标签:“签出”,
大小:'中',//小|中|大|灵敏
形状:“pill”,//pill | rect
颜色:“银色”//金色|蓝色|银色|黑色
},
//PayPal客户端ID-替换为您自己的
//创建PayPal应用程序:https://developer.paypal.com/developer/applications/create
客户:{
沙盒:“”,
生产:''
},
//在结账流程中向买家显示“立即付款”按钮
承诺:对,
//等待贝宝按钮被点击
支付:功能(数据、操作){
//对RESTAPI进行客户端调用以创建付款
返回操作.payment.create({
付款:{
交易:[
{
金额:{总计:'1.09',币种:'GBP'}
}
]
},
经验:{
输入字段:{
无运输:1
}
}
});
},
//等待客户授权付款
onAuthorize:函数(数据、操作){
//执行付款
返回actions.payment.execute().then(function()){
window.location.href=“”;
});
}
onCancel:函数(数据、操作){
//显示取消页面或返回购物车
}
}“#贝宝按钮容器”);
您需要添加一个,
来格式化每个附加项的JSON对象,比如onCancel。注意onAuthorize项的右括号后面的逗号
},
onCancel: function(data, actions) {
// Show a cancel page or return to cart
}
您需要添加一个
,
来格式化每个附加项的JSON对象,比如onCancel。注意onAuthorize项的右括号后面的逗号
},
onCancel: function(data, actions) {
// Show a cancel page or return to cart
}
通常,您需要同时使用onCancel和onError
onCancel: function(data, actions) {
console.log("You are a bummer!");
},
onError: function(err) {
console.log("PayPal is a bummer!");
}
通常,您需要同时使用onCancel和onError
onCancel: function(data, actions) {
console.log("You are a bummer!");
},
onError: function(err) {
console.log("PayPal is a bummer!");
}
检查浏览器控制台是否有错误…检查浏览器控制台是否有错误。。。