spree_gateway 3.7.5 → 3.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,21 @@
1
+ <fieldset data-hook="bank_transfer">
2
+ <legend><%= Spree.t(:bank_transfer) %></legend>
3
+ <table class="table table-condensed table-bordered">
4
+ <tr>
5
+ <th width="20%"><%= Spree.t('stripe.ach.account_holder_name') %>:</th>
6
+ <td><%= payment.source.account_holder_name %></td>
7
+ </tr>
8
+ <tr>
9
+ <th><%= Spree.t('stripe.ach.account_holder_type') %>:</th>
10
+ <td><%= payment.source.account_holder_type %></td>
11
+ </tr>
12
+ <tr>
13
+ <th><%= Spree.t('stripe.ach.routing_number') %>:</th>
14
+ <td><%= payment.source.routing_number %></td>
15
+ </tr>
16
+ <tr>
17
+ <th><%= Spree.t('stripe.ach.account_number') %>:</th>
18
+ <td><%= payment.source.account_number %></td>
19
+ </tr>
20
+ </table>
21
+ </fieldset>
@@ -0,0 +1,81 @@
1
+ <div class="payment-gateway">
2
+ <% param_prefix = "payment_source[#{payment_method.id}]" %>
3
+ <div class="payment-gateway-half-fields">
4
+ <div class="mb-4 payment-gateway-field checkout-content-inner-field">
5
+ <%= text_field_tag "#{param_prefix}[account_holder_name]", "#{@order.bill_address_firstname} #{@order.bill_address_lastname}", { id: "account_holder_name", class: 'spree-flat-input', placeholder: Spree.t('stripe.ach.account_holder_name')} %>
6
+ </div>
7
+ <div class="mb-4 payment-gateway-field checkout-content-inner-field">
8
+ <%= select_tag "#{param_prefix}[account_holder_type]", options_for_select(%w(Individual Company)), {id: "account_holder_type", class: 'spree-flat-input', placeholder: Spree.t('stripe.ach.account_holder_type')} %>
9
+ </div>
10
+
11
+ <div class="mb-4 payment-gateway-field checkout-content-inner-field" data-hook="account_number">
12
+ <%= text_field_tag "#{param_prefix}[routing_number]", '', {id: 'routing_number', class: 'spree-flat-input', autocomplete: "off", placeholder: Spree.t('stripe.ach.routing_number'), maxlength: 9} %>
13
+ </div>
14
+ <div class="mb-4 payment-gateway-field checkout-content-inner-field" data-hook="account_number">
15
+ <%= text_field_tag "#{param_prefix}[account_number]", '', {id: 'account_number', class: 'spree-flat-input', autocomplete: "off", placeholder: Spree.t('stripe.ach.account_number')} %>
16
+ </div>
17
+ <div class="mb-4 payment-gateway-field checkout-content-inner-field" data-hook="account_number">
18
+ <%= text_field_tag "#{param_prefix}[verify_account_number]", '', {id: 'verify_account_number', class: 'spree-flat-input', autocomplete: "off", placeholder: Spree.t('stripe.ach.verify_account_number')} %>
19
+ </div>
20
+ </div>
21
+ </div>
22
+
23
+ <script type="text/javascript" src="https://js.stripe.com/v3/"></script>
24
+ <script type="text/javascript">
25
+ var stripe = Stripe("<%= payment_method.preferred_publishable_key %>");
26
+ </script>
27
+
28
+ <script>
29
+ stripeResponseHandler = function(response) {
30
+ var paymentMethodId, token, bank_acc_status;
31
+ if (response.error) {
32
+ $('#stripeError').html(response.error.message);
33
+ var param_map = {
34
+ account_holder_name: '#account_holder_name',
35
+ account_holder_type: '#account_holder_type',
36
+ account_number: '#account_number',
37
+ routing_number: '#routing_number'
38
+ }
39
+ if (response.error.param){
40
+ errorField = Spree.stripePaymentMethod.find(param_map[response.error.param])
41
+ errorField.addClass('error');
42
+ errorField.parent().addClass('has-error');
43
+ }
44
+ return $('#stripeError').show();
45
+ } else {
46
+ token = response.token['id'];
47
+ bank_acc_status = response.token.bank_account['status'];
48
+ paymentMethodId = Spree.stripePaymentMethod.prop('id').split("_")[2];
49
+ Spree.stripePaymentMethod.append("<input type='hidden' class='stripeToken' name='payment_source[" + paymentMethodId + "][gateway_payment_profile_id]' value='" + token + "'/>");
50
+ Spree.stripePaymentMethod.append("<input type='hidden' class='stripeStatus' name='payment_source[" + paymentMethodId + "][status]' value='" + bank_acc_status + "'/>")
51
+ return Spree.stripePaymentMethod.parents("form").trigger('submit');
52
+ }
53
+ };
54
+
55
+ window.addEventListener('DOMContentLoaded', function () {
56
+ Spree.stripePaymentMethod = $('#payment_method_' + <%= payment_method.id %>);
57
+ Spree.stripePaymentMethod.prepend("<div id='stripeError' class='errorExplanation alert alert-danger' style='display:none'></div>");
58
+
59
+ $('#checkout_form_payment [data-hook=buttons]').click(function (e) {
60
+ var params;
61
+ $('#stripeError').hide();
62
+ Spree.stripePaymentMethod.find('#account_holder_name, #account_holder_type, #account_number, #routing_number').removeClass('error');
63
+ if (Spree.stripePaymentMethod.is(':visible')) {
64
+ e.preventDefault();
65
+
66
+ params = $.extend({
67
+ country: 'US',
68
+ currency: 'usd',
69
+ account_holder_name: $('#account_holder_name:visible').val(),
70
+ account_holder_type: $('#account_holder_type:visible').val(),
71
+ routing_number: $('#routing_number:visible').val(),
72
+ account_number: $('#account_number:visible').val()
73
+ }, Spree.stripeAdditionalInfo);
74
+
75
+ stripe.createToken('bank_account', params).then(stripeResponseHandler);
76
+
77
+ return false;
78
+ }
79
+ });
80
+ });
81
+ </script>
@@ -0,0 +1,16 @@
1
+ <p class="payment-type checkout-content-header">
2
+ <%= Spree.t('stripe.ach.verify_bank_account').upcase %>
3
+ </p>
4
+
5
+ <div class="payment-gateway">
6
+ <div class="payment-gateway-half-fields">
7
+ <input type="hidden" name="order[payment_id]" value= <%= payment.id %> />
8
+ <input type='hidden' name='verifyAch' value=true />
9
+ <div class="mb-4 payment-gateway-field checkout-content-inner-field">
10
+ <%= number_field_tag "amounts[]", nil, { id: "deposit1", class: 'spree-flat-input', placeholder: Spree.t('stripe.ach.first_deposit') } %>
11
+ </div>
12
+ <div class="mb-4 payment-gateway-field checkout-content-inner-field">
13
+ <%= number_field_tag "amounts[]", nil, { id: "deposit2", class: 'spree-flat-input', placeholder: Spree.t('stripe.ach.second_deposit') } %>
14
+ </div>
15
+ </div>
16
+ </div>
@@ -0,0 +1,10 @@
1
+ FactoryBot.define do
2
+ factory :check, class: Spree::Check do
3
+ account_holder_name { 'John Doe' }
4
+ account_holder_type { 'Individual' }
5
+ account_type { 'checking' }
6
+ routing_number { '110000000' }
7
+ account_number { '000123456789' }
8
+ association(:payment_method, factory: :credit_card_payment_method)
9
+ end
10
+ end
@@ -75,10 +75,10 @@ describe 'Admin Panel Stripe elements payment', type: :feature, :js => true do
75
75
  def fill_in_stripe_payment(invalid_name = false, invalid_number = false, invalid_code = false, invalid_expiration = false)
76
76
  fill_in 'Name *', with: invalid_name ? '' : 'Stripe Elements Gateway Payment'
77
77
  fill_in_card_number(invalid_number)
78
- fill_in 'Card Code *', with: invalid_code ? '1' : '123'
78
+ fill_in_cvc(invalid_code)
79
79
  fill_in_card_expiration(invalid_expiration)
80
80
 
81
- click_button "Update"
81
+ click_button 'Update'
82
82
  end
83
83
 
84
84
  def fill_in_card_number(invalid_number)
@@ -87,10 +87,20 @@ describe 'Admin Panel Stripe elements payment', type: :feature, :js => true do
87
87
  end
88
88
 
89
89
  def fill_in_card_expiration(invalid_expiration)
90
- card_expiry = invalid_expiration ? '01 / ' : "01 / #{Time.current.year + 1}"
90
+ valid_expiry = Spree.version.to_f >= 4.2 ? "01/#{Time.current.year + 1}" : "01 / #{Time.current.year + 1}"
91
+ invalid_expiry = Spree.version.to_f >= 4.2 ? '01/' : '01 / '
92
+
93
+ card_expiry = invalid_expiration ? invalid_expiry : valid_expiry
91
94
  fill_in_field('Expiration *', '#card_expiry1', card_expiry)
92
95
  end
93
96
 
97
+ def fill_in_cvc(invalid_code)
98
+ value = invalid_code ? '1' : '123'
99
+ label = Spree.version.to_f >= 4.2 ? 'Card Varification Code (CVC) *' : 'Card Code *'
100
+
101
+ fill_in label, with: value
102
+ end
103
+
94
104
  def fill_in_field(field_name, field_id, number)
95
105
  until page.find(field_id).value == number
96
106
  fill_in field_name, with: number
@@ -91,7 +91,10 @@ describe "Stripe checkout", type: :feature do
91
91
  expect(page).to have_css('.has-error #card_code.error')
92
92
  end
93
93
 
94
+ # this scenario will not occur on Spree 4.2 due to swapping jquery.payment to cleave
95
+ # see https://github.com/spree/spree/pull/10363
94
96
  it "shows an error with invalid expiry month field", :js => true do
97
+ skip if Spree.version.to_f >= 4.2
95
98
  fill_in 'card_number', with: '4242 4242 4242 4242'
96
99
  fill_in 'card_expiry', :with => "00 / #{Time.now.year + 1}"
97
100
  fill_in 'card_code', with: '123'
@@ -0,0 +1,185 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Gateway::StripeAchGateway do
4
+ let(:secret_key) { 'key' }
5
+ let(:email) { 'customer@example.com' }
6
+ let(:source) { Spree::Check.new }
7
+ let(:payment) {
8
+ double('Spree::Payment',
9
+ source: source,
10
+ order: double('Spree::Order',
11
+ email: email,
12
+ bill_address: bill_address,
13
+ user: double('Spree::User',
14
+ email: email)
15
+ )
16
+ )
17
+ }
18
+ let(:provider) do
19
+ double('provider').tap do |p|
20
+ p.stub(:purchase)
21
+ p.stub(:authorize)
22
+ p.stub(:capture)
23
+ p.stub(:verify)
24
+ end
25
+ end
26
+
27
+ before do
28
+ subject.preferences = { secret_key: secret_key }
29
+ subject.stub(:options_for_purchase_or_auth).and_return(['money','check','opts'])
30
+ subject.stub(:provider).and_return provider
31
+ end
32
+
33
+ describe '#create_profile' do
34
+ before do
35
+ payment.source.stub(:update!)
36
+ end
37
+
38
+ context 'with an order that has a bill address' do
39
+ let(:bill_address) {
40
+ double('Spree::Address',
41
+ address1: '123 Happy Road',
42
+ address2: 'Apt 303',
43
+ city: 'Suzarac',
44
+ zipcode: '95671',
45
+ state: double('Spree::State', name: 'Oregon'),
46
+ country: double('Spree::Country', name: 'United States')
47
+ )
48
+ }
49
+
50
+ it 'stores the bill address with the provider' do
51
+ subject.provider.should_receive(:store).with(payment.source, {
52
+ email: email,
53
+ login: secret_key,
54
+
55
+ address: {
56
+ address1: '123 Happy Road',
57
+ address2: 'Apt 303',
58
+ city: 'Suzarac',
59
+ zip: '95671',
60
+ state: 'Oregon',
61
+ country: 'United States'
62
+ }
63
+ }).and_return double.as_null_object
64
+
65
+ subject.create_profile payment
66
+ end
67
+ end
68
+
69
+ context 'with an order that does not have a bill address' do
70
+ let(:bill_address) { nil }
71
+
72
+ it 'does not store a bill address with the provider' do
73
+ subject.provider.should_receive(:store).with(payment.source, {
74
+ email: email,
75
+ login: secret_key
76
+ }).and_return double.as_null_object
77
+
78
+ subject.create_profile payment
79
+ end
80
+
81
+ end
82
+
83
+ context 'with a check represents payment_profile' do
84
+ let(:source) { Spree::Check.new(gateway_payment_profile_id: 'tok_profileid') }
85
+ let(:bill_address) { nil }
86
+
87
+ it 'stores the profile_id as a check' do
88
+ subject.provider.should_receive(:store).with(source.gateway_payment_profile_id, anything).and_return double.as_null_object
89
+
90
+ subject.create_profile payment
91
+ end
92
+ end
93
+ end
94
+
95
+ context 'purchasing' do
96
+ after do
97
+ subject.purchase(19.99, 'check', {})
98
+ end
99
+
100
+ it 'send the payment to the provider' do
101
+ provider.should_receive(:purchase).with('money', 'check', 'opts')
102
+ end
103
+ end
104
+
105
+ context 'authorizing' do
106
+ after do
107
+ subject.authorize(19.99, 'check', {})
108
+ end
109
+
110
+ it 'send the authorization to the provider' do
111
+ provider.should_receive(:authorize).with('money', 'check', 'opts')
112
+ end
113
+ end
114
+
115
+ context 'verifying' do
116
+ after do
117
+ subject.verify(source, {})
118
+ end
119
+
120
+ it 'send the verify to the provider' do
121
+ provider.should_receive(:verify).with(source, anything)
122
+ end
123
+ end
124
+
125
+ context 'capturing' do
126
+
127
+ after do
128
+ subject.capture(1234, 'response_code', {})
129
+ end
130
+
131
+ it 'convert the amount to cents' do
132
+ provider.should_receive(:capture).with(1234, anything, anything)
133
+ end
134
+
135
+ it 'use the response code as the authorization' do
136
+ provider.should_receive(:capture).with(anything, 'response_code', anything)
137
+ end
138
+ end
139
+
140
+ context 'capture with payment class' do
141
+ let(:gateway) do
142
+ gateway = described_class.new(active: true)
143
+ gateway.set_preference :secret_key, secret_key
144
+ gateway.stub(:options_for_purchase_or_auth).and_return(['money', 'check', 'opts'])
145
+ gateway.stub(:provider).and_return provider
146
+ gateway.stub source_required: true
147
+ gateway
148
+ end
149
+
150
+ let(:order) { Spree::Order.create }
151
+
152
+ let(:check) do
153
+ # mock_model(Spree::Check, :gateway_customer_profile_id => 'cus_abcde',
154
+ # :imported => false)
155
+ create :check, gateway_customer_profile_id: 'cus_abcde', imported: false
156
+ end
157
+
158
+ let(:payment) do
159
+ payment = Spree::Payment.new
160
+ payment.source = check
161
+ payment.order = order
162
+ payment.payment_method = gateway
163
+ payment.amount = 98.55
164
+ payment.state = 'pending'
165
+ payment.response_code = '12345'
166
+ payment
167
+ end
168
+
169
+ after do
170
+ payment.capture!
171
+ end
172
+
173
+ let!(:success_response) do
174
+ double('success_response',
175
+ success?: true,
176
+ authorization: '123',
177
+ avs_result: { 'code' => 'avs-code' },
178
+ cvv_result: { 'code' => 'cvv-code', 'message' => 'CVV Result' })
179
+ end
180
+
181
+ it 'gets correct amount' do
182
+ provider.should_receive(:capture).with(9855, '12345', anything).and_return(success_response)
183
+ end
184
+ end
185
+ end
@@ -1,68 +1,10 @@
1
- require 'simplecov'
2
- SimpleCov.start 'rails'
1
+ # Configure Rails Environment
2
+ ENV['RAILS_ENV'] = 'test'
3
3
 
4
- ENV["RAILS_ENV"] = "test"
4
+ require File.expand_path('../dummy/config/environment.rb', __FILE__)
5
5
 
6
- require File.expand_path("../dummy/config/environment.rb", __FILE__)
6
+ require 'spree_dev_tools/rspec/spec_helper'
7
7
 
8
- require 'rspec/rails'
9
- require 'rspec/active_model/mocks'
10
- require 'capybara/rspec'
11
- require 'capybara/rails'
12
- require 'capybara-screenshot/rspec'
13
- require "selenium-webdriver"
14
- require 'webdrivers'
15
- require 'database_cleaner'
16
- require 'ffaker'
17
- require 'rspec/active_model/mocks'
18
- require 'pry'
19
-
20
- Dir[File.join(File.dirname(__FILE__), "support", "**", "*.rb")].each { |f| require f }
21
-
22
- require 'spree/testing_support/factories'
23
- require 'spree/testing_support/order_walkthrough'
24
- require 'spree/testing_support/preferences'
25
- require 'spree/testing_support/capybara_ext'
26
- require 'spree/testing_support/authorization_helpers'
27
-
28
- FactoryBot.find_definitions
29
-
30
- RSpec.configure do |config|
31
- config.infer_spec_type_from_file_location!
32
- config.mock_with :rspec do |mock|
33
- mock.syntax = [:should, :expect]
34
- end
35
- config.raise_errors_for_deprecations!
36
- config.use_transactional_fixtures = false
37
- #config.filter_run focus: true
38
- #config.filter_run_excluding slow: true
39
-
40
- config.include FactoryBot::Syntax::Methods
41
- config.include Spree::TestingSupport::Preferences
42
-
43
- config.before :suite do
44
- DatabaseCleaner.strategy = :transaction
45
- DatabaseCleaner.clean_with :truncation
46
- end
47
-
48
- config.before do
49
- DatabaseCleaner.strategy = RSpec.current_example.metadata[:js] ? :truncation : :transaction
50
- DatabaseCleaner.start
51
- reset_spree_preferences
52
- create(:store)
53
- end
54
-
55
- config.after do
56
- DatabaseCleaner.clean
57
- end
58
-
59
- Capybara.register_driver :chrome do |app|
60
- Capybara::Selenium::Driver.new app,
61
- browser: :chrome,
62
- options: Selenium::WebDriver::Chrome::Options.new(
63
- args: %w[no-sandbox disable-dev-shm-usage disable-popup-blocking headless disable-gpu window-size=1920,1080 --enable-features=NetworkService,NetworkServiceInProcess --disable-features=VizDisplayCompositor],
64
- log_level: :error
65
- )
66
- end
67
- Capybara.javascript_driver = :chrome
68
- end
8
+ # Requires supporting ruby files with custom matchers and macros, etc,
9
+ # in spec/support/ and its subdirectories.
10
+ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].sort.each { |f| require f }
@@ -25,26 +25,7 @@ Gem::Specification.new do |s|
25
25
  s.add_dependency 'spree_core', spree_version
26
26
  s.add_dependency 'spree_extension'
27
27
 
28
- s.add_development_dependency 'appraisal'
29
- s.add_development_dependency 'bootstrap-sass'
30
28
  s.add_development_dependency 'braintree'
31
- s.add_development_dependency 'capybara'
32
- s.add_development_dependency 'capybara-screenshot'
33
- s.add_development_dependency 'coffee-rails'
34
- s.add_development_dependency 'database_cleaner'
35
- s.add_development_dependency 'factory_bot', '~> 4.7'
36
- s.add_development_dependency 'ffaker'
37
- s.add_development_dependency 'guard-rspec'
38
- s.add_development_dependency 'launchy'
39
- s.add_development_dependency 'mysql2'
40
- s.add_development_dependency 'pg'
41
- s.add_development_dependency 'pry'
42
- s.add_development_dependency 'puma'
43
29
  s.add_development_dependency 'rspec-activemodel-mocks'
44
- s.add_development_dependency 'rspec-rails'
45
- s.add_development_dependency 'sass-rails'
46
- s.add_development_dependency 'selenium-webdriver'
47
- s.add_development_dependency 'webdrivers'
48
- s.add_development_dependency 'simplecov'
49
- s.add_development_dependency 'sqlite3'
30
+ s.add_development_dependency 'spree_dev_tools'
50
31
  end