I'm using Braintree dropin to implement payments on a website. The initialization code of the dropin is the following:
braintree.dropin.create({
authorization: 'CLIENT_AUTHORIZATION',
container: '#dropin-container'
}, function (createErr, instance) {
button.addEventListener('click', function () {
instance.requestPaymentMethod(function (requestPaymentMethodErr, payload) {
// Submit payload.nonce to your server
});
});
});
I have a dropdown list of categories where for some categories the price of the item is ZERO. When those categories are chosen, I would like to remove the dropin from the page and put it back when the price is not ZERO.
There is a teardown function that I can call on the instance (which is the dropin instance in the code above) to remove the dropin, but I cannot access that instance from outside the dropin.create call.
Is there anyway that I can have access to that instance that is the second parameter of the callback function from outside so I can call teardown on it?
Thanks in advance for any help