Skip to content

Commit

Permalink
Fix SpreeBraintreeVzero loading issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Damian Kaczmarczyk committed Apr 9, 2021
1 parent 346fd21 commit a4b9e06
Show file tree
Hide file tree
Showing 3 changed files with 240 additions and 216 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ SpreeBraintreeVzero = {
}
}

$(document).ready(function() {
$(document).ready(function () {
var event = new Event('spreebraintree:ready');
paymentMethods = $('div[data-hook="checkout_payment_step"] input[type="radio"]').click(function (e) {
SpreeBraintreeVzero.setSaveAndContinueVisibility();
});
Expand All @@ -65,4 +66,5 @@ $(document).ready(function() {
SpreeBraintreeVzero.addDeviceData();
});
SpreeBraintreeVzero.setSaveAndContinueVisibility();
window.dispatchEvent(event);
})
20 changes: 18 additions & 2 deletions app/views/spree/braintree_vzero/_paypal_checkout.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<script type="text/javascript">
// TODO: Investiagate what kind of checkout (if any) steps should be included during paypal express payment
window.addEventListener('DOMContentLoaded', function() {
function setupBraintreePayPal() {
var checkoutFormId = '#update-cart';
var checkout;
SpreeBraintreeVzero.checkoutFormId = '#update-cart';
Expand Down Expand Up @@ -82,6 +82,22 @@
}
});
document.querySelector('#btnOpenFlow').addEventListener('click', function () { checkout.paypal.initAuthFlow(); }, false);
});
}

if(document.readyState !== 'loading') {
initBraintreePayPal()
} else {
window.addEventListener('DOMContentLoaded', initBraintreePayPal);
}

function initBraintreePayPal() {
if (typeof SpreeBraintreeVzero === "undefined") {
window.addEventListener('spreebraintree:ready', setupBraintreePayPal)
}
else {
setupBraintreePayPal()
}
}

</script>
<% end %>
Loading

0 comments on commit a4b9e06

Please sign in to comment.