|
| 1 | +<script type="text/javascript"> |
| 2 | + if(document.readyState !== 'loading') { |
| 3 | + setupBraintreePayPal() |
| 4 | + } else { |
| 5 | + window.addEventListener('DOMContentLoaded', setupBraintreePayPal); |
| 6 | + } |
| 7 | + |
| 8 | + function setupBraintreePayPal() { |
| 9 | + var payButton = document.getElementsByClassName('checkout-content-save-continue-button')[0]; |
| 10 | + |
| 11 | + braintree.setup("<%= payment_method.client_token(current_order) %>", "paypal", { |
| 12 | + headless: true, |
| 13 | + container: "paypal-container", |
| 14 | + singleUse: <%= payment_method.preferred_store_payments_in_vault.eql?('do_not_store') %>, |
| 15 | + amount: <%= @order.total %>, |
| 16 | + currency: "<%= current_currency %>", |
| 17 | + locale: "en_us", |
| 18 | + enableShippingAddress: false, |
| 19 | + enableBillingAddress: false, |
| 20 | + shippingAddressOverride: {}, //TODO: pass shipping address to PayPal |
| 21 | + displayName: "<%= payment_method.preferred_paypal_display_name %>", |
| 22 | + <% if payment_method.preferred_advanced_fraud_tools %> |
| 23 | + dataCollector: { |
| 24 | + kount: { |
| 25 | + environment: "<%= payment_method.preferred_server %>" |
| 26 | + <% if (kount_id = payment_method.preferred_kount_merchant_id).present? %> |
| 27 | + , |
| 28 | + merchantId: "<%= kount_id %>" |
| 29 | + <% end %> |
| 30 | + } |
| 31 | + }, |
| 32 | + <% end %> |
| 33 | + |
| 34 | + onReady: function (integration) { |
| 35 | + SpreeBraintreeVzero.deviceData = integration.deviceData; |
| 36 | + |
| 37 | + payButton.addEventListener('click', function(event) { |
| 38 | + event.preventDefault(); |
| 39 | + payButton.setAttribute('disabled', 'disabled'); |
| 40 | + |
| 41 | + integration.paypal.initAuthFlow(); |
| 42 | + }); |
| 43 | + }, |
| 44 | + |
| 45 | + onPaymentMethodReceived: function (result) { |
| 46 | + SpreeBraintreeVzero.addDeviceData(); |
| 47 | + |
| 48 | + //TODO: handle result - save nonce |
| 49 | + } |
| 50 | + }); |
| 51 | + } |
| 52 | +</script> |
0 commit comments