问题
While setting up a Paypal Smart Payment Button, I wanted to call an external function from the button listener onAuthorize. How to do it? External functions are not visible inside the button listener. In order to call them they have to be attached to the window object.
/* Paypal button code */
// Execute the payment
onAuthorize: function(data, actions) {$(this).attr('action')
return actions.payment.execute().then(function(data) {
// Show a confirmation message to the buyer
window.user_membership_activation(data);
});
}
/* Elsewhere in your page or included script */
window.user_membership_activation = function(data) {
// do something here
}
来源:https://stackoverflow.com/questions/57090296/how-to-call-external-javascript-function-from-inside-onauthorize-paypal-smart-pa