Skip to content

Commit 3858aa6

Browse files
authored
Added braintree.js onload callback to prevent braintree not defined error (spree-contrib#254)
1 parent 02a32e1 commit 3858aa6

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

app/views/spree/braintree_vzero/_paypal_checkout.html.erb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<img src="https://www.paypalobjects.com/en_US/i/btn/btn_xpressCheckout.gif" id="btnOpenFlow">
55
</div>
66

7-
<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
7+
<script src="https://js.braintreegateway.com/v2/braintree.js" onload="braintreeLoaded()"></script>
88
<script src="https://js.braintreegateway.com/js/braintree-2.32.1.min.js"></script>
99

1010
<script type="text/javascript">
@@ -84,10 +84,12 @@
8484
document.querySelector('#btnOpenFlow').addEventListener('click', function () { checkout.paypal.initAuthFlow(); }, false);
8585
}
8686

87-
if(document.readyState !== 'loading') {
88-
initBraintreePayPal()
89-
} else {
90-
window.addEventListener('DOMContentLoaded', initBraintreePayPal);
87+
function braintreeLoaded () {
88+
if(document.readyState !== 'loading') {
89+
initBraintreePayPal()
90+
} else {
91+
window.addEventListener('DOMContentLoaded', initBraintreePayPal);
92+
}
9193
}
9294

9395
function initBraintreePayPal() {

0 commit comments

Comments
 (0)