按钮启动时是否可以调用付款功能(),而无需用户单击实际的Paypal结帐按钮?
我尝试这样做,但是不起作用:
onEnter: function() {
this.payment();
},
这是我的完整代码:
<script>
paypal.Button.render({
env: 'sandbox', // sandbox | production
// PayPal Client IDs - replace with your own
// Create a PayPal app: https://developer.paypal.com/developer/applications/create
client: {
sandbox: '<insert sandbox client id>',
production: '<insert production client id>'
},
onEnter: function() {
this.payment();
},
// Show the buyer a 'Pay Now' button in the checkout flow
commit: true,
// payment() is called when the button is clicked
payment: function(data, actions) {
// Make a call to the REST api to create the payment
return actions.payment.create({
payment: {
transactions: [
{
amount: { total: '10.00', currency: 'USD' }
}
]
}
});
},
// onAuthorize() is called when the buyer approves the payment
onAuthorize: function(data, actions) {
// Make a call to the REST api to execute the payment
return actions.payment.execute().then(function() {
window.alert('Payment Complete!');
});
},
}, '#paypal-button-container');
</script>
还有其他方法可以做到这一点吗?
这是完整的代码:https://jsfiddle.net/h9nzg5js/