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.
Files changed (85) 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/solidus_six_saferpay/saferpay_payment.js +4 -1
  16. data/app/assets/javascripts/spree/backend/solidus_six_saferpay.js +2 -0
  17. data/app/assets/javascripts/spree/frontend/solidus_six_saferpay.js +2 -0
  18. data/app/assets/stylesheets/spree/backend/solidus_six_saferpay.css +4 -0
  19. data/app/assets/stylesheets/spree/frontend/solidus_six_saferpay.css +4 -0
  20. data/app/controllers/spree/solidus_six_saferpay/checkout_controller.rb +133 -17
  21. data/app/controllers/spree/solidus_six_saferpay/transaction/checkout_controller.rb +1 -1
  22. data/app/models/spree/payment_method/saferpay_payment_method.rb +1 -1
  23. data/app/models/spree/payment_method/saferpay_payment_page.rb +2 -2
  24. data/app/models/spree/payment_method/saferpay_transaction.rb +2 -2
  25. data/app/services/spree/solidus_six_saferpay/cancel_authorized_payment.rb +33 -0
  26. data/app/services/spree/solidus_six_saferpay/initialize_payment.rb +0 -1
  27. data/app/services/spree/solidus_six_saferpay/initialize_transaction.rb +0 -1
  28. data/app/services/spree/solidus_six_saferpay/inquire_payment.rb +27 -1
  29. data/app/views/spree/checkout/payment/_saferpay_payment.html.erb +2 -2
  30. data/app/views/spree/solidus_six_saferpay/checkout/{iframe_breakout_redirect.html.erb → iframe_breakout_redirect.erb} +1 -1
  31. data/bin/console +17 -0
  32. data/bin/rails +18 -0
  33. data/bin/rake +7 -0
  34. data/bin/setup +8 -0
  35. data/config/initializers/assets.rb +3 -0
  36. data/config/locales/de.yml +4 -1
  37. data/config/locales/en.yml +4 -1
  38. data/config/locales/fr.yml +4 -1
  39. data/config/routes.rb +8 -8
  40. data/lib/generators/solidus_six_saferpay/install/install_generator.rb +15 -3
  41. data/lib/solidus_six_saferpay.rb +6 -3
  42. data/lib/solidus_six_saferpay/configuration.rb +6 -7
  43. data/lib/solidus_six_saferpay/engine.rb +19 -10
  44. data/lib/solidus_six_saferpay/gateway.rb +11 -11
  45. data/lib/solidus_six_saferpay/payment_page_gateway.rb +8 -9
  46. data/lib/solidus_six_saferpay/transaction_gateway.rb +8 -9
  47. data/lib/solidus_six_saferpay/version.rb +3 -1
  48. data/solidus_six_saferpay.gemspec +42 -0
  49. data/spec/controllers/spree/solidus_six_saferpay/payment_page/checkout_controller_spec.rb +16 -0
  50. data/spec/controllers/spree/solidus_six_saferpay/transaction/checkout_controller_spec.rb +16 -0
  51. data/spec/factories/payment_methods.rb +23 -0
  52. data/spec/factories/payments.rb +11 -0
  53. data/spec/factories/spree/six_saferpay_payments.rb +118 -0
  54. data/spec/models/spree/six_saferpay_payment_spec.rb +203 -0
  55. data/spec/rails_helper.rb +73 -0
  56. data/spec/services/spree/solidus_six_saferpay/assert_payment_page_spec.rb +22 -0
  57. data/spec/services/spree/solidus_six_saferpay/authorize_payment_spec.rb +39 -0
  58. data/spec/services/spree/solidus_six_saferpay/authorize_transaction_spec.rb +24 -0
  59. data/spec/services/spree/solidus_six_saferpay/cancel_authorized_payment_spec.rb +58 -0
  60. data/spec/services/spree/solidus_six_saferpay/initialize_payment_page_spec.rb +81 -0
  61. data/spec/services/spree/solidus_six_saferpay/initialize_payment_spec.rb +40 -0
  62. data/spec/services/spree/solidus_six_saferpay/initialize_transaction_spec.rb +84 -0
  63. data/spec/services/spree/solidus_six_saferpay/inquire_payment_page_payment_spec.rb +20 -0
  64. data/spec/services/spree/solidus_six_saferpay/inquire_payment_spec.rb +39 -0
  65. data/spec/services/spree/solidus_six_saferpay/inquire_transaction_payment_spec.rb +21 -0
  66. data/spec/services/spree/solidus_six_saferpay/payment_validator_spec.rb +100 -0
  67. data/spec/services/spree/solidus_six_saferpay/process_authorized_payment_spec.rb +39 -0
  68. data/spec/services/spree/solidus_six_saferpay/process_payment_page_payment_spec.rb +20 -0
  69. data/spec/services/spree/solidus_six_saferpay/process_transaction_payment_spec.rb +20 -0
  70. data/spec/solidus_six_saferpay/configuration_spec.rb +15 -0
  71. data/spec/solidus_six_saferpay/error_handler_spec.rb +65 -0
  72. data/spec/solidus_six_saferpay/gateway_response_spec.rb +70 -0
  73. data/spec/solidus_six_saferpay/gateway_spec.rb +365 -0
  74. data/spec/solidus_six_saferpay/payment_page_gateway_spec.rb +392 -0
  75. data/spec/solidus_six_saferpay/transaction_gateway_spec.rb +390 -0
  76. data/spec/spec_helper.rb +21 -0
  77. data/spec/support/route_access.rb +6 -0
  78. data/spec/support/shared_examples/authorize_payment.rb +132 -0
  79. data/spec/support/shared_examples/checkout_controller.rb +342 -0
  80. data/spec/support/shared_examples/inquire_payment.rb +118 -0
  81. data/spec/support/shared_examples/process_authorized_payment.rb +202 -0
  82. data/spec/support/uses_payment_page_gateway.rb +29 -0
  83. data/spec/support/uses_transaction_gateway.rb +28 -0
  84. metadata +250 -101
  85. 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
@@ -39,7 +39,7 @@ module Spree
39
39
  'saferpay_payment'
40
40
  end
41
41
 
42
- def init_path
42
+ def init_path(order)
43
43
  raise NotImplementedError, "Must be implemented in SaferpayPaymentPage or SaferpayTransaction"
44
44
  end
45
45
  end
@@ -6,8 +6,8 @@ module Spree
6
6
  ::SolidusSixSaferpay::PaymentPageGateway
7
7
  end
8
8
 
9
- def init_path
10
- url_helpers.solidus_six_saferpay_payment_page_init_path
9
+ def init_path(order)
10
+ url_helpers.solidus_six_saferpay_payment_page_init_path(order.number)
11
11
  end
12
12
  end
13
13
  end
@@ -5,8 +5,8 @@ module Spree
5
5
  ::SolidusSixSaferpay::TransactionGateway
6
6
  end
7
7
 
8
- def init_path
9
- url_helpers.solidus_six_saferpay_transaction_init_path
8
+ def init_path(order)
9
+ url_helpers.solidus_six_saferpay_transaction_init_path(order.number)
10
10
  end
11
11
  end
12
12
  end
@@ -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
@@ -1,6 +1,5 @@
1
1
  module Spree
2
2
  module SolidusSixSaferpay
3
-
4
3
  class InitializePayment
5
4
 
6
5
  attr_reader :order, :payment_method, :redirect_url, :success
@@ -1,6 +1,5 @@
1
1
  module Spree
2
2
  module SolidusSixSaferpay
3
-
4
3
  class InitializeTransaction < InitializePayment
5
4
  include UseTransactionGateway
6
5
 
@@ -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(response_hash: inquiry.api_response.to_h)
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 %>
@@ -1,7 +1,7 @@
1
1
  <html>
2
2
  <body>
3
3
  <script type='text/javascript' charset='utf-8'>
4
- window.parent.document.location.href = "<%= @redirect_path %>"
4
+ window.parent.document.location.replace("<%= @redirect_path %>");
5
5
  </script>
6
6
  </body>
7
7
  </html>
@@ -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__)
@@ -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
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "rubygems"
5
+ require "bundler/setup"
6
+
7
+ load Gem.bin_path("rake", "rake")
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ gem install bundler --conservative
7
+ bundle update
8
+ bin/rake clobber
@@ -0,0 +1,3 @@
1
+ if Rails.application.config.respond_to?(:assets)
2
+ Rails.application.config.assets.precompile << 'solidus_six_saferpay_manifest.js'
3
+ end
@@ -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
- payment_source_not_created: Six Saferpay Zahlungsquelle konnte nicht erstellt werden.
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.
@@ -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
- payment_source_not_created: Six Saferpay payment source could not be created.
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.
@@ -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
- payment_source_not_created: La source de paiement Six Saferpay n'a pas pu être créée.
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.
@@ -1,17 +1,17 @@
1
- Spree::Core::Engine.routes.draw do
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, controller: :checkout, defaults: { format: :json }
6
- get :success, controller: :checkout
7
- get :fail, controller: :checkout
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, controller: :checkout, defaults: { format: :json }
12
- get :success, controller: :checkout
13
- get :fail, controller: :checkout
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 'bundle exec rake railties:install:migrations FROM=solidus_six_saferpay'
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 'bundle exec rake db:migrate'
25
+ run 'bin/rails db:migrate'
14
26
  else
15
- puts 'Skipping rake db:migrate, don\'t forget to run it!'
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
@@ -1,5 +1,8 @@
1
- require 'solidus_core'
2
- require "solidus_support"
1
+ # frozen_string_literal: true
3
2
 
4
- require "solidus_six_saferpay/engine"
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
- def self.config
5
- yield(self)
6
- end
3
+ include ActiveSupport::Configurable
4
+
7
5
 
8
- def self.error_handlers
9
- @error_handlers ||= []
10
- end
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
- class Engine < ::Rails::Engine
3
- isolate_namespace SolidusSixSaferpay
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
- initializer "solidus_six_payments.assets.precompile" do |app|
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(amount, transaction_id, options={})
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(amount, transaction_id, options = {})
86
- refund(amount, transaction_id, options)
82
+ def credit(amount_cents, transaction_id, options = {})
83
+ refund(amount_cents, transaction_id, options)
87
84
  end
88
85
 
89
- def refund(amount, transaction_id, options = {})
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: refund_amount.cents, currency_code: payment.currency)
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(amount, refund_response.transaction.id, options)
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