Skip to content

Commit c250080

Browse files
Merge pull request #341 from spark-solutions/SD-464
[SD-464] Fix Stripe JS for Spree 4.1
2 parents da95249 + 3193b63 commit c250080

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

lib/views/backend/spree/admin/payments/source_forms/_stripe.html.erb

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
</script>
77

88
<script>
9-
Spree.stripePaymentMethod = $('#payment_method_' + <%= payment_method.id %>);
109
var mapCC, stripeResponseHandler;
10+
1111
mapCC = function(ccType) {
1212
if (ccType === 'MasterCard') {
1313
return 'mastercard';
@@ -53,23 +53,27 @@
5353
}
5454
};
5555

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+
});
7377
});
7478
});
7579
</script>

0 commit comments

Comments
 (0)