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,61 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe SolidusAfterpay::PaymentSource, type: :model do
|
4
|
-
let(:payment_source) { described_class.new }
|
5
|
-
|
6
|
-
describe '#actions' do
|
7
|
-
subject { payment_source.actions }
|
8
|
-
|
9
|
-
it 'supports capture, void, and credit' do
|
10
|
-
is_expected.to eq(%w[capture void credit])
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe '#can_void?' do
|
15
|
-
subject { payment_source.can_void?(payment) }
|
16
|
-
|
17
|
-
let(:deferred?) { false }
|
18
|
-
let(:payment_method) { build(:afterpay_payment_method, preferred_deferred: deferred?) }
|
19
|
-
let(:payment) { build(:afterpay_payment, payment_method: payment_method) }
|
20
|
-
|
21
|
-
context 'with the immediate flow' do
|
22
|
-
it 'is always false' do
|
23
|
-
is_expected.to be(false)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'with the deferred flow' do
|
28
|
-
let(:deferred?) { true }
|
29
|
-
|
30
|
-
let(:payment_state) { 'AUTH_APPROVED' }
|
31
|
-
let(:gateway_response) { { paymentState: payment_state } }
|
32
|
-
let(:gateway) { instance_double(SolidusAfterpay::Gateway, find_payment: gateway_response) }
|
33
|
-
|
34
|
-
before do
|
35
|
-
allow(payment_method).to receive(:gateway).and_return(gateway)
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'when the payment exists and the payment state is voidable' do
|
39
|
-
it 'returns true' do
|
40
|
-
is_expected.to be(true)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'when the payment exists when the payment state is not voidable' do
|
45
|
-
let(:payment_state) { 'NOT_VOIDABLE' }
|
46
|
-
|
47
|
-
it 'returns false' do
|
48
|
-
is_expected.to be(false)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context "when the payment doesn't exist" do
|
53
|
-
let(:gateway_response) { nil }
|
54
|
-
|
55
|
-
it 'returns false' do
|
56
|
-
is_expected.to be(false)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe SolidusAfterpay::UserAgentGenerator do
|
4
|
-
describe '#generate' do
|
5
|
-
subject { user_agent_generator.generate }
|
6
|
-
|
7
|
-
let(:user_agent_generator) { described_class.new(merchant_id: merchant_id) }
|
8
|
-
let(:merchant_id) { 'MERCHANT_ID' }
|
9
|
-
let(:default_store) { build(:store, url: 'test.com') }
|
10
|
-
|
11
|
-
before do
|
12
|
-
stub_const('SolidusAfterpay::VERSION', '0.1.0')
|
13
|
-
allow(::Spree).to receive(:solidus_gem_version).and_return('3.0.1')
|
14
|
-
stub_const('RUBY_VERSION', '2.6.6')
|
15
|
-
allow(::Spree::Store).to receive(:default).and_return(default_store)
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'includes the production javascript' do
|
19
|
-
is_expected.to eq('SolidusAfterpay/0.1.0 (Solidus/3.0.1; Ruby/2.6.6; Merchant/MERCHANT_ID) https://test.com')
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,158 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe Spree::Order, type: :model do
|
6
|
-
let(:store) { create(:store) }
|
7
|
-
let(:user) { create(:user, email: "solidus@example.com") }
|
8
|
-
let(:order) { create(:order, user: user, store: store) }
|
9
|
-
|
10
|
-
describe "#available_payment_methods" do
|
11
|
-
it "includes frontend payment methods" do
|
12
|
-
payment_method = Spree::PaymentMethod::Check.create!({
|
13
|
-
name: "Fake",
|
14
|
-
active: true,
|
15
|
-
available_to_users: true,
|
16
|
-
available_to_admin: false
|
17
|
-
})
|
18
|
-
expect(order.available_payment_methods).to include(payment_method)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "includes 'both' payment methods" do
|
22
|
-
payment_method = Spree::PaymentMethod::Check.create!({
|
23
|
-
name: "Fake",
|
24
|
-
active: true,
|
25
|
-
available_to_users: true,
|
26
|
-
available_to_admin: true
|
27
|
-
})
|
28
|
-
expect(order.available_payment_methods).to include(payment_method)
|
29
|
-
end
|
30
|
-
|
31
|
-
# rubocop:disable RSpec/MultipleExpectations
|
32
|
-
it "does not include a payment method twice" do
|
33
|
-
payment_method = Spree::PaymentMethod::Check.create!({
|
34
|
-
name: "Fake",
|
35
|
-
active: true,
|
36
|
-
available_to_users: true,
|
37
|
-
available_to_admin: true
|
38
|
-
})
|
39
|
-
expect(order.available_payment_methods.count).to eq(1)
|
40
|
-
expect(order.available_payment_methods).to include(payment_method)
|
41
|
-
end
|
42
|
-
# rubocop:enable RSpec/MultipleExpectations
|
43
|
-
|
44
|
-
it "does not include inactive payment methods" do
|
45
|
-
Spree::PaymentMethod::Check.create!({
|
46
|
-
name: "Fake",
|
47
|
-
active: false,
|
48
|
-
available_to_users: true,
|
49
|
-
available_to_admin: true
|
50
|
-
})
|
51
|
-
expect(order.available_payment_methods.count).to eq(0)
|
52
|
-
end
|
53
|
-
|
54
|
-
context "with more than one payment method" do
|
55
|
-
subject { order.available_payment_methods }
|
56
|
-
|
57
|
-
let!(:first_method) {
|
58
|
-
FactoryBot.create(:payment_method, available_to_users: true,
|
59
|
-
available_to_admin: true)
|
60
|
-
}
|
61
|
-
let!(:second_method) {
|
62
|
-
FactoryBot.create(:payment_method, available_to_users: true,
|
63
|
-
available_to_admin: true)
|
64
|
-
}
|
65
|
-
|
66
|
-
before do
|
67
|
-
second_method.move_to_top
|
68
|
-
end
|
69
|
-
|
70
|
-
it "respects the order of methods based on position" do
|
71
|
-
is_expected.to eq([second_method, first_method])
|
72
|
-
end
|
73
|
-
|
74
|
-
context 'when a payment method responds to #available_for_order?' do
|
75
|
-
let(:third_method) {
|
76
|
-
FakePaymentMethod.create(name: 'Fake', available_to_users: true, available_to_admin: true)
|
77
|
-
}
|
78
|
-
|
79
|
-
before do
|
80
|
-
fake_payment_method_class = Class.new(SolidusSupport.payment_method_parent_class)
|
81
|
-
stub_const('FakePaymentMethod', fake_payment_method_class)
|
82
|
-
|
83
|
-
third_method
|
84
|
-
end
|
85
|
-
|
86
|
-
context 'when it responds with true' do
|
87
|
-
before do
|
88
|
-
FakePaymentMethod.class_eval { def available_for_order?(_order); true; end }
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'includes it in the result' do
|
92
|
-
is_expected.to eq([second_method, first_method, third_method])
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
context 'when it responds with false' do
|
97
|
-
before do
|
98
|
-
FakePaymentMethod.class_eval { def available_for_order?(_order); false; end }
|
99
|
-
end
|
100
|
-
|
101
|
-
it "doesn't include it in the result" do
|
102
|
-
is_expected.to eq([second_method, first_method])
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
context 'when the order has a store' do
|
109
|
-
let(:order) { create(:order) }
|
110
|
-
|
111
|
-
let!(:store_with_payment_methods) do
|
112
|
-
create(:store,
|
113
|
-
payment_methods: [payment_method_with_store])
|
114
|
-
end
|
115
|
-
let!(:payment_method_with_store) { create(:payment_method) }
|
116
|
-
let!(:store_without_payment_methods) { create(:store) }
|
117
|
-
let!(:payment_method_without_store) { create(:payment_method) }
|
118
|
-
|
119
|
-
context 'when the store has payment methods' do
|
120
|
-
before { order.update!(store: store_with_payment_methods) }
|
121
|
-
|
122
|
-
it 'returns only the matching payment methods for that store' do
|
123
|
-
expect(order.available_payment_methods).to match_array(
|
124
|
-
[payment_method_with_store]
|
125
|
-
)
|
126
|
-
end
|
127
|
-
|
128
|
-
context 'when the store has an extra payment method unavailable to users' do
|
129
|
-
let!(:admin_only_payment_method) do
|
130
|
-
create(:payment_method,
|
131
|
-
available_to_users: false,
|
132
|
-
available_to_admin: true)
|
133
|
-
end
|
134
|
-
|
135
|
-
before do
|
136
|
-
store_with_payment_methods.payment_methods << admin_only_payment_method
|
137
|
-
end
|
138
|
-
|
139
|
-
it 'returns only the payment methods available to users for that store' do
|
140
|
-
expect(order.available_payment_methods).to match_array(
|
141
|
-
[payment_method_with_store]
|
142
|
-
)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
context 'when the store does not have payment methods' do
|
148
|
-
before { order.update!(store: store_without_payment_methods) }
|
149
|
-
|
150
|
-
it 'returns all matching payment methods regardless of store' do
|
151
|
-
expect(order.available_payment_methods).to match_array(
|
152
|
-
[payment_method_with_store, payment_method_without_store]
|
153
|
-
)
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
@@ -1,127 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe SolidusAfterpay::CallbacksController, type: :request do
|
6
|
-
describe 'GET cancel' do
|
7
|
-
subject(:request) { get '/solidus_afterpay/callbacks/cancel', params: params }
|
8
|
-
|
9
|
-
let(:order) { create(:order_with_totals, state: 'payment') }
|
10
|
-
|
11
|
-
let(:params) { { order_number: order.number } }
|
12
|
-
|
13
|
-
it 'redirects to the order current checkout state page' do
|
14
|
-
request
|
15
|
-
expect(response).to redirect_to('/checkout/payment')
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe 'GET confirm' do
|
20
|
-
subject(:request) { get '/solidus_afterpay/callbacks/confirm', params: params }
|
21
|
-
|
22
|
-
let(:order) { create(:order_with_totals, state: 'payment', user: user) }
|
23
|
-
let(:payment_method) { create(:afterpay_payment_method) }
|
24
|
-
let(:user) { create(:user) }
|
25
|
-
|
26
|
-
let(:order_token) { 'ORDER_TOKEN' }
|
27
|
-
let(:order_number) { order.number }
|
28
|
-
let(:payment_method_id) { payment_method.id }
|
29
|
-
|
30
|
-
let(:params) { { orderToken: order_token, order_number: order_number, payment_method_id: payment_method_id } }
|
31
|
-
|
32
|
-
context 'when the user is logged in', with_signed_in_user: true do
|
33
|
-
context 'with valid data' do
|
34
|
-
it 'redirects to the order next checkout state page' do
|
35
|
-
request
|
36
|
-
expect(response).to redirect_to('/checkout/confirm')
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'moves the order to its next state' do
|
40
|
-
expect { request }.to change { order.reload.state }.from('payment').to('confirm')
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'creates a payment' do
|
44
|
-
expect { request }.to change { order.payments.count }.from(0).to(1)
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'sets the payment total equal to the order total' do
|
48
|
-
request
|
49
|
-
expect(order.payments.last.amount).to eq(order.total)
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'creates a payment source and assigns the order token to it' do
|
53
|
-
request
|
54
|
-
expect(order.payments.last.payment_source.token).to eq(order_token)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context 'when the order_token is missing' do
|
59
|
-
let(:order_token) { nil }
|
60
|
-
|
61
|
-
it 'redirects to the order current checkout state page' do
|
62
|
-
request
|
63
|
-
expect(response).to redirect_to('/checkout/payment')
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'when the order_number is invalid' do
|
68
|
-
let(:order_number) { 'INVALID_ORDER_NUMBER' }
|
69
|
-
|
70
|
-
it 'redirects to the cart page' do
|
71
|
-
request
|
72
|
-
expect(response).to redirect_to('/cart')
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'sets a resource not found flash message' do
|
76
|
-
request
|
77
|
-
expect(flash[:notice]).to eq('The resource you were looking for could not be found.')
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context 'when the payment_method_id is invalid' do
|
82
|
-
let(:payment_method_id) { 0 }
|
83
|
-
|
84
|
-
it 'redirects to the cart page' do
|
85
|
-
request
|
86
|
-
expect(response).to redirect_to('/cart')
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'sets a resource not found flash message' do
|
90
|
-
request
|
91
|
-
expect(flash[:notice]).to eq('The resource you were looking for could not be found.')
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context 'when the order is already in confirm state' do
|
96
|
-
let(:order) { create(:order_with_totals, state: 'confirm') }
|
97
|
-
|
98
|
-
it "doesn't move the order to its next state" do
|
99
|
-
expect { request }.not_to(change { order.reload.state })
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
context 'when the order is already completed' do
|
104
|
-
let(:order) { create(:completed_order_with_totals) }
|
105
|
-
|
106
|
-
it 'redirects to the order detail page' do
|
107
|
-
request
|
108
|
-
expect(response).to redirect_to("/orders/#{order.number}")
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
context 'when the user is a guest user', with_guest_session: true do
|
114
|
-
it 'redirects to the order next checkout state page' do
|
115
|
-
request
|
116
|
-
expect(response).to redirect_to('/checkout/confirm')
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
context 'when the user is not logged in' do
|
121
|
-
it 'redirects the user to vallalah' do
|
122
|
-
request
|
123
|
-
expect(response).to redirect_to('/cart')
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
@@ -1,190 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe SolidusAfterpay::CheckoutsController, type: :request do
|
6
|
-
describe 'POST create' do
|
7
|
-
subject(:request) { post '/solidus_afterpay/checkouts.json', params: params, headers: headers }
|
8
|
-
|
9
|
-
let(:order) { create(:order_with_totals, state: 'payment', user: user) }
|
10
|
-
let(:payment_method) { create(:afterpay_payment_method) }
|
11
|
-
let(:user) { create(:user, :with_api_key) }
|
12
|
-
|
13
|
-
let(:order_number) { order.number }
|
14
|
-
let(:payment_method_id) { payment_method.id }
|
15
|
-
|
16
|
-
let(:params) { { order_number: order_number, payment_method_id: payment_method_id } }
|
17
|
-
|
18
|
-
let(:order_token) { 'ORDER_TOKEN' }
|
19
|
-
let(:gateway_response_success?) { true }
|
20
|
-
let(:gateway_response_message) { 'Success message' }
|
21
|
-
let(:gateway_response_error_code) { nil }
|
22
|
-
let(:gateway_response_params) { { 'token' => order_token } }
|
23
|
-
let(:headers) { {} }
|
24
|
-
|
25
|
-
let(:gateway_response) do
|
26
|
-
ActiveMerchant::Billing::Response.new(
|
27
|
-
gateway_response_success?,
|
28
|
-
gateway_response_message,
|
29
|
-
gateway_response_params,
|
30
|
-
{ error_code: gateway_response_error_code }
|
31
|
-
)
|
32
|
-
end
|
33
|
-
|
34
|
-
let(:gateway) { instance_double(SolidusAfterpay::Gateway, create_checkout: gateway_response) }
|
35
|
-
|
36
|
-
before do
|
37
|
-
allow(SolidusAfterpay::Gateway).to receive(:new).and_return(gateway)
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'when the use solidus api config is set to false' do
|
41
|
-
context 'when the user is logged in', with_signed_in_user: true do
|
42
|
-
context 'with valid data' do
|
43
|
-
before do
|
44
|
-
allow(Spree::Order).to receive(:find_by!).with(number: order.number).and_return(order)
|
45
|
-
request
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'returns a 201 status code' do
|
49
|
-
expect(response).to have_http_status(:created)
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'returns the order_token' do
|
53
|
-
expect(JSON.parse(response.body)['token']).to eq(order_token)
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'returns the correct params' do
|
57
|
-
expect(JSON.parse(response.body)).to include('token', 'expires', 'redirectCheckoutUrl')
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'when no redirect URLs are passed as params' do
|
61
|
-
let(:redirect_confirm_url) do
|
62
|
-
"http://www.example.com/solidus_afterpay/callbacks/confirm?order_number=#{order.number}&payment_method_id=#{payment_method.id}"
|
63
|
-
end
|
64
|
-
|
65
|
-
let(:redirect_cancel_url) do
|
66
|
-
"http://www.example.com/solidus_afterpay/callbacks/cancel?order_number=#{order.number}&payment_method_id=#{payment_method.id}"
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'calls the create_checkout with the correct arguments' do
|
70
|
-
expect(gateway).to have_received(:create_checkout).with(
|
71
|
-
order,
|
72
|
-
redirect_confirm_url: redirect_confirm_url,
|
73
|
-
redirect_cancel_url: redirect_cancel_url
|
74
|
-
)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
context 'when redirect URLs are passed as params' do
|
79
|
-
let(:redirect_confirm_url) { 'http://www.example.com/confirm_url' }
|
80
|
-
let(:redirect_cancel_url) { 'http://www.example.com/cancel_url' }
|
81
|
-
|
82
|
-
let(:params) do
|
83
|
-
{ order_number: order_number, payment_method_id: payment_method_id,
|
84
|
-
redirect_confirm_url: redirect_confirm_url, redirect_cancel_url: redirect_cancel_url }
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'calls the create_checkout with the correct arguments' do
|
88
|
-
expect(gateway).to have_received(:create_checkout).with(
|
89
|
-
order,
|
90
|
-
redirect_confirm_url: redirect_confirm_url,
|
91
|
-
redirect_cancel_url: redirect_cancel_url
|
92
|
-
)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
context 'when the order_number is invalid' do
|
98
|
-
let(:order_number) { 'INVALID_ORDER_NUMBER' }
|
99
|
-
|
100
|
-
before { request }
|
101
|
-
|
102
|
-
it 'returns a 404 status code' do
|
103
|
-
expect(response).to have_http_status(:not_found)
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'returns a resource not found error message' do
|
107
|
-
expect(JSON.parse(response.body)['error']).to eq('The resource you were looking for could not be found.')
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context 'when the payment_method_id is invalid' do
|
112
|
-
let(:payment_method_id) { 0 }
|
113
|
-
|
114
|
-
before { request }
|
115
|
-
|
116
|
-
it 'returns a 404 status code' do
|
117
|
-
expect(response).to have_http_status(:not_found)
|
118
|
-
end
|
119
|
-
|
120
|
-
it 'returns a resource not found error message' do
|
121
|
-
expect(JSON.parse(response.body)['error']).to eq('The resource you were looking for could not be found.')
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context 'when the gateway responds with error' do
|
126
|
-
let(:gateway_response_success?) { false }
|
127
|
-
let(:gateway_response_message) { 'Error message' }
|
128
|
-
let(:gateway_response_error_code) { 'errorCode' }
|
129
|
-
|
130
|
-
before { request }
|
131
|
-
|
132
|
-
it 'returns a 422 status code' do
|
133
|
-
expect(response).to have_http_status(:unprocessable_entity)
|
134
|
-
end
|
135
|
-
|
136
|
-
it 'returns a resource not found error message' do
|
137
|
-
expect(JSON.parse(response.body)['error']).to eq(gateway_response_message)
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'returns the error_code' do
|
141
|
-
expect(JSON.parse(response.body)['errorCode']).to eq(gateway_response_error_code)
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
context 'when the user is a guest user', with_guest_session: true do
|
147
|
-
it 'returns a 201 status code' do
|
148
|
-
request
|
149
|
-
expect(response).to have_http_status(:created)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
context 'when the user is not logged in' do
|
154
|
-
it 'returns a 401 status code' do
|
155
|
-
request
|
156
|
-
expect(response).to have_http_status(:unauthorized)
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
context 'when the use solidus api config is set to true', use_solidus_api: true do
|
162
|
-
context 'when the user is logged in' do
|
163
|
-
let(:headers) { { Authorization: "Bearer #{user.spree_api_key}" } }
|
164
|
-
|
165
|
-
it 'returns a 201 status code' do
|
166
|
-
request
|
167
|
-
expect(response).to have_http_status(:created)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
context 'when the user is a guest user' do
|
172
|
-
let(:headers) { { 'X-Spree-Order-Token': order.guest_token } }
|
173
|
-
|
174
|
-
it 'returns a 201 status code' do
|
175
|
-
request
|
176
|
-
expect(response).to have_http_status(:created)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
context 'when the user is not logged in' do
|
181
|
-
let(:headers) { { Authorization: 'Bearer 1234' } }
|
182
|
-
|
183
|
-
it 'returns a 401 status code' do
|
184
|
-
request
|
185
|
-
expect(response).to have_http_status(:unauthorized)
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Configure Rails Environment
|
4
|
-
ENV['RAILS_ENV'] = 'test'
|
5
|
-
|
6
|
-
# Run Coverage report
|
7
|
-
require 'solidus_dev_support/rspec/coverage'
|
8
|
-
|
9
|
-
# Create the dummy app if it's still missing.
|
10
|
-
dummy_env = "#{__dir__}/dummy/config/environment.rb"
|
11
|
-
system 'bin/rake extension:test_app' unless File.exist? dummy_env
|
12
|
-
require dummy_env
|
13
|
-
|
14
|
-
# Requires factories and other useful helpers defined in spree_core.
|
15
|
-
require 'solidus_dev_support/rspec/feature_helper'
|
16
|
-
|
17
|
-
# Requires supporting ruby files with custom matchers and macros, etc,
|
18
|
-
# in spec/support/ and its subdirectories.
|
19
|
-
Dir["#{__dir__}/support/**/*.rb"].sort.each { |f| require f }
|
20
|
-
|
21
|
-
# Requires factories defined in lib/solidus_afterpay/testing_support/factories.rb
|
22
|
-
SolidusDevSupport::TestingSupport::Factories.load_for(SolidusAfterpay::Engine)
|
23
|
-
|
24
|
-
RSpec.configure do |config|
|
25
|
-
config.infer_spec_type_from_file_location!
|
26
|
-
config.use_transactional_fixtures = false
|
27
|
-
|
28
|
-
if Spree.solidus_gem_version < Gem::Version.new('2.11')
|
29
|
-
config.extend Spree::TestingSupport::AuthorizationHelpers::Request, type: :system
|
30
|
-
end
|
31
|
-
end
|
data/spec/support/auth.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.configure do |config|
|
4
|
-
config.include Devise::Test::IntegrationHelpers, type: :request
|
5
|
-
|
6
|
-
config.before(:each, with_signed_in_user: true) { login_as user }
|
7
|
-
|
8
|
-
config.before(:each, with_guest_session: true) do
|
9
|
-
# rubocop:disable RSpec/AnyInstance
|
10
|
-
allow_any_instance_of(ActionDispatch::Cookies::CookieJar).to(
|
11
|
-
receive(:signed).and_return({ guest_token: order.guest_token })
|
12
|
-
)
|
13
|
-
# rubocop:enable RSpec/AnyInstance
|
14
|
-
end
|
15
|
-
end
|
data/spec/support/preferences.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.configure do |config|
|
4
|
-
def described_class_source_location
|
5
|
-
described_class.instance_methods(false).map do |method|
|
6
|
-
described_class.instance_method(method).source_location.first
|
7
|
-
end.uniq.first
|
8
|
-
end
|
9
|
-
|
10
|
-
config.before(:each, use_solidus_api: true) do
|
11
|
-
SolidusAfterpay.configure do |c|
|
12
|
-
c.use_solidus_api = true
|
13
|
-
end
|
14
|
-
|
15
|
-
class_name = described_class.to_s.split('::').last
|
16
|
-
source_location = described_class_source_location
|
17
|
-
|
18
|
-
SolidusAfterpay.send(:remove_const, class_name)
|
19
|
-
load source_location
|
20
|
-
end
|
21
|
-
|
22
|
-
config.after(:each, use_solidus_api: true) do
|
23
|
-
SolidusAfterpay.configure do |c|
|
24
|
-
c.use_solidus_api = false
|
25
|
-
end
|
26
|
-
|
27
|
-
class_name = described_class.to_s.split('::').last
|
28
|
-
source_location = described_class_source_location
|
29
|
-
|
30
|
-
SolidusAfterpay.send(:remove_const, class_name)
|
31
|
-
load source_location
|
32
|
-
end
|
33
|
-
end
|
data/spec/support/vcr.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'vcr'
|
4
|
-
|
5
|
-
VCR.configure do |config|
|
6
|
-
config.ignore_localhost = true
|
7
|
-
config.cassette_library_dir = "spec/fixtures/vcr_casettes"
|
8
|
-
config.hook_into :webmock
|
9
|
-
config.configure_rspec_metadata!
|
10
|
-
config.allow_http_connections_when_no_cassette = false
|
11
|
-
|
12
|
-
config.filter_sensitive_data('<ENCODED_AUTH_HEADER>') do
|
13
|
-
Base64.strict_encode64(
|
14
|
-
"#{ENV.fetch('AFTERPAY_MERCHANT_ID',
|
15
|
-
'dummy_merchant_id')}:#{ENV.fetch('AFTERPAY_SECRET_KEY', 'dummy_secret_key')}"
|
16
|
-
)
|
17
|
-
end
|
18
|
-
end
|