spree_gateway 3.7.2 → 3.7.3
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_elements.html.erb +79 -0
- data/spec/features/admin/stripe_elements_payment_spec.rb +99 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/capybara_helper.rb +15 -0
- metadata +7 -3
- data/gemfiles/spree_3_2.gemfile +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b832706f129c2b7908c038c47257bad79e6d85461dcbf7f8866d3826758d03be
|
4
|
+
data.tar.gz: a40bd794bba10b1e0d5607d9819f3380c8cdf6e75fff2e349babc89696a25cd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50776548c2b0c3c3e1dcd9558137f8b8967f0147fba3655f37ff9bce37b13209a3c41b550c2f9a9fb84e5cd6add08ab1cc091f8ca99b843c7794572a27cf25e1
|
7
|
+
data.tar.gz: b47c03b664274987c52660429a327596450c8fd6594c511a33596e19d7e776beb2dc46f2f9388eed710603c21050843c7362dad64b0383a3c69b5860d27ef056
|
@@ -0,0 +1,79 @@
|
|
1
|
+
<%= render "spree/admin/payments/source_forms/gateway", payment_method: payment_method, previous_cards: payment_method.reusable_sources(@order) %>
|
2
|
+
|
3
|
+
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
|
4
|
+
<script type="text/javascript">
|
5
|
+
Stripe.setPublishableKey("<%= payment_method.preferred_publishable_key %>");
|
6
|
+
</script>
|
7
|
+
|
8
|
+
<script>
|
9
|
+
var mapCC, stripeElementResponseHandler;
|
10
|
+
|
11
|
+
mapCC = function(ccType) {
|
12
|
+
if (ccType === 'MasterCard') {
|
13
|
+
return 'mastercard';
|
14
|
+
} else if (ccType === 'Visa') {
|
15
|
+
return 'visa';
|
16
|
+
} else if (ccType === 'American Express') {
|
17
|
+
return 'amex';
|
18
|
+
} else if (ccType === 'Discover') {
|
19
|
+
return 'discover';
|
20
|
+
} else if (ccType === 'Diners Club') {
|
21
|
+
return 'dinersclub';
|
22
|
+
} else if (ccType === 'JCB') {
|
23
|
+
return 'jcb';
|
24
|
+
}
|
25
|
+
};
|
26
|
+
stripeElementResponseHandler = function(status, response) {
|
27
|
+
var paymentMethodId, token;
|
28
|
+
if (response.error) {
|
29
|
+
$('#stripeError').html(response.error.message);
|
30
|
+
var param_map = {
|
31
|
+
number: '#card_number',
|
32
|
+
exp_month: '#card_expiry',
|
33
|
+
exp_year: '#card_expiry',
|
34
|
+
cvc: '#card_code'
|
35
|
+
}
|
36
|
+
if (response.error.param) {
|
37
|
+
errorField = Spree.stripeElementsPaymentMethod.find(param_map[response.error.param])
|
38
|
+
errorField.addClass('error');
|
39
|
+
errorField.parent().addClass('has-error');
|
40
|
+
}
|
41
|
+
return $('#stripeError').show();
|
42
|
+
} else {
|
43
|
+
Spree.stripeElementsPaymentMethod.find('#card_number<%= payment_method.id %>, #card_expiry<%= payment_method.id %>, #card_code<%= payment_method.id %>').prop("disabled", true);
|
44
|
+
Spree.stripeElementsPaymentMethod.find(".ccType").prop("disabled", false);
|
45
|
+
Spree.stripeElementsPaymentMethod.find(".ccType").val(mapCC(response.card.brand));
|
46
|
+
token = response['id'];
|
47
|
+
paymentMethodId = Spree.stripeElementsPaymentMethod.prop('id').split("_")[2];
|
48
|
+
Spree.stripeElementsPaymentMethod.append("<input type='hidden' class='stripeToken' name='payment_source[" + paymentMethodId + "][gateway_payment_profile_id]' value='" + token + "'/>");
|
49
|
+
Spree.stripeElementsPaymentMethod.append("<input type='hidden' class='stripeToken' name='payment_source[" + paymentMethodId + "][last_digits]' value='" + response.card.last4 + "'/>");
|
50
|
+
Spree.stripeElementsPaymentMethod.append("<input type='hidden' class='stripeToken' name='payment_source[" + paymentMethodId + "][month]' value='" + response.card.exp_month + "'/>");
|
51
|
+
Spree.stripeElementsPaymentMethod.append("<input type='hidden' class='stripeToken' name='payment_source[" + paymentMethodId + "][year]' value='" + response.card.exp_year + "'/>");
|
52
|
+
return Spree.stripeElementsPaymentMethod.parents("form").trigger('submit');
|
53
|
+
}
|
54
|
+
};
|
55
|
+
|
56
|
+
window.addEventListener('DOMContentLoaded', function() {
|
57
|
+
Spree.stripeElementsPaymentMethod = $('#payment_method_' + <%= payment_method.id %>);
|
58
|
+
|
59
|
+
Spree.ready(function() {
|
60
|
+
Spree.stripeElementsPaymentMethod.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.stripeElementsPaymentMethod.find('#card_number, #card_expiry, #card_code').removeClass('error');
|
65
|
+
if (Spree.stripeElementsPaymentMethod.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, stripeElementResponseHandler);
|
74
|
+
return false;
|
75
|
+
}
|
76
|
+
});
|
77
|
+
});
|
78
|
+
});
|
79
|
+
</script>
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Admin Panel Stripe elements payment', type: :feature, :js => true do
|
4
|
+
stub_authorization!
|
5
|
+
|
6
|
+
let!(:country) { create(:country, :states_required => true) }
|
7
|
+
let!(:state) { create(:state, :country => country) }
|
8
|
+
let!(:shipping_method) { create(:shipping_method) }
|
9
|
+
let!(:stock_location) { create(:stock_location) }
|
10
|
+
let!(:mug) { create(:product, :name => 'RoR Mug') }
|
11
|
+
let!(:zone) { create(:zone) }
|
12
|
+
let!(:stripe_elements_payment_method) do
|
13
|
+
Spree::Gateway::StripeElementsGateway.create!(
|
14
|
+
:name => 'Stripe Element',
|
15
|
+
:preferred_secret_key => 'sk_test_VCZnDv3GLU15TRvn8i2EsaAN',
|
16
|
+
:preferred_publishable_key => 'pk_test_Cuf0PNtiAkkMpTVC2gwYDMIg'
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
let!(:order) { OrderWalkthrough.up_to(:payment) }
|
21
|
+
before { visit spree.new_admin_order_payment_path(order.number) }
|
22
|
+
|
23
|
+
it 'can process a valid payment' do
|
24
|
+
fill_in_stripe_payment
|
25
|
+
wait_for { !page.has_current_path?(spree.admin_order_payments_path(order.number)) }
|
26
|
+
|
27
|
+
expect(page.body).to have_content('Payment has been successfully created!')
|
28
|
+
expect(page).to have_current_path spree.admin_order_payments_path(order.number)
|
29
|
+
end
|
30
|
+
|
31
|
+
if Spree.version.to_f >= 4.1
|
32
|
+
it 'shows an error with an invalid card name' do
|
33
|
+
fill_in_stripe_payment(true)
|
34
|
+
|
35
|
+
expect(page).to have_content("Credit card Name can't be blank")
|
36
|
+
expect(page).to have_current_path spree.admin_order_payments_path(order.number)
|
37
|
+
end
|
38
|
+
else
|
39
|
+
it 'can proces valid payment with invalid card name' do
|
40
|
+
fill_in_stripe_payment(true)
|
41
|
+
wait_for { !page.has_current_path?(spree.admin_order_payments_path(order.number)) }
|
42
|
+
|
43
|
+
expect(page.body).to have_content('Payment has been successfully created!')
|
44
|
+
expect(page).to have_current_path spree.admin_order_payments_path(order.number)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'shows an error with an invalid card number' do
|
49
|
+
fill_in_stripe_payment(false, true)
|
50
|
+
|
51
|
+
expect(page).to have_content('The card number is not a valid credit card number.')
|
52
|
+
expect(page).to have_current_path spree.new_admin_order_payment_path(order.number)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'shows an error with an invalid card code' do
|
56
|
+
fill_in_stripe_payment(false, false, true)
|
57
|
+
|
58
|
+
expect(page).to have_content("Your card's security code is invalid.")
|
59
|
+
expect(page).to have_current_path spree.new_admin_order_payment_path(order.number)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'shows an error with an invalid card expiration' do
|
63
|
+
fill_in_stripe_payment(false, false, false, true)
|
64
|
+
|
65
|
+
if Spree.version.to_f >= 4.1
|
66
|
+
expect(page).to have_content('Credit card Month is not a number')
|
67
|
+
expect(page).to have_content('Credit card Year is not a number')
|
68
|
+
expect(page).to have_current_path spree.admin_order_payments_path(order.number)
|
69
|
+
else
|
70
|
+
expect(page).to have_content("Your card's expiration year is invalid.")
|
71
|
+
expect(page).to have_current_path spree.new_admin_order_payment_path(order.number)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def fill_in_stripe_payment(invalid_name = false, invalid_number = false, invalid_code = false, invalid_expiration = false)
|
76
|
+
fill_in 'Name *', with: invalid_name ? '' : 'Stripe Elements Gateway Payment'
|
77
|
+
fill_in_card_number(invalid_number)
|
78
|
+
fill_in 'Card Code *', with: invalid_code ? '1' : '123'
|
79
|
+
fill_in_card_expiration(invalid_expiration)
|
80
|
+
|
81
|
+
click_button "Update"
|
82
|
+
end
|
83
|
+
|
84
|
+
def fill_in_card_number(invalid_number)
|
85
|
+
number = invalid_number ? '123' : '4242 4242 4242 4242'
|
86
|
+
fill_in_field('Card Number *', '#card_number1', number)
|
87
|
+
end
|
88
|
+
|
89
|
+
def fill_in_card_expiration(invalid_expiration)
|
90
|
+
card_expiry = invalid_expiration ? '01 / ' : "01 / #{Time.current.year + 1}"
|
91
|
+
fill_in_field('Expiration *', '#card_expiry1', card_expiry)
|
92
|
+
end
|
93
|
+
|
94
|
+
def fill_in_field(field_name, field_id, number)
|
95
|
+
until page.find(field_id).value == number
|
96
|
+
fill_in field_name, with: number
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -23,6 +23,7 @@ require 'spree/testing_support/factories'
|
|
23
23
|
require 'spree/testing_support/order_walkthrough'
|
24
24
|
require 'spree/testing_support/preferences'
|
25
25
|
require 'spree/testing_support/capybara_ext'
|
26
|
+
require 'spree/testing_support/authorization_helpers'
|
26
27
|
|
27
28
|
FactoryBot.find_definitions
|
28
29
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
if Spree.version.to_f < 3.7
|
2
|
+
module CapybaraHelper
|
3
|
+
def wait_for(options = {})
|
4
|
+
default_options = { error: nil, seconds: 5 }.merge(options)
|
5
|
+
|
6
|
+
Selenium::WebDriver::Wait.new(timeout: default_options[:seconds]).until { yield }
|
7
|
+
rescue Selenium::WebDriver::Error::TimeOutError
|
8
|
+
default_options[:error].nil? ? false : raise(default_options[:error])
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.include CapybaraHelper, type: :feature
|
14
|
+
end
|
15
|
+
end
|
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.7.
|
4
|
+
version: 3.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Spree Commerce
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: spree_core
|
@@ -410,7 +410,6 @@ files:
|
|
410
410
|
- db/migrate/20130415222802_update_balanced_payment_method_type.rb
|
411
411
|
- db/migrate/20131008221012_update_paypal_payment_method_type.rb
|
412
412
|
- db/migrate/20131112133401_migrate_stripe_preferences.rb
|
413
|
-
- gemfiles/spree_3_2.gemfile
|
414
413
|
- gemfiles/spree_3_5.gemfile
|
415
414
|
- gemfiles/spree_3_7.gemfile
|
416
415
|
- gemfiles/spree_4_0.gemfile
|
@@ -425,12 +424,14 @@ files:
|
|
425
424
|
- lib/views/backend/spree/admin/log_entries/_stripe.html.erb
|
426
425
|
- lib/views/backend/spree/admin/payments/source_forms/_quickcheckout.html.erb
|
427
426
|
- lib/views/backend/spree/admin/payments/source_forms/_stripe.html.erb
|
427
|
+
- lib/views/backend/spree/admin/payments/source_forms/_stripe_elements.html.erb
|
428
428
|
- lib/views/backend/spree/admin/payments/source_views/_stripe.html.erb
|
429
429
|
- lib/views/frontend/spree/checkout/payment/_stripe.html.erb
|
430
430
|
- lib/views/frontend/spree/checkout/payment/_stripe_additional_info.html.erb
|
431
431
|
- lib/views/frontend/spree/checkout/payment/_stripe_apple_pay.html.erb
|
432
432
|
- lib/views/frontend/spree/checkout/payment/_stripe_elements.html.erb
|
433
433
|
- script/rails
|
434
|
+
- spec/features/admin/stripe_elements_payment_spec.rb
|
434
435
|
- spec/features/stripe_checkout_spec.rb
|
435
436
|
- spec/models/gateway/authorize_net_cim_spec.rb
|
436
437
|
- spec/models/gateway/authorize_net_spec.rb
|
@@ -460,6 +461,7 @@ files:
|
|
460
461
|
- spec/models/spree/order_spec.rb
|
461
462
|
- spec/requests/apple_pay_domain_verification.rb
|
462
463
|
- spec/spec_helper.rb
|
464
|
+
- spec/support/capybara_helper.rb
|
463
465
|
- spec/support/wait_for_stripe.rb
|
464
466
|
- spree_gateway.gemspec
|
465
467
|
homepage: https://spreecommerce.org
|
@@ -487,6 +489,7 @@ signing_key:
|
|
487
489
|
specification_version: 4
|
488
490
|
summary: Additional Payment Gateways for Spree Commerce
|
489
491
|
test_files:
|
492
|
+
- spec/features/admin/stripe_elements_payment_spec.rb
|
490
493
|
- spec/features/stripe_checkout_spec.rb
|
491
494
|
- spec/models/gateway/authorize_net_cim_spec.rb
|
492
495
|
- spec/models/gateway/authorize_net_spec.rb
|
@@ -516,4 +519,5 @@ test_files:
|
|
516
519
|
- spec/models/spree/order_spec.rb
|
517
520
|
- spec/requests/apple_pay_domain_verification.rb
|
518
521
|
- spec/spec_helper.rb
|
522
|
+
- spec/support/capybara_helper.rb
|
519
523
|
- spec/support/wait_for_stripe.rb
|