全面披露:我在布伦特里工作。如果您还有其他问题,请随时联系
支持人员。
虽然使用 DropIn 无法实现该解决方案,但我建议根据付款方式是否可请求动态启用或禁用您的提交按钮。请参见下面的示例。
var submitButton = document.querySelector('#submit-button');
braintree.dropin.create({
authorization: 'client_token',
container: '#bt-dropin'
}, function (err, dropinInstance) {
submitButton.addEventListener('click', function () {
dropinInstance.requestPaymentMethod(function (err, payload) {
document.querySelector('#nonce').value = payload.nonce;
form.submit();
});
});
if (dropinInstance.isPaymentMethodRequestable()) {
// This will be true if you generated the client token
// with a customer ID and there is a saved payment method
// available to tokenize with that customer.
submitButton.removeAttribute('disabled');
}
dropinInstance.on('paymentMethodRequestable', function (event) {
console.log(event.type); // The type of Payment Method, e.g 'CreditCard', 'PayPalAccount'.
console.log(event.paymentMethodIsSelected); // true if a customer has selected a payment method when paymentMethodRequestable fires
submitButton.removeAttribute('disabled');
});
dropinInstance.on('noPaymentMethodRequestable', function () {
submitButton.setAttribute('disabled', true);
});
});
为了获得更多控制,我建议查看我们的托管字段解决方案。