Comments (15)
@idl3 unfortunately there is no callback to hook into. Out of curiosity, which integration are you using? Drop-in?
from braintree-web.
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?
from braintree-web.
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.
from braintree-web.
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);
});
}
});
from braintree-web.
@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 browserified
code to provide feedback and debug issues. So thanks for that! I think if we were to actually do this though, it would make more sense for us to emit the onLoad
event back to you after the iFrame was actually written to the DOM. That code gets executed as part of dropin.create
so emitting the ONLOAD
event before that could lead to a race condition.
Taking that even further, would it make more sense for the ONLOAD
event to be emitted from inside of our iFrame after we have composed and rendered our UI? That would eliminate the need for an arbitrary setTimeout
and I would imagine instead of onLoad
, we could have something like an onReady
callback. What are your thoughts on that?
from braintree-web.
Yeah onReady
seems to be perfect 👍
My solution was a very hackish attempt for it to work ;) couldn't figure out how to place the emit inside the dropin.create
method. I'll see what I can do on my end get things going before an official release is out 👯
We're excited to be moving production over to braintree this weekend, so fingers crossed :)
from braintree-web.
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.
from braintree-web.
I have modified the code to now callback only after the initialize has been called.
And its now updated to 2.6.0!
Here's the gist for anyone who needs its.
https://gist.github.com/idl3/d20efa6d7a4c18110752
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
from braintree-web.
@idl3 thanks for taking the time to do that. We are working on implementing an official onReady
callback mechanism for an upcoming release. I'll be sure to post here when its out.
from braintree-web.
@idl3 thank you for your patience. We recently released version 2.7.0
which includes support for an onReady
callback. Using the example provided above, you can now do this:
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!
from braintree-web.
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
Now, I need to take the 2.7.0 put it on our repository and using that on our bower list. This only because you ship only the minified version here. It does not make sense for me.
from braintree-web.
Excellent, thank you very much! Please update the documentation, I was looking for this feature.
from braintree-web.
@chuchuva will do! Sorry it's taking longer than expected to get the new documentation out.
from braintree-web.
Awesome stuff :) Thanks for this!
from braintree-web.
Works very good, thanks!
from braintree-web.
Related Issues (20)
- Failed to execute 'postMessage' on 'Window' since yesterday (v2 braintree.js) HOT 1
- Hosted Fields backspace/delete not working on android HOT 1
- Safari don't show Google Pay button from time to time HOT 2
- TypeError: undefined is not an object (evaluating 'braintree_web__WEBPACK_IMPORTED_MODULE_12__.ApplePaySession.canMakePayments') HOT 1
- threeDSecure cardinal-sdk-setup-timeout HOT 6
- No callback function for loadPayPalSDK method HOT 3
- threeDSecure flow stops if Init request to cardinal fails HOT 5
- Hosted fields assets 404. HOT 3
- Upgrading to 3.98.0 hosted fields HOT 5
- ApplePay within an iframe HOT 7
- Support for text-fill-color styling in autofill styles HOT 1
- patch_payment_resource returns generic 422 on second request HOT 1
- Action required: Updates to required 3D Secure data fields HOT 1
- Request: Make commit messages meaningful HOT 1
- PayPal Button Integration not working on Production environment HOT 1
- Request: Include 3DS error codes in verifyPayload HOT 2
- Postal code validation does not work HOT 1
- Refused to display 'https://www.sandbox.paypal.com/' in a frame because it set 'X-Frame-Options' to 'sameorigin'." HOT 2
- Changes to Visa 3DS Data Requirements HOT 2
- Property 'updatePayment' does not exist on type 'PayPalCheckout' (braintree-web version: 3.102.0) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from braintree-web.