diff --git a/app/assets/javascripts/solidus_paypal_braintree/checkout.js b/app/assets/javascripts/solidus_paypal_braintree/checkout.js index a0e24df0..83a0a510 100644 --- a/app/assets/javascripts/solidus_paypal_braintree/checkout.js +++ b/app/assets/javascripts/solidus_paypal_braintree/checkout.js @@ -105,4 +105,16 @@ $(function() { $.when.apply($, fieldPromises).done(enableSubmit); } + + var $paypalButton = $("#paypal-button"); + if ($paypalButton.length > 0) { + var button = new SolidusPaypalBraintree.createPaypalButton($paypalButton[0], paypalOptions, (typeof options === 'undefined') ? {} : options); + button.initialize(); + } + + var $applePayButton = $('#apple-pay-button'); + if ($applePayButton.length > 0) { + var button = new SolidusPaypalBraintree.createApplePayButton($applePayButton[0], applePayOptions); + button.initialize(); + } }); diff --git a/app/assets/javascripts/solidus_paypal_braintree/constants.js b/app/assets/javascripts/solidus_paypal_braintree/constants.js index 450873c1..f35e82d2 100644 --- a/app/assets/javascripts/solidus_paypal_braintree/constants.js +++ b/app/assets/javascripts/solidus_paypal_braintree/constants.js @@ -68,14 +68,3 @@ SolidusPaypalBraintree = { return new (Function.prototype.bind.apply(klass, [null].concat(normalizedArgs))); } }; - -BraintreeError = { - DEFAULT: "Something bad happened!", - - getErrorFromSlug: function(slug) { - error = BraintreeError.DEFAULT - if (slug in BraintreeError) - error = BraintreeError[slug] - return error - } -} diff --git a/app/views/spree/shared/_apple_pay_button.html.erb b/app/views/spree/shared/_apple_pay_button.html.erb index affe669b..b3efeb70 100644 --- a/app/views/spree/shared/_apple_pay_button.html.erb +++ b/app/views/spree/shared/_apple_pay_button.html.erb @@ -3,7 +3,6 @@ diff --git a/app/views/spree/shared/_braintree_errors.html.erb b/app/views/spree/shared/_braintree_errors.html.erb index 791a39c7..edea4b5b 100644 --- a/app/views/spree/shared/_braintree_errors.html.erb +++ b/app/views/spree/shared/_braintree_errors.html.erb @@ -1,13 +1,22 @@ diff --git a/app/views/spree/shared/_paypal_braintree_head_scripts.html.erb b/app/views/spree/shared/_paypal_braintree_head_scripts.html.erb index cfd20fc6..91935b66 100644 --- a/app/views/spree/shared/_paypal_braintree_head_scripts.html.erb +++ b/app/views/spree/shared/_paypal_braintree_head_scripts.html.erb @@ -1,22 +1,22 @@ <% content_for :head do %> - - + + <% if current_store.braintree_configuration.paypal? %> - + <% end %> <% if current_store.braintree_configuration.credit_card? %> - + <% if current_store.braintree_configuration.three_d_secure? %> - + <% end %> <% end %> <% if current_store.braintree_configuration.apple_pay? %> - + <% end %> - <%= javascript_include_tag "solidus_paypal_braintree/checkout" %> + <%= javascript_include_tag "solidus_paypal_braintree/checkout", async: true %> <% end %> diff --git a/app/views/spree/shared/_paypal_cart_button.html.erb b/app/views/spree/shared/_paypal_cart_button.html.erb index 091a7237..0b38651b 100644 --- a/app/views/spree/shared/_paypal_cart_button.html.erb +++ b/app/views/spree/shared/_paypal_cart_button.html.erb @@ -3,6 +3,8 @@
+<%= render "spree/shared/braintree_errors" %> + diff --git a/lib/views/frontend/spree/shared/_paypal_checkout_button.html.erb b/lib/views/frontend/spree/shared/_paypal_checkout_button.html.erb index 38427961..f10957f1 100644 --- a/lib/views/frontend/spree/shared/_paypal_checkout_button.html.erb +++ b/lib/views/frontend/spree/shared/_paypal_checkout_button.html.erb @@ -24,7 +24,4 @@ messaging: '<%= paypal_button_preference(:paypal_button_messaging, store: current_store) %>' } } - - var button = new SolidusPaypalBraintree.createPaypalButton(document.querySelector("#paypal-button"), paypalOptions); - button.initialize();