-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Callback function to braintree.setup #19
Comments
@idl3 unfortunately there is no callback to hook into. Out of curiosity, which integration are you using? Drop-in? |
Yup Drop-in! Just wondering if theres a reason why a setup callback wouldn't be included? Wouldn't it just be accepting another argument into options and running that at the end of the setup process? |
It is certainly something we can explore. I will sync up with the team to discuss our options and let you know where we end up. Thanks for posting this issue. |
I've modified a unminified version of braintree.js 2.5.1 to include a "onLoad" callback function that will fire after the iframe has been injected into the DOM, after which a .load function listener can be used to fire any form instantiation methods afterwards. You can see the modified script here https://gist.github.com/idl3/8bf95acc821de2659eff I added a new bus event called ONLOAD and also its own callback method which is then injected into the client.initialize portion. How I would then use the setup function is as follows, braintree.setup(
braintree_token,
'dropin', {
container: 'dropin',
paymentMethodNonceReceived: function (event, nonce) {
$('.braintree-checkout').append("<input type='hidden' name='payment_method_nonce' value='"+ nonce +"'></input>");
$.ajax({
url: '#{braintree_charge_path}',
type: 'post',
data: $('.braintree-checkout').serialize(),
context: $('.braintree-checkout'),
beforeSend: function(evt, xhr, settings){
// beforesend stuff etc.
},
complete: function(evt, xhr, status){
// completed stuff etc.
},
error: function(evt, xhr, status, error){
// show error message if fails
}
});
},
onLoad: function(){
$('iframe[name="braintree-dropin-frame"]').load(function(){
setTimeout(function(){
// i set a timeout as sometimes the animation transition from the swirling lock to the completed form may take a second or so.
},1500);
});
}
}); |
@idl3 this is really awesome! I certainly see the need for a hook to let you know when the Drop-In is ready and it is something we are discussing internally. I also know how difficult it is to work your way through Taking that even further, would it make more sense for the |
Yeah We're excited to be moving production over to braintree this weekend, so fingers crossed :) |
This is really great! Thanks @idl3 I was looking for this too and I think it's absolutely needed in the official version, I mean a callback to know when the drop-in is ready. |
I have modified the code to now callback only after the initialize has been called. For the paranoid that I have put a backdoor in there, do a git diff between the original here at https://js.braintreegateway.com/js/braintree-2.6.0.js |
Comment here braintree#19 (comment)
@idl3 thanks for taking the time to do that. We are working on implementing an official |
@idl3 thank you for your patience. We recently released version braintree.setup(braintree_token, 'dropin', {
container: 'dropin',
paymentMethodNonceReceived: function (event, nonce) {
...
},
onReady: function () {
// console.log('Braintree is ready');
}
}); We are working on adding this new functionality to our documentation, but you can take advantage of this feature now! |
It's really good, but unfortunately you still haven't a unminified version of this repository, can I ask why while we can see there is an unminified version here: https://js.braintreegateway.com/js/braintree-2.7.0.js |
Excellent, thank you very much! Please update the documentation, I was looking for this feature. |
@chuchuva will do! Sorry it's taking longer than expected to get the new documentation out. |
Awesome stuff :) Thanks for this! |
Works very good, thanks! |
Hey Jeff,
Would there be a callback function somewhere in the pipeline?
The use case would be to activate the form (or show the submit button) only after braintree has finished loading. This way we wont have a premature form submission from users who are too eager to click on submit buttons!
Cheers,
Ernest
The text was updated successfully, but these errors were encountered: