archetype_spree_gateway 3.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +39 -0
  5. data/Gemfile +9 -0
  6. data/Guardfile +9 -0
  7. data/LICENSE.md +26 -0
  8. data/README.md +105 -0
  9. data/Rakefile +15 -0
  10. data/app/models/spree/billing_integration.rb +21 -0
  11. data/app/models/spree/check.rb +41 -0
  12. data/app/models/spree/gateway/authorize_net.rb +45 -0
  13. data/app/models/spree/gateway/authorize_net_cim.rb +213 -0
  14. data/app/models/spree/gateway/balanced_gateway.rb +64 -0
  15. data/app/models/spree/gateway/banwire.rb +15 -0
  16. data/app/models/spree/gateway/beanstream.rb +193 -0
  17. data/app/models/spree/gateway/braintree_gateway.rb +184 -0
  18. data/app/models/spree/gateway/card_save.rb +10 -0
  19. data/app/models/spree/gateway/cyber_source.rb +10 -0
  20. data/app/models/spree/gateway/data_cash.rb +10 -0
  21. data/app/models/spree/gateway/epay.rb +10 -0
  22. data/app/models/spree/gateway/eway.rb +18 -0
  23. data/app/models/spree/gateway/eway_rapid.rb +14 -0
  24. data/app/models/spree/gateway/maxipago.rb +14 -0
  25. data/app/models/spree/gateway/migs.rb +11 -0
  26. data/app/models/spree/gateway/moneris.rb +10 -0
  27. data/app/models/spree/gateway/pay_junction.rb +14 -0
  28. data/app/models/spree/gateway/pay_pal_gateway.rb +12 -0
  29. data/app/models/spree/gateway/payflow_pro.rb +15 -0
  30. data/app/models/spree/gateway/paymill.rb +12 -0
  31. data/app/models/spree/gateway/payu_polska_gateway.rb +24 -0
  32. data/app/models/spree/gateway/pin_gateway.rb +60 -0
  33. data/app/models/spree/gateway/quickpay.rb +9 -0
  34. data/app/models/spree/gateway/sage_pay.rb +11 -0
  35. data/app/models/spree/gateway/secure_pay_au.rb +10 -0
  36. data/app/models/spree/gateway/spreedly_core_gateway.rb +11 -0
  37. data/app/models/spree/gateway/stripe_ach_gateway.rb +60 -0
  38. data/app/models/spree/gateway/stripe_apple_pay_gateway.rb +10 -0
  39. data/app/models/spree/gateway/stripe_elements_gateway.rb +61 -0
  40. data/app/models/spree/gateway/stripe_gateway.rb +151 -0
  41. data/app/models/spree/gateway/usa_epay_transaction.rb +9 -0
  42. data/app/models/spree/gateway/worldpay.rb +91 -0
  43. data/app/models/spree/payu_polska.rb +41 -0
  44. data/app/models/spree_gateway/apple_pay_order_decorator.rb +20 -0
  45. data/app/models/spree_gateway/apple_pay_payment_decorator.rb +9 -0
  46. data/app/models/spree_gateway/credit_card_decorator.rb +10 -0
  47. data/app/models/spree_gateway/order_decorator.rb +28 -0
  48. data/app/models/spree_gateway/payment_decorator.rb +36 -0
  49. data/app/views/spree/checkout/_payment_confirm.html.erb +39 -0
  50. data/app/views/spree/checkout/_payu.html +12 -0
  51. data/config/initializers/inflections.rb +3 -0
  52. data/config/initializers/spree_permitted_attributes.rb +5 -0
  53. data/config/locales/bg.yml +4 -0
  54. data/config/locales/de.yml +4 -0
  55. data/config/locales/en.yml +47 -0
  56. data/config/locales/sv.yml +4 -0
  57. data/config/routes.rb +19 -0
  58. data/db/migrate/20200317135551_add_spree_check_payment_source.rb +22 -0
  59. data/db/migrate/20200422114908_add_intent_key_to_payment.rb +5 -0
  60. data/lib/active_merchant/billing/stripe_gateway_decorator.rb +33 -0
  61. data/lib/controllers/spree/api/v2/storefront/intents_controller.rb +45 -0
  62. data/lib/controllers/spree/apple_pay_domain_verification_controller.rb +11 -0
  63. data/lib/generators/spree_gateway/install/install_generator.rb +19 -0
  64. data/lib/spree_frontend/controllers/spree/checkout_controller_decorator.rb +19 -0
  65. data/lib/spree_gateway/engine.rb +80 -0
  66. data/lib/spree_gateway/version.rb +5 -0
  67. data/lib/spree_gateway.rb +4 -0
  68. data/lib/views/backend/spree/admin/log_entries/_braintree.html.erb +31 -0
  69. data/lib/views/backend/spree/admin/log_entries/_stripe.html.erb +28 -0
  70. data/lib/views/backend/spree/admin/payments/source_forms/_quickcheckout.html.erb +8 -0
  71. data/lib/views/backend/spree/admin/payments/source_forms/_stripe.html.erb +79 -0
  72. data/lib/views/backend/spree/admin/payments/source_forms/_stripe_ach.html.erb +86 -0
  73. data/lib/views/backend/spree/admin/payments/source_forms/_stripe_apple_pay.html.erb +0 -0
  74. data/lib/views/backend/spree/admin/payments/source_forms/_stripe_elements.html.erb +79 -0
  75. data/lib/views/backend/spree/admin/payments/source_views/_stripe.html.erb +1 -0
  76. data/lib/views/backend/spree/admin/payments/source_views/_stripe_ach.html.erb +21 -0
  77. data/lib/views/backend/spree/admin/payments/source_views/_stripe_apple_pay.html.erb +1 -0
  78. data/lib/views/backend/spree/admin/payments/source_views/_stripe_elements.html.erb +1 -0
  79. data/lib/views/frontend/spree/checkout/payment/_stripe.html.erb +86 -0
  80. data/lib/views/frontend/spree/checkout/payment/_stripe_ach.html.erb +81 -0
  81. data/lib/views/frontend/spree/checkout/payment/_stripe_ach_verify.html.erb +16 -0
  82. data/lib/views/frontend/spree/checkout/payment/_stripe_additional_info.html.erb +16 -0
  83. data/lib/views/frontend/spree/checkout/payment/_stripe_apple_pay.html.erb +109 -0
  84. data/lib/views/frontend/spree/checkout/payment/_stripe_elements.html.erb +110 -0
  85. data/script/rails +7 -0
  86. data/spec/factories/check_factory.rb +10 -0
  87. data/spec/features/admin/stripe_elements_payment_spec.rb +100 -0
  88. data/spec/features/stripe_checkout_spec.rb +130 -0
  89. data/spec/features/stripe_elements_3ds_checkout_spec.rb +225 -0
  90. data/spec/models/gateway/authorize_net_cim_spec.rb +29 -0
  91. data/spec/models/gateway/authorize_net_spec.rb +23 -0
  92. data/spec/models/gateway/balanced_gateway_spec.rb +17 -0
  93. data/spec/models/gateway/banwire_spec.rb +11 -0
  94. data/spec/models/gateway/beanstream_spec.rb +17 -0
  95. data/spec/models/gateway/braintree_gateway_spec.rb +420 -0
  96. data/spec/models/gateway/card_save_spec.rb +11 -0
  97. data/spec/models/gateway/cyber_source_spec.rb +11 -0
  98. data/spec/models/gateway/data_cash_spec.rb +11 -0
  99. data/spec/models/gateway/epay_spec.rb +11 -0
  100. data/spec/models/gateway/eway_rapid_spec.rb +23 -0
  101. data/spec/models/gateway/eway_spec.rb +29 -0
  102. data/spec/models/gateway/maxipago_spec.rb +17 -0
  103. data/spec/models/gateway/moneris_spec.rb +11 -0
  104. data/spec/models/gateway/pay_junction_spec.rb +23 -0
  105. data/spec/models/gateway/pay_pal_spec.rb +11 -0
  106. data/spec/models/gateway/payflow_pro_spec.rb +23 -0
  107. data/spec/models/gateway/paymill_spec.rb +11 -0
  108. data/spec/models/gateway/pin_gateway_spec.rb +54 -0
  109. data/spec/models/gateway/quickpay_spec.rb +11 -0
  110. data/spec/models/gateway/sage_pay_spec.rb +11 -0
  111. data/spec/models/gateway/secure_pay_au_spec.rb +11 -0
  112. data/spec/models/gateway/stripe_ach_gateway_spec.rb +186 -0
  113. data/spec/models/gateway/stripe_gateway_spec.rb +199 -0
  114. data/spec/models/gateway/usa_epay_transaction_spec.rb +49 -0
  115. data/spec/models/gateway/worldpay_spec.rb +11 -0
  116. data/spec/models/spree/order_spec.rb +79 -0
  117. data/spec/requests/apple_pay_domain_verification.rb +45 -0
  118. data/spec/requests/spree/api/v2/storefront/intents_controller_spec.rb +198 -0
  119. data/spec/spec_helper.rb +10 -0
  120. data/spec/support/order_walktrough.rb +73 -0
  121. data/spec/support/wait_for_stripe.rb +27 -0
  122. data/spec/support/within_stripe_3ds_popup.rb +10 -0
  123. data/spree_gateway.gemspec +37 -0
  124. metadata +277 -0
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Gateway::Quickpay do
4
+ let(:gateway) { described_class.create!(name: 'QuickpayGateway', stores: [::Spree::Store.default]) }
5
+
6
+ context '.provider_class' do
7
+ it 'is a Quickpay gateway' do
8
+ expect(gateway.provider_class).to eq ::ActiveMerchant::Billing::QuickpayV10Gateway
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Gateway::SagePay do
4
+ let(:gateway) { described_class.create!(name: 'SagePay', stores: [::Spree::Store.default]) }
5
+
6
+ context '.provider_class' do
7
+ it 'is a SagePay gateway' do
8
+ expect(gateway.provider_class).to eq ::ActiveMerchant::Billing::SagePayGateway
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Gateway::SecurePayAU do
4
+ let(:gateway) { described_class.create!(name: 'SecurePayAU', stores: [::Spree::Store.default]) }
5
+
6
+ context '.provider_class' do
7
+ it 'is a SecurePayAU gateway' do
8
+ expect(gateway.provider_class).to eq ::ActiveMerchant::Billing::SecurePayAuGateway
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,186 @@
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
+ params: {})
180
+ end
181
+
182
+ it 'gets correct amount' do
183
+ provider.should_receive(:capture).with(9855, '12345', anything).and_return(success_response)
184
+ end
185
+ end
186
+ end
@@ -0,0 +1,199 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Gateway::StripeGateway do
4
+ let(:secret_key) { 'key' }
5
+ let(:email) { 'customer@example.com' }
6
+ let(:source) { Spree::CreditCard.new }
7
+
8
+ let(:payment) {
9
+ double('Spree::Payment',
10
+ source: source,
11
+ order: double('Spree::Order',
12
+ email: email,
13
+ bill_address: bill_address
14
+ )
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
+ end
24
+ end
25
+
26
+ before do
27
+ subject.preferences = { secret_key: secret_key }
28
+ subject.stub(:options_for_purchase_or_auth).and_return(['money','cc','opts'])
29
+ subject.stub(:provider).and_return provider
30
+ end
31
+
32
+ describe '#create_profile' do
33
+ before do
34
+ payment.source.stub(:update!)
35
+ end
36
+
37
+ context 'with an order that has a bill address' do
38
+ let(:bill_address) {
39
+ double('Spree::Address',
40
+ address1: '123 Happy Road',
41
+ address2: 'Apt 303',
42
+ city: 'Suzarac',
43
+ zipcode: '95671',
44
+ state: double('Spree::State', name: 'Oregon'),
45
+ country: double('Spree::Country', name: 'United States')
46
+ )
47
+ }
48
+
49
+ it 'stores the bill address with the provider' do
50
+ subject.provider.should_receive(:store).with(payment.source, {
51
+ email: email,
52
+ login: secret_key,
53
+
54
+ address: {
55
+ address1: '123 Happy Road',
56
+ address2: 'Apt 303',
57
+ city: 'Suzarac',
58
+ zip: '95671',
59
+ state: 'Oregon',
60
+ country: 'United States'
61
+ }
62
+ }).and_return double.as_null_object
63
+
64
+ subject.create_profile payment
65
+ end
66
+ end
67
+
68
+ context 'with an order that does not have a bill address' do
69
+ let(:bill_address) { nil }
70
+
71
+ it 'does not store a bill address with the provider' do
72
+ subject.provider.should_receive(:store).with(payment.source, {
73
+ email: email,
74
+ login: secret_key,
75
+ }).and_return double.as_null_object
76
+
77
+ subject.create_profile payment
78
+ end
79
+
80
+ # Regression test for #141
81
+ context "correcting the card type" do
82
+ before do
83
+ # We don't care about this method for these tests
84
+ subject.provider.stub(:store).and_return(double.as_null_object)
85
+ end
86
+
87
+ it "converts 'American Express' to 'american_express'" do
88
+ payment.source.cc_type = 'American Express'
89
+ subject.create_profile(payment)
90
+ expect(payment.source.cc_type).to eq('american_express')
91
+ end
92
+
93
+ it "converts 'Diners Club' to 'diners_club'" do
94
+ payment.source.cc_type = 'Diners Club'
95
+ subject.create_profile(payment)
96
+ expect(payment.source.cc_type).to eq('diners_club')
97
+ end
98
+
99
+ it "converts 'Visa' to 'visa'" do
100
+ payment.source.cc_type = 'Visa'
101
+ subject.create_profile(payment)
102
+ expect(payment.source.cc_type).to eq('visa')
103
+ end
104
+ end
105
+ end
106
+
107
+ context 'with a card represents payment_profile' do
108
+ let(:source) { Spree::CreditCard.new(gateway_payment_profile_id: 'tok_profileid') }
109
+ let(:bill_address) { nil }
110
+
111
+ it 'stores the profile_id as a card' do
112
+ subject.provider.should_receive(:store).with(source.gateway_payment_profile_id, anything).and_return double.as_null_object
113
+
114
+ subject.create_profile payment
115
+ end
116
+ end
117
+ end
118
+
119
+ context 'purchasing' do
120
+ after do
121
+ subject.purchase(19.99, 'credit card', {})
122
+ end
123
+
124
+ it 'send the payment to the provider' do
125
+ provider.should_receive(:purchase).with('money','cc','opts')
126
+ end
127
+ end
128
+
129
+ context 'authorizing' do
130
+ after do
131
+ subject.authorize(19.99, 'credit card', {})
132
+ end
133
+
134
+ it 'send the authorization to the provider' do
135
+ provider.should_receive(:authorize).with('money','cc','opts')
136
+ end
137
+ end
138
+
139
+ context 'capturing' do
140
+
141
+ after do
142
+ subject.capture(1234, 'response_code', {})
143
+ end
144
+
145
+ it 'convert the amount to cents' do
146
+ provider.should_receive(:capture).with(1234,anything,anything)
147
+ end
148
+
149
+ it 'use the response code as the authorization' do
150
+ provider.should_receive(:capture).with(anything,'response_code',anything)
151
+ end
152
+ end
153
+
154
+ context 'capture with payment class' do
155
+ let(:gateway) do
156
+ gateway = described_class.new(active: true)
157
+ gateway.set_preference :secret_key, secret_key
158
+ gateway.stub(:options_for_purchase_or_auth).and_return(['money','cc','opts'])
159
+ gateway.stub(:provider).and_return provider
160
+ gateway.stub :source_required => true
161
+ gateway
162
+ end
163
+
164
+ let(:order) { Spree::Order.create }
165
+
166
+ let(:card) do
167
+ # mock_model(Spree::CreditCard, :gateway_customer_profile_id => 'cus_abcde',
168
+ # :imported => false)
169
+ create :credit_card, gateway_customer_profile_id: 'cus_abcde', imported: false
170
+ end
171
+
172
+ let(:payment) do
173
+ payment = Spree::Payment.new
174
+ payment.source = card
175
+ payment.order = order
176
+ payment.payment_method = gateway
177
+ payment.amount = 98.55
178
+ payment.state = 'pending'
179
+ payment.response_code = '12345'
180
+ payment
181
+ end
182
+
183
+ let!(:success_response) do
184
+ double('success_response', :success? => true,
185
+ :params => {},
186
+ :authorization => '123',
187
+ :avs_result => { 'code' => 'avs-code' },
188
+ :cvv_result => { 'code' => 'cvv-code', 'message' => "CVV Result"})
189
+ end
190
+
191
+ after do
192
+ payment.capture!
193
+ end
194
+
195
+ it 'gets correct amount' do
196
+ provider.should_receive(:capture).with(9855,'12345',anything).and_return(success_response)
197
+ end
198
+ end
199
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Gateway::UsaEpayTransaction do
4
+ before do
5
+ Spree::Gateway.update_all(active: false)
6
+ @gateway = Spree::Gateway::UsaEpayTransaction.create!(name: 'USA EPay Gateway', active: true, stores: [::Spree::Store.default])
7
+ @gateway.set_preference(:login, '0r19zQBdp5nS8i3t4hFxz0di13yf56q1')
8
+ @gateway.save!
9
+
10
+ country = Spree::Country.find_by(name: 'United States of America')
11
+ state = create(:state, name: 'Maryland', abbr: 'MD', country: country)
12
+ address = create(:address,
13
+ firstname: 'John',
14
+ lastname: 'Doe',
15
+ address1: '1234 My Street',
16
+ address2: 'Apt 1',
17
+ city: 'Washington DC',
18
+ zipcode: '20123',
19
+ phone: '(555)555-5555',
20
+ state: state,
21
+ country: country)
22
+
23
+ order = create(:order_with_totals, bill_address: address, ship_address: address)
24
+ order.update_with_updater!
25
+
26
+ credit_card = create(:credit_card,
27
+ verification_value: '123',
28
+ number: '4111111111111111',
29
+ month: 9,
30
+ year: Time.now.year + 1,
31
+ name: 'John Doe',
32
+ cc_type: '')
33
+
34
+ @payment = create(:payment, source: credit_card, order: order, payment_method: @gateway, amount: 10.00)
35
+ end
36
+
37
+ context 'purchasing' do
38
+ it 'can purchase a payment' do
39
+ skip 'login key is no longer valid'
40
+ expect(@payment.purchase!).to be_truthy
41
+ end
42
+ end
43
+
44
+ context '.provider_class' do
45
+ it 'is a UsaEpayTransaction gateway' do
46
+ expect(@gateway.provider_class).to eq ::ActiveMerchant::Billing::UsaEpayTransactionGateway
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Gateway::Worldpay do
4
+ let(:gateway) { described_class.create!(name: 'Worldpay', stores: [::Spree::Store.default]) }
5
+
6
+ context '.provider_class' do
7
+ it 'is a Worldpay gateway' do
8
+ expect(gateway.provider_class).to eq ::ActiveMerchant::Billing::WorldpayGateway
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Order do
4
+ let(:order_one) { OrderWalkthrough.up_to(:payment) }
5
+ let(:order_two) { OrderWalkthrough.up_to(:payment) }
6
+ let(:stripe_apple_pay_payment_method) do
7
+ Spree::Gateway::StripeApplePayGateway.create!(
8
+ name: 'ApplePay',
9
+ preferred_domain_verification_certificate: FFaker::Lorem.characters(20),
10
+ stores: [::Spree::Store.default]
11
+ )
12
+ end
13
+ let(:stripe_credit_card_payment_method) do
14
+ Spree::Gateway::StripeGateway.create!(
15
+ name: 'CreditCard',
16
+ preferred_secret_key: FFaker::Lorem.characters(20),
17
+ preferred_publishable_key: FFaker::Lorem.characters(20),
18
+ stores: [::Spree::Store.default]
19
+ )
20
+ end
21
+
22
+ before do
23
+ Spree::Config[:always_include_confirm_step] = true
24
+ allow_any_instance_of(Spree::PaymentMethod).to receive(:source_required?).and_return(false)
25
+
26
+ order_one.payments.create(payment_method_id: stripe_apple_pay_payment_method.id,
27
+ amount: 29.99,
28
+ state: 'completed')
29
+ order_two.payments.create(payment_method_id: stripe_credit_card_payment_method.id,
30
+ amount: 29.99,
31
+ state: 'completed')
32
+ order_one.update_totals
33
+ order_two.update_totals
34
+ end
35
+
36
+ describe '#paid_with_apple_pay?' do
37
+ context 'when an order was paid with Apply Pay' do
38
+ it 'returns true' do
39
+ expect(order_one.paid_with_apple_pay?).to eq true
40
+ end
41
+ end
42
+
43
+ context 'when an order was paid with Credit Card' do
44
+ it 'returns false' do
45
+ expect(order_two.paid_with_apple_pay?).to eq false
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '#confirmation_required?' do
51
+ context 'when an order was paid with Apply Pay' do
52
+ it 'returns false' do
53
+ expect(order_one.confirmation_required?).to eq false
54
+ end
55
+ end
56
+
57
+ context 'when an order was paid with Credit Card' do
58
+ it 'returns true' do
59
+ expect(order_two.confirmation_required?).to eq true
60
+ end
61
+ end
62
+ end
63
+
64
+ context 'when an order was paid with Apply Pay' do
65
+ it 'proceeds to Complete order state' do
66
+ order_one.next
67
+
68
+ expect(order_one.state).to eq 'complete'
69
+ end
70
+ end
71
+
72
+ context 'when an order was paid with Credit Card' do
73
+ it 'proceeds to Confirm order state' do
74
+ order_two.next
75
+
76
+ expect(order_two.state).to eq 'confirm'
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Apple Pay Domain Verification', type: :request do
4
+ let(:domain_verification_certificate) { FFaker::Lorem.characters(20) }
5
+ let(:stripe_apple_pay_payment_method) do
6
+ Spree::Gateway::StripeApplePayGateway.create!(
7
+ name: 'ApplePay',
8
+ preferred_domain_verification_certificate: domain_verification_certificate
9
+ )
10
+ end
11
+ let(:execute) { get '/.well-known/apple-developer-merchantid-domain-association' }
12
+
13
+ shared_examples 'returns 404' do
14
+ it 'returns RecordNotFound exception' do
15
+ expect { execute }.to raise_exception(ActiveRecord::RecordNotFound)
16
+ end
17
+ end
18
+
19
+ context 'apple pay gateway exists' do
20
+ before do
21
+ stripe_apple_pay_payment_method
22
+ execute
23
+ end
24
+
25
+ it 'returns 200 HTTP status' do
26
+ expect(response.status).to eq(200)
27
+ end
28
+
29
+ it 'renders domain verification certificate' do
30
+ expect(response.body).to eq domain_verification_certificate
31
+ end
32
+ end
33
+
34
+ context 'apple pay gateway doesnt exist' do
35
+ it_behaves_like 'returns 404'
36
+ end
37
+
38
+ context 'apple pay gateway not active' do
39
+ before do
40
+ stripe_apple_pay_payment_method.update_column(:active, false)
41
+ end
42
+
43
+ it_behaves_like 'returns 404'
44
+ end
45
+ end