solidus_six_saferpay 0.1.8.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2169c1b1f790ec1dcc28392c40f539850b50763f19b05aa8f081065c58cf45f
4
- data.tar.gz: 664168547eb8918651455a7b63c0c7ab97e641fdd9495041ce7a4aefbbbff0b2
3
+ metadata.gz: 5e228b5766fec776fecd596f1f9316553ed3bc9d48c4ada1adfebb470da63c7c
4
+ data.tar.gz: 1367d382455ade917798c68ced6fd717e71dafd2caeb2cefccde0d58517903e7
5
5
  SHA512:
6
- metadata.gz: b39396e4cc40b5329e510c9744564ad0296a756ab4ff6e467bee60bc44b7825ff5359b4aebde2ea479ded6f986b96c02f44ea527ef77d022da8e87dd02d10810
7
- data.tar.gz: 582f78f26f3ea9b03e99f9ad28a95551ededba3c38003085a4d0952afffbc381a2317859df484948d98bc0a5e58d28ca510a1a890406b39552cb394047f16469
6
+ metadata.gz: 181ec3d7959392e3b7c0a100be584091507e74cdab7fb76efe19eaa406ae36ec4bc0777b8927c54d3e41518b52808f0d26e3202a35d703aaf63eced9d3c38199
7
+ data.tar.gz: 71c01086a0e866e1a0aa48e71304c057ff662cc268db3e961ef9761eb3182f7282c28ccdd2acfd1f7f827cc3939eb64d41921cfbb3f5f590066b2e572da3c5b6
data/README.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  The `solidus_six_saferpay` engine adds checkout options for the Saferpay Payment Page ([Integration Guide](https://saferpay.github.io/sndbx/Integration_PP.html), [JSON API documentation](http://saferpay.github.io/jsonapi/#ChapterPaymentPage)) and the Saferpay Transaction ([Integration Guide](https://saferpay.github.io/sndbx/Integration_trx.html), [JSON API documentation](https://saferpay.github.io/sndbx/Integration_trx.html)).
4
4
 
5
+ ### Disclaimer
6
+ This gem is built to be a general-purpose integration of the Six Saferpay payment interface. However due to lack of resources and because we are (as far as we know) the only users of this gem, we are only testing our use cases (PaymentPage). Therefore we can not guarantee that this will work in any other solidus shop. If you consider using this gem, please test everything thoroughly.
7
+
5
8
  ## Status
6
9
  Travis CI status: [![Build Status](https://travis-ci.org/fadendaten/solidus_six_saferpay.svg?branch=master)](https://travis-ci.org/fadendaten/solidus_six_saferpay)
7
10
 
@@ -3,8 +3,6 @@ module Spree
3
3
  class CheckoutController < StoreController
4
4
 
5
5
  def init
6
- # loading the order is not shared between actions because the success
7
- # action must break out of the iframe
8
6
  @order = current_order
9
7
  redirect_to(spree.cart_path) && return unless @order
10
8
 
@@ -21,9 +19,9 @@ module Spree
21
19
  end
22
20
 
23
21
  def success
24
- # loading the order is not shared between actions because the success
25
- # action must break out of the iframe
26
- @order = current_order
22
+ order_number = params[:order_number]
23
+ @order = Spree::Order.find_by(number: order_number)
24
+
27
25
  if @order.nil?
28
26
  @redirect_path = spree.cart_path
29
27
  render :iframe_breakout_redirect, layout: false
@@ -75,9 +73,9 @@ module Spree
75
73
  end
76
74
 
77
75
  def fail
78
- # loading the order is not shared between actions because the success
79
- # action must break out of the iframe
80
- @order = current_order
76
+ order_number = params[:order_number]
77
+ @order = Spree::Order.find_by(number: order_number)
78
+
81
79
  if @order.nil?
82
80
  @redirect_path = spree.cart_path
83
81
  render :iframe_breakout_redirect, layout: false
@@ -86,11 +84,13 @@ module Spree
86
84
 
87
85
  saferpay_payment = Spree::SixSaferpayPayment.where(order_id: @order.id).order(:created_at).last
88
86
 
87
+
89
88
  if saferpay_payment
90
89
  payment_inquiry = inquire_payment(saferpay_payment)
91
90
  flash[:error] = payment_inquiry.user_message
92
91
  else
93
- flash[:error] = I18n.t(:general_error, scope: [:solidus_six_saferpay, :errors])
92
+ user_message = I18n.t(:general_error, scope: [:solidus_six_saferpay, :errors])
93
+ flash[:error] = user_message
94
94
  end
95
95
 
96
96
  @redirect_path = order_checkout_path(:payment)
@@ -21,6 +21,7 @@ module Spree
21
21
  if inquiry.success?
22
22
  saferpay_payment.update_attributes(response_hash: inquiry.api_response.to_h)
23
23
  else
24
+ saferpay_payment.update_attributes(response_hash: saferpay_payment.response_hash.merge(error: "#{inquiry.error_name}"))
24
25
  general_error = I18n.t(:general_error, scope: [:solidus_six_saferpay, :errors])
25
26
  specific_error = I18n.t(inquiry.error_name, scope: [:six_saferpay, :error_names])
26
27
  @user_message = "#{general_error}: #{specific_error}"
data/config/routes.rb CHANGED
@@ -4,14 +4,14 @@ Spree::Core::Engine.routes.draw do
4
4
  namespace :solidus_six_saferpay do
5
5
  namespace :payment_page do
6
6
  get :init, controller: :checkout, defaults: { format: :json }
7
- get :success, controller: :checkout
8
- get :fail, controller: :checkout
7
+ get 'success/:order_number', to: 'checkout#success', as: :success
8
+ get 'fail/:order_number', to: 'checkout#fail', as: :fail
9
9
  end
10
10
 
11
11
  namespace :transaction do
12
12
  get :init, controller: :checkout, defaults: { format: :json }
13
- get :success, controller: :checkout
14
- get :fail, controller: :checkout
13
+ get 'success/:order_number', to: 'checkout#success', as: :success
14
+ get 'fail/:order_number', to: 'checkout#fail', as: :fail
15
15
  end
16
16
  end
17
17
  end
@@ -5,9 +5,6 @@ module SolidusSixSaferpay
5
5
 
6
6
  def initialize(options = {})
7
7
  SixSaferpay.configure do |config|
8
- config.success_url = options.fetch(:success_url)
9
- config.fail_url = options.fetch(:fail_url)
10
-
11
8
  # Allow config via ENV for static values
12
9
  config.customer_id = options.fetch(:customer_id) { ENV.fetch('SIX_SAFERPAY_CUSTOMER_ID') }
13
10
  config.terminal_id = options.fetch(:terminal_id) { ENV.fetch('SIX_SAFERPAY_TERMINAL_ID') }
@@ -87,24 +84,23 @@ module SolidusSixSaferpay
87
84
  end
88
85
 
89
86
  def refund(amount, transaction_id, options = {})
90
- Rollbar.error("Disabled Refund for: #{transaction_id}")
91
- # payment = Spree::Payment.find_by!(response_code: transaction_id)
92
- # refund_amount = Spree::Money.new(amount, currency: payment.currency)
87
+ payment = Spree::Payment.find_by!(response_code: transaction_id)
88
+ refund_amount = Spree::Money.new(amount, currency: payment.currency)
93
89
 
94
- # saferpay_amount = SixSaferpay::Amount.new(value: refund_amount.cents, currency_code: payment.currency)
95
- # saferpay_refund = SixSaferpay::Refund.new(amount: saferpay_amount, order_id: payment.order.number)
96
- # capture_reference = SixSaferpay::CaptureReference.new(capture_id: payment.transaction_id)
90
+ saferpay_amount = SixSaferpay::Amount.new(value: refund_amount.cents, currency_code: payment.currency)
91
+ saferpay_refund = SixSaferpay::Refund.new(amount: saferpay_amount, order_id: payment.order.number)
92
+ capture_reference = SixSaferpay::CaptureReference.new(capture_id: payment.transaction_id)
97
93
 
98
- # payment_refund = SixSaferpay::SixTransaction::Refund.new(refund: saferpay_refund, capture_reference: capture_reference)
94
+ payment_refund = SixSaferpay::SixTransaction::Refund.new(refund: saferpay_refund, capture_reference: capture_reference)
99
95
 
100
- # if refund_response = SixSaferpay::Client.post(payment_refund)
96
+ if refund_response = SixSaferpay::Client.post(payment_refund)
101
97
 
102
- # # actually capture the refund
103
- # capture(amount, refund_response.transaction.id, options)
104
- # end
98
+ # actually capture the refund
99
+ capture(amount, refund_response.transaction.id, options)
100
+ end
105
101
 
106
- # rescue SixSaferpay::Error => e
107
- # handle_error(e, refund_response)
102
+ rescue SixSaferpay::Error => e
103
+ handle_error(e, refund_response)
108
104
  end
109
105
 
110
106
  private
@@ -157,7 +153,7 @@ module SolidusSixSaferpay
157
153
  )
158
154
  payer = SixSaferpay::Payer.new(language_code: I18n.locale, billing_address: billing_address, delivery_address: delivery_address)
159
155
 
160
- params = { payment: payment, payer: payer }
156
+ params = { payment: payment, payer: payer, return_urls: return_urls(order) }
161
157
 
162
158
  six_payment_methods = payment_method.enabled_payment_methods
163
159
  params.merge!(payment_methods: six_payment_methods) unless six_payment_methods.blank?
@@ -165,6 +161,10 @@ module SolidusSixSaferpay
165
161
  params
166
162
  end
167
163
 
164
+ def return_urls(order)
165
+ raise NotImplementedError, "Must be implemented in PaymentPageGateway or TransactionGateway"
166
+ end
167
+
168
168
  def response(success, message, api_response, options = {})
169
169
  GatewayResponse.new(success, message, api_response, options)
170
170
  end
@@ -1,15 +1,6 @@
1
1
  module SolidusSixSaferpay
2
2
  class PaymentPageGateway < Gateway
3
3
 
4
- def initialize(options = {})
5
- super(
6
- options.merge(
7
- success_url: url_helpers.solidus_six_saferpay_payment_page_success_url,
8
- fail_url: url_helpers.solidus_six_saferpay_payment_page_fail_url
9
- )
10
- )
11
- end
12
-
13
4
  def inquire(saferpay_payment, options = {})
14
5
  inquire_response = perform_assert_request(saferpay_payment, options)
15
6
 
@@ -47,6 +38,14 @@ module SolidusSixSaferpay
47
38
  SixSaferpay::SixPaymentPage::Initialize.new(interface_initialize_params(order, payment_method))
48
39
  end
49
40
 
41
+ def return_urls(order)
42
+ SixSaferpay::ReturnUrls.new(
43
+ success: url_helpers.solidus_six_saferpay_payment_page_success_url(order.number),
44
+ fd_fail: url_helpers.solidus_six_saferpay_payment_page_fail_url(order.number),
45
+ fd_abort: url_helpers.solidus_six_saferpay_payment_page_fail_url(order.number)
46
+ )
47
+ end
48
+
50
49
  def perform_assert_request(saferpay_payment, options = {})
51
50
  payment_page_assert = SixSaferpay::SixPaymentPage::Assert.new(token: saferpay_payment.token)
52
51
  SixSaferpay::Client.post(payment_page_assert)
@@ -1,15 +1,6 @@
1
1
  module SolidusSixSaferpay
2
2
  class TransactionGateway < Gateway
3
3
 
4
- def initialize(options = {})
5
- super(
6
- options.merge(
7
- success_url: url_helpers.solidus_six_saferpay_transaction_success_url,
8
- fail_url: url_helpers.solidus_six_saferpay_transaction_fail_url
9
- )
10
- )
11
- end
12
-
13
4
  def inquire(saferpay_payment, options = {})
14
5
  transaction_inquire = SixSaferpay::SixTransaction::Inquire.new(transaction_reference: saferpay_payment.transaction_id)
15
6
  inquire_response = SixSaferpay::Client.post(transaction_inquire)
@@ -43,5 +34,13 @@ module SolidusSixSaferpay
43
34
  def interface_initialize_object(order, payment_method)
44
35
  SixSaferpay::SixTransaction::Initialize.new(interface_initialize_params(order, payment_method))
45
36
  end
37
+
38
+ def return_urls(order)
39
+ SixSaferpay::ReturnUrls.new(
40
+ success: url_helpers.solidus_six_saferpay_transaction_success_url(order.number),
41
+ fd_fail: url_helpers.solidus_six_saferpay_transaction_fail_url(order.number),
42
+ fd_abort: url_helpers.solidus_six_saferpay_transaction_fail_url(order.number)
43
+ )
44
+ end
46
45
  end
47
46
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusSixSaferpay
4
- VERSION = '0.1.8.1'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -63,7 +63,7 @@ RSpec.describe Spree::SolidusSixSaferpay::PaymentPage::CheckoutController, type:
63
63
  let(:order) { nil }
64
64
 
65
65
  it 'redirects to the cart page via iframe breakout' do
66
- get :success
66
+ get :success, params: { order_number: "not_found" }
67
67
  expect(assigns(:redirect_path)).to eq(routes.cart_path)
68
68
  expect(response).to render_template :iframe_breakout_redirect
69
69
  end
@@ -73,7 +73,7 @@ RSpec.describe Spree::SolidusSixSaferpay::PaymentPage::CheckoutController, type:
73
73
  let(:order) { create(:order_ready_to_ship) }
74
74
 
75
75
  it 'redirects to the cart page via iframe breakout' do
76
- get :success
76
+ get :success, params: { order_number: order.number }
77
77
  expect(assigns(:redirect_path)).to eq(routes.cart_path)
78
78
  expect(response).to render_template :iframe_breakout_redirect
79
79
  end
@@ -83,7 +83,7 @@ RSpec.describe Spree::SolidusSixSaferpay::PaymentPage::CheckoutController, type:
83
83
  let!(:payment) { nil }
84
84
 
85
85
  it 'raises an error because no payment exists' do
86
- expect{ get(:success) }.to raise_error(Spree::Core::GatewayError)
86
+ expect{ get(:success, params: { order_number: order.number }) }.to raise_error(Spree::Core::GatewayError)
87
87
  end
88
88
  end
89
89
 
@@ -97,7 +97,7 @@ RSpec.describe Spree::SolidusSixSaferpay::PaymentPage::CheckoutController, type:
97
97
  expect(Spree::SolidusSixSaferpay::AssertPaymentPage).to receive(:call).with(payment).and_return(payment_assert)
98
98
  expect(Spree::SolidusSixSaferpay::InquirePaymentPagePayment).to receive(:call).with(payment).and_return(payment_inquiry)
99
99
 
100
- get :success
100
+ get :success, params: { order_number: order.number }
101
101
  end
102
102
 
103
103
  context 'when the payment assert is successful' do
@@ -112,7 +112,7 @@ RSpec.describe Spree::SolidusSixSaferpay::PaymentPage::CheckoutController, type:
112
112
  it 'processes the asserted payment' do
113
113
  expect(Spree::SolidusSixSaferpay::ProcessPaymentPagePayment).to receive(:call).with(payment).and_return(processed_payment)
114
114
 
115
- get :success
115
+ get :success, params: { order_number: order.number }
116
116
  end
117
117
 
118
118
  context 'when the processing is successful' do
@@ -120,6 +120,7 @@ RSpec.describe Spree::SolidusSixSaferpay::PaymentPage::CheckoutController, type:
120
120
 
121
121
  before do
122
122
  allow(Spree::SolidusSixSaferpay::ProcessPaymentPagePayment).to receive(:call).with(payment).and_return(processed_payment)
123
+ allow(Spree::Order).to receive(:find_by).with(number: order.number).and_return(order)
123
124
  end
124
125
 
125
126
 
@@ -129,7 +130,7 @@ RSpec.describe Spree::SolidusSixSaferpay::PaymentPage::CheckoutController, type:
129
130
  it 'moves order to next state' do
130
131
  expect(order).to receive(:next!)
131
132
 
132
- get :success
133
+ get :success, params: { order_number: order.number }
133
134
  end
134
135
  end
135
136
 
@@ -139,7 +140,7 @@ RSpec.describe Spree::SolidusSixSaferpay::PaymentPage::CheckoutController, type:
139
140
  it 'does not modify the order state' do
140
141
  expect(order).not_to receive(:next!)
141
142
 
142
- get :success
143
+ get :success, params: { order_number: order.number }
143
144
  end
144
145
  end
145
146
  end
@@ -152,7 +153,7 @@ RSpec.describe Spree::SolidusSixSaferpay::PaymentPage::CheckoutController, type:
152
153
  end
153
154
 
154
155
  it 'displays an error message' do
155
- get :success
156
+ get :success, params: { order_number: order.number }
156
157
 
157
158
  expect(flash[:error]).to eq("payment processing message")
158
159
  end
@@ -170,12 +171,12 @@ RSpec.describe Spree::SolidusSixSaferpay::PaymentPage::CheckoutController, type:
170
171
  it 'inquires the payment' do
171
172
  expect(Spree::SolidusSixSaferpay::InquirePaymentPagePayment).to receive(:call).with(payment).and_return(payment_inquiry)
172
173
 
173
- get :success
174
+ get :success, params: { order_number: order.number }
174
175
  end
175
176
 
176
177
  it 'displays an error message' do
177
178
  expect(Spree::SolidusSixSaferpay::InquirePaymentPagePayment).to receive(:call).with(payment).and_return(payment_inquiry)
178
- get :success
179
+ get :success, params: { order_number: order.number }
179
180
 
180
181
  expect(flash[:error]).to eq("payment inquiry message")
181
182
  end
@@ -190,13 +191,13 @@ RSpec.describe Spree::SolidusSixSaferpay::PaymentPage::CheckoutController, type:
190
191
  it 'inquires the payment' do
191
192
  expect(Spree::SolidusSixSaferpay::InquirePaymentPagePayment).to receive(:call).with(payment).and_return(payment_inquiry)
192
193
 
193
- get :fail
194
+ get :fail, params: { order_number: order.number }
194
195
  end
195
196
 
196
197
  it 'displays an error message' do
197
198
  expect(Spree::SolidusSixSaferpay::InquirePaymentPagePayment).to receive(:call).with(payment).and_return(payment_inquiry)
198
199
 
199
- get :fail
200
+ get :fail, params: { order_number: order.number }
200
201
 
201
202
  expect(flash[:error]).to eq("payment inquiry message")
202
203
  end
@@ -63,7 +63,7 @@ RSpec.describe Spree::SolidusSixSaferpay::Transaction::CheckoutController, type:
63
63
  let(:order) { nil }
64
64
 
65
65
  it 'redirects to the cart page via iframe breakout' do
66
- get :success
66
+ get :success, params: { order_number: 'not_found' }
67
67
  expect(assigns(:redirect_path)).to eq(routes.cart_path)
68
68
  expect(response).to render_template :iframe_breakout_redirect
69
69
  end
@@ -73,7 +73,7 @@ RSpec.describe Spree::SolidusSixSaferpay::Transaction::CheckoutController, type:
73
73
  let(:order) { create(:order_ready_to_ship) }
74
74
 
75
75
  it 'redirects to the cart page via iframe breakout' do
76
- get :success
76
+ get :success, params: { order_number: order.number }
77
77
  expect(assigns(:redirect_path)).to eq(routes.cart_path)
78
78
  expect(response).to render_template :iframe_breakout_redirect
79
79
  end
@@ -83,7 +83,7 @@ RSpec.describe Spree::SolidusSixSaferpay::Transaction::CheckoutController, type:
83
83
  let!(:payment) { nil }
84
84
 
85
85
  it 'raises an error because no payment exists' do
86
- expect{ get(:success) }.to raise_error(Spree::Core::GatewayError)
86
+ expect{ get(:success, params: { order_number: order.number }) }.to raise_error(Spree::Core::GatewayError)
87
87
  end
88
88
  end
89
89
 
@@ -97,7 +97,7 @@ RSpec.describe Spree::SolidusSixSaferpay::Transaction::CheckoutController, type:
97
97
  expect(Spree::SolidusSixSaferpay::AuthorizeTransaction).to receive(:call).with(payment).and_return(payment_assert)
98
98
  expect(Spree::SolidusSixSaferpay::InquireTransactionPayment).to receive(:call).with(payment).and_return(payment_inquiry)
99
99
 
100
- get :success
100
+ get :success, params: { order_number: order.number }
101
101
  end
102
102
 
103
103
  context 'when the payment assert is successful' do
@@ -112,7 +112,7 @@ RSpec.describe Spree::SolidusSixSaferpay::Transaction::CheckoutController, type:
112
112
  it 'processes the asserted payment' do
113
113
  expect(Spree::SolidusSixSaferpay::ProcessTransactionPayment).to receive(:call).with(payment).and_return(processed_payment)
114
114
 
115
- get :success
115
+ get :success, params: { order_number: order.number }
116
116
  end
117
117
 
118
118
  context 'when the processing is successful' do
@@ -120,6 +120,7 @@ RSpec.describe Spree::SolidusSixSaferpay::Transaction::CheckoutController, type:
120
120
 
121
121
  before do
122
122
  allow(Spree::SolidusSixSaferpay::ProcessTransactionPayment).to receive(:call).with(payment).and_return(processed_payment)
123
+ allow(Spree::Order).to receive(:find_by).with(number: order.number).and_return(order)
123
124
  end
124
125
 
125
126
  context 'when the default success handling is applied' do
@@ -129,7 +130,7 @@ RSpec.describe Spree::SolidusSixSaferpay::Transaction::CheckoutController, type:
129
130
  it 'moves order to next state' do
130
131
  expect(order).to receive(:next!)
131
132
 
132
- get :success
133
+ get :success, params: { order_number: order.number }
133
134
  end
134
135
  end
135
136
 
@@ -139,7 +140,7 @@ RSpec.describe Spree::SolidusSixSaferpay::Transaction::CheckoutController, type:
139
140
  it 'does not modify the order state' do
140
141
  expect(order).not_to receive(:next!)
141
142
 
142
- get :success
143
+ get :success, params: { order_number: order.number }
143
144
  end
144
145
  end
145
146
  end
@@ -156,13 +157,13 @@ RSpec.describe Spree::SolidusSixSaferpay::Transaction::CheckoutController, type:
156
157
  it 'does not modify the order state' do
157
158
  expect(order).not_to receive(:next!)
158
159
 
159
- get :success
160
+ get :success, params: { order_number: order.number }
160
161
  end
161
162
 
162
163
  it 'executes the custom handler' do
163
164
  expect(order).to receive(:email)
164
165
 
165
- get :success
166
+ get :success, params: { order_number: order.number }
166
167
  end
167
168
  end
168
169
  end
@@ -175,7 +176,7 @@ RSpec.describe Spree::SolidusSixSaferpay::Transaction::CheckoutController, type:
175
176
  end
176
177
 
177
178
  it 'displays an error message' do
178
- get :success
179
+ get :success, params: { order_number: order.number }
179
180
 
180
181
  expect(flash[:error]).to eq("payment processing message")
181
182
  end
@@ -193,12 +194,12 @@ RSpec.describe Spree::SolidusSixSaferpay::Transaction::CheckoutController, type:
193
194
  it 'inquires the payment' do
194
195
  expect(Spree::SolidusSixSaferpay::InquireTransactionPayment).to receive(:call).with(payment).and_return(payment_inquiry)
195
196
 
196
- get :success
197
+ get :success, params: { order_number: order.number }
197
198
  end
198
199
 
199
200
  it 'displays an error message' do
200
201
  expect(Spree::SolidusSixSaferpay::InquireTransactionPayment).to receive(:call).with(payment).and_return(payment_inquiry)
201
- get :success
202
+ get :success, params: { order_number: order.number }
202
203
 
203
204
  expect(flash[:error]).to eq("payment inquiry message")
204
205
  end
@@ -213,13 +214,13 @@ RSpec.describe Spree::SolidusSixSaferpay::Transaction::CheckoutController, type:
213
214
  it 'inquires the payment' do
214
215
  expect(Spree::SolidusSixSaferpay::InquireTransactionPayment).to receive(:call).with(payment).and_return(payment_inquiry)
215
216
 
216
- get :fail
217
+ get :fail, params: { order_number: order.number }
217
218
  end
218
219
 
219
220
  it 'displays an error message' do
220
221
  expect(Spree::SolidusSixSaferpay::InquireTransactionPayment).to receive(:call).with(payment).and_return(payment_inquiry)
221
222
 
222
- get :fail
223
+ get :fail, params: { order_number: order.number }
223
224
 
224
225
  expect(flash[:error]).to eq("payment inquiry message")
225
226
  end
@@ -44,8 +44,8 @@ module Spree
44
44
  expect(subject).to be_success
45
45
  end
46
46
 
47
- it 'does not update the response hash' do
48
- expect { subject.call }.not_to change { payment.response_hash }
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
49
  end
50
50
 
51
51
  it 'sets the user message according to the api error code' do
@@ -44,8 +44,8 @@ module Spree
44
44
  expect(subject).to be_success
45
45
  end
46
46
 
47
- it 'does not update the response hash' do
48
- expect { subject.call }.not_to change { payment.response_hash }
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
49
  end
50
50
 
51
51
  it 'sets the user message according to the api error code' do
@@ -7,15 +7,11 @@ module SolidusSixSaferpay
7
7
  let(:terminal_id) { 'TERMINAL_ID' }
8
8
  let(:username) { 'USERNAME' }
9
9
  let(:password) { 'PASSWORD' }
10
- let(:success_url) { '/api/endpoints/success' }
11
- let(:fail_url) { '/api/endpoints/fail' }
12
10
  let(:base_url) { 'https://test.saferpay-api-host.test' }
13
11
  let(:css_url) { '/custom/css/url' }
14
12
 
15
13
  let(:gateway) do
16
14
  described_class.new(
17
- success_url: success_url,
18
- fail_url: fail_url,
19
15
  customer_id: customer_id,
20
16
  terminal_id: terminal_id,
21
17
  username: username,
@@ -29,8 +25,6 @@ module SolidusSixSaferpay
29
25
 
30
26
  it 'configures the API client' do
31
27
  gateway = described_class.new(
32
- success_url: success_url,
33
- fail_url: fail_url,
34
28
  customer_id: customer_id,
35
29
  terminal_id: terminal_id,
36
30
  username: username,
@@ -45,8 +39,6 @@ module SolidusSixSaferpay
45
39
  expect(config.terminal_id).to eq(terminal_id)
46
40
  expect(config.username).to eq(username)
47
41
  expect(config.password).to eq(password)
48
- expect(config.success_url).to eq(success_url)
49
- expect(config.fail_url).to eq(fail_url)
50
42
  expect(config.base_url).to eq(base_url)
51
43
  expect(config.css_url).to eq(css_url)
52
44
  end
@@ -63,10 +55,7 @@ module SolidusSixSaferpay
63
55
  end
64
56
 
65
57
  it 'falls back to ENV vars' do
66
- gateway = described_class.new(
67
- success_url: success_url,
68
- fail_url: fail_url
69
- )
58
+ gateway = described_class.new
70
59
 
71
60
  config = SixSaferpay.config
72
61
 
@@ -74,8 +63,6 @@ module SolidusSixSaferpay
74
63
  expect(config.terminal_id).to eq(terminal_id)
75
64
  expect(config.username).to eq(username)
76
65
  expect(config.password).to eq(password)
77
- expect(config.success_url).to eq(success_url)
78
- expect(config.fail_url).to eq(fail_url)
79
66
  expect(config.base_url).to eq(base_url)
80
67
  expect(config.css_url).to eq(css_url)
81
68
  end
@@ -8,8 +8,6 @@ module SolidusSixSaferpay
8
8
  let(:terminal_id) { 'TERMINAL_ID' }
9
9
  let(:username) { 'USERNAME' }
10
10
  let(:password) { 'PASSWORD' }
11
- let(:success_url) { '/api/endpoints/success' }
12
- let(:fail_url) { '/api/endpoints/fail' }
13
11
  let(:base_url) { 'https://test.saferpay-api-host.test' }
14
12
  let(:css_url) { '/custom/css/url' }
15
13
 
@@ -38,17 +36,6 @@ module SolidusSixSaferpay
38
36
  allow(ENV).to receive(:fetch).with('SIX_SAFERPAY_CSS_URL').and_return(css_url)
39
37
  end
40
38
 
41
- describe '#initialize' do
42
- it 'configures the API client with correct urls by default' do
43
- described_class.new
44
-
45
- config = SixSaferpay.config
46
-
47
- expect(config.success_url).to eq(solidus_six_saferpay_payment_page_success_url)
48
- expect(config.fail_url).to eq(solidus_six_saferpay_payment_page_fail_url)
49
- end
50
- end
51
-
52
39
  describe '#initialize_payment' do
53
40
 
54
41
  let(:saferpay_billing_address) do
@@ -111,11 +98,19 @@ module SolidusSixSaferpay
111
98
  delivery_address: saferpay_shipping_address
112
99
  )
113
100
  end
101
+ let(:return_urls) do
102
+ instance_double("SixSaferpay::ReturnUrls",
103
+ success: solidus_six_saferpay_payment_page_success_url(order),
104
+ fd_fail: solidus_six_saferpay_payment_page_fail_url(order),
105
+ fd_abort: solidus_six_saferpay_payment_page_fail_url(order),
106
+ )
107
+ end
114
108
 
115
109
  let(:initialize_params) do
116
110
  {
117
111
  payment: saferpay_payment,
118
- payer: saferpay_payer
112
+ payer: saferpay_payer,
113
+ return_urls: return_urls
119
114
  }
120
115
  end
121
116
 
@@ -185,6 +180,13 @@ module SolidusSixSaferpay
185
180
  delivery_address: saferpay_shipping_address
186
181
  ).and_return(saferpay_payer)
187
182
 
183
+ # mock return_urls
184
+ expect(SixSaferpay::ReturnUrls).to receive(:new).with(
185
+ success: solidus_six_saferpay_payment_page_success_url(order),
186
+ fd_fail: solidus_six_saferpay_payment_page_fail_url(order),
187
+ fd_abort: solidus_six_saferpay_payment_page_fail_url(order),
188
+ ).and_return(return_urls)
189
+
188
190
  expect(SixSaferpay::SixPaymentPage::Initialize).to receive(:new).with(initialize_params).and_return(saferpay_initialize)
189
191
 
190
192
  expect(SixSaferpay::Client).to receive(:post).with(saferpay_initialize).and_return(api_initialize_response)
@@ -8,8 +8,6 @@ module SolidusSixSaferpay
8
8
  let(:terminal_id) { 'TERMINAL_ID' }
9
9
  let(:username) { 'USERNAME' }
10
10
  let(:password) { 'PASSWORD' }
11
- let(:success_url) { '/api/endpoints/success' }
12
- let(:fail_url) { '/api/endpoints/fail' }
13
11
  let(:base_url) { 'https://test.saferpay-api-host.test' }
14
12
  let(:css_url) { '/custom/css/url' }
15
13
 
@@ -38,17 +36,6 @@ module SolidusSixSaferpay
38
36
  allow(ENV).to receive(:fetch).with('SIX_SAFERPAY_CSS_URL').and_return(css_url)
39
37
  end
40
38
 
41
- describe '#initialize' do
42
- it 'configures the API client with correct urls by default' do
43
- described_class.new
44
-
45
- config = SixSaferpay.config
46
-
47
- expect(config.success_url).to eq(solidus_six_saferpay_transaction_success_url)
48
- expect(config.fail_url).to eq(solidus_six_saferpay_transaction_fail_url)
49
- end
50
- end
51
-
52
39
  describe '#initialize_payment' do
53
40
 
54
41
  let(:saferpay_billing_address) do
@@ -112,10 +99,19 @@ module SolidusSixSaferpay
112
99
  )
113
100
  end
114
101
 
102
+ let(:return_urls) do
103
+ instance_double("SixSaferpay::ReturnUrls",
104
+ success: solidus_six_saferpay_transaction_success_url(order),
105
+ fd_fail: solidus_six_saferpay_transaction_fail_url(order),
106
+ fd_abort: solidus_six_saferpay_transaction_fail_url(order),
107
+ )
108
+ end
109
+
115
110
  let(:initialize_params) do
116
111
  {
117
112
  payment: saferpay_payment,
118
- payer: saferpay_payer
113
+ payer: saferpay_payer,
114
+ return_urls: return_urls
119
115
  }
120
116
  end
121
117
 
@@ -189,6 +185,13 @@ module SolidusSixSaferpay
189
185
  delivery_address: saferpay_shipping_address
190
186
  ).and_return(saferpay_payer)
191
187
 
188
+ # mock return_urls
189
+ expect(SixSaferpay::ReturnUrls).to receive(:new).with(
190
+ success: solidus_six_saferpay_transaction_success_url(order),
191
+ fd_fail: solidus_six_saferpay_transaction_fail_url(order),
192
+ fd_abort: solidus_six_saferpay_transaction_fail_url(order),
193
+ ).and_return(return_urls)
194
+
192
195
  expect(SixSaferpay::SixTransaction::Initialize).to receive(:new).with(initialize_params).and_return(saferpay_initialize)
193
196
 
194
197
  expect(SixSaferpay::Client).to receive(:post).with(saferpay_initialize).and_return(api_initialize_response)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_six_saferpay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Kiener
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-01 00:00:00.000000000 Z
11
+ date: 2020-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core
@@ -366,7 +366,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
366
366
  - !ruby/object:Gem::Version
367
367
  version: '0'
368
368
  requirements: []
369
- rubygems_version: 3.0.3
369
+ rubyforge_project:
370
+ rubygems_version: 2.7.6
370
371
  signing_key:
371
372
  specification_version: 4
372
373
  summary: Saferpay Payment Page and Transaction payment methods for Solidus