solidus_afterpay 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -0
- data/Gemfile +6 -3
- data/README.md +55 -23
- data/app/assets/javascripts/solidus_afterpay/afterpay_checkout.js +11 -11
- data/app/assets/javascripts/solidus_afterpay/afterpay_checkout_button.js +85 -0
- data/app/assets/javascripts/solidus_afterpay/afterpay_init.js +12 -0
- data/app/assets/javascripts/solidus_afterpay/backend/afterpay_autocomplete.js +9 -0
- data/app/assets/javascripts/spree/backend/solidus_afterpay.js +3 -1
- data/app/assets/javascripts/spree/frontend/solidus_afterpay.js +2 -0
- data/app/controllers/solidus_afterpay/callbacks_controller.rb +5 -1
- data/app/controllers/solidus_afterpay/checkouts_controller.rb +8 -2
- data/app/controllers/solidus_afterpay/express_callbacks_controller.rb +65 -0
- data/app/decorators/controllers/solidus_afterpay/spree/orders_controller_decorator.rb +13 -0
- data/app/helpers/solidus_afterpay/afterpay_helper.rb +5 -4
- data/app/models/solidus_afterpay/gateway.rb +37 -10
- data/app/models/solidus_afterpay/order_component_builder.rb +34 -5
- data/app/models/solidus_afterpay/payment_method.rb +43 -10
- data/app/models/solidus_afterpay/payment_source.rb +1 -1
- data/app/presentes/solidus_afterpay/order_presenter.rb +17 -0
- data/app/presentes/solidus_afterpay/shipping_rate_presenter.rb +28 -0
- data/app/services/solidus_afterpay/base_service.rb +13 -0
- data/app/services/solidus_afterpay/shipping_rate_builder_service.rb +32 -0
- data/app/services/solidus_afterpay/update_order_addresses_service.rb +45 -0
- data/app/services/solidus_afterpay/update_order_attributes_service.rb +49 -0
- data/app/views/solidus_afterpay/_afterpay_checkout_button.html.erb +9 -0
- data/app/views/solidus_afterpay/_afterpay_javascript.html.erb +4 -1
- data/app/views/spree/api/payments/source_views/_afterpay.json.jbuilder +1 -1
- data/app/views/spree/shared/_afterpay_messaging.html.erb +14 -12
- data/bin/sandbox +1 -1
- data/config/locales/en.yml +4 -0
- data/config/routes.rb +2 -0
- data/lib/generators/solidus_afterpay/install/templates/initializer.rb +12 -0
- data/lib/solidus_afterpay/configuration.rb +29 -0
- data/lib/solidus_afterpay/engine.rb +1 -1
- data/lib/solidus_afterpay/testing_support/factories.rb +20 -0
- data/lib/solidus_afterpay/version.rb +1 -1
- data/solidus_afterpay.gemspec +4 -4
- metadata +23 -73
- data/spec/fixtures/vcr_casettes/create_checkout/invalid.yml +0 -65
- data/spec/fixtures/vcr_casettes/create_checkout/valid.yml +0 -64
- data/spec/fixtures/vcr_casettes/credit/invalid.yml +0 -61
- data/spec/fixtures/vcr_casettes/credit/valid.yml +0 -63
- data/spec/fixtures/vcr_casettes/deferred/authorize/declined_payment.yml +0 -120
- data/spec/fixtures/vcr_casettes/deferred/authorize/invalid.yml +0 -61
- data/spec/fixtures/vcr_casettes/deferred/authorize/valid.yml +0 -120
- data/spec/fixtures/vcr_casettes/deferred/capture/invalid.yml +0 -61
- data/spec/fixtures/vcr_casettes/deferred/capture/valid.yml +0 -140
- data/spec/fixtures/vcr_casettes/deferred/void/invalid.yml +0 -61
- data/spec/fixtures/vcr_casettes/deferred/void/valid.yml +0 -137
- data/spec/fixtures/vcr_casettes/find_payment/invalid.yml +0 -61
- data/spec/fixtures/vcr_casettes/find_payment/valid.yml +0 -140
- data/spec/fixtures/vcr_casettes/immediate/capture/declined_payment.yml +0 -120
- data/spec/fixtures/vcr_casettes/immediate/capture/invalid.yml +0 -61
- data/spec/fixtures/vcr_casettes/immediate/capture/valid.yml +0 -134
- data/spec/fixtures/vcr_casettes/retrieve_configuration/valid.yml +0 -67
- data/spec/helpers/solidus_afterpay/afterpay_helper_spec.rb +0 -23
- data/spec/models/solidus_afterpay/gateway_spec.rb +0 -418
- data/spec/models/solidus_afterpay/order_component_builder_spec.rb +0 -137
- data/spec/models/solidus_afterpay/payment_method_spec.rb +0 -143
- data/spec/models/solidus_afterpay/payment_source_spec.rb +0 -61
- data/spec/models/solidus_afterpay/user_agent_generator_spec.rb +0 -22
- data/spec/models/spree/order_spec.rb +0 -158
- data/spec/requests/solidus_afterpay/callbacks_controller_spec.rb +0 -127
- data/spec/requests/solidus_afterpay/checkouts_controller_spec.rb +0 -190
- data/spec/spec_helper.rb +0 -31
- data/spec/support/auth.rb +0 -15
- data/spec/support/preferences.rb +0 -33
- data/spec/support/vcr.rb +0 -18
@@ -1,418 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe SolidusAfterpay::Gateway do
|
4
|
-
let(:gateway) { described_class.new(options) }
|
5
|
-
let(:options) do
|
6
|
-
{
|
7
|
-
merchant_id: ENV.fetch('AFTERPAY_MERCHANT_ID', 'dummy_merchant_id'),
|
8
|
-
secret_key: ENV.fetch('AFTERPAY_SECRET_KEY', 'dummy_secret_key'),
|
9
|
-
test_mode: true
|
10
|
-
}
|
11
|
-
end
|
12
|
-
|
13
|
-
describe '#authorize' do
|
14
|
-
subject(:response) { gateway.authorize(amount, payment_source, gateway_options) }
|
15
|
-
|
16
|
-
let(:order_token) { '002.m6d9jkrtv1p0j4jqslklhfq9k4nl54jo2530d58kf6snpqq1' }
|
17
|
-
let(:deferred?) { false }
|
18
|
-
let(:payment_method) { build(:afterpay_payment_method, preferred_deferred: deferred?) }
|
19
|
-
|
20
|
-
let(:amount) { 1000 }
|
21
|
-
let(:payment_source) { build(:afterpay_payment_source, token: order_token, payment_method: payment_method) }
|
22
|
-
let(:gateway_options) { {} }
|
23
|
-
|
24
|
-
context 'with the immediate flow' do
|
25
|
-
it 'returns a successful response' do
|
26
|
-
is_expected.to be_success
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'with the deferred flow' do
|
31
|
-
let(:deferred?) { true }
|
32
|
-
|
33
|
-
context 'with valid params', vcr: 'deferred/authorize/valid' do
|
34
|
-
it 'authorize the afterpay payment with the order_token' do
|
35
|
-
is_expected.to be_success
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'with an invalid token', vcr: 'deferred/authorize/invalid' do
|
40
|
-
let(:order_token) { 'INVALID_TOKEN' }
|
41
|
-
|
42
|
-
it 'returns an unsuccesfull response' do
|
43
|
-
is_expected.not_to be_success
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'returns the error message from Afterpay in the response' do
|
47
|
-
expect(response.message).to eq('Cannot complete payment, expired or invalid token.')
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'returns the error_code from Afterpay in the response' do
|
51
|
-
expect(response.error_code).to eq('invalid_token')
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context 'with an invalid credit card', vcr: 'deferred/authorize/declined_payment' do
|
56
|
-
let(:order_token) { '002.ijlqnvko1o4ou45uabplrl9pqao8u2v52njs2972r24hje65' }
|
57
|
-
|
58
|
-
it 'returns an unsuccesfull response' do
|
59
|
-
is_expected.not_to be_success
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'returns the error message from Afterpay in the response' do
|
63
|
-
expect(response.message).to eq(
|
64
|
-
'Payment declined. Please contact the Afterpay Customer Service team for more information.'
|
65
|
-
)
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'returns the error_code from Afterpay in the response' do
|
69
|
-
expect(response.error_code).to eq('payment_declined')
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe '#capture' do
|
76
|
-
subject(:response) { gateway.capture(amount, response_code, gateway_options) }
|
77
|
-
|
78
|
-
let(:order_token) { '002.nt7e0ioqj00fh0ua1nbqcj6vcn9obtfsglqvrj9ijpo3edfc' }
|
79
|
-
let(:deferred?) { false }
|
80
|
-
let(:payment_source) { build(:afterpay_payment_source, token: order_token) }
|
81
|
-
let(:payment_method) { build(:afterpay_payment_method, preferred_deferred: deferred?) }
|
82
|
-
let(:payment) { build(:afterpay_payment, source: payment_source, payment_method: payment_method) }
|
83
|
-
|
84
|
-
let(:amount) { 1000 }
|
85
|
-
let(:response_code) { '100101782114' }
|
86
|
-
let(:gateway_options) { { originator: payment, currency: 'USD' } }
|
87
|
-
|
88
|
-
context 'with the immediate flow' do
|
89
|
-
context 'with valid params', vcr: 'immediate/capture/valid' do
|
90
|
-
it 'captures the afterpay payment with the order_token' do
|
91
|
-
is_expected.to be_success
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context 'with an invalid token', vcr: 'immediate/capture/invalid' do
|
96
|
-
let(:order_token) { 'INVALID_TOKEN' }
|
97
|
-
|
98
|
-
it 'returns an unsuccesfull response' do
|
99
|
-
is_expected.not_to be_success
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'returns the error message from Afterpay in the response' do
|
103
|
-
expect(response.message).to eq('Cannot complete payment, expired or invalid token.')
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'returns the error_code from Afterpay in the response' do
|
107
|
-
expect(response.error_code).to eq('invalid_token')
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context 'with an invalid credit card', vcr: 'immediate/capture/declined_payment' do
|
112
|
-
let(:order_token) { '002.kj16plsn63eqfacueg767cp7l34e9ph5tms4ql14o2iid7l1' }
|
113
|
-
|
114
|
-
it 'returns an unsuccesfull response' do
|
115
|
-
is_expected.not_to be_success
|
116
|
-
end
|
117
|
-
|
118
|
-
it 'returns the error message from Afterpay in the response' do
|
119
|
-
expect(response.message).to eq(
|
120
|
-
'Payment declined. Please contact the Afterpay Customer Service team for more information.'
|
121
|
-
)
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'returns the error_code from Afterpay in the response' do
|
125
|
-
expect(response.error_code).to eq('payment_declined')
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
context 'with the deferred flow' do
|
131
|
-
let(:deferred?) { true }
|
132
|
-
|
133
|
-
context 'with valid params', vcr: 'deferred/capture/valid' do
|
134
|
-
it 'captures the afterpay payment with the order_id' do
|
135
|
-
is_expected.to be_success
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
context 'with an invalid payment ID', vcr: 'deferred/capture/invalid' do
|
140
|
-
let(:response_code) { 'INVALID_RESPONSE_CODE' }
|
141
|
-
|
142
|
-
it 'returns an unsuccesfull response' do
|
143
|
-
is_expected.not_to be_success
|
144
|
-
end
|
145
|
-
|
146
|
-
it 'returns the error message from Afterpay in the response' do
|
147
|
-
expect(response.message).to eq('Afterpay payment ID not found.')
|
148
|
-
end
|
149
|
-
|
150
|
-
it 'returns the error_code from Afterpay in the response' do
|
151
|
-
expect(response.error_code).to eq('not_found')
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
describe '#purchase' do
|
158
|
-
subject(:response) { gateway.purchase(amount, payment_source, gateway_options) }
|
159
|
-
|
160
|
-
let(:order_token) { '002.nt7e0ioqj00fh0ua1nbqcj6vcn9obtfsglqvrj9ijpo3edfc' }
|
161
|
-
let(:deferred?) { false }
|
162
|
-
let(:payment_method) { build(:afterpay_payment_method, preferred_deferred: deferred?) }
|
163
|
-
let(:payment) { build(:afterpay_payment, source: payment_source, payment_method: payment_method) }
|
164
|
-
|
165
|
-
let(:amount) { 1000 }
|
166
|
-
let(:payment_source) { build(:afterpay_payment_source, token: order_token, payment_method: payment_method) }
|
167
|
-
let(:gateway_options) { { originator: payment, currency: 'USD' } }
|
168
|
-
|
169
|
-
context 'with the immediate flow' do
|
170
|
-
context 'with valid params', vcr: 'immediate/capture/valid' do
|
171
|
-
it 'authorize and captures the afterpay payment with the order_token' do
|
172
|
-
is_expected.to be_success
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
context 'with an invalid token', vcr: 'immediate/capture/invalid' do
|
177
|
-
let(:order_token) { 'INVALID_TOKEN' }
|
178
|
-
|
179
|
-
it 'returns an unsuccesfull response' do
|
180
|
-
is_expected.not_to be_success
|
181
|
-
end
|
182
|
-
|
183
|
-
it 'returns the error message from Afterpay in the response' do
|
184
|
-
expect(response.message).to eq('Cannot complete payment, expired or invalid token.')
|
185
|
-
end
|
186
|
-
|
187
|
-
it 'returns the error_code from Afterpay in the response' do
|
188
|
-
expect(response.error_code).to eq('invalid_token')
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
context 'with an invalid credit card', vcr: 'immediate/capture/declined_payment' do
|
193
|
-
let(:order_token) { '002.kj16plsn63eqfacueg767cp7l34e9ph5tms4ql14o2iid7l1' }
|
194
|
-
|
195
|
-
it 'returns an unsuccesfull response' do
|
196
|
-
is_expected.not_to be_success
|
197
|
-
end
|
198
|
-
|
199
|
-
it 'returns the error message from Afterpay in the response' do
|
200
|
-
expect(response.message).to eq(
|
201
|
-
'Payment declined. Please contact the Afterpay Customer Service team for more information.'
|
202
|
-
)
|
203
|
-
end
|
204
|
-
|
205
|
-
it 'returns the error_code from Afterpay in the response' do
|
206
|
-
expect(response.error_code).to eq('payment_declined')
|
207
|
-
end
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
context 'with the deferred flow' do
|
212
|
-
let(:deferred?) { true }
|
213
|
-
|
214
|
-
context 'with valid params', vcr: 'deferred/authorize/valid' do
|
215
|
-
it 'authorize and captures the afterpay payment with the order_token' do
|
216
|
-
VCR.use_cassette('deferred/capture/valid') do
|
217
|
-
is_expected.to be_success
|
218
|
-
end
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
context 'with an invalid token', vcr: 'deferred/authorize/invalid' do
|
223
|
-
let(:order_token) { 'INVALID_TOKEN' }
|
224
|
-
|
225
|
-
it 'returns an unsuccesfull response' do
|
226
|
-
is_expected.not_to be_success
|
227
|
-
end
|
228
|
-
|
229
|
-
it 'returns the error message from Afterpay in the response' do
|
230
|
-
expect(response.message).to eq('Cannot complete payment, expired or invalid token.')
|
231
|
-
end
|
232
|
-
|
233
|
-
it 'returns the error_code from Afterpay in the response' do
|
234
|
-
expect(response.error_code).to eq('invalid_token')
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
context 'with an invalid credit card', vcr: 'deferred/authorize/declined_payment' do
|
239
|
-
let(:order_token) { '002.kj16plsn63eqfacueg767cp7l34e9ph5tms4ql14o2iid7l1' }
|
240
|
-
|
241
|
-
it 'returns an unsuccesfull response' do
|
242
|
-
is_expected.not_to be_success
|
243
|
-
end
|
244
|
-
|
245
|
-
it 'returns the error message from Afterpay in the response' do
|
246
|
-
expect(response.message).to eq(
|
247
|
-
'Payment declined. Please contact the Afterpay Customer Service team for more information.'
|
248
|
-
)
|
249
|
-
end
|
250
|
-
|
251
|
-
it 'returns the error_code from Afterpay in the response' do
|
252
|
-
expect(response.error_code).to eq('payment_declined')
|
253
|
-
end
|
254
|
-
end
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
describe '#credit' do
|
259
|
-
subject(:response) { gateway.credit(amount, response_code, gateway_options) }
|
260
|
-
|
261
|
-
let(:payment) { build(:afterpay_payment) }
|
262
|
-
let(:refund) { build(:refund, payment: payment) }
|
263
|
-
|
264
|
-
let(:amount) { 1000 }
|
265
|
-
let(:response_code) { '100101768366' }
|
266
|
-
let(:gateway_options) { { originator: refund } }
|
267
|
-
|
268
|
-
context 'with valid params', vcr: 'credit/valid' do
|
269
|
-
it 'refunds the amount using the response_code' do
|
270
|
-
is_expected.to be_success
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
context 'with an invalid response_code', vcr: 'credit/invalid' do
|
275
|
-
let(:response_code) { 'INVALID_RESPONSE_CODE' }
|
276
|
-
|
277
|
-
it 'returns an unsuccesfull response' do
|
278
|
-
is_expected.not_to be_success
|
279
|
-
end
|
280
|
-
|
281
|
-
it 'returns the error message from Afterpay in the response' do
|
282
|
-
expect(response.message).to eq('Afterpay payment ID not found.')
|
283
|
-
end
|
284
|
-
|
285
|
-
it 'returns the error_code from Afterpay in the response' do
|
286
|
-
expect(response.error_code).to eq('not_found')
|
287
|
-
end
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
describe '#void' do
|
292
|
-
subject(:response) { gateway.void(response_code, gateway_options) }
|
293
|
-
|
294
|
-
let(:deferred?) { false }
|
295
|
-
let(:amount) { 10 }
|
296
|
-
let(:payment_method) { build(:afterpay_payment_method, preferred_deferred: deferred?) }
|
297
|
-
let(:payment) { build(:afterpay_payment, payment_method: payment_method, amount: amount) }
|
298
|
-
|
299
|
-
let(:response_code) { '100101785223' }
|
300
|
-
let(:gateway_options) { { originator: payment, currency: 'USD' } }
|
301
|
-
|
302
|
-
context 'with the immediate flow' do
|
303
|
-
it 'returns an unsuccessful response' do
|
304
|
-
is_expected.not_to be_success
|
305
|
-
end
|
306
|
-
|
307
|
-
it 'returns the error message from Afterpay in the response' do
|
308
|
-
expect(response.message).to eq("Transaction can't be voided")
|
309
|
-
end
|
310
|
-
|
311
|
-
it 'returns the error_code from Afterpay in the response' do
|
312
|
-
expect(response.error_code).to eq('void_not_allowed')
|
313
|
-
end
|
314
|
-
end
|
315
|
-
|
316
|
-
context 'with the deferred flow' do
|
317
|
-
let(:deferred?) { true }
|
318
|
-
|
319
|
-
context 'with valid params', vcr: 'deferred/void/valid' do
|
320
|
-
it 'voids the payment using the response_code' do
|
321
|
-
is_expected.to be_success
|
322
|
-
end
|
323
|
-
end
|
324
|
-
|
325
|
-
context 'with an invalid response_code', vcr: 'deferred/void/invalid' do
|
326
|
-
let(:response_code) { 'INVALID_RESPONSE_CODE' }
|
327
|
-
|
328
|
-
it 'returns an unsuccesfull response' do
|
329
|
-
is_expected.not_to be_success
|
330
|
-
end
|
331
|
-
|
332
|
-
it 'returns the error message from Afterpay in the response' do
|
333
|
-
expect(response.message).to eq('Afterpay payment ID not found.')
|
334
|
-
end
|
335
|
-
|
336
|
-
it 'returns the error_code from Afterpay in the response' do
|
337
|
-
expect(response.error_code).to eq('not_found')
|
338
|
-
end
|
339
|
-
end
|
340
|
-
end
|
341
|
-
end
|
342
|
-
|
343
|
-
describe '#create_checkout' do
|
344
|
-
subject(:response) { gateway.create_checkout(order, gateway_options) }
|
345
|
-
|
346
|
-
let(:redirect_confirm_url) { 'https://merchantsite.com/confirm' }
|
347
|
-
let(:redirect_cancel_url) { 'https://merchantsite.com/cancel' }
|
348
|
-
|
349
|
-
let(:order) { build(:order_with_line_items) }
|
350
|
-
let(:gateway_options) { { redirect_confirm_url: redirect_confirm_url, redirect_cancel_url: redirect_cancel_url } }
|
351
|
-
|
352
|
-
context 'with valid params', vcr: 'create_checkout/valid' do
|
353
|
-
it 'creates the checkout' do
|
354
|
-
is_expected.to be_success
|
355
|
-
end
|
356
|
-
|
357
|
-
it 'returns the order_token' do
|
358
|
-
expect(response.params).to include('token')
|
359
|
-
end
|
360
|
-
end
|
361
|
-
|
362
|
-
context 'with an invalid params', vcr: 'create_checkout/invalid' do
|
363
|
-
let(:redirect_confirm_url) { 'INVALID_URL' }
|
364
|
-
|
365
|
-
it 'returns an unsuccesfull response' do
|
366
|
-
is_expected.not_to be_success
|
367
|
-
end
|
368
|
-
|
369
|
-
it 'returns the error message from Afterpay in the response' do
|
370
|
-
expect(response.message).to eq('merchant.redirectConfirmUrl must be a valid URL')
|
371
|
-
end
|
372
|
-
|
373
|
-
it 'returns the error_code from Afterpay in the response' do
|
374
|
-
expect(response.error_code).to eq('invalid_object')
|
375
|
-
end
|
376
|
-
end
|
377
|
-
end
|
378
|
-
|
379
|
-
describe '#find_payment' do
|
380
|
-
subject(:response) { gateway.find_payment(order_id: order_id) }
|
381
|
-
|
382
|
-
let(:order_id) { '100101785223' }
|
383
|
-
|
384
|
-
context 'with valid params', vcr: 'find_payment/valid' do
|
385
|
-
it 'retrieves the Afterpay payment' do
|
386
|
-
expect(response).to include('id' => order_id)
|
387
|
-
end
|
388
|
-
end
|
389
|
-
|
390
|
-
context 'with an invalid params', vcr: 'find_payment/invalid' do
|
391
|
-
let(:order_id) { 'INVALID_ORDER_ID' }
|
392
|
-
|
393
|
-
it 'returns nil' do
|
394
|
-
is_expected.to be_nil
|
395
|
-
end
|
396
|
-
end
|
397
|
-
end
|
398
|
-
|
399
|
-
describe '#retrieve_configuration' do
|
400
|
-
subject(:response) { gateway.retrieve_configuration }
|
401
|
-
|
402
|
-
context 'with valid response', vcr: 'retrieve_configuration/valid' do
|
403
|
-
it 'retrieves the afterpay configuration' do
|
404
|
-
expect(response).to include('minimumAmount', 'maximumAmount')
|
405
|
-
end
|
406
|
-
end
|
407
|
-
|
408
|
-
context 'with invalid response' do
|
409
|
-
before do
|
410
|
-
allow(::Afterpay::API::Configuration::Retrieve).to receive(:call).and_raise(::Afterpay::BaseError.new(nil))
|
411
|
-
end
|
412
|
-
|
413
|
-
it 'retrieves the afterpay configuration' do
|
414
|
-
expect(response).to be_nil
|
415
|
-
end
|
416
|
-
end
|
417
|
-
end
|
418
|
-
end
|
@@ -1,137 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe SolidusAfterpay::OrderComponentBuilder do
|
4
|
-
let(:order) { build(:order_with_line_items) }
|
5
|
-
let(:redirect_confirm_url) { 'https://merchantsite.com/confirm' }
|
6
|
-
let(:redirect_cancel_url) { 'https://merchantsite.com/cancel' }
|
7
|
-
|
8
|
-
let(:builder) do
|
9
|
-
described_class.new(
|
10
|
-
order: order,
|
11
|
-
redirect_confirm_url: redirect_confirm_url,
|
12
|
-
redirect_cancel_url: redirect_cancel_url
|
13
|
-
)
|
14
|
-
end
|
15
|
-
|
16
|
-
describe '#call' do
|
17
|
-
subject(:result) { builder.call }
|
18
|
-
|
19
|
-
let(:expected_result_not_combined) do
|
20
|
-
Afterpay::Components::Order.new(
|
21
|
-
amount: Afterpay::Components::Money.new(amount: '110.0', currency: 'USD'),
|
22
|
-
billing: Afterpay::Components::Contact.new(
|
23
|
-
area1: 'Herndon',
|
24
|
-
area2: nil,
|
25
|
-
country_code: nil,
|
26
|
-
line1: 'PO Box 1337',
|
27
|
-
line2: 'Northwest',
|
28
|
-
name: 'John',
|
29
|
-
phone_number: '555-555-0199',
|
30
|
-
postcode: order.billing_address.zipcode,
|
31
|
-
region: 'AL'
|
32
|
-
),
|
33
|
-
consumer: Afterpay::Components::Consumer.new(
|
34
|
-
email: order.user.email,
|
35
|
-
given_names: 'John',
|
36
|
-
phone_number: nil,
|
37
|
-
surname: nil
|
38
|
-
),
|
39
|
-
courier: nil,
|
40
|
-
discounts: nil,
|
41
|
-
items: [
|
42
|
-
Afterpay::Components::Item.new(
|
43
|
-
name: order.line_items.first.name,
|
44
|
-
price: Afterpay::Components::Money.new(
|
45
|
-
amount: '10.0',
|
46
|
-
currency: 'USD'
|
47
|
-
),
|
48
|
-
quantity: 1,
|
49
|
-
sku: order.line_items.first.sku
|
50
|
-
)
|
51
|
-
],
|
52
|
-
merchant: Afterpay::Components::Merchant.new(
|
53
|
-
redirect_confirm_url: 'https://merchantsite.com/confirm',
|
54
|
-
redirect_cancel_url: 'https://merchantsite.com/cancel'
|
55
|
-
),
|
56
|
-
merchant_reference: order.number,
|
57
|
-
payment_type: nil,
|
58
|
-
shipping: Afterpay::Components::Contact.new(
|
59
|
-
area1: 'Herndon',
|
60
|
-
area2: nil,
|
61
|
-
country_code: nil,
|
62
|
-
line1: 'A Different Road',
|
63
|
-
line2: 'Northwest',
|
64
|
-
name: 'John',
|
65
|
-
phone_number: '555-555-0199',
|
66
|
-
postcode: order.shipping_address.zipcode,
|
67
|
-
region: 'AL'
|
68
|
-
),
|
69
|
-
shipping_amount: nil,
|
70
|
-
tax_amount: nil
|
71
|
-
)
|
72
|
-
end
|
73
|
-
|
74
|
-
let(:expected_result_combined) do
|
75
|
-
Afterpay::Components::Order.new(
|
76
|
-
amount: Afterpay::Components::Money.new(amount: '110.0', currency: 'USD'),
|
77
|
-
billing: Afterpay::Components::Contact.new(
|
78
|
-
area1: 'Herndon',
|
79
|
-
area2: nil,
|
80
|
-
country_code: nil,
|
81
|
-
line1: 'PO Box 1337',
|
82
|
-
line2: 'Northwest',
|
83
|
-
name: 'John Von Doe',
|
84
|
-
phone_number: '555-555-0199',
|
85
|
-
postcode: order.billing_address.zipcode,
|
86
|
-
region: 'AL'
|
87
|
-
),
|
88
|
-
consumer: Afterpay::Components::Consumer.new(
|
89
|
-
email: order.user.email,
|
90
|
-
given_names: 'John',
|
91
|
-
phone_number: nil,
|
92
|
-
surname: 'Von Doe'
|
93
|
-
),
|
94
|
-
courier: nil,
|
95
|
-
discounts: nil,
|
96
|
-
items: [
|
97
|
-
Afterpay::Components::Item.new(
|
98
|
-
name: order.line_items.first.name,
|
99
|
-
price: Afterpay::Components::Money.new(
|
100
|
-
amount: '10.0',
|
101
|
-
currency: 'USD'
|
102
|
-
),
|
103
|
-
quantity: 1,
|
104
|
-
sku: order.line_items.first.sku
|
105
|
-
)
|
106
|
-
],
|
107
|
-
merchant: Afterpay::Components::Merchant.new(
|
108
|
-
redirect_confirm_url: 'https://merchantsite.com/confirm',
|
109
|
-
redirect_cancel_url: 'https://merchantsite.com/cancel'
|
110
|
-
),
|
111
|
-
merchant_reference: order.number,
|
112
|
-
payment_type: nil,
|
113
|
-
shipping: Afterpay::Components::Contact.new(
|
114
|
-
area1: 'Herndon',
|
115
|
-
area2: nil,
|
116
|
-
country_code: nil,
|
117
|
-
line1: 'A Different Road',
|
118
|
-
line2: 'Northwest',
|
119
|
-
name: 'John Von Doe',
|
120
|
-
phone_number: '555-555-0199',
|
121
|
-
postcode: order.shipping_address.zipcode,
|
122
|
-
region: 'AL'
|
123
|
-
),
|
124
|
-
shipping_amount: nil,
|
125
|
-
tax_amount: nil
|
126
|
-
)
|
127
|
-
end
|
128
|
-
|
129
|
-
let(:expected_result) do
|
130
|
-
SolidusSupport.combined_first_and_last_name_in_address? ? expected_result_combined : expected_result_not_combined
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'returns the correct payload' do
|
134
|
-
expect(result.as_json).to eq(expected_result.as_json)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
@@ -1,143 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe SolidusAfterpay::PaymentMethod, type: :model do
|
4
|
-
let(:payment_method) { described_class.new }
|
5
|
-
|
6
|
-
describe "#gateway_class" do
|
7
|
-
subject { payment_method.gateway_class }
|
8
|
-
|
9
|
-
it { is_expected.to eq(SolidusAfterpay::Gateway) }
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "#payment_source_class" do
|
13
|
-
subject { payment_method.payment_source_class }
|
14
|
-
|
15
|
-
it { is_expected.to eq(SolidusAfterpay::PaymentSource) }
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "#partial_name" do
|
19
|
-
subject { payment_method.partial_name }
|
20
|
-
|
21
|
-
it { is_expected.to eq('afterpay') }
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "#try_void" do
|
25
|
-
subject { payment_method.try_void(payment) }
|
26
|
-
|
27
|
-
let(:response_code) { 'RESPONSE_CODE' }
|
28
|
-
let(:payment_source) { build(:afterpay_payment_source) }
|
29
|
-
let(:payment) { build(:afterpay_payment, response_code: response_code, source: payment_source) }
|
30
|
-
|
31
|
-
let(:can_void?) { true }
|
32
|
-
let(:gateway_response_success?) { true }
|
33
|
-
let(:gateway_response) { ActiveMerchant::Billing::Response.new(gateway_response_success?, '') }
|
34
|
-
|
35
|
-
let(:gateway_options) { { originator: payment, currency: 'USD' } }
|
36
|
-
|
37
|
-
before do
|
38
|
-
allow(payment_source).to receive(:can_void?).and_return(can_void?)
|
39
|
-
allow(payment_method).to receive(:void).with(response_code, gateway_options).and_return(gateway_response)
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'when the void completes successful' do
|
43
|
-
it 'returns the void response' do
|
44
|
-
is_expected.to eq(gateway_response)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context 'when the void throws an error' do
|
49
|
-
let(:gateway_response_success?) { false }
|
50
|
-
|
51
|
-
it { is_expected.to be(false) }
|
52
|
-
end
|
53
|
-
|
54
|
-
context "when the payment can't be voided" do
|
55
|
-
let(:can_void?) { false }
|
56
|
-
|
57
|
-
it { is_expected.to be(false) }
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "#available_for_order?" do
|
62
|
-
subject { payment_method.available_for_order?(order) }
|
63
|
-
|
64
|
-
let(:preferred_minimum_amount) { nil }
|
65
|
-
let(:preferred_maximum_amount) { nil }
|
66
|
-
let(:preferred_currency) { nil }
|
67
|
-
|
68
|
-
let(:payment_method) do
|
69
|
-
described_class.new(
|
70
|
-
preferred_minimum_amount: preferred_minimum_amount,
|
71
|
-
preferred_maximum_amount: preferred_maximum_amount,
|
72
|
-
preferred_currency: preferred_currency
|
73
|
-
)
|
74
|
-
end
|
75
|
-
|
76
|
-
let(:order) { build(:order, currency: order_currency, total: order_total) }
|
77
|
-
let(:order_total) { 5 }
|
78
|
-
let(:order_currency) { 'USD' }
|
79
|
-
|
80
|
-
let(:configuration) do
|
81
|
-
require 'hashie'
|
82
|
-
|
83
|
-
Hashie::Mash.new({
|
84
|
-
minimumAmount: { amount: '1', currency: 'USD' },
|
85
|
-
maximumAmount: { amount: '10', currency: 'USD' }
|
86
|
-
})
|
87
|
-
end
|
88
|
-
|
89
|
-
before do
|
90
|
-
allow(payment_method.gateway).to receive(:retrieve_configuration).and_return(configuration)
|
91
|
-
end
|
92
|
-
|
93
|
-
context 'when preference settings are nil' do
|
94
|
-
context 'when order total is inside the range' do
|
95
|
-
it { is_expected.to be(true) }
|
96
|
-
end
|
97
|
-
|
98
|
-
context 'when order total is outside the range' do
|
99
|
-
let(:order_total) { 11 }
|
100
|
-
|
101
|
-
it { is_expected.to be(false) }
|
102
|
-
end
|
103
|
-
|
104
|
-
context 'when order currency is different from afterpay configuration' do
|
105
|
-
let(:order_currency) { 'EUR' }
|
106
|
-
|
107
|
-
it { is_expected.to be(false) }
|
108
|
-
end
|
109
|
-
|
110
|
-
context "when afterpay configuration doesn't include the minumumAmount" do
|
111
|
-
let(:configuration) do
|
112
|
-
require 'hashie'
|
113
|
-
|
114
|
-
Hashie::Mash.new({ maximumAmount: { amount: '10', currency: 'USD' } })
|
115
|
-
end
|
116
|
-
|
117
|
-
it { is_expected.to be(true) }
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
context 'when preference settings are not nil' do
|
122
|
-
let(:preferred_minimum_amount) { 1 }
|
123
|
-
let(:preferred_maximum_amount) { 10 }
|
124
|
-
let(:preferred_currency) { 'USD' }
|
125
|
-
|
126
|
-
context 'when order total is inside the range' do
|
127
|
-
it { is_expected.to be(true) }
|
128
|
-
end
|
129
|
-
|
130
|
-
context 'when order total is outside the range' do
|
131
|
-
let(:order_total) { 11 }
|
132
|
-
|
133
|
-
it { is_expected.to be(false) }
|
134
|
-
end
|
135
|
-
|
136
|
-
context 'when order currency is different from afterpay configuration' do
|
137
|
-
let(:order_currency) { 'EUR' }
|
138
|
-
|
139
|
-
it { is_expected.to be(false) }
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|