|
6 | 6 | </script> |
7 | 7 |
|
8 | 8 | <script> |
9 | | - Spree.stripePaymentMethod = $('#payment_method_' + <%= payment_method.id %>); |
10 | 9 | var mapCC, stripeResponseHandler; |
| 10 | + |
11 | 11 | mapCC = function(ccType) { |
12 | 12 | if (ccType === 'MasterCard') { |
13 | 13 | return 'mastercard'; |
|
53 | 53 | } |
54 | 54 | }; |
55 | 55 |
|
56 | | - Spree.ready(function() { |
57 | | - Spree.stripePaymentMethod.prepend("<div id='stripeError' class='errorExplanation alert alert-danger' style='display:none'></div>"); |
58 | | - return $('#new_payment [data-hook=buttons]').click(function() { |
59 | | - var expiration, params; |
60 | | - $('#stripeError').hide(); |
61 | | - Spree.stripePaymentMethod.find('#card_number, #card_expiry, #card_code').removeClass('error'); |
62 | | - if (Spree.stripePaymentMethod.is(':visible')) { |
63 | | - expiration = $('.cardExpiry:visible').payment('cardExpiryVal'); |
64 | | - params = $.extend({ |
65 | | - number: $('.cardNumber:visible').val(), |
66 | | - cvc: $('.cardCode:visible').val(), |
67 | | - exp_month: expiration.month || 0, |
68 | | - exp_year: expiration.year || 0 |
69 | | - }, Spree.stripeAdditionalInfo); |
70 | | - Stripe.card.createToken(params, stripeResponseHandler); |
71 | | - return false; |
72 | | - } |
| 56 | + window.addEventListener('DOMContentLoaded', function() { |
| 57 | + Spree.stripePaymentMethod = $('#payment_method_' + <%= payment_method.id %>); |
| 58 | + |
| 59 | + Spree.ready(function() { |
| 60 | + Spree.stripePaymentMethod.prepend("<div id='stripeError' class='errorExplanation alert alert-danger' style='display:none'></div>"); |
| 61 | + return $('#new_payment [data-hook=buttons]').click(function() { |
| 62 | + var expiration, params; |
| 63 | + $('#stripeError').hide(); |
| 64 | + Spree.stripePaymentMethod.find('#card_number, #card_expiry, #card_code').removeClass('error'); |
| 65 | + if (Spree.stripePaymentMethod.is(':visible')) { |
| 66 | + expiration = $('.cardExpiry:visible').payment('cardExpiryVal'); |
| 67 | + params = $.extend({ |
| 68 | + number: $('.cardNumber:visible').val(), |
| 69 | + cvc: $('.cardCode:visible').val(), |
| 70 | + exp_month: expiration.month || 0, |
| 71 | + exp_year: expiration.year || 0 |
| 72 | + }, Spree.stripeAdditionalInfo); |
| 73 | + Stripe.card.createToken(params, stripeResponseHandler); |
| 74 | + return false; |
| 75 | + } |
| 76 | + }); |
73 | 77 | }); |
74 | 78 | }); |
75 | 79 | </script> |
0 commit comments