solidus_six_saferpay 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/javascripts/solidus_six_saferpay/saferpay_payment.js +4 -1
- data/app/controllers/spree/solidus_six_saferpay/checkout_controller.rb +93 -16
- data/app/controllers/spree/solidus_six_saferpay/transaction/checkout_controller.rb +1 -1
- data/app/models/spree/payment_method/saferpay_payment_method.rb +1 -1
- data/app/models/spree/payment_method/saferpay_payment_page.rb +2 -2
- data/app/models/spree/payment_method/saferpay_transaction.rb +2 -2
- data/app/services/spree/solidus_six_saferpay/cancel_authorized_payment.rb +33 -0
- data/app/services/spree/solidus_six_saferpay/initialize_payment.rb +0 -1
- data/app/services/spree/solidus_six_saferpay/initialize_transaction.rb +0 -1
- data/app/services/spree/solidus_six_saferpay/inquire_payment.rb +26 -1
- data/app/views/spree/checkout/payment/_saferpay_payment.html.erb +2 -2
- data/app/views/spree/solidus_six_saferpay/checkout/{iframe_breakout_redirect.html.erb → iframe_breakout_redirect.erb} +1 -1
- data/config/locales/de.yml +3 -0
- data/config/locales/en.yml +3 -0
- data/config/locales/fr.yml +3 -0
- data/config/routes.rb +2 -2
- data/lib/solidus_six_saferpay/configuration.rb +2 -0
- data/lib/solidus_six_saferpay/gateway.rb +6 -7
- data/lib/solidus_six_saferpay/version.rb +1 -1
- data/spec/controllers/spree/solidus_six_saferpay/payment_page/checkout_controller_spec.rb +8 -198
- data/spec/controllers/spree/solidus_six_saferpay/transaction/checkout_controller_spec.rb +8 -221
- data/spec/services/spree/solidus_six_saferpay/assert_payment_page_spec.rb +2 -128
- data/spec/services/spree/solidus_six_saferpay/authorize_transaction_spec.rb +3 -127
- data/spec/services/spree/solidus_six_saferpay/cancel_authorized_payment_spec.rb +58 -0
- data/spec/services/spree/solidus_six_saferpay/initialize_payment_page_spec.rb +0 -2
- data/spec/services/spree/solidus_six_saferpay/initialize_transaction_spec.rb +0 -1
- data/spec/services/spree/solidus_six_saferpay/inquire_payment_page_payment_spec.rb +2 -98
- data/spec/services/spree/solidus_six_saferpay/inquire_transaction_payment_spec.rb +2 -98
- data/spec/services/spree/solidus_six_saferpay/process_payment_page_payment_spec.rb +1 -206
- data/spec/services/spree/solidus_six_saferpay/process_transaction_payment_spec.rb +1 -200
- data/spec/support/shared_examples/authorize_payment.rb +132 -0
- data/spec/support/shared_examples/checkout_controller.rb +342 -0
- data/spec/support/shared_examples/inquire_payment.rb +118 -0
- data/spec/support/shared_examples/process_authorized_payment.rb +202 -0
- metadata +14 -6
- data/app/services/spree/solidus_six_saferpay/inquire_transaction.rb +0 -7
- data/spec/controllers/spree/solidus_six_saferpay/checkout_controller_spec.rb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a50764caa3e856291be76ef3516ec267c44b056b8824aad3970cb7ba227454e
|
4
|
+
data.tar.gz: d0e1a19041a511d2485415d32efba781ff2558a0d75088e32f1fc20b90ece359
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5e7411ccb2307f1ddd9f0cb4b94a38e8e0ec5702a7a78387dd35593197febb77a684067e6b6e879babc34611de359ec3b38fd79ecc9ac34995ffdf7dbc14b3a
|
7
|
+
data.tar.gz: cd0b224c254e21bb70a3c17576474ab46b2e5b4f8d9ecc9e8a90c3c28e6a1866bdbe596254e6f377bd332954b5a9e9e35a02c60916dce7fc78149abcd1db86e3
|
@@ -18,7 +18,10 @@ let SaferpayPayment = {
|
|
18
18
|
},
|
19
19
|
|
20
20
|
error: function(xhr) {
|
21
|
-
|
21
|
+
// We have no other option for displaying this message, so to inform
|
22
|
+
// the user we must alert
|
23
|
+
alert(xhr.responseJSON.errors);
|
24
|
+
window.location.replace(xhr.responseJSON.redirect_url);
|
22
25
|
return false;
|
23
26
|
},
|
24
27
|
})
|
@@ -3,9 +3,25 @@ module Spree
|
|
3
3
|
class CheckoutController < StoreController
|
4
4
|
|
5
5
|
def init
|
6
|
-
|
7
|
-
|
6
|
+
order_number = params[:order_number]
|
7
|
+
@order = Spree::Order.find_by(number: order_number)
|
8
8
|
|
9
|
+
# We must make sure that the order for which the user requests a
|
10
|
+
# payment is still their `current_order`.
|
11
|
+
# This can be false if the user tries to add something to the cart
|
12
|
+
# after getting to the payment checkout step, and then switches back to
|
13
|
+
# the payment step and starts the payment process by selecting a
|
14
|
+
# payment method.
|
15
|
+
# In that case, we redirect to the checkout path so the user needs to
|
16
|
+
# go through the checkout process again to ensure that the real
|
17
|
+
# `current_order` contains all necessary information.
|
18
|
+
if @order.nil? || @order != current_order
|
19
|
+
render json: {
|
20
|
+
redirect_url: spree.cart_path,
|
21
|
+
errors: t('.order_was_modified_after_confirmation')
|
22
|
+
}, status: 422
|
23
|
+
return
|
24
|
+
end
|
9
25
|
|
10
26
|
payment_method = Spree::PaymentMethod.find(params[:payment_method_id])
|
11
27
|
initialized_payment = initialize_payment(@order, payment_method)
|
@@ -14,7 +30,10 @@ module Spree
|
|
14
30
|
redirect_url = initialized_payment.redirect_url
|
15
31
|
render json: { redirect_url: redirect_url }
|
16
32
|
else
|
17
|
-
render json: {
|
33
|
+
render json: {
|
34
|
+
redirect_url: spree.cart_path,
|
35
|
+
errors: t('.checkout_not_initialized')
|
36
|
+
}, status: 422
|
18
37
|
end
|
19
38
|
end
|
20
39
|
|
@@ -23,6 +42,20 @@ module Spree
|
|
23
42
|
@order = Spree::Order.find_by(number: order_number)
|
24
43
|
|
25
44
|
if @order.nil?
|
45
|
+
handle_order_not_found(order_number)
|
46
|
+
|
47
|
+
flash[:error] = t('.error_while_processing_payment')
|
48
|
+
@redirect_path = spree.cart_path
|
49
|
+
render :iframe_breakout_redirect, layout: false
|
50
|
+
return
|
51
|
+
end
|
52
|
+
|
53
|
+
saferpay_payment = Spree::SixSaferpayPayment.where(order_id: @order.id).order(:created_at).last
|
54
|
+
|
55
|
+
if saferpay_payment.nil?
|
56
|
+
handle_payment_not_found(@order)
|
57
|
+
|
58
|
+
flash[:error] = t('.error_while_processing_payment')
|
26
59
|
@redirect_path = spree.cart_path
|
27
60
|
render :iframe_breakout_redirect, layout: false
|
28
61
|
return
|
@@ -31,17 +64,14 @@ module Spree
|
|
31
64
|
# ensure that completed orders don't try to reprocess the
|
32
65
|
# authorization. This could happen if a user presses the back button
|
33
66
|
# after completing an order.
|
67
|
+
# There is no error handling because it should look like you are simply
|
68
|
+
# redirected to the cart page.
|
34
69
|
if @order.completed?
|
35
70
|
@redirect_path = spree.cart_path
|
36
71
|
render :iframe_breakout_redirect, layout: false
|
37
72
|
return
|
38
73
|
end
|
39
74
|
|
40
|
-
saferpay_payment = Spree::SixSaferpayPayment.where(order_id: @order.id).order(:created_at).last
|
41
|
-
|
42
|
-
if saferpay_payment.nil?
|
43
|
-
raise Spree::Core::GatewayError, t('.saferpay_payment_not_found')
|
44
|
-
end
|
45
75
|
|
46
76
|
# NOTE: PaymentPage payments are authorized directly. Instead, we
|
47
77
|
# perform an ASSERT here to gather the necessary details.
|
@@ -77,6 +107,9 @@ module Spree
|
|
77
107
|
@order = Spree::Order.find_by(number: order_number)
|
78
108
|
|
79
109
|
if @order.nil?
|
110
|
+
handle_order_not_found(order_number)
|
111
|
+
|
112
|
+
flash[:error] = t('.error_while_processing_payment')
|
80
113
|
@redirect_path = spree.cart_path
|
81
114
|
render :iframe_breakout_redirect, layout: false
|
82
115
|
return
|
@@ -84,15 +117,19 @@ module Spree
|
|
84
117
|
|
85
118
|
saferpay_payment = Spree::SixSaferpayPayment.where(order_id: @order.id).order(:created_at).last
|
86
119
|
|
120
|
+
if saferpay_payment.nil?
|
121
|
+
handle_payment_not_found(@order)
|
87
122
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
user_message = I18n.t(:general_error, scope: [:solidus_six_saferpay, :errors])
|
93
|
-
flash[:error] = user_message
|
123
|
+
flash[:error] = t('.error_while_processing_payment')
|
124
|
+
@redirect_path = spree.cart_path
|
125
|
+
render :iframe_breakout_redirect, layout: false
|
126
|
+
return
|
94
127
|
end
|
95
128
|
|
129
|
+
|
130
|
+
payment_inquiry = inquire_payment(saferpay_payment)
|
131
|
+
flash[:error] = payment_inquiry.user_message
|
132
|
+
|
96
133
|
@redirect_path = order_checkout_path(:payment)
|
97
134
|
render :iframe_breakout_redirect, layout: false
|
98
135
|
end
|
@@ -115,13 +152,53 @@ module Spree
|
|
115
152
|
raise NotImplementedError, "Must be implemented in PaymentPageCheckoutController or TransactionCheckoutController"
|
116
153
|
end
|
117
154
|
|
155
|
+
# Allows overriding of success behaviour in host application by setting
|
156
|
+
# SolidusSixSaferpay.config.payment_processing_order_not_found_handler
|
157
|
+
#
|
158
|
+
# If not overridden, it will call the configured error handler without actually raising any errors
|
159
|
+
#
|
160
|
+
# Example
|
161
|
+
# config.payment_processing_order_not_found_handler = Proc.new do |context, order_number|
|
162
|
+
# puts "No solidus order with this number: #{order_number}!"
|
163
|
+
# end
|
164
|
+
#
|
165
|
+
def handle_order_not_found(order_number)
|
166
|
+
if order_not_found_handler = ::SolidusSixSaferpay.config.payment_processing_order_not_found_handler.presence
|
167
|
+
order_not_found_handler.call(self, order_number)
|
168
|
+
else
|
169
|
+
::SolidusSixSaferpay::ErrorHandler.handle(
|
170
|
+
StandardError.new("No solidus order could be found for number #{order_number}"),
|
171
|
+
level: :error
|
172
|
+
)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
# Allows overriding of success behaviour in host application by setting
|
177
|
+
# SolidusSixSaferpay.config.payment_processing_payment_not_found_handler
|
178
|
+
#
|
179
|
+
# If not overridden, it will call the configured error handler without actually raising any errors
|
180
|
+
#
|
181
|
+
# Example
|
182
|
+
# config.payment_processing_payment_not_found_handler = Proc.new { |context, order| puts "No saferpay payment found for #{order}!" }
|
183
|
+
#
|
184
|
+
def handle_payment_not_found(order)
|
185
|
+
if payment_not_found_handler = ::SolidusSixSaferpay.config.payment_processing_payment_not_found_handler.presence
|
186
|
+
payment_not_found_handler.call(self, order)
|
187
|
+
else
|
188
|
+
::SolidusSixSaferpay::ErrorHandler.handle(
|
189
|
+
StandardError.new("No Saferpay Payment found for order #{order.number}"),
|
190
|
+
level: :error
|
191
|
+
)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
118
195
|
# Allows overriding of success behaviour in host application by setting
|
119
196
|
# SolidusSixSaferpay.config.payment_processing_success_handler
|
120
197
|
#
|
121
|
-
#
|
198
|
+
# If not overridden, it will ensure that the order state is no longer "payment"
|
122
199
|
#
|
123
200
|
# Example
|
124
|
-
# config.payment_processing_success_handler = Proc.new { |order| puts "Order #{order} has been successfully paid!" }
|
201
|
+
# config.payment_processing_success_handler = Proc.new { |context, order| puts "Order #{order} has been successfully paid!" }
|
125
202
|
#
|
126
203
|
def handle_payment_processing_success
|
127
204
|
if success_handler = ::SolidusSixSaferpay.config.payment_processing_success_handler.presence
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Spree
|
2
2
|
module SolidusSixSaferpay
|
3
|
-
# explicit parent must be stated, otherwise Spree::CheckoutController has precendence
|
4
3
|
module Transaction
|
4
|
+
# explicit parent must be stated, otherwise Spree::CheckoutController has precendence
|
5
5
|
class CheckoutController < SolidusSixSaferpay::CheckoutController
|
6
6
|
|
7
7
|
private
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Spree
|
2
|
+
module SolidusSixSaferpay
|
3
|
+
class CancelAuthorizedPayment
|
4
|
+
|
5
|
+
attr_reader :saferpay_payment
|
6
|
+
|
7
|
+
def self.call(saferpay_payment)
|
8
|
+
new(saferpay_payment).call
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(saferpay_payment)
|
12
|
+
@saferpay_payment = saferpay_payment
|
13
|
+
end
|
14
|
+
|
15
|
+
def call
|
16
|
+
if transaction_id = saferpay_payment.transaction_id
|
17
|
+
gateway.void(saferpay_payment.transaction_id)
|
18
|
+
else
|
19
|
+
::SolidusSixSaferpay::ErrorHandler.handle(
|
20
|
+
::SolidusSixSaferpay::InvalidSaferpayPayment.new(
|
21
|
+
details: "Can not cancel payment #{saferpay_payment.id} because it has no transaction ID.")
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def gateway
|
29
|
+
::SolidusSixSaferpay::Gateway.new
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -19,7 +19,7 @@ module Spree
|
|
19
19
|
inquiry = gateway.inquire(saferpay_payment)
|
20
20
|
|
21
21
|
if inquiry.success?
|
22
|
-
saferpay_payment.update_attributes(
|
22
|
+
saferpay_payment.update_attributes(saferpay_payment_attributes(inquiry.api_response))
|
23
23
|
else
|
24
24
|
saferpay_payment.update_attributes(response_hash: saferpay_payment.response_hash.merge(error: "#{inquiry.error_name}"))
|
25
25
|
general_error = I18n.t(:general_error, scope: [:solidus_six_saferpay, :errors])
|
@@ -39,6 +39,31 @@ module Spree
|
|
39
39
|
def gateway
|
40
40
|
raise NotImplementedError, "Must be implemented in AssertPaymentPage or AuthorizeTransaction with UsePaymentPageGateway or UseTransactionGateway"
|
41
41
|
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def saferpay_payment_attributes(saferpay_response)
|
46
|
+
payment_means = saferpay_response.payment_means
|
47
|
+
brand = payment_means.brand
|
48
|
+
card = payment_means.card
|
49
|
+
|
50
|
+
attributes = {
|
51
|
+
transaction_id: saferpay_response.transaction.id,
|
52
|
+
transaction_status: saferpay_response.transaction.status,
|
53
|
+
transaction_date: DateTime.parse(saferpay_response.transaction.date),
|
54
|
+
six_transaction_reference: saferpay_response.transaction.six_transaction_reference,
|
55
|
+
display_text: saferpay_response.payment_means.display_text,
|
56
|
+
response_hash: saferpay_response.to_h
|
57
|
+
}
|
58
|
+
|
59
|
+
if card
|
60
|
+
attributes[:masked_number] = card.masked_number
|
61
|
+
attributes[:expiration_year] = card.exp_year
|
62
|
+
attributes[:expiration_month] = card.exp_month
|
63
|
+
end
|
64
|
+
|
65
|
+
attributes
|
66
|
+
end
|
42
67
|
end
|
43
68
|
end
|
44
69
|
end
|
@@ -3,10 +3,10 @@
|
|
3
3
|
<iframe class="saferpay-iframe" width='100%' height='550px' id="<%= payment_container_id %>" src="" frameborder="0">
|
4
4
|
</iframe>
|
5
5
|
<script charset="utf-8">
|
6
|
-
SaferpayPayment.registerIframePaymentMethod({id: "<%= payment_method.id %>", initUrl: "<%= payment_method.init_path %>", containerId: "#<%= payment_container_id %>"})
|
6
|
+
SaferpayPayment.registerIframePaymentMethod({id: "<%= payment_method.id %>", initUrl: "<%= payment_method.init_path(@order) %>", containerId: "#<%= payment_container_id %>"})
|
7
7
|
</script>
|
8
8
|
<% else %>
|
9
9
|
<script charset="utf-8">
|
10
|
-
SaferpayPayment.registerExternalRedirectPaymentMethod({id: "<%= payment_method.id %>", initUrl: "<%= payment_method.init_path %>"})
|
10
|
+
SaferpayPayment.registerExternalRedirectPaymentMethod({id: "<%= payment_method.id %>", initUrl: "<%= payment_method.init_path(@order) %>"})
|
11
11
|
</script>
|
12
12
|
<% end %>
|
data/config/locales/de.yml
CHANGED
@@ -5,7 +5,9 @@ de:
|
|
5
5
|
checkout: &checkout
|
6
6
|
init:
|
7
7
|
checkout_not_initialized: Zahlung konnte nicht gestartet werden.
|
8
|
+
order_was_modified_after_confirmation: Bestellung wurde nach der Bestätigung verändert. Bitte starten Sie den Zahlungsvorgang erneut.
|
8
9
|
success:
|
10
|
+
error_while_processing_payment: Beim Verarbeiten der Bezahlung ist ein Fehler aufgetreten. Bitte starten Sie den Zahlungsvorgang erneut.
|
9
11
|
saferpay_payment_not_found: Six Saferpay Zahlung kann nicht gefunden werden.
|
10
12
|
fail:
|
11
13
|
payment_failed: Die Zahlung konnte nicht abgeschlossen werden.
|
@@ -19,6 +21,7 @@ de:
|
|
19
21
|
errors:
|
20
22
|
general_error: Bezahlungsfehler
|
21
23
|
liability_shift_not_granted: Haftungsumkehr wurde abgelehnt
|
24
|
+
saferpay_payment_not_found: Saferpay Payment konnte nicht gefunden werden
|
22
25
|
six_saferpay:
|
23
26
|
error_names:
|
24
27
|
ACTION_NOT_SUPPORTED: Die angeforderte Aktion wird im Kontext der Aktion nicht unterstützt un kann mit den Anforderungsdaten nicht ausgeführt werden.
|
data/config/locales/en.yml
CHANGED
@@ -5,7 +5,9 @@ en:
|
|
5
5
|
checkout: &checkout
|
6
6
|
init:
|
7
7
|
checkout_not_initialized: Payment could not be initialized.
|
8
|
+
order_was_modified_after_confirmation: Order was modified after confirmation. Please restart the checkout process.
|
8
9
|
success:
|
10
|
+
error_while_processing_payment: An error occurred while processing the payment. Please restart the checkout process.
|
9
11
|
saferpay_payment_not_found: Six Saferpay payment can not be found.
|
10
12
|
fail:
|
11
13
|
payment_failed: The payment could not be completed.
|
@@ -19,6 +21,7 @@ en:
|
|
19
21
|
errors:
|
20
22
|
general_error: Payment Error
|
21
23
|
liability_shift_not_granted: Liability Shift was rejected
|
24
|
+
saferpay_payment_not_found: Saferpay Payment could not be found
|
22
25
|
six_saferpay:
|
23
26
|
error_names:
|
24
27
|
ACTION_NOT_SUPPORTED: The requested action is not supported in the given context or the action can't be executed with the request data.
|
data/config/locales/fr.yml
CHANGED
@@ -5,7 +5,9 @@ fr:
|
|
5
5
|
checkout: &checkout
|
6
6
|
init:
|
7
7
|
checkout_not_initialized: Le paiement n'a pas pu être initialisé.
|
8
|
+
order_was_modified_after_confirmation: La commande a été modifiée après confirmation. Veuillez redémarrer le processus de paiement.
|
8
9
|
success:
|
10
|
+
error_while_processing_payment: Une erreur s'est produite lors du traitement du paiement. Veuillez redémarrer le processus de paiement.
|
9
11
|
saferpay_payment_not_found: Paiement Six Saferpay est introuvable.
|
10
12
|
fail:
|
11
13
|
payment_failed: Le paiement n'a pas pu être complété.
|
@@ -18,6 +20,7 @@ fr:
|
|
18
20
|
solidus_six_saferpay:
|
19
21
|
errors:
|
20
22
|
liability_shift_not_granted: Le transfert de responsabilité a été rejeté
|
23
|
+
saferpay_payment_not_found: Saferpay Payment est introuvable
|
21
24
|
six_saferpay:
|
22
25
|
error_names:
|
23
26
|
ACTION_NOT_SUPPORTED: l'action demandé n'es pas prise en charge dans le contexte de l'action et ne peut pas être exécutée avec les données de la demande.
|
data/config/routes.rb
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
Spree::Core::Engine.routes.draw do
|
4
4
|
namespace :solidus_six_saferpay do
|
5
5
|
namespace :payment_page do
|
6
|
-
get :init,
|
6
|
+
get 'init/:order_number', to: 'checkout#init', as: :init, defaults: { format: :json }
|
7
7
|
get 'success/:order_number', to: 'checkout#success', as: :success
|
8
8
|
get 'fail/:order_number', to: 'checkout#fail', as: :fail
|
9
9
|
end
|
10
10
|
|
11
11
|
namespace :transaction do
|
12
|
-
get :init,
|
12
|
+
get 'init/:order_number', to: 'checkout#init', as: :init, defaults: { format: :json }
|
13
13
|
get 'success/:order_number', to: 'checkout#success', as: :success
|
14
14
|
get 'fail/:order_number', to: 'checkout#fail', as: :fail
|
15
15
|
end
|
@@ -3,6 +3,8 @@ module SolidusSixSaferpay
|
|
3
3
|
include ActiveSupport::Configurable
|
4
4
|
|
5
5
|
|
6
|
+
config_accessor(:payment_processing_order_not_found_handler)
|
7
|
+
config_accessor(:payment_processing_payment_not_found_handler)
|
6
8
|
config_accessor(:payment_processing_success_handler)
|
7
9
|
config_accessor(:error_handlers) { [] }
|
8
10
|
end
|
@@ -40,7 +40,7 @@ module SolidusSixSaferpay
|
|
40
40
|
capture(amount, saferpay_payment.transaction_id, options)
|
41
41
|
end
|
42
42
|
|
43
|
-
def capture(
|
43
|
+
def capture(_amount, transaction_id, options={})
|
44
44
|
transaction_reference = SixSaferpay::TransactionReference.new(transaction_id: transaction_id)
|
45
45
|
payment_capture = SixSaferpay::SixTransaction::Capture.new(transaction_reference: transaction_reference)
|
46
46
|
|
@@ -79,15 +79,14 @@ module SolidusSixSaferpay
|
|
79
79
|
end
|
80
80
|
|
81
81
|
# aliased to #refund for compatibility with solidus internals
|
82
|
-
def credit(
|
83
|
-
refund(
|
82
|
+
def credit(amount_cents, transaction_id, options = {})
|
83
|
+
refund(amount_cents, transaction_id, options)
|
84
84
|
end
|
85
85
|
|
86
|
-
def refund(
|
86
|
+
def refund(amount_cents, transaction_id, options = {})
|
87
87
|
payment = Spree::Payment.find_by!(response_code: transaction_id)
|
88
|
-
refund_amount = Spree::Money.new(amount, currency: payment.currency)
|
89
88
|
|
90
|
-
saferpay_amount = SixSaferpay::Amount.new(value:
|
89
|
+
saferpay_amount = SixSaferpay::Amount.new(value: amount_cents, currency_code: payment.currency)
|
91
90
|
saferpay_refund = SixSaferpay::Refund.new(amount: saferpay_amount, order_id: payment.order.number)
|
92
91
|
capture_reference = SixSaferpay::CaptureReference.new(capture_id: payment.transaction_id)
|
93
92
|
|
@@ -96,7 +95,7 @@ module SolidusSixSaferpay
|
|
96
95
|
if refund_response = SixSaferpay::Client.post(payment_refund)
|
97
96
|
|
98
97
|
# actually capture the refund
|
99
|
-
capture(
|
98
|
+
capture(amount_cents, refund_response.transaction.id, options)
|
100
99
|
end
|
101
100
|
|
102
101
|
rescue SixSaferpay::Error => e
|