我正在使用braintree paypal结帐以进行付款,付款正常,但无法得到答复,这是我的代码
<script type="text/javascript">
var form = document.querySelector('#payment-form');
var client_token = "<?php echo BraintreeClientToken::generate(); ?>";
braintree.dropin.create({
authorization: client_token,
selector: '#bt-dropin',
paypal: {
flow: 'vault',
onSuccess: function (nonce, email) {
alert('sdsdsd123');
console.log(JSON.stringify(nonce));
},
},
}, function (createErr, instance) {
if (createErr) {
console.log('Error', createErr);
return;
}
form.addEventListener('submit', function (event) {
event.preventDefault();
instance.requestPaymentMethod(function (err, payload) {
if (err) {
console.log('Error', err);
return;
} else {
console.log("Payment confirmation");
console.log(payload);
}
// Add the nonce to the form and submit
document.querySelector('#nonce').value = payload.nonce;
form.submit();
});
});
},
);
var checkout = new Demo({
formID: 'payment-form'
});
,但无法在OnSuccess功能中获得响应,任何人都可以告诉我Cani如何获得此成功响应,
全面披露:我在Braintree工作。如果您还有其他疑问,请随时联系支持。
看来,您可能会混淆Braintree JSV2在UI中的PayPal与Braintree JSV3 Drop-In UI的实现。JSV3中不支持onSuccess
选项。JSV3中PayPal对象的配置选项的完整列表可在此处找到。
根据您提供的代码,建议删除您的onSuccess
回调函数。您仍然应该能够通过将代码放在instance.requestPaymentMethod
回调功能中来实现所需的结果:
<script type="text/javascript">
var form = document.querySelector('#payment-form');
var client_token = "<?php echo BraintreeClientToken::generate(); ?>";
braintree.dropin.create({
authorization: client_token,
selector: '#bt-dropin',
paypal: {
flow: 'vault'
}
}, function (createErr, instance) {
if (createErr) {
console.log('Error', createErr);
return;
}
form.addEventListener('submit', function (event) {
event.preventDefault();
instance.requestPaymentMethod(function (err, payload) {
if (err) {
console.log('Error', err);
return;
}
console.log("Payment confirmation");
console.log(payload);
alert('sdsdsd123');
console.log(payload.nonce);
// Add the nonce to the form and submit
document.querySelector('#nonce').value = payload.nonce;
form.submit();
});
});
});
</script>