spree_gateway 3.6.7 → 3.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/spree_gateway/version.rb +1 -1
- data/lib/views/backend/spree/admin/payments/source_forms/_stripe.html.erb +22 -18
- data/lib/views/frontend/spree/checkout/payment/_stripe.html.erb +21 -19
- data/lib/views/frontend/spree/checkout/payment/_stripe_additional_info.html.erb +11 -9
- data/lib/views/frontend/spree/checkout/payment/_stripe_apple_pay.html.erb +12 -9
- data/lib/views/frontend/spree/checkout/payment/_stripe_elements.html.erb +17 -13
- data/spec/features/stripe_checkout_spec.rb +23 -18
- data/spec/spec_helper.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bf7f502de95f41992227df814d11998e447bfe6f302d5654e09f99240b023db
|
4
|
+
data.tar.gz: 38e633ffafb01bb31934dcdec4df4a9c6444f1c728e1f1d41a623f2ec9514689
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32dfea7c11e4a71f89a75bd092667c381d48b03611e857a86e3c11930100132c0f8d84a44288883d04c96a88557fe02aad27ce43600db56b93c3967ba2021d98
|
7
|
+
data.tar.gz: 9a1f8074d43f5feee5b128c8204edb8916f4eb975a0e3463f76e28e5d1a6825b3f79ba261c470a2039c3d1066fe0aa0337e0ea9ffde7e4c96111244316d79828
|
@@ -6,8 +6,8 @@
|
|
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,23 +53,27 @@
|
|
53
53
|
}
|
54
54
|
};
|
55
55
|
|
56
|
-
|
57
|
-
Spree.stripePaymentMethod
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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>
|
@@ -6,8 +6,6 @@
|
|
6
6
|
</script>
|
7
7
|
|
8
8
|
<script>
|
9
|
-
Spree.stripePaymentMethod = $('#payment_method_' + <%= payment_method.id %>);
|
10
|
-
|
11
9
|
var mapCC, stripeResponseHandler;
|
12
10
|
|
13
11
|
mapCC = function(ccType) {
|
@@ -57,23 +55,27 @@
|
|
57
55
|
}
|
58
56
|
};
|
59
57
|
|
60
|
-
|
61
|
-
Spree.stripePaymentMethod
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
58
|
+
window.addEventListener('DOMContentLoaded', function() {
|
59
|
+
Spree.stripePaymentMethod = $('#payment_method_' + <%= payment_method.id %>);
|
60
|
+
|
61
|
+
Spree.ready(function() {
|
62
|
+
Spree.stripePaymentMethod.prepend("<div id='stripeError' class='errorExplanation alert alert-danger' style='display:none'></div>");
|
63
|
+
return $('#checkout_form_payment [data-hook=buttons]').click(function() {
|
64
|
+
var expiration, params;
|
65
|
+
$('#stripeError').hide();
|
66
|
+
Spree.stripePaymentMethod.find('#card_number, #card_expiry, #card_code').removeClass('error');
|
67
|
+
if (Spree.stripePaymentMethod.is(':visible')) {
|
68
|
+
expiration = $('.cardExpiry:visible').payment('cardExpiryVal');
|
69
|
+
params = $.extend({
|
70
|
+
number: $('.cardNumber:visible').val(),
|
71
|
+
cvc: $('.cardCode:visible').val(),
|
72
|
+
exp_month: expiration.month || 0,
|
73
|
+
exp_year: expiration.year || 0
|
74
|
+
}, Spree.stripeAdditionalInfo);
|
75
|
+
Stripe.card.createToken(params, stripeResponseHandler);
|
76
|
+
return false;
|
77
|
+
}
|
78
|
+
});
|
77
79
|
});
|
78
80
|
});
|
79
81
|
</script>
|
@@ -1,14 +1,16 @@
|
|
1
1
|
<% bill_address ||= @order.bill_address %>
|
2
2
|
<%- if @order.has_checkout_step?('address') -%>
|
3
3
|
<script>
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
4
|
+
window.addEventListener('DOMContentLoaded', function() {
|
5
|
+
Spree.stripeAdditionalInfo = {
|
6
|
+
name: "<%= bill_address.full_name %>",
|
7
|
+
address_line1: "<%= bill_address.address1 %>",
|
8
|
+
address_line2: "<%= bill_address.address2 %>",
|
9
|
+
address_city: "<%= bill_address.city %>",
|
10
|
+
address_state: "<%= bill_address.state_text %>",
|
11
|
+
address_zip: "<%= bill_address.zipcode %>",
|
12
|
+
address_country: "<%= bill_address.country %>"
|
13
|
+
};
|
14
|
+
});
|
13
15
|
</script>
|
14
16
|
<%- end -%>
|
@@ -7,7 +7,6 @@
|
|
7
7
|
<script type="text/javascript" src="https://js.stripe.com/v3/"></script>
|
8
8
|
|
9
9
|
<script>
|
10
|
-
Spree.stripeApplePayPaymentMethod = $('#payment_method_' + <%= payment_method.id %>);
|
11
10
|
var stripeApplePay = Stripe("<%= payment_method.preferred_publishable_key %>");
|
12
11
|
var elements = stripeApplePay.elements();
|
13
12
|
|
@@ -82,14 +81,18 @@
|
|
82
81
|
form.submit();
|
83
82
|
});
|
84
83
|
|
85
|
-
|
86
|
-
Spree.stripeApplePayPaymentMethod
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
84
|
+
window.addEventListener('DOMContentLoaded', function() {
|
85
|
+
Spree.stripeApplePayPaymentMethod = $('#payment_method_' + <%= payment_method.id %>);
|
86
|
+
|
87
|
+
Spree.ready(function() {
|
88
|
+
Spree.stripeApplePayPaymentMethod.prepend("<div id='stripeApplePayError' class='errorExplanation alert alert-danger' style='display:none'></div>");
|
89
|
+
var form = document.getElementById('checkout_form_payment');
|
90
|
+
form.addEventListener('submit', function(e) {
|
91
|
+
if (Spree.stripeApplePayPaymentMethod.is(':visible')) {
|
92
|
+
$('#stripeApplePayError').hide();
|
93
|
+
e.preventDefault();
|
94
|
+
}
|
95
|
+
});
|
93
96
|
});
|
94
97
|
});
|
95
98
|
</script>
|
@@ -24,7 +24,6 @@
|
|
24
24
|
<script type="text/javascript" src="https://js.stripe.com/v3/"></script>
|
25
25
|
|
26
26
|
<script>
|
27
|
-
Spree.stripeElementsPaymentMethod = $('#payment_method_' + <%= payment_method.id %>);
|
28
27
|
var stripeElements = Stripe("<%= payment_method.preferred_publishable_key %>");
|
29
28
|
var elements = stripeElements.elements();
|
30
29
|
|
@@ -55,6 +54,22 @@
|
|
55
54
|
});
|
56
55
|
card.mount('#card-element');
|
57
56
|
|
57
|
+
window.addEventListener('DOMContentLoaded', function() {
|
58
|
+
Spree.stripeElementsPaymentMethod = $('#payment_method_' + <%= payment_method.id %>);
|
59
|
+
|
60
|
+
Spree.ready(function() {
|
61
|
+
Spree.stripeElementsPaymentMethod.prepend("<div id='stripeElementsError' class='errorExplanation alert alert-danger' style='display:none'></div>");
|
62
|
+
var form = document.getElementById('checkout_form_payment');
|
63
|
+
form.addEventListener('submit', function(e) {
|
64
|
+
if (Spree.stripeElementsPaymentMethod.is(':visible')) {
|
65
|
+
$('#stripeElementsError').hide();
|
66
|
+
e.preventDefault();
|
67
|
+
createStripeElementsToken();
|
68
|
+
}
|
69
|
+
});
|
70
|
+
});
|
71
|
+
});
|
72
|
+
|
58
73
|
function addCreditCardFieldToForm(form, name, value) {
|
59
74
|
var hiddenInput = document.createElement('input');
|
60
75
|
|
@@ -87,18 +102,7 @@
|
|
87
102
|
}
|
88
103
|
});
|
89
104
|
};
|
90
|
-
|
91
|
-
Spree.ready(function() {
|
92
|
-
Spree.stripeElementsPaymentMethod.prepend("<div id='stripeElementsError' class='errorExplanation alert alert-danger' style='display:none'></div>");
|
93
|
-
var form = document.getElementById('checkout_form_payment');
|
94
|
-
form.addEventListener('submit', function(e) {
|
95
|
-
if (Spree.stripeElementsPaymentMethod.is(':visible')) {
|
96
|
-
$('#stripeElementsError').hide();
|
97
|
-
e.preventDefault();
|
98
|
-
createStripeElementsToken();
|
99
|
-
}
|
100
|
-
});
|
101
|
-
});
|
105
|
+
|
102
106
|
</script>
|
103
107
|
|
104
108
|
<%= render 'spree/checkout/payment/stripe_additional_info' %>
|
@@ -29,6 +29,7 @@ describe "Stripe checkout", type: :feature do
|
|
29
29
|
Spree::CheckoutController.any_instance.stub(:current_order => order)
|
30
30
|
Spree::CheckoutController.any_instance.stub(:try_spree_current_user => user)
|
31
31
|
Spree::CheckoutController.any_instance.stub(:skip_state_validation? => true)
|
32
|
+
Spree::OrdersController.any_instance.stub(try_spree_current_user: user)
|
32
33
|
|
33
34
|
# Capybara should wait up to 10 seconds for async. changes to be applied
|
34
35
|
Capybara.default_max_wait_time = 10
|
@@ -42,34 +43,38 @@ describe "Stripe checkout", type: :feature do
|
|
42
43
|
|
43
44
|
# This will pass the CC data to the server and the StripeGateway class handles it
|
44
45
|
it "can process a valid payment (without JS)" do
|
45
|
-
fill_in
|
46
|
-
fill_in
|
47
|
-
fill_in
|
46
|
+
fill_in 'card_number', with: '4242 4242 4242 4242'
|
47
|
+
fill_in 'card_code', with: '123'
|
48
|
+
fill_in 'card_expiry', with: "01 / #{Time.current.year + 1}"
|
48
49
|
click_button "Save and Continue"
|
49
50
|
expect(page.current_url).to include("/checkout/confirm")
|
50
51
|
click_button "Place Order"
|
51
|
-
|
52
|
+
order = Spree::Order.complete.last
|
53
|
+
expect(page.current_url).to include("/orders/#{order.number}")
|
54
|
+
expect(page).to have_content(order.number)
|
52
55
|
end
|
53
56
|
|
54
57
|
# This will fetch a token from Stripe.com and then pass that to the webserver.
|
55
58
|
# The server then processes the payment using that token.
|
56
59
|
it "can process a valid payment (with JS)", :js => true do
|
57
|
-
fill_in
|
60
|
+
fill_in 'card_number', with: '4242 4242 4242 4242'
|
58
61
|
# Otherwise ccType field does not get updated correctly
|
59
62
|
page.execute_script("$('.cardNumber').trigger('change')")
|
60
|
-
fill_in
|
61
|
-
fill_in
|
63
|
+
fill_in 'card_code', with: '123'
|
64
|
+
fill_in 'card_expiry', with: "01 / #{Time.current.year + 1}"
|
62
65
|
click_button "Save and Continue"
|
63
66
|
wait_for_stripe # Wait for Stripe API to return + form to submit
|
64
67
|
expect(page).to have_css('#checkout_form_confirm')
|
65
68
|
expect(page.current_url).to include("/checkout/confirm")
|
66
69
|
click_button "Place Order"
|
67
|
-
|
70
|
+
order = Spree::Order.complete.last
|
71
|
+
expect(page.current_url).to include("/orders/#{order.number}")
|
72
|
+
expect(page).to have_content(order.number)
|
68
73
|
end
|
69
74
|
|
70
75
|
it "shows an error with an invalid credit card number", :js => true do
|
71
76
|
# Card number is NOT valid. Fails Luhn checksum
|
72
|
-
fill_in
|
77
|
+
fill_in 'card_number', with: '4242 4242 4242 4249'
|
73
78
|
click_button "Save and Continue"
|
74
79
|
wait_for_stripe
|
75
80
|
expect(page).to have_content("Your card number is incorrect")
|
@@ -77,9 +82,9 @@ describe "Stripe checkout", type: :feature do
|
|
77
82
|
end
|
78
83
|
|
79
84
|
it "shows an error with invalid security fields", :js => true do
|
80
|
-
fill_in
|
81
|
-
fill_in
|
82
|
-
fill_in
|
85
|
+
fill_in 'card_number', with: '4242 4242 4242 4242'
|
86
|
+
fill_in 'card_expiry', with: "01 / #{Time.current.year + 1}"
|
87
|
+
fill_in 'card_code', with: '99'
|
83
88
|
click_button "Save and Continue"
|
84
89
|
wait_for_stripe
|
85
90
|
expect(page).to have_content("Your card's security code is invalid.")
|
@@ -87,9 +92,9 @@ describe "Stripe checkout", type: :feature do
|
|
87
92
|
end
|
88
93
|
|
89
94
|
it "shows an error with invalid expiry month field", :js => true do
|
90
|
-
fill_in
|
91
|
-
fill_in
|
92
|
-
fill_in
|
95
|
+
fill_in 'card_number', with: '4242 4242 4242 4242'
|
96
|
+
fill_in 'card_expiry', :with => "00 / #{Time.now.year + 1}"
|
97
|
+
fill_in 'card_code', with: '123'
|
93
98
|
click_button "Save and Continue"
|
94
99
|
wait_for_stripe
|
95
100
|
expect(page).to have_content("Your card's expiration month is invalid.")
|
@@ -97,9 +102,9 @@ describe "Stripe checkout", type: :feature do
|
|
97
102
|
end
|
98
103
|
|
99
104
|
it "shows an error with invalid expiry year field", :js => true do
|
100
|
-
fill_in
|
101
|
-
fill_in
|
102
|
-
fill_in
|
105
|
+
fill_in 'card_number', with: '4242 4242 4242 4242'
|
106
|
+
fill_in 'card_expiry', with: '12 / '
|
107
|
+
fill_in 'card_code', with: '123'
|
103
108
|
click_button "Save and Continue"
|
104
109
|
wait_for_stripe
|
105
110
|
expect(page).to have_content("Your card's expiration year is invalid.")
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_gateway
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Spree Commerce
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: spree_core
|