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
@@ -1,228 +1,16 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module Spree
|
4
|
+
module SolidusSixSaferpay
|
5
|
+
RSpec.describe Transaction::CheckoutController do
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
let(:initialize_payment_service_class) { InitializeTransaction }
|
8
|
+
let(:authorize_payment_service_class) { AuthorizeTransaction }
|
9
|
+
let(:process_authorization_service_class) { ProcessTransactionPayment }
|
10
|
+
let(:inquire_payment_service_class) { InquireTransactionPayment }
|
9
11
|
|
10
|
-
|
12
|
+
it_behaves_like "checkout_controller"
|
11
13
|
|
12
|
-
before do
|
13
|
-
allow(controller).to receive_messages try_spree_current_user: user
|
14
|
-
allow(controller).to receive_messages current_order: order
|
15
|
-
end
|
16
|
-
|
17
|
-
describe 'GET init' do
|
18
|
-
let(:success) { false }
|
19
|
-
let(:redirect_url) { '/saferpay/redirect/url' }
|
20
|
-
let(:initialized_payment) { instance_double("Spree::SolidusSixSaferpay::InitializeTransaction", success?: success, redirect_url: redirect_url) }
|
21
|
-
|
22
|
-
it 'tries to the saferpay payment' do
|
23
|
-
expect(Spree::SolidusSixSaferpay::InitializeTransaction).to receive(:call).with(order, payment_method).and_return(initialized_payment)
|
24
|
-
|
25
|
-
get :init, params: { payment_method_id: payment_method.id }
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
context 'when payment initialize succeeds' do
|
30
|
-
let(:success) { true }
|
31
|
-
|
32
|
-
before do
|
33
|
-
allow(Spree::SolidusSixSaferpay::InitializeTransaction).to receive(:call).with(order, payment_method).and_return(initialized_payment)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'returns the redirect_url' do
|
37
|
-
get :init, params: { payment_method_id: payment_method.id }
|
38
|
-
|
39
|
-
body = JSON.parse(response.body)
|
40
|
-
expect(body["redirect_url"]).to eq(redirect_url)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'when payment initialize fails' do
|
45
|
-
let(:success) { false }
|
46
|
-
|
47
|
-
before do
|
48
|
-
allow(Spree::SolidusSixSaferpay::InitializeTransaction).to receive(:call).with(order, payment_method).and_return(initialized_payment)
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'returns an error' do
|
52
|
-
get :init, params: { payment_method_id: payment_method.id }
|
53
|
-
|
54
|
-
expect(response.body).to match(/errors/)
|
55
|
-
expect(response.status).to eq(422)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
describe 'GET success' do
|
62
|
-
context 'when the order is not found' do
|
63
|
-
let(:order) { nil }
|
64
|
-
|
65
|
-
it 'redirects to the cart page via iframe breakout' do
|
66
|
-
get :success
|
67
|
-
expect(assigns(:redirect_path)).to eq(routes.cart_path)
|
68
|
-
expect(response).to render_template :iframe_breakout_redirect
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context 'when the order is already completed' do
|
73
|
-
let(:order) { create(:order_ready_to_ship) }
|
74
|
-
|
75
|
-
it 'redirects to the cart page via iframe breakout' do
|
76
|
-
get :success
|
77
|
-
expect(assigns(:redirect_path)).to eq(routes.cart_path)
|
78
|
-
expect(response).to render_template :iframe_breakout_redirect
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context 'when payment could not be created' do
|
83
|
-
let!(:payment) { nil }
|
84
|
-
|
85
|
-
it 'raises an error because no payment exists' do
|
86
|
-
expect{ get(:success) }.to raise_error(Spree::Core::GatewayError)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
context 'when payment create was successful' do
|
91
|
-
let!(:payment) { create(:six_saferpay_payment, order: order) }
|
92
|
-
let(:assert_success) { false }
|
93
|
-
let(:payment_assert) { instance_double("Spree::SolidusSixSaferpay::AuthorizeTransaction", success?: assert_success) }
|
94
|
-
let(:payment_inquiry) { instance_double("Spree::SolidusSixSaferpay::InquireTransactionPayment", user_message: "payment inquiry message") }
|
95
|
-
|
96
|
-
it 'asserts the payment' do
|
97
|
-
expect(Spree::SolidusSixSaferpay::AuthorizeTransaction).to receive(:call).with(payment).and_return(payment_assert)
|
98
|
-
expect(Spree::SolidusSixSaferpay::InquireTransactionPayment).to receive(:call).with(payment).and_return(payment_inquiry)
|
99
|
-
|
100
|
-
get :success
|
101
|
-
end
|
102
|
-
|
103
|
-
context 'when the payment assert is successful' do
|
104
|
-
let(:assert_success) { true }
|
105
|
-
let(:process_success) { false }
|
106
|
-
let(:processed_payment) { instance_double("Spree::SolidusSixSaferpay::ProcessTransactionPayment", success?: process_success, user_message: "payment processing message") }
|
107
|
-
|
108
|
-
before do
|
109
|
-
allow(Spree::SolidusSixSaferpay::AuthorizeTransaction).to receive(:call).with(payment).and_return(payment_assert)
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'processes the asserted payment' do
|
113
|
-
expect(Spree::SolidusSixSaferpay::ProcessTransactionPayment).to receive(:call).with(payment).and_return(processed_payment)
|
114
|
-
|
115
|
-
get :success
|
116
|
-
end
|
117
|
-
|
118
|
-
context 'when the processing is successful' do
|
119
|
-
let(:process_success) { true }
|
120
|
-
|
121
|
-
before do
|
122
|
-
allow(Spree::SolidusSixSaferpay::ProcessTransactionPayment).to receive(:call).with(payment).and_return(processed_payment)
|
123
|
-
end
|
124
|
-
|
125
|
-
context 'when the default success handling is applied' do
|
126
|
-
context 'when order is in payment state' do
|
127
|
-
let(:order) { create(:order, state: :payment) }
|
128
|
-
|
129
|
-
it 'moves order to next state' do
|
130
|
-
expect(order).to receive(:next!)
|
131
|
-
|
132
|
-
get :success
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
context 'when order is already in complete state' do
|
137
|
-
let(:order) { create(:order, state: :complete) }
|
138
|
-
|
139
|
-
it 'does not modify the order state' do
|
140
|
-
expect(order).not_to receive(:next!)
|
141
|
-
|
142
|
-
get :success
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
context 'when a custom success handling is applied' do
|
148
|
-
let(:custom_handler) do
|
149
|
-
Proc.new { |context, order| order.email }
|
150
|
-
end
|
151
|
-
|
152
|
-
before do
|
153
|
-
allow(::SolidusSixSaferpay.config).to receive(:payment_processing_success_handler).and_return(custom_handler)
|
154
|
-
end
|
155
|
-
|
156
|
-
it 'does not modify the order state' do
|
157
|
-
expect(order).not_to receive(:next!)
|
158
|
-
|
159
|
-
get :success
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'executes the custom handler' do
|
163
|
-
expect(order).to receive(:email)
|
164
|
-
|
165
|
-
get :success
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
context 'when the processing fails' do
|
171
|
-
let(:process_success) { false }
|
172
|
-
|
173
|
-
before do
|
174
|
-
allow(Spree::SolidusSixSaferpay::ProcessTransactionPayment).to receive(:call).with(payment).and_return(processed_payment)
|
175
|
-
end
|
176
|
-
|
177
|
-
it 'displays an error message' do
|
178
|
-
get :success
|
179
|
-
|
180
|
-
expect(flash[:error]).to eq("payment processing message")
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
end
|
185
|
-
|
186
|
-
context 'when the payment assert fails' do
|
187
|
-
let(:assert_success) { false }
|
188
|
-
|
189
|
-
before do
|
190
|
-
allow(Spree::SolidusSixSaferpay::AuthorizeTransaction).to receive(:call).with(payment).and_return(payment_assert)
|
191
|
-
end
|
192
|
-
|
193
|
-
it 'inquires the payment' do
|
194
|
-
expect(Spree::SolidusSixSaferpay::InquireTransactionPayment).to receive(:call).with(payment).and_return(payment_inquiry)
|
195
|
-
|
196
|
-
get :success
|
197
|
-
end
|
198
|
-
|
199
|
-
it 'displays an error message' do
|
200
|
-
expect(Spree::SolidusSixSaferpay::InquireTransactionPayment).to receive(:call).with(payment).and_return(payment_inquiry)
|
201
|
-
get :success
|
202
|
-
|
203
|
-
expect(flash[:error]).to eq("payment inquiry message")
|
204
|
-
end
|
205
|
-
end
|
206
14
|
end
|
207
15
|
end
|
208
|
-
|
209
|
-
describe 'GET fail' do
|
210
|
-
let!(:payment) { create(:six_saferpay_payment, order: order) }
|
211
|
-
let(:payment_inquiry) { instance_double("Spree::SolidusSixSaferpay::InquireTransactionPayment", user_message: "payment inquiry message") }
|
212
|
-
|
213
|
-
it 'inquires the payment' do
|
214
|
-
expect(Spree::SolidusSixSaferpay::InquireTransactionPayment).to receive(:call).with(payment).and_return(payment_inquiry)
|
215
|
-
|
216
|
-
get :fail
|
217
|
-
end
|
218
|
-
|
219
|
-
it 'displays an error message' do
|
220
|
-
expect(Spree::SolidusSixSaferpay::InquireTransactionPayment).to receive(:call).with(payment).and_return(payment_inquiry)
|
221
|
-
|
222
|
-
get :fail
|
223
|
-
|
224
|
-
expect(flash[:error]).to eq("payment inquiry message")
|
225
|
-
end
|
226
|
-
|
227
|
-
end
|
228
16
|
end
|
@@ -14,135 +14,9 @@ module Spree
|
|
14
14
|
end
|
15
15
|
|
16
16
|
describe '#call' do
|
17
|
-
let(:
|
18
|
-
|
19
|
-
let(:transaction_date) { "2015-01-30T12:45:22.258+01:00" }
|
20
|
-
let(:amount_value) { "100" }
|
21
|
-
let(:amount_currency) { "USD" }
|
22
|
-
let(:brand_name) { 'PaymentBrand' }
|
23
|
-
let(:display_text) { "xxxx xxxx xxxx 1234" }
|
24
|
-
let(:six_transaction_reference) { "0:0:3:723n4MAjMdhjSAhAKEUdA8jtl9jb" }
|
25
|
-
|
26
|
-
let(:payment_means) do
|
27
|
-
SixSaferpay::ResponsePaymentMeans.new(
|
28
|
-
brand: SixSaferpay::Brand.new(name: brand_name),
|
29
|
-
display_text: display_text
|
30
|
-
)
|
31
|
-
end
|
32
|
-
|
33
|
-
# https://saferpay.github.io/jsonapi/#Payment_v1_PaymentPage_Initialize
|
34
|
-
let(:api_response) do
|
35
|
-
SixSaferpay::SixPaymentPage::AssertResponse.new(
|
36
|
-
response_header: SixSaferpay::ResponseHeader.new(request_id: 'test', spec_version: 'test'),
|
37
|
-
transaction: SixSaferpay::Transaction.new(
|
38
|
-
type: "PAYMENT",
|
39
|
-
status: transaction_status,
|
40
|
-
id: transaction_id,
|
41
|
-
date: transaction_date,
|
42
|
-
amount: SixSaferpay::Amount.new(value: amount_value, currency_code: amount_currency),
|
43
|
-
six_transaction_reference: six_transaction_reference,
|
44
|
-
),
|
45
|
-
payment_means: payment_means
|
46
|
-
)
|
47
|
-
end
|
48
|
-
|
49
|
-
let(:gateway_response) do
|
50
|
-
::SolidusSixSaferpay::GatewayResponse.new(
|
51
|
-
gateway_success,
|
52
|
-
"initialize success: #{gateway_success}",
|
53
|
-
api_response
|
54
|
-
)
|
55
|
-
end
|
56
|
-
|
57
|
-
# stub gateway to return our mock response
|
58
|
-
before do
|
59
|
-
allow(subject).to receive(:gateway).
|
60
|
-
and_return(double('gateway', authorize: gateway_response))
|
61
|
-
end
|
62
|
-
|
63
|
-
context 'when not successful' do
|
64
|
-
let(:gateway_success) { false }
|
65
|
-
|
66
|
-
it 'indicates failure' do
|
67
|
-
subject.call
|
68
|
-
|
69
|
-
expect(subject).not_to be_success
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'does not update the payment attributes' do
|
73
|
-
expect { subject.call }.not_to change { payment.transaction_id }
|
74
|
-
expect { subject.call }.not_to change { payment.transaction_status }
|
75
|
-
expect { subject.call }.not_to change { payment.transaction_date }
|
76
|
-
expect { subject.call }.not_to change { payment.six_transaction_reference }
|
77
|
-
expect { subject.call }.not_to change { payment.display_text }
|
78
|
-
expect { subject.call }.not_to change { payment.response_hash }
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context 'when successful' do
|
83
|
-
let(:gateway_success) { true }
|
84
|
-
|
85
|
-
it 'updates the transaction_id' do
|
86
|
-
expect { subject.call }.to change { payment.transaction_id }.from(nil).to(transaction_id)
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'updates the transaction status' do
|
90
|
-
expect { subject.call }.to change { payment.transaction_status }.from(nil).to(transaction_status)
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'updates the transaction date' do
|
94
|
-
expect { subject.call }.to change { payment.transaction_date }.from(nil).to(DateTime.parse(transaction_date))
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'updates the six_transaction_reference' do
|
98
|
-
expect { subject.call }.to change { payment.six_transaction_reference }.from(nil).to(six_transaction_reference)
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'updates the display_text' do
|
102
|
-
expect { subject.call }.to change { payment.display_text }.from(nil).to(display_text)
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'updates the response hash' do
|
106
|
-
expect { subject.call }.to change { payment.response_hash }.from(payment.response_hash).to(api_response.to_h)
|
107
|
-
end
|
108
|
-
|
109
|
-
context 'when the payment was made with a card' do
|
110
|
-
let(:masked_number) { "xxxx xxxx xxxx 5555" }
|
111
|
-
let(:exp_year) { "19" }
|
112
|
-
let(:exp_month) { "5" }
|
113
|
-
let(:payment_means) do
|
114
|
-
SixSaferpay::ResponsePaymentMeans.new(
|
115
|
-
brand: SixSaferpay::Brand.new(name: brand_name),
|
116
|
-
display_text: display_text,
|
117
|
-
card: SixSaferpay::ResponseCard.new(
|
118
|
-
masked_number: masked_number,
|
119
|
-
exp_year: exp_year,
|
120
|
-
exp_month: exp_month
|
121
|
-
)
|
122
|
-
)
|
123
|
-
end
|
124
|
-
|
125
|
-
it 'updates the masked number' do
|
126
|
-
expect { subject.call }.to change { payment.masked_number }.from(nil).to(masked_number)
|
127
|
-
end
|
128
|
-
|
129
|
-
it 'updates the expiry year' do
|
130
|
-
expect { subject.call }.to change { payment.expiration_year }.from(nil).to(exp_year)
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'updates the expiry month' do
|
134
|
-
expect { subject.call }.to change { payment.expiration_month }.from(nil).to(exp_month)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
it 'indicates success' do
|
139
|
-
subject.call
|
140
|
-
|
141
|
-
expect(subject).to be_success
|
142
|
-
end
|
143
|
-
end
|
17
|
+
let(:api_response_class) { SixSaferpay::SixPaymentPage::AssertResponse }
|
18
|
+
it_behaves_like "authorize_payment"
|
144
19
|
end
|
145
|
-
|
146
20
|
end
|
147
21
|
end
|
148
22
|
end
|
@@ -14,135 +14,11 @@ module Spree
|
|
14
14
|
end
|
15
15
|
|
16
16
|
describe '#call' do
|
17
|
-
let(:
|
18
|
-
|
19
|
-
let(:transaction_date) { "2015-01-30T12:45:22.258+01:00" }
|
20
|
-
let(:amount_value) { "100" }
|
21
|
-
let(:amount_currency) { "USD" }
|
22
|
-
let(:brand_name) { 'PaymentBrand' }
|
23
|
-
let(:display_text) { "xxxx xxxx xxxx 1234" }
|
24
|
-
let(:six_transaction_reference) { "0:0:3:723n4MAjMdhjSAhAKEUdA8jtl9jb" }
|
25
|
-
|
26
|
-
let(:payment_means) do
|
27
|
-
SixSaferpay::ResponsePaymentMeans.new(
|
28
|
-
brand: SixSaferpay::Brand.new(name: brand_name),
|
29
|
-
display_text: display_text
|
30
|
-
)
|
31
|
-
end
|
32
|
-
|
33
|
-
# https://saferpay.github.io/jsonapi/#Payment_v1_PaymentPage_Initialize
|
34
|
-
let(:api_response) do
|
35
|
-
SixSaferpay::SixPaymentPage::AssertResponse.new(
|
36
|
-
response_header: SixSaferpay::ResponseHeader.new(request_id: 'test', spec_version: 'test'),
|
37
|
-
transaction: SixSaferpay::Transaction.new(
|
38
|
-
type: "PAYMENT",
|
39
|
-
status: transaction_status,
|
40
|
-
id: transaction_id,
|
41
|
-
date: transaction_date,
|
42
|
-
amount: SixSaferpay::Amount.new(value: amount_value, currency_code: amount_currency),
|
43
|
-
six_transaction_reference: six_transaction_reference,
|
44
|
-
),
|
45
|
-
payment_means: payment_means
|
46
|
-
)
|
47
|
-
end
|
48
|
-
|
49
|
-
let(:gateway_response) do
|
50
|
-
::SolidusSixSaferpay::GatewayResponse.new(
|
51
|
-
gateway_success,
|
52
|
-
"initialize success: #{gateway_success}",
|
53
|
-
api_response
|
54
|
-
)
|
55
|
-
end
|
56
|
-
|
57
|
-
# stub gateway to return our mock response
|
58
|
-
before do
|
59
|
-
allow(subject).to receive(:gateway).
|
60
|
-
and_return(double('gateway', authorize: gateway_response))
|
61
|
-
end
|
62
|
-
|
63
|
-
context 'when not successful' do
|
64
|
-
let(:gateway_success) { false }
|
65
|
-
|
66
|
-
it 'indicates failure' do
|
67
|
-
subject.call
|
68
|
-
|
69
|
-
expect(subject).not_to be_success
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'does not update the payment attributes' do
|
73
|
-
expect { subject.call }.not_to change { payment.transaction_id }
|
74
|
-
expect { subject.call }.not_to change { payment.transaction_status }
|
75
|
-
expect { subject.call }.not_to change { payment.transaction_date }
|
76
|
-
expect { subject.call }.not_to change { payment.six_transaction_reference }
|
77
|
-
expect { subject.call }.not_to change { payment.display_text }
|
78
|
-
expect { subject.call }.not_to change { payment.response_hash }
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context 'when successful' do
|
83
|
-
let(:gateway_success) { true }
|
84
|
-
|
85
|
-
it 'updates the transaction_id' do
|
86
|
-
expect { subject.call }.to change { payment.transaction_id }.from(nil).to(transaction_id)
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'updates the transaction status' do
|
90
|
-
expect { subject.call }.to change { payment.transaction_status }.from(nil).to(transaction_status)
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'updates the transaction date' do
|
94
|
-
expect { subject.call }.to change { payment.transaction_date }.from(nil).to(DateTime.parse(transaction_date))
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'updates the six_transaction_reference' do
|
98
|
-
expect { subject.call }.to change { payment.six_transaction_reference }.from(nil).to(six_transaction_reference)
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'updates the display_text' do
|
102
|
-
expect { subject.call }.to change { payment.display_text }.from(nil).to(display_text)
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'updates the response hash' do
|
106
|
-
expect { subject.call }.to change { payment.response_hash }.from(payment.response_hash).to(api_response.to_h)
|
107
|
-
end
|
108
|
-
|
109
|
-
context 'when the payment was made with a card' do
|
110
|
-
let(:masked_number) { "xxxx xxxx xxxx 5555" }
|
111
|
-
let(:exp_year) { "19" }
|
112
|
-
let(:exp_month) { "5" }
|
113
|
-
let(:payment_means) do
|
114
|
-
SixSaferpay::ResponsePaymentMeans.new(
|
115
|
-
brand: SixSaferpay::Brand.new(name: brand_name),
|
116
|
-
display_text: display_text,
|
117
|
-
card: SixSaferpay::ResponseCard.new(
|
118
|
-
masked_number: masked_number,
|
119
|
-
exp_year: exp_year,
|
120
|
-
exp_month: exp_month
|
121
|
-
)
|
122
|
-
)
|
123
|
-
end
|
124
|
-
|
125
|
-
it 'updates the masked number' do
|
126
|
-
expect { subject.call }.to change { payment.masked_number }.from(nil).to(masked_number)
|
127
|
-
end
|
128
|
-
|
129
|
-
it 'updates the expiry year' do
|
130
|
-
expect { subject.call }.to change { payment.expiration_year }.from(nil).to(exp_year)
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'updates the expiry month' do
|
134
|
-
expect { subject.call }.to change { payment.expiration_month }.from(nil).to(exp_month)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
it 'indicates success' do
|
139
|
-
subject.call
|
140
|
-
|
141
|
-
expect(subject).to be_success
|
142
|
-
end
|
143
|
-
end
|
17
|
+
let(:api_response_class) { SixSaferpay::SixTransaction::AuthorizeResponse }
|
18
|
+
it_behaves_like "authorize_payment"
|
144
19
|
end
|
145
20
|
|
21
|
+
|
146
22
|
end
|
147
23
|
end
|
148
24
|
end
|