solidus_six_saferpay 0.1.5 → 0.3.0
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 +36 -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/solidus_six_saferpay/saferpay_payment.js +4 -1
- 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/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 +133 -17
- 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 +27 -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/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 +4 -1
- data/config/locales/en.yml +4 -1
- data/config/locales/fr.yml +4 -1
- data/config/routes.rb +8 -8
- 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 +6 -7
- data/lib/solidus_six_saferpay/engine.rb +19 -10
- data/lib/solidus_six_saferpay/gateway.rb +11 -11
- data/lib/solidus_six_saferpay/payment_page_gateway.rb +8 -9
- data/lib/solidus_six_saferpay/transaction_gateway.rb +8 -9
- data/lib/solidus_six_saferpay/version.rb +3 -1
- data/solidus_six_saferpay.gemspec +42 -0
- data/spec/controllers/spree/solidus_six_saferpay/payment_page/checkout_controller_spec.rb +16 -0
- data/spec/controllers/spree/solidus_six_saferpay/transaction/checkout_controller_spec.rb +16 -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 +22 -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 +24 -0
- 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 +81 -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 +84 -0
- data/spec/services/spree/solidus_six_saferpay/inquire_payment_page_payment_spec.rb +20 -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 +21 -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 +20 -0
- data/spec/services/spree/solidus_six_saferpay/process_transaction_payment_spec.rb +20 -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 +365 -0
- data/spec/solidus_six_saferpay/payment_page_gateway_spec.rb +392 -0
- data/spec/solidus_six_saferpay/transaction_gateway_spec.rb +390 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/support/route_access.rb +6 -0
- 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
- data/spec/support/uses_payment_page_gateway.rb +29 -0
- data/spec/support/uses_transaction_gateway.rb +28 -0
- metadata +250 -101
- data/app/services/spree/solidus_six_saferpay/inquire_transaction.rb +0 -7
@@ -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,8 +19,9 @@ 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
|
+
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}"
|
@@ -38,6 +39,31 @@ module Spree
|
|
38
39
|
def gateway
|
39
40
|
raise NotImplementedError, "Must be implemented in AssertPaymentPage or AuthorizeTransaction with UsePaymentPageGateway or UseTransactionGateway"
|
40
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
|
41
67
|
end
|
42
68
|
end
|
43
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/bin/console
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require "bundler/setup"
|
6
|
+
require "solidus_six_saferpay"
|
7
|
+
|
8
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
9
|
+
# with your gem easier. You can also use a different console, if you like.
|
10
|
+
$LOAD_PATH.unshift(*Dir["#{__dir__}/../app/*"])
|
11
|
+
|
12
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
13
|
+
# require "pry"
|
14
|
+
# Pry.start
|
15
|
+
|
16
|
+
require "irb"
|
17
|
+
IRB.start(__FILE__)
|
data/bin/rails
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
app_root = 'sandbox'
|
6
|
+
|
7
|
+
unless File.exist? "#{app_root}/bin/rails"
|
8
|
+
warn 'Creating the sandbox app...'
|
9
|
+
Dir.chdir "#{__dir__}/.." do
|
10
|
+
system "#{__dir__}/sandbox" or begin # rubocop:disable Style/AndOr
|
11
|
+
warn 'Automatic creation of the sandbox app failed'
|
12
|
+
exit 1
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Dir.chdir app_root
|
18
|
+
exec 'bin/rails', *ARGV
|
data/bin/rake
ADDED
data/bin/setup
ADDED
data/config/locales/de.yml
CHANGED
@@ -5,8 +5,10 @@ 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:
|
9
|
-
|
10
|
+
error_while_processing_payment: Beim Verarbeiten der Bezahlung ist ein Fehler aufgetreten. Bitte starten Sie den Zahlungsvorgang erneut.
|
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.
|
12
14
|
payment_page:
|
@@ -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,8 +5,10 @@ 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:
|
9
|
-
|
10
|
+
error_while_processing_payment: An error occurred while processing the payment. Please restart the checkout process.
|
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.
|
12
14
|
payment_page:
|
@@ -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,8 +5,10 @@ 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:
|
9
|
-
|
10
|
+
error_while_processing_payment: Une erreur s'est produite lors du traitement du paiement. Veuillez redémarrer le processus de paiement.
|
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é.
|
12
14
|
payment_page:
|
@@ -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
@@ -1,17 +1,17 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
Spree::Core::Engine.routes.draw do
|
3
4
|
namespace :solidus_six_saferpay do
|
4
5
|
namespace :payment_page do
|
5
|
-
get :init,
|
6
|
-
get :success,
|
7
|
-
get :fail,
|
6
|
+
get 'init/:order_number', to: 'checkout#init', as: :init, defaults: { format: :json }
|
7
|
+
get 'success/:order_number', to: 'checkout#success', as: :success
|
8
|
+
get 'fail/:order_number', to: 'checkout#fail', as: :fail
|
8
9
|
end
|
9
10
|
|
10
11
|
namespace :transaction do
|
11
|
-
get :init,
|
12
|
-
get :success,
|
13
|
-
get :fail,
|
12
|
+
get 'init/:order_number', to: 'checkout#init', as: :init, defaults: { format: :json }
|
13
|
+
get 'success/:order_number', to: 'checkout#success', as: :success
|
14
|
+
get 'fail/:order_number', to: 'checkout#fail', as: :fail
|
14
15
|
end
|
15
16
|
end
|
16
|
-
|
17
17
|
end
|
@@ -1,18 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SolidusSixSaferpay
|
2
4
|
module Generators
|
3
5
|
class InstallGenerator < Rails::Generators::Base
|
4
6
|
class_option :auto_run_migrations, type: :boolean, default: false
|
5
7
|
|
8
|
+
def add_javascripts
|
9
|
+
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_six_saferpay\n"
|
10
|
+
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_six_saferpay\n"
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_stylesheets
|
14
|
+
inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_six_saferpay\n", before: %r{\*/}, verbose: true
|
15
|
+
inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_six_saferpay\n", before: %r{\*/}, verbose: true
|
16
|
+
end
|
17
|
+
|
6
18
|
def add_migrations
|
7
|
-
run '
|
19
|
+
run 'bin/rails railties:install:migrations FROM=solidus_six_saferpay'
|
8
20
|
end
|
9
21
|
|
10
22
|
def run_migrations
|
11
23
|
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
|
12
24
|
if run_migrations
|
13
|
-
run '
|
25
|
+
run 'bin/rails db:migrate'
|
14
26
|
else
|
15
|
-
puts 'Skipping
|
27
|
+
puts 'Skipping bin/rails db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output
|
16
28
|
end
|
17
29
|
end
|
18
30
|
end
|
data/lib/solidus_six_saferpay.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
-
|
2
|
-
require "solidus_support"
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
require
|
3
|
+
require 'solidus_core'
|
4
|
+
require 'solidus_support'
|
5
5
|
require 'six_saferpay'
|
6
|
+
|
7
|
+
require 'solidus_six_saferpay/version'
|
8
|
+
require 'solidus_six_saferpay/engine'
|
@@ -1,12 +1,11 @@
|
|
1
1
|
module SolidusSixSaferpay
|
2
|
-
|
3
2
|
class Configuration
|
4
|
-
|
5
|
-
|
6
|
-
end
|
3
|
+
include ActiveSupport::Configurable
|
4
|
+
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
config_accessor(:payment_processing_order_not_found_handler)
|
7
|
+
config_accessor(:payment_processing_payment_not_found_handler)
|
8
|
+
config_accessor(:payment_processing_success_handler)
|
9
|
+
config_accessor(:error_handlers) { [] }
|
11
10
|
end
|
12
11
|
end
|
@@ -1,6 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spree/core'
|
1
4
|
module SolidusSixSaferpay
|
2
|
-
|
3
|
-
|
5
|
+
|
6
|
+
def self.config
|
7
|
+
@config ||= Configuration.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configure
|
11
|
+
yield config
|
12
|
+
end
|
13
|
+
|
14
|
+
class Engine < Rails::Engine
|
15
|
+
include SolidusSupport::EngineExtensions::Decorators
|
16
|
+
|
17
|
+
isolate_namespace ::Spree
|
18
|
+
|
19
|
+
engine_name 'solidus_six_saferpay'
|
4
20
|
|
5
21
|
config.autoload_paths += Dir["#{config.root}/lib/**/"]
|
6
22
|
config.eager_load_paths += Dir["#{config.root}/lib/**/"]
|
@@ -10,16 +26,9 @@ module SolidusSixSaferpay
|
|
10
26
|
app.config.spree.payment_methods << Spree::PaymentMethod::SaferpayTransaction
|
11
27
|
end
|
12
28
|
|
13
|
-
|
14
|
-
app.config.assets.precompile += %w( solidus_six_saferpay/application.css )
|
15
|
-
app.config.assets.precompile += %w( solidus_six_saferpay/saferpay_payment.js )
|
16
|
-
app.config.assets.precompile += %w( solidus_six_saferpay/credit_cards/**/*.png )
|
17
|
-
end
|
18
|
-
|
29
|
+
# use rspec for tests
|
19
30
|
config.generators do |g|
|
20
31
|
g.test_framework :rspec
|
21
|
-
g.fixture_replacement :factory_bot
|
22
|
-
g.factory_bot dir: 'spec/factories'
|
23
32
|
end
|
24
33
|
end
|
25
34
|
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') }
|
@@ -43,7 +40,7 @@ module SolidusSixSaferpay
|
|
43
40
|
capture(amount, saferpay_payment.transaction_id, options)
|
44
41
|
end
|
45
42
|
|
46
|
-
def capture(
|
43
|
+
def capture(_amount, transaction_id, options={})
|
47
44
|
transaction_reference = SixSaferpay::TransactionReference.new(transaction_id: transaction_id)
|
48
45
|
payment_capture = SixSaferpay::SixTransaction::Capture.new(transaction_reference: transaction_reference)
|
49
46
|
|
@@ -82,15 +79,14 @@ module SolidusSixSaferpay
|
|
82
79
|
end
|
83
80
|
|
84
81
|
# aliased to #refund for compatibility with solidus internals
|
85
|
-
def credit(
|
86
|
-
refund(
|
82
|
+
def credit(amount_cents, transaction_id, options = {})
|
83
|
+
refund(amount_cents, transaction_id, options)
|
87
84
|
end
|
88
85
|
|
89
|
-
def refund(
|
86
|
+
def refund(amount_cents, transaction_id, options = {})
|
90
87
|
payment = Spree::Payment.find_by!(response_code: transaction_id)
|
91
|
-
refund_amount = Spree::Money.new(amount, currency: payment.currency)
|
92
88
|
|
93
|
-
saferpay_amount = SixSaferpay::Amount.new(value:
|
89
|
+
saferpay_amount = SixSaferpay::Amount.new(value: amount_cents, currency_code: payment.currency)
|
94
90
|
saferpay_refund = SixSaferpay::Refund.new(amount: saferpay_amount, order_id: payment.order.number)
|
95
91
|
capture_reference = SixSaferpay::CaptureReference.new(capture_id: payment.transaction_id)
|
96
92
|
|
@@ -99,7 +95,7 @@ module SolidusSixSaferpay
|
|
99
95
|
if refund_response = SixSaferpay::Client.post(payment_refund)
|
100
96
|
|
101
97
|
# actually capture the refund
|
102
|
-
capture(
|
98
|
+
capture(amount_cents, refund_response.transaction.id, options)
|
103
99
|
end
|
104
100
|
|
105
101
|
rescue SixSaferpay::Error => e
|
@@ -156,7 +152,7 @@ module SolidusSixSaferpay
|
|
156
152
|
)
|
157
153
|
payer = SixSaferpay::Payer.new(language_code: I18n.locale, billing_address: billing_address, delivery_address: delivery_address)
|
158
154
|
|
159
|
-
params = { payment: payment, payer: payer }
|
155
|
+
params = { payment: payment, payer: payer, return_urls: return_urls(order) }
|
160
156
|
|
161
157
|
six_payment_methods = payment_method.enabled_payment_methods
|
162
158
|
params.merge!(payment_methods: six_payment_methods) unless six_payment_methods.blank?
|
@@ -164,6 +160,10 @@ module SolidusSixSaferpay
|
|
164
160
|
params
|
165
161
|
end
|
166
162
|
|
163
|
+
def return_urls(order)
|
164
|
+
raise NotImplementedError, "Must be implemented in PaymentPageGateway or TransactionGateway"
|
165
|
+
end
|
166
|
+
|
167
167
|
def response(success, message, api_response, options = {})
|
168
168
|
GatewayResponse.new(success, message, api_response, options)
|
169
169
|
end
|