Можно ли вызвать функцию оплаты () при нажатии кнопки, чтобы пользователи не нажимали фактическую кнопку оплаты 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/