solidus_six_saferpay 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +35 -0
  3. data/.gem_release.yml +5 -0
  4. data/.github/stale.yml +17 -0
  5. data/.gitignore +18 -0
  6. data/.rspec +2 -0
  7. data/.rubocop.yml +2 -0
  8. data/.travis.yml +12 -0
  9. data/Gemfile +33 -0
  10. data/LICENSE +26 -0
  11. data/README.md +36 -20
  12. data/Rakefile +4 -54
  13. data/app/assets/config/solidus_six_saferpay_manifest.js +1 -0
  14. data/app/assets/images/solidus_six_saferpay/.keep +0 -0
  15. data/app/assets/javascripts/spree/backend/solidus_six_saferpay.js +2 -0
  16. data/app/assets/javascripts/spree/frontend/solidus_six_saferpay.js +2 -0
  17. data/app/assets/stylesheets/solidus_six_saferpay/loading_animation.scss +0 -27
  18. data/app/assets/stylesheets/solidus_six_saferpay/payments.scss +4 -1
  19. data/app/assets/stylesheets/spree/backend/solidus_six_saferpay.css +4 -0
  20. data/app/assets/stylesheets/spree/frontend/solidus_six_saferpay.css +4 -0
  21. data/app/controllers/spree/solidus_six_saferpay/checkout_controller.rb +56 -10
  22. data/app/services/spree/solidus_six_saferpay/inquire_payment.rb +1 -0
  23. data/app/views/spree/checkout/payment/_saferpay_payment.html.erb +1 -1
  24. data/app/views/spree/six_saferpay_payments/_six_saferpay_payment.html.erb +2 -2
  25. data/bin/console +17 -0
  26. data/bin/rails +18 -0
  27. data/bin/rake +7 -0
  28. data/bin/setup +8 -0
  29. data/config/initializers/assets.rb +3 -0
  30. data/config/locales/de.yml +1 -1
  31. data/config/locales/en.yml +1 -1
  32. data/config/locales/fr.yml +1 -1
  33. data/config/routes.rb +6 -6
  34. data/lib/generators/solidus_six_saferpay/install/install_generator.rb +15 -3
  35. data/lib/solidus_six_saferpay.rb +6 -3
  36. data/lib/solidus_six_saferpay/configuration.rb +4 -7
  37. data/lib/solidus_six_saferpay/engine.rb +19 -10
  38. data/lib/solidus_six_saferpay/gateway.rb +5 -4
  39. data/lib/solidus_six_saferpay/payment_page_gateway.rb +8 -9
  40. data/lib/solidus_six_saferpay/transaction_gateway.rb +8 -9
  41. data/lib/solidus_six_saferpay/version.rb +3 -1
  42. data/solidus_six_saferpay.gemspec +42 -0
  43. data/spec/controllers/spree/solidus_six_saferpay/checkout_controller_spec.rb +41 -0
  44. data/spec/controllers/spree/solidus_six_saferpay/payment_page/checkout_controller_spec.rb +206 -0
  45. data/spec/controllers/spree/solidus_six_saferpay/transaction/checkout_controller_spec.rb +229 -0
  46. data/spec/factories/payment_methods.rb +23 -0
  47. data/spec/factories/payments.rb +11 -0
  48. data/spec/factories/spree/six_saferpay_payments.rb +118 -0
  49. data/spec/models/spree/six_saferpay_payment_spec.rb +203 -0
  50. data/spec/rails_helper.rb +73 -0
  51. data/spec/services/spree/solidus_six_saferpay/assert_payment_page_spec.rb +148 -0
  52. data/spec/services/spree/solidus_six_saferpay/authorize_payment_spec.rb +39 -0
  53. data/spec/services/spree/solidus_six_saferpay/authorize_transaction_spec.rb +148 -0
  54. data/spec/services/spree/solidus_six_saferpay/initialize_payment_page_spec.rb +83 -0
  55. data/spec/services/spree/solidus_six_saferpay/initialize_payment_spec.rb +40 -0
  56. data/spec/services/spree/solidus_six_saferpay/initialize_transaction_spec.rb +85 -0
  57. data/spec/services/spree/solidus_six_saferpay/inquire_payment_page_payment_spec.rb +116 -0
  58. data/spec/services/spree/solidus_six_saferpay/inquire_payment_spec.rb +39 -0
  59. data/spec/services/spree/solidus_six_saferpay/inquire_transaction_payment_spec.rb +117 -0
  60. data/spec/services/spree/solidus_six_saferpay/payment_validator_spec.rb +100 -0
  61. data/spec/services/spree/solidus_six_saferpay/process_authorized_payment_spec.rb +39 -0
  62. data/spec/services/spree/solidus_six_saferpay/process_payment_page_payment_spec.rb +225 -0
  63. data/spec/services/spree/solidus_six_saferpay/process_transaction_payment_spec.rb +219 -0
  64. data/spec/solidus_six_saferpay/configuration_spec.rb +15 -0
  65. data/spec/solidus_six_saferpay/error_handler_spec.rb +65 -0
  66. data/spec/solidus_six_saferpay/gateway_response_spec.rb +70 -0
  67. data/spec/solidus_six_saferpay/gateway_spec.rb +365 -0
  68. data/spec/solidus_six_saferpay/payment_page_gateway_spec.rb +392 -0
  69. data/spec/solidus_six_saferpay/transaction_gateway_spec.rb +390 -0
  70. data/spec/spec_helper.rb +21 -0
  71. data/spec/support/route_access.rb +6 -0
  72. data/spec/support/uses_payment_page_gateway.rb +29 -0
  73. data/spec/support/uses_transaction_gateway.rb +28 -0
  74. metadata +240 -99
@@ -0,0 +1,39 @@
1
+ require 'rails_helper'
2
+
3
+ module Spree
4
+ module SolidusSixSaferpay
5
+ RSpec.describe ProcessAuthorizedPayment do
6
+
7
+ let(:payment) { create(:six_saferpay_payment, :authorized) }
8
+
9
+ let(:service) { described_class.new(payment) }
10
+
11
+ describe '.call' do
12
+ it 'calls an initialized service with given order and payment method' do
13
+ expect(described_class).to receive(:new).with(payment).and_return(service)
14
+ expect(service).to receive(:call)
15
+
16
+ described_class.call(payment)
17
+ end
18
+ end
19
+
20
+ describe '#call' do
21
+ it 'fails because gateway raises an error' do
22
+ expect { service.call }.to raise_error(NotImplementedError)
23
+ end
24
+ end
25
+
26
+ describe '#gateway' do
27
+ it 'raises an error because the gateway must be defined in subclasses' do
28
+ expect { service.gateway }.to raise_error(NotImplementedError)
29
+ end
30
+ end
31
+
32
+ describe '#success?' do
33
+ it 'is initially false' do
34
+ expect(service).not_to be_success
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,225 @@
1
+ require 'rails_helper'
2
+
3
+ module Spree
4
+ module SolidusSixSaferpay
5
+ RSpec.describe ProcessPaymentPagePayment do
6
+
7
+ let(:payment) { create(:six_saferpay_payment, :authorized) }
8
+
9
+ subject { described_class.new(payment) }
10
+
11
+ describe '#gateway' do
12
+ it_behaves_like "it uses the payment page gateway"
13
+ end
14
+
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
+
221
+ end
222
+
223
+ end
224
+ end
225
+ end
@@ -0,0 +1,219 @@
1
+ require 'rails_helper'
2
+
3
+ module Spree
4
+ module SolidusSixSaferpay
5
+ RSpec.describe ProcessTransactionPayment do
6
+
7
+ let(:payment) { create(:six_saferpay_payment, :authorized) }
8
+
9
+ subject { described_class.new(payment) }
10
+
11
+ describe '#gateway' do
12
+ it_behaves_like "it uses the transaction gateway"
13
+ end
14
+
15
+ describe '#call' do
16
+ context 'liability_shift check' do
17
+
18
+ before do
19
+ allow(subject).to receive(:gateway).and_return(double('gateway'))
20
+
21
+
22
+ # ensure other methods don't modify outcome
23
+ allow(subject).to receive(:validate_payment!)
24
+ allow(subject).to receive(:cancel_old_solidus_payments)
25
+ allow(payment).to receive(:create_solidus_payment!)
26
+ end
27
+
28
+ context 'when liability shift is required' do
29
+ context 'and liability shift is not granted' do
30
+
31
+ let(:payment) { create(:six_saferpay_payment, :authorized, :without_liability_shift) }
32
+
33
+ it 'cancels the payment' do
34
+ expect(payment.payment_method.preferred_require_liability_shift).to be true
35
+ expect(payment.liability.liability_shift).to be false
36
+
37
+ expect(subject.gateway).to receive(:void).with(payment.transaction_id)
38
+
39
+ subject.call
40
+ end
41
+
42
+ it 'indicates failure' do
43
+ expect(payment.payment_method.preferred_require_liability_shift).to be true
44
+ expect(payment.liability.liability_shift).to be false
45
+
46
+ expect(subject.gateway).to receive(:void).with(payment.transaction_id)
47
+
48
+ subject.call
49
+
50
+ expect(subject).not_to be_success
51
+ end
52
+
53
+ end
54
+
55
+ context 'and liability shift is granted' do
56
+ it "doesn't cancel the payment" do
57
+ expect(payment.payment_method.preferred_require_liability_shift).to be true
58
+ expect(payment.liability.liability_shift).to be true
59
+
60
+ expect(subject.gateway).not_to receive(:void)
61
+
62
+ subject.call
63
+ end
64
+
65
+ it 'passes the liability shift check' do
66
+ expect(payment.payment_method.preferred_require_liability_shift).to be true
67
+ expect(payment.liability.liability_shift).to be true
68
+
69
+ subject.call
70
+
71
+ expect(subject).to be_success
72
+ end
73
+ end
74
+ end
75
+
76
+ context 'when liability shift is not required' do
77
+ let(:payment_method) { create(:saferpay_payment_method, :no_require_liability_shift) }
78
+
79
+ context 'and liability shift is not granted' do
80
+ let(:payment) { create(:six_saferpay_payment, :authorized, :without_liability_shift, payment_method: payment_method) }
81
+
82
+ it "doesn't cancel the payment" do
83
+ expect(payment.payment_method.preferred_require_liability_shift).to be false
84
+ expect(payment.liability.liability_shift).to be false
85
+
86
+ expect(subject.gateway).not_to receive(:void)
87
+
88
+ subject.call
89
+ end
90
+
91
+ it 'passes the liability shift check' do
92
+ expect(payment.payment_method.preferred_require_liability_shift).to be false
93
+ expect(payment.liability.liability_shift).to be false
94
+ subject.call
95
+
96
+ expect(subject).to be_success
97
+ end
98
+ end
99
+
100
+ context 'and liability shift is granted' do
101
+ let(:payment) { create(:six_saferpay_payment, :authorized, payment_method: payment_method) }
102
+ it "doesn't cancel the payment" do
103
+ expect(payment.payment_method.preferred_require_liability_shift).to be false
104
+ expect(payment.liability.liability_shift).to be true
105
+
106
+ expect(subject.gateway).not_to receive(:void)
107
+
108
+ subject.call
109
+ end
110
+
111
+ it 'passes the liability shift check' do
112
+ expect(payment.payment_method.preferred_require_liability_shift).to be false
113
+ expect(payment.liability.liability_shift).to be true
114
+ subject.call
115
+
116
+ expect(subject).to be_success
117
+ end
118
+ end
119
+ end
120
+ end
121
+
122
+ context 'payment validation' do
123
+ before do
124
+ allow(subject).to receive(:gateway).and_return(double('gateway'))
125
+
126
+
127
+ # ensure other methods don't modify outcome
128
+ allow(subject).to receive(:check_liability_shift_requirements!)
129
+ allow(subject).to receive(:cancel_old_solidus_payments)
130
+ allow(payment).to receive(:create_solidus_payment!)
131
+ end
132
+
133
+ it 'validates the payment' do
134
+ expect(PaymentValidator).to receive(:call).with(payment)
135
+ subject.call
136
+ end
137
+
138
+ context 'when the payment is invalid' do
139
+ it 'cancels the payment' do
140
+ expect(subject.gateway).to receive(:void).with(payment.transaction_id)
141
+
142
+ subject.call
143
+ end
144
+
145
+ it 'indicates failure' do
146
+ allow(subject.gateway).to receive(:void).with(payment.transaction_id)
147
+
148
+ subject.call
149
+
150
+ expect(subject).not_to be_success
151
+ end
152
+ end
153
+
154
+ context 'when the payment is valid' do
155
+ before do
156
+ allow(PaymentValidator).to receive(:call).with(payment).and_return(true)
157
+ end
158
+
159
+ it "doesn't cancel the payment" do
160
+ expect(subject.gateway).not_to receive(:void)
161
+
162
+ subject.call
163
+ end
164
+
165
+ it 'indicates success' do
166
+ subject.call
167
+
168
+ expect(subject).to be_success
169
+ end
170
+ end
171
+ end
172
+
173
+ context 'when the payment has passed all validations' do
174
+ before do
175
+ allow(subject).to receive(:check_liability_shift_requirements!).and_return(true)
176
+ allow(subject).to receive(:validate_payment!).and_return(true)
177
+ end
178
+
179
+ context 'when previous solidus payments exist for this order' do
180
+ let(:order) { payment.order }
181
+ let!(:previous_payment_invalid) { create(:payment_using_saferpay, order: order) }
182
+ let!(:previous_payment_checkout) { create(:payment_using_saferpay, order: order) }
183
+
184
+ before do
185
+ # This is bad practice because we mock which payments are invalidated here.
186
+ # The reason is that you can't stub methods on AR objects that
187
+ # are loaded from the DB and because #solidus_payments_to_cancel
188
+ # is just AR scopes, I prefer this test over using stuff like
189
+ # #expect_any_instance_of
190
+ allow(subject).to receive(:solidus_payments_to_cancel).and_return([previous_payment_checkout])
191
+ end
192
+
193
+ it 'cancels old solidus payments' do
194
+ expect(previous_payment_invalid).not_to receive(:cancel!)
195
+ expect(previous_payment_checkout).to receive(:cancel!)
196
+
197
+ subject.call
198
+ end
199
+ end
200
+
201
+ it 'creates a new solidus payment' do
202
+ expect(payment).to receive(:create_solidus_payment!)
203
+
204
+ subject.call
205
+ end
206
+
207
+ it 'indicates success' do
208
+ allow(payment).to receive(:create_solidus_payment!)
209
+
210
+ subject.call
211
+
212
+ expect(subject).to be_success
213
+ end
214
+ end
215
+
216
+ end
217
+ end
218
+ end
219
+ end