solidus_six_saferpay 0.1.3 → 0.1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +35 -0
- data/.gem_release.yml +5 -0
- data/.github/stale.yml +17 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +12 -0
- data/Gemfile +33 -0
- data/LICENSE +26 -0
- data/README.md +33 -20
- data/Rakefile +4 -54
- data/app/assets/config/solidus_six_saferpay_manifest.js +1 -0
- data/app/assets/images/solidus_six_saferpay/.keep +0 -0
- data/app/assets/javascripts/spree/backend/solidus_six_saferpay.js +2 -0
- data/app/assets/javascripts/spree/frontend/solidus_six_saferpay.js +2 -0
- data/app/assets/stylesheets/solidus_six_saferpay/loading_animation.scss +0 -27
- data/app/assets/stylesheets/solidus_six_saferpay/payments.scss +4 -1
- data/app/assets/stylesheets/spree/backend/solidus_six_saferpay.css +4 -0
- data/app/assets/stylesheets/spree/frontend/solidus_six_saferpay.css +4 -0
- data/app/controllers/spree/solidus_six_saferpay/checkout_controller.rb +56 -10
- data/app/views/spree/checkout/payment/_saferpay_payment.html.erb +1 -1
- data/app/views/spree/six_saferpay_payments/_six_saferpay_payment.html.erb +2 -2
- data/bin/console +17 -0
- data/bin/rails +18 -0
- data/bin/rake +7 -0
- data/bin/setup +8 -0
- data/config/initializers/assets.rb +3 -0
- data/config/locales/de.yml +1 -1
- data/config/locales/en.yml +1 -1
- data/config/locales/fr.yml +1 -1
- data/config/routes.rb +2 -2
- data/lib/generators/solidus_six_saferpay/install/install_generator.rb +15 -3
- data/lib/solidus_six_saferpay.rb +6 -3
- data/lib/solidus_six_saferpay/configuration.rb +4 -7
- data/lib/solidus_six_saferpay/engine.rb +19 -10
- data/lib/solidus_six_saferpay/gateway.rb +13 -12
- data/lib/solidus_six_saferpay/version.rb +3 -1
- data/solidus_six_saferpay.gemspec +42 -0
- data/spec/controllers/spree/solidus_six_saferpay/checkout_controller_spec.rb +41 -0
- data/spec/controllers/spree/solidus_six_saferpay/payment_page/checkout_controller_spec.rb +205 -0
- data/spec/controllers/spree/solidus_six_saferpay/transaction/checkout_controller_spec.rb +228 -0
- data/spec/factories/payment_methods.rb +23 -0
- data/spec/factories/payments.rb +11 -0
- data/spec/factories/spree/six_saferpay_payments.rb +118 -0
- data/spec/models/spree/six_saferpay_payment_spec.rb +203 -0
- data/spec/rails_helper.rb +73 -0
- data/spec/services/spree/solidus_six_saferpay/assert_payment_page_spec.rb +148 -0
- data/spec/services/spree/solidus_six_saferpay/authorize_payment_spec.rb +39 -0
- data/spec/services/spree/solidus_six_saferpay/authorize_transaction_spec.rb +148 -0
- data/spec/services/spree/solidus_six_saferpay/initialize_payment_page_spec.rb +83 -0
- data/spec/services/spree/solidus_six_saferpay/initialize_payment_spec.rb +40 -0
- data/spec/services/spree/solidus_six_saferpay/initialize_transaction_spec.rb +85 -0
- data/spec/services/spree/solidus_six_saferpay/inquire_payment_page_payment_spec.rb +116 -0
- data/spec/services/spree/solidus_six_saferpay/inquire_payment_spec.rb +39 -0
- data/spec/services/spree/solidus_six_saferpay/inquire_transaction_payment_spec.rb +117 -0
- data/spec/services/spree/solidus_six_saferpay/payment_validator_spec.rb +100 -0
- data/spec/services/spree/solidus_six_saferpay/process_authorized_payment_spec.rb +39 -0
- data/spec/services/spree/solidus_six_saferpay/process_payment_page_payment_spec.rb +225 -0
- data/spec/services/spree/solidus_six_saferpay/process_transaction_payment_spec.rb +219 -0
- data/spec/solidus_six_saferpay/configuration_spec.rb +15 -0
- data/spec/solidus_six_saferpay/error_handler_spec.rb +65 -0
- data/spec/solidus_six_saferpay/gateway_response_spec.rb +70 -0
- data/spec/solidus_six_saferpay/gateway_spec.rb +378 -0
- data/spec/solidus_six_saferpay/payment_page_gateway_spec.rb +390 -0
- data/spec/solidus_six_saferpay/transaction_gateway_spec.rb +387 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/support/route_access.rb +6 -0
- data/spec/support/uses_payment_page_gateway.rb +29 -0
- data/spec/support/uses_transaction_gateway.rb +28 -0
- metadata +241 -101
@@ -0,0 +1,228 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe Spree::SolidusSixSaferpay::Transaction::CheckoutController, type: :controller do
|
4
|
+
routes { Spree::Core::Engine.routes }
|
5
|
+
|
6
|
+
let(:user) { create(:user) }
|
7
|
+
let(:order) { create(:order) }
|
8
|
+
let(:payment_method) { create(:saferpay_payment_method_transaction) }
|
9
|
+
|
10
|
+
let(:subject) { described_class.new }
|
11
|
+
|
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
|
+
end
|
207
|
+
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
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
FactoryBot.define do
|
2
|
+
|
3
|
+
factory :saferpay_payment_method, class: Spree::PaymentMethod::SaferpayPaymentMethod do
|
4
|
+
name { "saferpay_payment_method" }
|
5
|
+
preferred_require_liability_shift { true }
|
6
|
+
|
7
|
+
trait :no_require_liability_shift do
|
8
|
+
preferred_require_liability_shift { false }
|
9
|
+
end
|
10
|
+
|
11
|
+
trait :no_as_iframe do
|
12
|
+
preferred_as_iframe { false }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
factory :saferpay_payment_method_payment_page, class: Spree::PaymentMethod::SaferpayPaymentPage, parent: :saferpay_payment_method do
|
17
|
+
name { "saferpay_payment_page" }
|
18
|
+
end
|
19
|
+
|
20
|
+
factory :saferpay_payment_method_transaction, class: Spree::PaymentMethod::SaferpayTransaction, parent: :saferpay_payment_method do
|
21
|
+
name { "saferpay_transaction" }
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
FactoryBot.define do
|
2
|
+
|
3
|
+
factory :payment_using_saferpay, class: Spree::Payment do
|
4
|
+
association(:payment_method, factory: :saferpay_payment_method)
|
5
|
+
source { create(:six_saferpay_payment, :authorized, order: order, payment_method: payment_method) }
|
6
|
+
order
|
7
|
+
state { 'checkout' }
|
8
|
+
response_code { '12345' }
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
FactoryBot.define do
|
2
|
+
factory :six_saferpay_payment, class: Spree::SixSaferpayPayment do
|
3
|
+
order
|
4
|
+
association :payment_method, factory: :saferpay_payment_method
|
5
|
+
expiration { Time.current + 2.hours }
|
6
|
+
sequence(:token, (1..100000).to_a.shuffle.to_enum)
|
7
|
+
|
8
|
+
trait :authorized do
|
9
|
+
sequence(:transaction_id) { |n| "TRANSACTION_ID_#{n}" }
|
10
|
+
transaction_status { "AUTHORIZED" }
|
11
|
+
transaction_date { DateTime.parse("2019-07-25T13:34:44.677+02:00") }
|
12
|
+
sequence(:six_transaction_reference) { |n| "SIX_TRANSACTION_REFERENCE_#{n}" }
|
13
|
+
display_text { "xxxx xxxx xxxx 1234" }
|
14
|
+
|
15
|
+
response_hash do
|
16
|
+
{
|
17
|
+
response_header: {
|
18
|
+
request_id: "request-id",
|
19
|
+
spec_version: "1.12"
|
20
|
+
},
|
21
|
+
transaction: {
|
22
|
+
type: "PAYMENT",
|
23
|
+
status: "AUTHORIZED",
|
24
|
+
id: "0QKl2GAnEK0OvA90vClhAESYEGYb",
|
25
|
+
date: "2019-07-25T13:34:44.677+02:00",
|
26
|
+
amount: {
|
27
|
+
value: "20000",
|
28
|
+
currency_code: "CHF"
|
29
|
+
},
|
30
|
+
order_id: "ORDER_ID",
|
31
|
+
acquirer_name: "ACQUIRER_NAME",
|
32
|
+
acquirer_reference: "ACQUIRER_REFERENCE",
|
33
|
+
six_transaction_reference: "SIX_TRANASACTION_REFERENCE",
|
34
|
+
approval_code: "APPROVAL CODE"
|
35
|
+
},
|
36
|
+
payment_means: {
|
37
|
+
brand: {
|
38
|
+
payment_method: "MASTERCARD",
|
39
|
+
name: "MasterCard"
|
40
|
+
},
|
41
|
+
display_text: "xxxx xxxx xxxx 1234",
|
42
|
+
card: {
|
43
|
+
masked_number: "xxxxxxxxxxxx1234",
|
44
|
+
exp_year: 2019,
|
45
|
+
exp_month: 7,
|
46
|
+
holder_name: "John Doe",
|
47
|
+
country_code: "US"
|
48
|
+
}
|
49
|
+
},
|
50
|
+
payer: {
|
51
|
+
ip_address: "IP ADDRESS",
|
52
|
+
ip_location: "CH",
|
53
|
+
delivery_address: {
|
54
|
+
first_name: "Simon",
|
55
|
+
last_name: "Knorrli",
|
56
|
+
street: "STREET",
|
57
|
+
zip: "ZIP",
|
58
|
+
city: "CITY",
|
59
|
+
country_code: "CH"
|
60
|
+
},
|
61
|
+
billing_address: {
|
62
|
+
first_name: "Simon",
|
63
|
+
last_name: "Knorrli",
|
64
|
+
street: "STREET",
|
65
|
+
zip: "ZIP",
|
66
|
+
city: "CITY",
|
67
|
+
country_code: "CH"
|
68
|
+
}
|
69
|
+
},
|
70
|
+
liability: {
|
71
|
+
liability_shift: true,
|
72
|
+
liable_entity: "ThreeDs",
|
73
|
+
three_ds: {
|
74
|
+
authenticated: true,
|
75
|
+
liability_shift: true,
|
76
|
+
xid: "3DS-XID"
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
trait :without_liability_shift do
|
85
|
+
authorized
|
86
|
+
|
87
|
+
after(:build) do |payment|
|
88
|
+
payment.response_hash.merge!(
|
89
|
+
liability: {
|
90
|
+
liability_shift: false,
|
91
|
+
liable_entity: "ThreeDs",
|
92
|
+
three_ds: {
|
93
|
+
authenticated: false,
|
94
|
+
liability_shift: false,
|
95
|
+
xid: "3DS-XID"
|
96
|
+
}
|
97
|
+
}
|
98
|
+
)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
trait :dcc do
|
103
|
+
authorized
|
104
|
+
|
105
|
+
after(:build) do |payment|
|
106
|
+
payment.response_hash.merge!(
|
107
|
+
dcc: {
|
108
|
+
payer_amount: {
|
109
|
+
value: "18972",
|
110
|
+
currency_code: "USD"
|
111
|
+
}
|
112
|
+
}
|
113
|
+
)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,203 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
RSpec.describe SixSaferpayPayment, type: :model do
|
5
|
+
let(:payment) { FactoryBot.create(:six_saferpay_payment) }
|
6
|
+
describe 'associations' do
|
7
|
+
it { is_expected.to belong_to :order }
|
8
|
+
it { is_expected.to belong_to :payment_method }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'validations' do
|
12
|
+
it { is_expected.to validate_presence_of :token }
|
13
|
+
it { is_expected.to validate_presence_of :expiration }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#create_solidus_payment!" do
|
17
|
+
it 'creates a Solidus::Payment with the correct information' do
|
18
|
+
expect(Spree::Payment.count).to eq(0)
|
19
|
+
solidus_payment = payment.create_solidus_payment!
|
20
|
+
expect(Spree::Payment.count).to eq(1)
|
21
|
+
expect(solidus_payment.order).to eq(payment.order)
|
22
|
+
expect(solidus_payment.payment_method).to eq(payment.payment_method)
|
23
|
+
expect(solidus_payment.response_code).to eq(payment.transaction_id)
|
24
|
+
expect(solidus_payment.amount).to eq(payment.order.total)
|
25
|
+
expect(solidus_payment.source).to eq(payment)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#address' do
|
30
|
+
it "returns the order's billing address" do
|
31
|
+
expect(payment.address).to eq(payment.order.bill_address)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#payment_means' do
|
36
|
+
context 'when the payment is still unprocessed' do
|
37
|
+
it 'returns nil' do
|
38
|
+
expect(payment.payment_means).to be_nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when the payment is authorized' do
|
43
|
+
let(:payment) { FactoryBot.create(:six_saferpay_payment, :authorized) }
|
44
|
+
|
45
|
+
it 'returns a SixSaferpay::ResponsePaymentMeans' do
|
46
|
+
expect(payment.payment_means).to be_a(SixSaferpay::ResponsePaymentMeans)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'sets the API response attributes correctly' do
|
50
|
+
expect(payment.payment_means.brand.payment_method).to eq("MASTERCARD")
|
51
|
+
expect(payment.payment_means.brand.name).to eq("MasterCard")
|
52
|
+
expect(payment.payment_means.display_text).to eq("xxxx xxxx xxxx 1234")
|
53
|
+
expect(payment.payment_means.card.masked_number).to eq("xxxxxxxxxxxx1234")
|
54
|
+
expect(payment.payment_means.card.exp_year).to eq(2019)
|
55
|
+
expect(payment.payment_means.card.exp_month).to eq(7)
|
56
|
+
expect(payment.payment_means.card.holder_name).to eq("John Doe")
|
57
|
+
expect(payment.payment_means.card.country_code).to eq("US")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#transaction' do
|
63
|
+
context 'when the payment is still unprocessed' do
|
64
|
+
it 'returns nil' do
|
65
|
+
expect(payment.transaction).to be_nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'when the payment is authorized' do
|
70
|
+
let(:payment) { FactoryBot.create(:six_saferpay_payment, :authorized) }
|
71
|
+
|
72
|
+
it 'returns a SixSaferpay::Transaction' do
|
73
|
+
expect(payment.transaction).to be_a(SixSaferpay::Transaction)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'sets the API response attributes correctly' do
|
77
|
+
expect(payment.transaction.type).to eq("PAYMENT")
|
78
|
+
expect(payment.transaction.status).to eq("AUTHORIZED")
|
79
|
+
expect(payment.transaction.amount.value).to eq('20000')
|
80
|
+
expect(payment.transaction.amount.currency_code).to eq("CHF")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#liability' do
|
86
|
+
context 'when the payment is still unprocessed' do
|
87
|
+
it 'returns nil' do
|
88
|
+
expect(payment.liability).to be_nil
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'when the payment is authorized' do
|
93
|
+
let(:payment) { FactoryBot.create(:six_saferpay_payment, :authorized) }
|
94
|
+
it 'returns a SixSaferpay::Liability' do
|
95
|
+
expect(payment.liability).to be_a(SixSaferpay::Liability)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'sets the API response attributes correctly' do
|
99
|
+
expect(payment.liability.liability_shift).to be true
|
100
|
+
expect(payment.liability.liable_entity).to eq("ThreeDs")
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe '#card' do
|
106
|
+
context 'when the payment is still unprocessed' do
|
107
|
+
it 'returns nil' do
|
108
|
+
expect(payment.card).to be_nil
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'when the payment is authorized' do
|
113
|
+
let(:payment) { FactoryBot.create(:six_saferpay_payment, :authorized) }
|
114
|
+
|
115
|
+
it 'returns a SixSaferpay::ResponseCard' do
|
116
|
+
expect(payment.card).to be_a(SixSaferpay::ResponseCard)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe '#name' do
|
122
|
+
context 'when the payment is still unprocessed' do
|
123
|
+
it 'returns nil' do
|
124
|
+
expect(payment.name).to be_nil
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context 'when the payment is authorized' do
|
129
|
+
let(:payment) { FactoryBot.create(:six_saferpay_payment, :authorized) }
|
130
|
+
|
131
|
+
it 'returns the card holder name' do
|
132
|
+
expect(payment.name).to eq("John Doe")
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe '#brand_name' do
|
138
|
+
context 'when the payment is still unprocessed' do
|
139
|
+
it 'returns nil' do
|
140
|
+
expect(payment.brand_name).to be_nil
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'when the payment is authorized' do
|
145
|
+
let(:payment) { FactoryBot.create(:six_saferpay_payment, :authorized) }
|
146
|
+
|
147
|
+
it 'returns the brand name' do
|
148
|
+
expect(payment.brand_name).to eq("MasterCard")
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe '#month' do
|
154
|
+
context 'when the payment is still unprocessed' do
|
155
|
+
it 'returns nil' do
|
156
|
+
expect(payment.month).to be_nil
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'when the payment is authorized' do
|
161
|
+
let(:payment) { FactoryBot.create(:six_saferpay_payment, :authorized) }
|
162
|
+
|
163
|
+
it 'returns the card expiration month' do
|
164
|
+
expect(payment.month).to eq(7)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe '#year' do
|
170
|
+
context 'when the payment is still unprocessed' do
|
171
|
+
it 'returns nil' do
|
172
|
+
expect(payment.year).to be_nil
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context 'when the payment is authorized' do
|
177
|
+
let(:payment) { FactoryBot.create(:six_saferpay_payment, :authorized) }
|
178
|
+
|
179
|
+
it 'returns the card expiration year' do
|
180
|
+
expect(payment.year).to eq(2019)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
describe '#icon_name' do
|
186
|
+
context 'when the payment is still unprocessed' do
|
187
|
+
it 'returns nil' do
|
188
|
+
expect(payment.icon_name).to be_nil
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
context 'when the payment is authorized' do
|
193
|
+
let(:payment) { FactoryBot.create(:six_saferpay_payment, :authorized) }
|
194
|
+
|
195
|
+
it 'returns a downcased brand name' do
|
196
|
+
expect(payment.icon_name).to eq("mastercard")
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
|