solidus_six_saferpay 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/solidus_six_saferpay/saferpay_payment.js +4 -1
  3. data/app/controllers/spree/solidus_six_saferpay/checkout_controller.rb +93 -16
  4. data/app/controllers/spree/solidus_six_saferpay/transaction/checkout_controller.rb +1 -1
  5. data/app/models/spree/payment_method/saferpay_payment_method.rb +1 -1
  6. data/app/models/spree/payment_method/saferpay_payment_page.rb +2 -2
  7. data/app/models/spree/payment_method/saferpay_transaction.rb +2 -2
  8. data/app/services/spree/solidus_six_saferpay/cancel_authorized_payment.rb +33 -0
  9. data/app/services/spree/solidus_six_saferpay/initialize_payment.rb +0 -1
  10. data/app/services/spree/solidus_six_saferpay/initialize_transaction.rb +0 -1
  11. data/app/services/spree/solidus_six_saferpay/inquire_payment.rb +26 -1
  12. data/app/views/spree/checkout/payment/_saferpay_payment.html.erb +2 -2
  13. data/app/views/spree/solidus_six_saferpay/checkout/{iframe_breakout_redirect.html.erb → iframe_breakout_redirect.erb} +1 -1
  14. data/config/locales/de.yml +3 -0
  15. data/config/locales/en.yml +3 -0
  16. data/config/locales/fr.yml +3 -0
  17. data/config/routes.rb +2 -2
  18. data/lib/solidus_six_saferpay/configuration.rb +2 -0
  19. data/lib/solidus_six_saferpay/gateway.rb +6 -7
  20. data/lib/solidus_six_saferpay/version.rb +1 -1
  21. data/spec/controllers/spree/solidus_six_saferpay/payment_page/checkout_controller_spec.rb +8 -198
  22. data/spec/controllers/spree/solidus_six_saferpay/transaction/checkout_controller_spec.rb +8 -221
  23. data/spec/services/spree/solidus_six_saferpay/assert_payment_page_spec.rb +2 -128
  24. data/spec/services/spree/solidus_six_saferpay/authorize_transaction_spec.rb +3 -127
  25. data/spec/services/spree/solidus_six_saferpay/cancel_authorized_payment_spec.rb +58 -0
  26. data/spec/services/spree/solidus_six_saferpay/initialize_payment_page_spec.rb +0 -2
  27. data/spec/services/spree/solidus_six_saferpay/initialize_transaction_spec.rb +0 -1
  28. data/spec/services/spree/solidus_six_saferpay/inquire_payment_page_payment_spec.rb +2 -98
  29. data/spec/services/spree/solidus_six_saferpay/inquire_transaction_payment_spec.rb +2 -98
  30. data/spec/services/spree/solidus_six_saferpay/process_payment_page_payment_spec.rb +1 -206
  31. data/spec/services/spree/solidus_six_saferpay/process_transaction_payment_spec.rb +1 -200
  32. data/spec/support/shared_examples/authorize_payment.rb +132 -0
  33. data/spec/support/shared_examples/checkout_controller.rb +342 -0
  34. data/spec/support/shared_examples/inquire_payment.rb +118 -0
  35. data/spec/support/shared_examples/process_authorized_payment.rb +202 -0
  36. metadata +14 -6
  37. data/app/services/spree/solidus_six_saferpay/inquire_transaction.rb +0 -7
  38. data/spec/controllers/spree/solidus_six_saferpay/checkout_controller_spec.rb +0 -41
@@ -14,135 +14,9 @@ module Spree
14
14
  end
15
15
 
16
16
  describe '#call' do
17
- let(:transaction_status) { "AUTHORIZED" }
18
- let(:transaction_id) { "723n4MAjMdhjSAhAKEUdA8jtl9jb" }
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(:transaction_status) { "AUTHORIZED" }
18
- let(:transaction_id) { "723n4MAjMdhjSAhAKEUdA8jtl9jb" }
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
@@ -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))
@@ -39,7 +39,6 @@ module Spree
39
39
  )
40
40
  end
41
41
 
42
- # stub gateway to return our mock response
43
42
  before do
44
43
  allow(subject).to receive(:gateway).
45
44
  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
- before do
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 'adds the error message to the response hash' do
48
- expect { subject.call }.to change { payment.response_hash }.from({}).to({error: error_name})
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