solidus_six_saferpay 0.1.8 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/README.md +3 -0
- data/app/assets/javascripts/solidus_six_saferpay/saferpay_payment.js +4 -1
- data/app/controllers/spree/solidus_six_saferpay/checkout_controller.rb +65 -41
- data/app/controllers/spree/solidus_six_saferpay/transaction/checkout_controller.rb +1 -1
- data/app/models/spree/payment_method/saferpay_payment_method.rb +1 -1
- data/app/models/spree/payment_method/saferpay_payment_page.rb +2 -2
- data/app/models/spree/payment_method/saferpay_transaction.rb +2 -2
- data/app/services/spree/solidus_six_saferpay/cancel_authorized_payment.rb +33 -0
- data/app/services/spree/solidus_six_saferpay/initialize_payment.rb +0 -1
- data/app/services/spree/solidus_six_saferpay/initialize_transaction.rb +0 -1
- data/app/services/spree/solidus_six_saferpay/inquire_payment.rb +27 -1
- data/app/services/spree/solidus_six_saferpay/order_not_found_handler.rb +28 -0
- data/app/services/spree/solidus_six_saferpay/payment_not_found_handler.rb +28 -0
- data/app/services/spree/solidus_six_saferpay/payment_processing_success_handler.rb +26 -0
- data/app/views/spree/checkout/payment/_saferpay_payment.html.erb +2 -2
- data/app/views/spree/solidus_six_saferpay/checkout/{iframe_breakout_redirect.html.erb → iframe_breakout_redirect.erb} +1 -1
- data/config/locales/de.yml +3 -0
- data/config/locales/en.yml +3 -0
- data/config/locales/fr.yml +3 -0
- data/config/routes.rb +6 -6
- data/lib/solidus_six_saferpay/configuration.rb +0 -2
- data/lib/solidus_six_saferpay/gateway.rb +11 -11
- data/lib/solidus_six_saferpay/payment_page_gateway.rb +8 -9
- data/lib/solidus_six_saferpay/transaction_gateway.rb +8 -9
- data/lib/solidus_six_saferpay/version.rb +1 -1
- data/solidus_six_saferpay.gemspec +2 -1
- data/spec/controllers/spree/solidus_six_saferpay/payment_page/checkout_controller_spec.rb +8 -197
- data/spec/controllers/spree/solidus_six_saferpay/transaction/checkout_controller_spec.rb +8 -220
- data/spec/services/spree/solidus_six_saferpay/assert_payment_page_spec.rb +2 -128
- data/spec/services/spree/solidus_six_saferpay/authorize_transaction_spec.rb +3 -127
- data/spec/services/spree/solidus_six_saferpay/cancel_authorized_payment_spec.rb +58 -0
- data/spec/services/spree/solidus_six_saferpay/initialize_payment_page_spec.rb +0 -2
- data/spec/services/spree/solidus_six_saferpay/initialize_transaction_spec.rb +0 -1
- data/spec/services/spree/solidus_six_saferpay/inquire_payment_page_payment_spec.rb +2 -98
- data/spec/services/spree/solidus_six_saferpay/inquire_transaction_payment_spec.rb +2 -98
- data/spec/services/spree/solidus_six_saferpay/order_not_found_handler_spec.rb +30 -0
- data/spec/services/spree/solidus_six_saferpay/payment_not_found_handler_spec.rb +30 -0
- data/spec/services/spree/solidus_six_saferpay/payment_processing_success_handler_spec.rb +34 -0
- data/spec/services/spree/solidus_six_saferpay/process_payment_page_payment_spec.rb +1 -206
- data/spec/services/spree/solidus_six_saferpay/process_transaction_payment_spec.rb +1 -200
- data/spec/solidus_six_saferpay/configuration_spec.rb +0 -3
- data/spec/solidus_six_saferpay/gateway_spec.rb +1 -14
- data/spec/solidus_six_saferpay/payment_page_gateway_spec.rb +16 -14
- data/spec/solidus_six_saferpay/transaction_gateway_spec.rb +17 -14
- data/spec/support/shared_examples/authorize_payment.rb +132 -0
- data/spec/support/shared_examples/checkout_controller.rb +294 -0
- data/spec/support/shared_examples/inquire_payment.rb +118 -0
- data/spec/support/shared_examples/process_authorized_payment.rb +202 -0
- metadata +41 -10
- data/app/services/spree/solidus_six_saferpay/inquire_transaction.rb +0 -7
- data/spec/controllers/spree/solidus_six_saferpay/checkout_controller_spec.rb +0 -41
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
module SolidusSixSaferpay
|
5
|
+
RSpec.describe CancelAuthorizedPayment do
|
6
|
+
|
7
|
+
|
8
|
+
let(:service) { described_class.new(payment) }
|
9
|
+
|
10
|
+
describe '.call' do
|
11
|
+
let(:payment) { create(:six_saferpay_payment) }
|
12
|
+
|
13
|
+
it 'calls an initialized service with given order and payment method' do
|
14
|
+
expect(described_class).to receive(:new).with(payment).and_return(service)
|
15
|
+
expect(service).to receive(:call)
|
16
|
+
|
17
|
+
described_class.call(payment)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#call' do
|
22
|
+
let(:gateway) { instance_double(::SolidusSixSaferpay::Gateway) }
|
23
|
+
|
24
|
+
before do
|
25
|
+
allow(service).to receive(:gateway).and_return(gateway)
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when the payment has not been authorized yet' do
|
29
|
+
let(:payment) { create(:six_saferpay_payment) }
|
30
|
+
|
31
|
+
it 'does not cancel the payment' do
|
32
|
+
expect(gateway).not_to receive(:void)
|
33
|
+
|
34
|
+
service.call
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'is treated as an error' do
|
38
|
+
expect(::SolidusSixSaferpay::ErrorHandler).to receive(:handle).with(instance_of(::SolidusSixSaferpay::InvalidSaferpayPayment))
|
39
|
+
|
40
|
+
service.call
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when the payment has been authorized already' do
|
45
|
+
let(:payment) { create(:six_saferpay_payment, :authorized) }
|
46
|
+
|
47
|
+
it 'voids the payment' do
|
48
|
+
expect(gateway).to receive(:void).with(payment.transaction_id)
|
49
|
+
|
50
|
+
service.call
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -9,7 +9,6 @@ module Spree
|
|
9
9
|
|
10
10
|
subject { described_class.new(order, payment_method) }
|
11
11
|
|
12
|
-
|
13
12
|
describe '#gateway' do
|
14
13
|
it_behaves_like "it uses the payment page gateway"
|
15
14
|
end
|
@@ -37,7 +36,6 @@ module Spree
|
|
37
36
|
)
|
38
37
|
end
|
39
38
|
|
40
|
-
# stub gateway to return our mock response
|
41
39
|
before do
|
42
40
|
allow(subject).to receive(:gateway).
|
43
41
|
and_return(double('gateway', initialize_payment: gateway_response))
|
@@ -5,112 +5,16 @@ module Spree
|
|
5
5
|
RSpec.describe InquirePaymentPagePayment do
|
6
6
|
|
7
7
|
let(:payment) { create(:six_saferpay_payment) }
|
8
|
-
|
9
8
|
subject { described_class.new(payment) }
|
10
9
|
|
11
|
-
|
12
10
|
describe '#gateway' do
|
13
11
|
it_behaves_like "it uses the payment page gateway"
|
14
12
|
end
|
15
13
|
|
16
|
-
|
17
14
|
describe '#call' do
|
18
|
-
|
19
|
-
|
20
|
-
allow(subject).to receive(:gateway).and_return(double('gateway', inquire: gateway_response))
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'when gateway response is not successful' do
|
24
|
-
let(:gateway_success) { false }
|
25
|
-
let(:error_behaviour) { "ABORT" }
|
26
|
-
let(:error_name) { "VALIDATION_FAILED" }
|
27
|
-
let(:error_message) { "Request validation failed" }
|
28
|
-
let(:api_response) { nil }
|
29
|
-
let(:translated_general_error) { "General Error" }
|
30
|
-
let(:translated_user_message) { "User Message" }
|
31
|
-
|
32
|
-
let(:gateway_response) do
|
33
|
-
::SolidusSixSaferpay::GatewayResponse.new(
|
34
|
-
gateway_success,
|
35
|
-
"initialize success: #{gateway_success}",
|
36
|
-
api_response,
|
37
|
-
error_name: error_name,
|
38
|
-
)
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'still indicates success' do
|
42
|
-
subject.call
|
43
|
-
|
44
|
-
expect(subject).to be_success
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'does not update the response hash' do
|
48
|
-
expect { subject.call }.not_to change { payment.response_hash }
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'sets the user message according to the api error code' do
|
52
|
-
expect(I18n).to receive(:t).with(:general_error, scope: [:solidus_six_saferpay, :errors]).and_return(translated_general_error)
|
53
|
-
expect(I18n).to receive(:t).with(error_name, scope: [:six_saferpay, :error_names]).and_return(translated_user_message)
|
54
|
-
subject.call
|
55
|
-
|
56
|
-
expect(subject.user_message).to eq("#{translated_general_error}: #{translated_user_message}")
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'when successful' do
|
61
|
-
let(:transaction_status) { "AUTHORIZED" }
|
62
|
-
let(:transaction_id) { "723n4MAjMdhjSAhAKEUdA8jtl9jb" }
|
63
|
-
let(:transaction_date) { "2015-01-30T12:45:22.258+01:00" }
|
64
|
-
let(:amount_value) { "100" }
|
65
|
-
let(:amount_currency) { "USD" }
|
66
|
-
let(:brand_name) { 'PaymentBrand' }
|
67
|
-
let(:display_text) { "xxxx xxxx xxxx 1234" }
|
68
|
-
let(:six_transaction_reference) { "0:0:3:723n4MAjMdhjSAhAKEUdA8jtl9jb" }
|
69
|
-
|
70
|
-
let(:payment_means) do
|
71
|
-
SixSaferpay::ResponsePaymentMeans.new(
|
72
|
-
brand: SixSaferpay::Brand.new(name: brand_name),
|
73
|
-
display_text: display_text
|
74
|
-
)
|
75
|
-
end
|
76
|
-
|
77
|
-
# https://saferpay.github.io/jsonapi/#Payment_v1_PaymentPage_Assert
|
78
|
-
let(:api_response) do
|
79
|
-
SixSaferpay::SixPaymentPage::AssertResponse.new(
|
80
|
-
response_header: SixSaferpay::ResponseHeader.new(request_id: 'test', spec_version: 'test'),
|
81
|
-
transaction: SixSaferpay::Transaction.new(
|
82
|
-
type: "PAYMENT",
|
83
|
-
status: transaction_status,
|
84
|
-
id: transaction_id,
|
85
|
-
date: transaction_date,
|
86
|
-
amount: SixSaferpay::Amount.new(value: amount_value, currency_code: amount_currency),
|
87
|
-
six_transaction_reference: six_transaction_reference,
|
88
|
-
),
|
89
|
-
payment_means: payment_means
|
90
|
-
)
|
91
|
-
end
|
92
|
-
|
93
|
-
let(:gateway_success) { true }
|
94
|
-
let(:gateway_response) do
|
95
|
-
::SolidusSixSaferpay::GatewayResponse.new(
|
96
|
-
gateway_success,
|
97
|
-
"initialize success: #{gateway_success}",
|
98
|
-
api_response
|
99
|
-
)
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'updates the response hash' do
|
103
|
-
expect { subject.call }.to change { payment.response_hash }.from(payment.response_hash).to(api_response.to_h)
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'indicates success' do
|
107
|
-
subject.call
|
108
|
-
|
109
|
-
expect(subject).to be_success
|
110
|
-
end
|
111
|
-
end
|
15
|
+
let(:api_response_class) { SixSaferpay::SixPaymentPage::AssertResponse }
|
16
|
+
it_behaves_like "inquire_payment"
|
112
17
|
end
|
113
|
-
|
114
18
|
end
|
115
19
|
end
|
116
20
|
end
|
@@ -5,111 +5,15 @@ module Spree
|
|
5
5
|
RSpec.describe InquireTransactionPayment do
|
6
6
|
|
7
7
|
let(:payment) { create(:six_saferpay_payment) }
|
8
|
-
|
9
8
|
subject { described_class.new(payment) }
|
10
9
|
|
11
|
-
|
12
10
|
describe '#gateway' do
|
13
11
|
it_behaves_like "it uses the transaction gateway"
|
14
12
|
end
|
15
13
|
|
16
|
-
|
17
14
|
describe '#call' do
|
18
|
-
|
19
|
-
|
20
|
-
allow(subject).to receive(:gateway).and_return(double('gateway', inquire: gateway_response))
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'when gateway response is not successful' do
|
24
|
-
let(:gateway_success) { false }
|
25
|
-
let(:error_behaviour) { "ABORT" }
|
26
|
-
let(:error_name) { "VALIDATION_FAILED" }
|
27
|
-
let(:error_message) { "Request validation failed" }
|
28
|
-
let(:api_response) { nil }
|
29
|
-
let(:translated_general_error) { "General Error" }
|
30
|
-
let(:translated_user_message) { "User Message" }
|
31
|
-
|
32
|
-
let(:gateway_response) do
|
33
|
-
::SolidusSixSaferpay::GatewayResponse.new(
|
34
|
-
gateway_success,
|
35
|
-
"initialize success: #{gateway_success}",
|
36
|
-
api_response,
|
37
|
-
error_name: error_name,
|
38
|
-
)
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'still indicates success' do
|
42
|
-
subject.call
|
43
|
-
|
44
|
-
expect(subject).to be_success
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'does not update the response hash' do
|
48
|
-
expect { subject.call }.not_to change { payment.response_hash }
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'sets the user message according to the api error code' do
|
52
|
-
expect(I18n).to receive(:t).with(:general_error, scope: [:solidus_six_saferpay, :errors]).once.and_return(translated_general_error)
|
53
|
-
expect(I18n).to receive(:t).with(error_name, scope: [:six_saferpay, :error_names]).once.and_return(translated_user_message)
|
54
|
-
|
55
|
-
subject.call
|
56
|
-
|
57
|
-
expect(subject.user_message).to eq("#{translated_general_error}: #{translated_user_message}")
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context 'when successful' do
|
62
|
-
let(:transaction_status) { "AUTHORIZED" }
|
63
|
-
let(:transaction_id) { "723n4MAjMdhjSAhAKEUdA8jtl9jb" }
|
64
|
-
let(:transaction_date) { "2015-01-30T12:45:22.258+01:00" }
|
65
|
-
let(:amount_value) { "100" }
|
66
|
-
let(:amount_currency) { "USD" }
|
67
|
-
let(:brand_name) { 'PaymentBrand' }
|
68
|
-
let(:display_text) { "xxxx xxxx xxxx 1234" }
|
69
|
-
let(:six_transaction_reference) { "0:0:3:723n4MAjMdhjSAhAKEUdA8jtl9jb" }
|
70
|
-
|
71
|
-
let(:payment_means) do
|
72
|
-
SixSaferpay::ResponsePaymentMeans.new(
|
73
|
-
brand: SixSaferpay::Brand.new(name: brand_name),
|
74
|
-
display_text: display_text
|
75
|
-
)
|
76
|
-
end
|
77
|
-
|
78
|
-
# https://saferpay.github.io/jsonapi/#Payment_v1_PaymentPage_Assert
|
79
|
-
let(:api_response) do
|
80
|
-
SixSaferpay::SixPaymentPage::AssertResponse.new(
|
81
|
-
response_header: SixSaferpay::ResponseHeader.new(request_id: 'test', spec_version: 'test'),
|
82
|
-
transaction: SixSaferpay::Transaction.new(
|
83
|
-
type: "PAYMENT",
|
84
|
-
status: transaction_status,
|
85
|
-
id: transaction_id,
|
86
|
-
date: transaction_date,
|
87
|
-
amount: SixSaferpay::Amount.new(value: amount_value, currency_code: amount_currency),
|
88
|
-
six_transaction_reference: six_transaction_reference,
|
89
|
-
),
|
90
|
-
payment_means: payment_means
|
91
|
-
)
|
92
|
-
end
|
93
|
-
|
94
|
-
let(:gateway_success) { true }
|
95
|
-
let(:gateway_response) do
|
96
|
-
::SolidusSixSaferpay::GatewayResponse.new(
|
97
|
-
gateway_success,
|
98
|
-
"initialize success: #{gateway_success}",
|
99
|
-
api_response
|
100
|
-
)
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'updates the response hash' do
|
104
|
-
expect { subject.call }.to change { payment.response_hash }.from(payment.response_hash).to(api_response.to_h)
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'indicates success' do
|
108
|
-
subject.call
|
109
|
-
|
110
|
-
expect(subject).to be_success
|
111
|
-
end
|
112
|
-
end
|
15
|
+
let(:api_response_class) { SixSaferpay::SixTransaction::InquireResponse }
|
16
|
+
it_behaves_like "inquire_payment"
|
113
17
|
end
|
114
18
|
|
115
19
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
module SolidusSixSaferpay
|
5
|
+
RSpec.describe OrderNotFoundHandler do
|
6
|
+
|
7
|
+
let(:controller) { instance_double(SolidusSixSaferpay::CheckoutController) }
|
8
|
+
let(:order_number) { "R123445678" }
|
9
|
+
|
10
|
+
subject { described_class.new(controller_context: controller, order_number: order_number) }
|
11
|
+
|
12
|
+
describe '.call' do
|
13
|
+
it 'calls a new instance with given parameters' do
|
14
|
+
expect(described_class).to receive(:new).with(controller_context: controller, order_number: order_number).and_return(subject)
|
15
|
+
expect(subject).to receive(:call)
|
16
|
+
|
17
|
+
described_class.call(controller_context: controller, order_number: order_number)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#call' do
|
22
|
+
it 'informs about the error' do
|
23
|
+
expect(::SolidusSixSaferpay::ErrorHandler).to receive(:handle).with(instance_of(StandardError))
|
24
|
+
|
25
|
+
subject.call
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
module SolidusSixSaferpay
|
5
|
+
RSpec.describe PaymentNotFoundHandler do
|
6
|
+
|
7
|
+
let(:controller) { instance_double(SolidusSixSaferpay::CheckoutController) }
|
8
|
+
let(:order) { instance_double(Spree::Order, number: "R12345678") }
|
9
|
+
|
10
|
+
subject { described_class.new(controller_context: controller, order: order) }
|
11
|
+
|
12
|
+
describe '.call' do
|
13
|
+
it 'calls a new instance with given parameters' do
|
14
|
+
expect(described_class).to receive(:new).with(controller_context: controller, order: order).and_return(subject)
|
15
|
+
expect(subject).to receive(:call)
|
16
|
+
|
17
|
+
described_class.call(controller_context: controller, order: order)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#call' do
|
22
|
+
it 'informs about the error' do
|
23
|
+
expect(::SolidusSixSaferpay::ErrorHandler).to receive(:handle).with(instance_of(StandardError))
|
24
|
+
|
25
|
+
subject.call
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
module SolidusSixSaferpay
|
5
|
+
RSpec.describe PaymentProcessingSuccessHandler do
|
6
|
+
|
7
|
+
let(:controller) { instance_double(SolidusSixSaferpay::CheckoutController) }
|
8
|
+
let(:order) { instance_double(Spree::Order, number: "R12345678") }
|
9
|
+
|
10
|
+
subject { described_class.new(controller_context: controller, order: order) }
|
11
|
+
|
12
|
+
describe '.call' do
|
13
|
+
it 'calls a new instance with given parameters' do
|
14
|
+
expect(described_class).to receive(:new).with(controller_context: controller, order: order).and_return(subject)
|
15
|
+
expect(subject).to receive(:call)
|
16
|
+
|
17
|
+
described_class.call(controller_context: controller, order: order)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#call' do
|
22
|
+
context 'when the order is in payment state' do
|
23
|
+
let(:order) { instance_double(Spree::Order, number: "R12345678", payment?: true) }
|
24
|
+
|
25
|
+
it 'advances the order to the next state' do
|
26
|
+
expect(order).to receive(:next!)
|
27
|
+
|
28
|
+
subject.call
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -13,213 +13,8 @@ module Spree
|
|
13
13
|
end
|
14
14
|
|
15
15
|
describe '#call' do
|
16
|
-
|
17
|
-
before do
|
18
|
-
allow(subject).to receive(:gateway).and_return(double('gateway'))
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'liability_shift check' do
|
22
|
-
|
23
|
-
before do
|
24
|
-
allow(subject).to receive(:gateway).and_return(double('gateway'))
|
25
|
-
|
26
|
-
|
27
|
-
# ensure other methods don't modify outcome
|
28
|
-
allow(subject).to receive(:validate_payment!)
|
29
|
-
allow(subject).to receive(:cancel_old_solidus_payments)
|
30
|
-
allow(payment).to receive(:create_solidus_payment!)
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'when liability shift is required' do
|
34
|
-
context 'and liability shift is not granted' do
|
35
|
-
|
36
|
-
let(:payment) { create(:six_saferpay_payment, :authorized, :without_liability_shift) }
|
37
|
-
|
38
|
-
it 'cancels the payment' do
|
39
|
-
expect(payment.payment_method.preferred_require_liability_shift).to be true
|
40
|
-
expect(payment.liability.liability_shift).to be false
|
41
|
-
|
42
|
-
expect(subject.gateway).to receive(:void).with(payment.transaction_id)
|
43
|
-
|
44
|
-
subject.call
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'indicates failure' do
|
48
|
-
expect(payment.payment_method.preferred_require_liability_shift).to be true
|
49
|
-
expect(payment.liability.liability_shift).to be false
|
50
|
-
|
51
|
-
expect(subject.gateway).to receive(:void).with(payment.transaction_id)
|
52
|
-
|
53
|
-
subject.call
|
54
|
-
|
55
|
-
expect(subject).not_to be_success
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'and liability shift is granted' do
|
61
|
-
it "doesn't cancel the payment" do
|
62
|
-
expect(payment.payment_method.preferred_require_liability_shift).to be true
|
63
|
-
expect(payment.liability.liability_shift).to be true
|
64
|
-
|
65
|
-
expect(subject.gateway).not_to receive(:void)
|
66
|
-
|
67
|
-
subject.call
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'passes the liability shift check' do
|
71
|
-
expect(payment.payment_method.preferred_require_liability_shift).to be true
|
72
|
-
expect(payment.liability.liability_shift).to be true
|
73
|
-
|
74
|
-
subject.call
|
75
|
-
|
76
|
-
expect(subject).to be_success
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context 'when liability shift is not required' do
|
82
|
-
let(:payment_method) { create(:saferpay_payment_method, :no_require_liability_shift) }
|
83
|
-
|
84
|
-
context 'and liability shift is not granted' do
|
85
|
-
let(:payment) { create(:six_saferpay_payment, :authorized, :without_liability_shift, payment_method: payment_method) }
|
86
|
-
|
87
|
-
it "doesn't cancel the payment" do
|
88
|
-
expect(payment.payment_method.preferred_require_liability_shift).to be false
|
89
|
-
expect(payment.liability.liability_shift).to be false
|
90
|
-
|
91
|
-
expect(subject.gateway).not_to receive(:void)
|
92
|
-
|
93
|
-
subject.call
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'passes the liability shift check' do
|
97
|
-
expect(payment.payment_method.preferred_require_liability_shift).to be false
|
98
|
-
expect(payment.liability.liability_shift).to be false
|
99
|
-
subject.call
|
100
|
-
|
101
|
-
expect(subject).to be_success
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
context 'and liability shift is granted' do
|
106
|
-
let(:payment) { create(:six_saferpay_payment, :authorized, payment_method: payment_method) }
|
107
|
-
it "doesn't cancel the payment" do
|
108
|
-
expect(payment.payment_method.preferred_require_liability_shift).to be false
|
109
|
-
expect(payment.liability.liability_shift).to be true
|
110
|
-
|
111
|
-
expect(subject.gateway).not_to receive(:void)
|
112
|
-
|
113
|
-
subject.call
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'passes the liability shift check' do
|
117
|
-
expect(payment.payment_method.preferred_require_liability_shift).to be false
|
118
|
-
expect(payment.liability.liability_shift).to be true
|
119
|
-
subject.call
|
120
|
-
|
121
|
-
expect(subject).to be_success
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
context 'payment validation' do
|
128
|
-
before do
|
129
|
-
allow(subject).to receive(:gateway).and_return(double('gateway'))
|
130
|
-
|
131
|
-
|
132
|
-
# ensure other methods don't modify outcome
|
133
|
-
allow(subject).to receive(:check_liability_shift_requirements!)
|
134
|
-
allow(subject).to receive(:cancel_old_solidus_payments)
|
135
|
-
allow(payment).to receive(:create_solidus_payment!)
|
136
|
-
end
|
137
|
-
|
138
|
-
it 'validates the payment' do
|
139
|
-
expect(PaymentValidator).to receive(:call).with(payment)
|
140
|
-
subject.call
|
141
|
-
end
|
142
|
-
|
143
|
-
context 'when the payment is invalid' do
|
144
|
-
it 'cancels the payment' do
|
145
|
-
expect(subject.gateway).to receive(:void).with(payment.transaction_id)
|
146
|
-
|
147
|
-
subject.call
|
148
|
-
end
|
149
|
-
|
150
|
-
it 'indicates failure' do
|
151
|
-
allow(subject.gateway).to receive(:void).with(payment.transaction_id)
|
152
|
-
|
153
|
-
subject.call
|
154
|
-
|
155
|
-
expect(subject).not_to be_success
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
context 'when the payment is valid' do
|
160
|
-
before do
|
161
|
-
allow(PaymentValidator).to receive(:call).with(payment).and_return(true)
|
162
|
-
end
|
163
|
-
|
164
|
-
it "doesn't cancel the payment" do
|
165
|
-
expect(subject.gateway).not_to receive(:void)
|
166
|
-
|
167
|
-
subject.call
|
168
|
-
end
|
169
|
-
|
170
|
-
it 'indicates success' do
|
171
|
-
subject.call
|
172
|
-
|
173
|
-
expect(subject).to be_success
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
context 'when the payment has passed all validations' do
|
179
|
-
before do
|
180
|
-
allow(subject).to receive(:check_liability_shift_requirements!).and_return(true)
|
181
|
-
allow(subject).to receive(:validate_payment!).and_return(true)
|
182
|
-
end
|
183
|
-
|
184
|
-
context 'when previous solidus payments exist for this order' do
|
185
|
-
let(:order) { payment.order }
|
186
|
-
let!(:previous_payment_invalid) { create(:payment_using_saferpay, order: order) }
|
187
|
-
let!(:previous_payment_checkout) { create(:payment_using_saferpay, order: order) }
|
188
|
-
|
189
|
-
before do
|
190
|
-
# This is bad practice because we mock which payments are invalidated here.
|
191
|
-
# The reason is that you can't stub methods on AR objects that
|
192
|
-
# are loaded from the DB and because #solidus_payments_to_cancel
|
193
|
-
# is just AR scopes, I prefer this test over using stuff like
|
194
|
-
# #expect_any_instance_of
|
195
|
-
allow(subject).to receive(:solidus_payments_to_cancel).and_return([previous_payment_checkout])
|
196
|
-
end
|
197
|
-
|
198
|
-
it 'cancels old solidus payments' do
|
199
|
-
expect(previous_payment_invalid).not_to receive(:cancel!)
|
200
|
-
expect(previous_payment_checkout).to receive(:cancel!)
|
201
|
-
|
202
|
-
subject.call
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
it 'creates a new solidus payment' do
|
207
|
-
expect(payment).to receive(:create_solidus_payment!)
|
208
|
-
|
209
|
-
subject.call
|
210
|
-
end
|
211
|
-
|
212
|
-
it 'indicates success' do
|
213
|
-
allow(payment).to receive(:create_solidus_payment!)
|
214
|
-
|
215
|
-
subject.call
|
216
|
-
|
217
|
-
expect(subject).to be_success
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
16
|
+
it_behaves_like 'process_authorized_payment'
|
221
17
|
end
|
222
|
-
|
223
18
|
end
|
224
19
|
end
|
225
20
|
end
|