我正在我的网站上整合paypal快速结账按钮,我有以下代码:
paypal.Button.render({
env: 'sandbox', // Optional: specify 'sandbox' environment
style: {
size: 'medium',
color: 'blue',
shape: 'rect'
},
payment: function(resolve, reject) {
var CREATE_PAYMENT_URL = 'http://example.com/create-payment';
paypal.request.post(CREATE_PAYMENT_UR)
.then(function(data) {
resolve(data.paymentID);
})
.catch(function(err) {
reject(err);
});
},
onAuthorize: function(data) {
// Note: you can display a confirmation page before executing
var EXECUTE_PAYMENT_URL = 'http://example.com/execute-payment';
paypal.request.post(EXECUTE_PAYMENT_URL, {
paymentID: data.paymentID,
payerID: data.payerID,
})
.then(function(data) { /* Go to a success page */ })
.catch(function(err) { /* Go to an error page */ });
}
}, '#paypal-button');
我想分别设置payment
和onAuthorize
。有没有办法做到这一点?
类似于:`paypal.Button.onAuthorize = function(){};
答案 0 :(得分:1)
如果有帮助,您可以单独创建功能
function payment() {
...
}
function onAuthorize() {
...
}
paypal.Button.render({
payment: payment,
onAuthorize: onAuthorize
});