solidus_six_saferpay 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +220 -0
- data/Rakefile +56 -0
- data/app/assets/config/solidus_six_saferpay_manifest.js +2 -0
- data/app/assets/images/solidus_six_saferpay/credit_cards/icons/amex.png +0 -0
- data/app/assets/images/solidus_six_saferpay/credit_cards/icons/cirrus.png +0 -0
- data/app/assets/images/solidus_six_saferpay/credit_cards/icons/delta.png +0 -0
- data/app/assets/images/solidus_six_saferpay/credit_cards/icons/diners_club.png +0 -0
- data/app/assets/images/solidus_six_saferpay/credit_cards/icons/directdebit.png +0 -0
- data/app/assets/images/solidus_six_saferpay/credit_cards/icons/discover.png +0 -0
- data/app/assets/images/solidus_six_saferpay/credit_cards/icons/egold.png +0 -0
- data/app/assets/images/solidus_six_saferpay/credit_cards/icons/maestro.png +0 -0
- data/app/assets/images/solidus_six_saferpay/credit_cards/icons/mastercard.png +0 -0
- data/app/assets/images/solidus_six_saferpay/credit_cards/icons/paypal.png +0 -0
- data/app/assets/images/solidus_six_saferpay/credit_cards/icons/solo.png +0 -0
- data/app/assets/images/solidus_six_saferpay/credit_cards/icons/switch.png +0 -0
- data/app/assets/images/solidus_six_saferpay/credit_cards/icons/twint.png +0 -0
- data/app/assets/images/solidus_six_saferpay/credit_cards/icons/visa.png +0 -0
- data/app/assets/images/solidus_six_saferpay/credit_cards/icons/visaelectron.png +0 -0
- data/app/assets/images/solidus_six_saferpay/credit_cards/icons/westernunion.png +0 -0
- data/app/assets/images/solidus_six_saferpay/credit_cards/icons/wirecard.png +0 -0
- data/app/assets/images/solidus_six_saferpay/credit_cards/icons/worldpay.png +0 -0
- data/app/assets/javascripts/solidus_six_saferpay/application.js +14 -0
- data/app/assets/javascripts/solidus_six_saferpay/saferpay_payment.js +120 -0
- data/app/assets/stylesheets/solidus_six_saferpay/application.css +15 -0
- data/app/assets/stylesheets/solidus_six_saferpay/loading_animation.scss +30 -0
- data/app/assets/stylesheets/solidus_six_saferpay/payments.scss +10 -0
- data/app/controllers/solidus_six_saferpay/application_controller.rb +5 -0
- data/app/controllers/spree/solidus_six_saferpay/checkout_controller.rb +93 -0
- data/app/controllers/spree/solidus_six_saferpay/payment_page/checkout_controller.rb +27 -0
- data/app/controllers/spree/solidus_six_saferpay/transaction/checkout_controller.rb +27 -0
- data/app/helpers/solidus_six_saferpay/application_helper.rb +4 -0
- data/app/jobs/solidus_six_saferpay/application_job.rb +4 -0
- data/app/mailers/solidus_six_saferpay/application_mailer.rb +6 -0
- data/app/models/solidus_six_saferpay/application_record.rb +5 -0
- data/app/models/spree/payment_method/saferpay_payment_method.rb +46 -0
- data/app/models/spree/payment_method/saferpay_payment_page.rb +13 -0
- data/app/models/spree/payment_method/saferpay_transaction.rb +12 -0
- data/app/models/spree/six_saferpay_payment.rb +69 -0
- data/app/services/spree/route_access.rb +5 -0
- data/app/services/spree/solidus_six_saferpay/assert_payment_page.rb +8 -0
- data/app/services/spree/solidus_six_saferpay/authorize_payment.rb +60 -0
- data/app/services/spree/solidus_six_saferpay/authorize_transaction.rb +8 -0
- data/app/services/spree/solidus_six_saferpay/initialize_payment.rb +57 -0
- data/app/services/spree/solidus_six_saferpay/initialize_payment_page.rb +15 -0
- data/app/services/spree/solidus_six_saferpay/initialize_transaction.rb +16 -0
- data/app/services/spree/solidus_six_saferpay/inquire_payment.rb +43 -0
- data/app/services/spree/solidus_six_saferpay/inquire_payment_page_payment.rb +7 -0
- data/app/services/spree/solidus_six_saferpay/inquire_transaction.rb +7 -0
- data/app/services/spree/solidus_six_saferpay/inquire_transaction_payment.rb +7 -0
- data/app/services/spree/solidus_six_saferpay/payment_validator.rb +62 -0
- data/app/services/spree/solidus_six_saferpay/process_authorized_payment.rb +87 -0
- data/app/services/spree/solidus_six_saferpay/process_payment_page_payment.rb +7 -0
- data/app/services/spree/solidus_six_saferpay/process_transaction_payment.rb +7 -0
- data/app/services/spree/solidus_six_saferpay/use_payment_page_gateway.rb +11 -0
- data/app/services/spree/solidus_six_saferpay/use_transaction_gateway.rb +11 -0
- data/app/views/spree/admin/payments/source_views/_saferpay_payment.erb +36 -0
- data/app/views/spree/api/payments/source_views/_saferpay_payment.json.jbuilder +1 -0
- data/app/views/spree/checkout/payment/_saferpay_payment.html.erb +12 -0
- data/app/views/spree/six_saferpay_payments/_six_saferpay_payment.html.erb +16 -0
- data/app/views/spree/solidus_six_saferpay/checkout/iframe_breakout_redirect.html.erb +7 -0
- data/config/locales/de.yml +52 -0
- data/config/locales/en.yml +52 -0
- data/config/locales/fr.yml +51 -0
- data/config/routes.rb +17 -0
- data/db/migrate/20190523075638_create_six_saferpay_payments.rb +31 -0
- data/lib/generators/solidus_six_saferpay/install/install_generator.rb +20 -0
- data/lib/solidus_six_saferpay.rb +5 -0
- data/lib/solidus_six_saferpay/configuration.rb +12 -0
- data/lib/solidus_six_saferpay/engine.rb +25 -0
- data/lib/solidus_six_saferpay/error_handler.rb +21 -0
- data/lib/solidus_six_saferpay/gateway.rb +183 -0
- data/lib/solidus_six_saferpay/gateway_response.rb +38 -0
- data/lib/solidus_six_saferpay/invalid_saferpay_payment.rb +11 -0
- data/lib/solidus_six_saferpay/payment_page_gateway.rb +55 -0
- data/lib/solidus_six_saferpay/transaction_gateway.rb +47 -0
- data/lib/solidus_six_saferpay/version.rb +3 -0
- data/lib/tasks/solidus_six_saferpay_tasks.rake +4 -0
- metadata +319 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
---
|
2
|
+
de:
|
3
|
+
spree:
|
4
|
+
solidus_six_saferpay:
|
5
|
+
checkout: &checkout
|
6
|
+
init:
|
7
|
+
checkout_not_initialized: Zahlung konnte nicht gestartet werden.
|
8
|
+
success:
|
9
|
+
payment_source_not_created: Six Saferpay Zahlungsquelle konnte nicht erstellt werden.
|
10
|
+
fail:
|
11
|
+
payment_failed: Die Zahlung konnte nicht abgeschlossen werden.
|
12
|
+
payment_page:
|
13
|
+
checkout:
|
14
|
+
<<: *checkout
|
15
|
+
transaction:
|
16
|
+
checkout:
|
17
|
+
<<: *checkout
|
18
|
+
solidus_six_saferpay:
|
19
|
+
errors:
|
20
|
+
general_error: Bezahlungsfehler
|
21
|
+
liability_shift_not_granted: Haftungsumkehr wurde abgelehnt
|
22
|
+
six_saferpay:
|
23
|
+
error_names:
|
24
|
+
ACTION_NOT_SUPPORTED: Die angeforderte Aktion wird im Kontext der Aktion nicht unterstützt un kann mit den Anforderungsdaten nicht ausgeführt werden.
|
25
|
+
ALIAS_INVALID: Der Alias ist nicht bekannt oder wird bereits verwendet (bei Registrierung).
|
26
|
+
AMOUNT_INVALID: Der Betrag entspricht nicht den Einschränkungen für diese Aktion.
|
27
|
+
AUTHENTICATION_FAILED: Falsches Password, falsches Client-Zertifikat, ungültiges Token, falscher HMAC.
|
28
|
+
BLOCKED_BY_RISK_MANAGEMENT: Aktion vom Risikomanagement gesperrt.
|
29
|
+
CARD_CHECK_FAILED: Ungültige Kartennummer oder CVC.
|
30
|
+
CARD_CVC_INVALID: Falscher CVC eingegeben.
|
31
|
+
CARD_CVC_REQUIRED: CVC nicht eingegeben, aber erforderlich.
|
32
|
+
CARD_EXPIRED: Karte abgelaufen.
|
33
|
+
COMMUNICATION_FAILED: Die Kommunikation zum Prozessor ist fehlgeschlagen.
|
34
|
+
COMMUNICATION_TIMEOUT: Saferpay hat nicht rechtzeitig eine Antwort vom externen System erhalten. Es ist möglich, dass eine Autorisierung erstellt wurde, aber Saferpay kann dies nicht wissen.
|
35
|
+
CONDITION_NOT_SATISFIED: Die in der Anfrage definierte Bedingung konnte nicht erfüllt werden.
|
36
|
+
CURRENCY_INVALID: Währung stimmt nicht mit der Währungstransaktion überein.
|
37
|
+
GENERAL_DECLINED: Transaktion aus einem unbekannten Grund abgelehnt.
|
38
|
+
INTERNAL_ERROR: Interner Fehler in Saferpay.
|
39
|
+
NO_CONTRACT: Für die Kombination aus Marke und Währung ist kein Vertrag verfügbar.
|
40
|
+
NO_CREDITS_AVAILABLE: Für dieses Konto ist kein Guthaben mehr verfügbar.
|
41
|
+
PAYMENTMEANS_INVALID: Ungültiges Zahlungsmittel (z. B. ungültige Karte).
|
42
|
+
PERMISSION_DENIED: Keine Berechtigung (z. B. Terminal gehört nicht dem Kunden).
|
43
|
+
3DS_AUTHENTICATION_FAILED: Die 3D-sichere Authentifizierung ist fehlgeschlagen - die Transaktion muss abgebrochen werden.
|
44
|
+
TOKEN_EXPIRED: Das Token ist abgelaufen.
|
45
|
+
TOKEN_INVALID: Das Token ist für diesen Kunden nicht vorhanden oder wird bereits verwendet.
|
46
|
+
TRANSACTION_ABORTED: Die Transaktion wurde von Kundin/Kunde abgebrochen.
|
47
|
+
TRANSACTION_ALREADY_CAPTURED: Transaktion bereits erfasst.
|
48
|
+
TRANSACTION_DECLINED: Vom Prozessor abgelehnt.
|
49
|
+
TRANSACTION_IN_WRONG_STATE: Transaktion befindet sich in falschem Zustand.
|
50
|
+
TRANSACTION_NOT_FOUND: Transaktion konnte nicht gefunden werden.
|
51
|
+
TRANSACTION_NOT_STARTED: Die Transaktion wurde noch nicht von der Bezahlung gestartet. Daher ist kein endgültiges Ergebnis für die Transaktion verfügbar.
|
52
|
+
VALIDATION_FAILED: Validierung fehlgeschlagen.
|
@@ -0,0 +1,52 @@
|
|
1
|
+
---
|
2
|
+
en:
|
3
|
+
spree:
|
4
|
+
solidus_six_saferpay:
|
5
|
+
checkout: &checkout
|
6
|
+
init:
|
7
|
+
checkout_not_initialized: Payment could not be initialized.
|
8
|
+
success:
|
9
|
+
payment_source_not_created: Six Saferpay payment source could not be created.
|
10
|
+
fail:
|
11
|
+
payment_failed: The payment could not be completed.
|
12
|
+
payment_page:
|
13
|
+
checkout:
|
14
|
+
<<: *checkout
|
15
|
+
transaction:
|
16
|
+
checkout:
|
17
|
+
<<: *checkout
|
18
|
+
solidus_six_saferpay:
|
19
|
+
errors:
|
20
|
+
general_error: Payment Error
|
21
|
+
liability_shift_not_granted: Liability Shift was rejected
|
22
|
+
six_saferpay:
|
23
|
+
error_names:
|
24
|
+
ACTION_NOT_SUPPORTED: The requested action is not supported in the given context or the action can't be executed with the request data.
|
25
|
+
ALIAS_INVALID: The alias is not known or already used (in case of registration).
|
26
|
+
AMOUNT_INVALID: The amount does not adhere to the restrictions for this action.
|
27
|
+
AUTHENTICATION_FAILED: Wrong password, wrong client certificate, invalid token, wrong HMAC.
|
28
|
+
BLOCKED_BY_RISK_MANAGEMENT: Action blocked by risk management.
|
29
|
+
CARD_CHECK_FAILED: Invalid card number or cvc.
|
30
|
+
CARD_CVC_INVALID: Wrong cvc entered.
|
31
|
+
CARD_CVC_REQUIRED: Cvc not entered but required.
|
32
|
+
CARD_EXPIRED: Card expired.
|
33
|
+
COMMUNICATION_FAILED: The communication to the processor failed.
|
34
|
+
COMMUNICATION_TIMEOUT: Saferpay did not receive a response from the external system in time. It’s possible that an authorization was created, but Saferpay is not able to know this.
|
35
|
+
CONDITION_NOT_SATISFIED: The condition which was defined in the request could not be satisfied.
|
36
|
+
CURRENCY_INVALID: Currency does not match referenced transaction currency.
|
37
|
+
GENERAL_DECLINED: Transaction declined by unknown reason.
|
38
|
+
INTERNAL_ERROR: Internal error in Saferpay.
|
39
|
+
NO_CONTRACT: No contract available for the brand / currency combination.
|
40
|
+
NO_CREDITS_AVAILABLE: No more credits available for this account.
|
41
|
+
PAYMENTMEANS_INVALID: Invalid means of payment (e.g. invalid card).
|
42
|
+
PERMISSION_DENIED: No permission (e.g. terminal does not belong to the customer).
|
43
|
+
3DS_AUTHENTICATION_FAILED: 3D-secure authentication failed – the transaction must be aborted.
|
44
|
+
TOKEN_EXPIRED: The token is expired.
|
45
|
+
TOKEN_INVALID: The token either does not exist for this customer or was already used.
|
46
|
+
TRANSACTION_ABORTED: The transaction was aborted by the payer.
|
47
|
+
TRANSACTION_ALREADY_CAPTURED: Transaction already captured.
|
48
|
+
TRANSACTION_DECLINED: Declined by the processor.
|
49
|
+
TRANSACTION_IN_WRONG_STATE: Transaction is in the wrong state.
|
50
|
+
TRANSACTION_NOT_FOUND: Transaction could not be found.
|
51
|
+
TRANSACTION_NOT_STARTED: The transaction was not started by the payer. Therefore, no final result for the transaction is available.
|
52
|
+
VALIDATION_FAILED: Validation failed.
|
@@ -0,0 +1,51 @@
|
|
1
|
+
---
|
2
|
+
fr:
|
3
|
+
spree:
|
4
|
+
solidus_six_saferpay:
|
5
|
+
checkout: &checkout
|
6
|
+
init:
|
7
|
+
checkout_not_initialized: Le paiement n'a pas pu être initialisé.
|
8
|
+
success:
|
9
|
+
payment_source_not_created: La source de paiement Six Saferpay n'a pas pu être créée.
|
10
|
+
fail:
|
11
|
+
payment_failed: Le paiement n'a pas pu être complété.
|
12
|
+
payment_page:
|
13
|
+
checkout:
|
14
|
+
<<: *checkout
|
15
|
+
transaction:
|
16
|
+
checkout:
|
17
|
+
<<: *checkout
|
18
|
+
solidus_six_saferpay:
|
19
|
+
errors:
|
20
|
+
liability_shift_not_granted: Le transfert de responsabilité a été rejeté
|
21
|
+
six_saferpay:
|
22
|
+
error_names:
|
23
|
+
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.
|
24
|
+
ALIAS_INVALID: l'alias es inconnu ou est déjà utilisé (à l'enregistrement).
|
25
|
+
AMOUNT_INVALID: le mentant ne correspond pas aux restrictions pour cette action.
|
26
|
+
AUTHENTICATION_FAILED: Mot de passe incorrect, certificat client incorrect, jeton non valide, HMAC incorrect.
|
27
|
+
BLOCKED_BY_RISK_MANAGEMENT: action bloquée par la gestion des risques.
|
28
|
+
CARD_CHECK_FAILED: Numéro de carte ou CVC non valide.
|
29
|
+
CARD_CVC_INVALID: CVC incorrect entré.
|
30
|
+
CARD_CVC_REQUIRED: CVC non entré, mais obligatoire.
|
31
|
+
CARD_EXPIRED: La carte a expiré.
|
32
|
+
COMMUNICATION_FAILED: la communication avec le processeur a échoué.
|
33
|
+
COMMUNICATION_TIMEOUT: Saferpay n'a pas reçu de réponse du système externe à temps. Il est possible qu'une autorisation ait été créée, mais Saferpay ne peut pas le savoir.
|
34
|
+
CONDITION_NOT_SATISFIED: la condition définie dans la demande n'a pas pu être remplie.
|
35
|
+
CURRENCY_INVALID: la devise ne correspond pas à la transaction de devise.
|
36
|
+
GENERAL_DECLINED: transaction rejetée pour une raison inconnue.
|
37
|
+
INTERNAL_ERROR: erreur interne dans Saferpay.
|
38
|
+
NO_CONTRACT: Il n'y a pas de contrat pour la combinaison marque / devise.
|
39
|
+
NO_CREDITS_AVAILABLE: plus aucun crédit disponible pour ce compte.
|
40
|
+
PAYMENTMEANS_INVALID: Offre non valide (par exemple, carte invalide).
|
41
|
+
PERMISSION_DENIED: Aucune autorisation (par exemple, le terminal n'est pas la propriété du client).
|
42
|
+
3DS_AUTHENTICATION_FAILED: L'authentification 3D Secure a échoué - la transaction doit être abandonnée.
|
43
|
+
TOKEN_EXPIRED: le jeton a expiré.
|
44
|
+
TOKEN_INVALID: le jeton n'existe pas pour ce client ou est déjà utilisé.
|
45
|
+
TRANSACTION_ABORTED: La transaction a été annulée par le paiement.
|
46
|
+
TRANSACTION_ALREADY_CAPTURED: transaction déjà enregistrée.
|
47
|
+
TRANSACTION_DECLINED: rejeté par le processeur.
|
48
|
+
TRANSACTION_IN_WRONG_STATE: La transaction est dans un état incorrect.
|
49
|
+
TRANSACTION_NOT_FOUND: La transaction n'a pas pu être trouvée.
|
50
|
+
TRANSACTION_NOT_STARTED: La transaction n'a pas encore été lancée depuis le paiement. Par conséquent, aucun résultat final n'est disponible pour la transaction.
|
51
|
+
VALIDATION_FAILED: la validation a échoué.
|
data/config/routes.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Spree::Core::Engine.routes.draw do
|
2
|
+
|
3
|
+
namespace :solidus_six_saferpay do
|
4
|
+
namespace :payment_page do
|
5
|
+
get :init, controller: :checkout, defaults: { format: :json }
|
6
|
+
get :success, controller: :checkout
|
7
|
+
get :fail, controller: :checkout
|
8
|
+
end
|
9
|
+
|
10
|
+
namespace :transaction do
|
11
|
+
get :init, controller: :checkout, defaults: { format: :json }
|
12
|
+
get :success, controller: :checkout
|
13
|
+
get :fail, controller: :checkout
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class CreateSixSaferpayPayments < ActiveRecord::Migration[5.1]
|
2
|
+
def change
|
3
|
+
create_table :spree_six_saferpay_payments do |t|
|
4
|
+
t.references :order
|
5
|
+
t.references :payment_method
|
6
|
+
|
7
|
+
t.string :token
|
8
|
+
t.datetime :expiration
|
9
|
+
t.string :redirect_url
|
10
|
+
t.string :transaction_id
|
11
|
+
t.string :transaction_status
|
12
|
+
t.datetime :transaction_date
|
13
|
+
t.string :six_transaction_reference
|
14
|
+
t.string :display_text
|
15
|
+
t.string :masked_number
|
16
|
+
t.string :expiration_year
|
17
|
+
t.string :expiration_month
|
18
|
+
t.text :response_hash
|
19
|
+
|
20
|
+
t.timestamps
|
21
|
+
end
|
22
|
+
|
23
|
+
add_index :spree_six_saferpay_payments, :token, unique: true
|
24
|
+
add_index :spree_six_saferpay_payments, :transaction_id, unique: true
|
25
|
+
add_index :spree_six_saferpay_payments, :six_transaction_reference, unique: true
|
26
|
+
|
27
|
+
# hack around foreign_key restriction by manually defining them
|
28
|
+
add_foreign_key :spree_six_saferpay_payments, :spree_orders, column: :order_id
|
29
|
+
add_foreign_key :spree_six_saferpay_payments, :spree_payment_methods, column: :payment_method_id
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module SolidusSixSaferpay
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
class_option :auto_run_migrations, type: :boolean, default: false
|
5
|
+
|
6
|
+
def add_migrations
|
7
|
+
run 'bundle exec rake railties:install:migrations FROM=solidus_six_saferpay'
|
8
|
+
end
|
9
|
+
|
10
|
+
def run_migrations
|
11
|
+
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
|
12
|
+
if run_migrations
|
13
|
+
run 'bundle exec rake db:migrate'
|
14
|
+
else
|
15
|
+
puts 'Skipping rake db:migrate, don\'t forget to run it!'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module SolidusSixSaferpay
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace SolidusSixSaferpay
|
4
|
+
|
5
|
+
config.autoload_paths += Dir["#{config.root}/lib/**/"]
|
6
|
+
config.eager_load_paths += Dir["#{config.root}/lib/**/"]
|
7
|
+
|
8
|
+
initializer "spree.six_payment.payment_methods", :after => "spree.register.payment_methods" do |app|
|
9
|
+
app.config.spree.payment_methods << Spree::PaymentMethod::SaferpayPaymentPage
|
10
|
+
app.config.spree.payment_methods << Spree::PaymentMethod::SaferpayTransaction
|
11
|
+
end
|
12
|
+
|
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
|
+
|
19
|
+
config.generators do |g|
|
20
|
+
g.test_framework :rspec
|
21
|
+
g.fixture_replacement :factory_bot
|
22
|
+
g.factory_bot dir: 'spec/factories'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module SolidusSixSaferpay
|
2
|
+
|
3
|
+
class ErrorHandler
|
4
|
+
# Use a custom error handler so that host applications can configure their
|
5
|
+
# error handling
|
6
|
+
def self.handle(error, level: :error)
|
7
|
+
Rails.logger.send(level, error)
|
8
|
+
|
9
|
+
Configuration.error_handlers.each do |handler|
|
10
|
+
if !handler.respond_to?(:call)
|
11
|
+
Rails.logger.warn("SolidusSixSaferpay::Configuration ERROR: The attached error handler #{handler} can not be called with #{handler}.call(error, level: level)")
|
12
|
+
|
13
|
+
# skip to next handler
|
14
|
+
next
|
15
|
+
end
|
16
|
+
handler.call(error, level: level)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,183 @@
|
|
1
|
+
module SolidusSixSaferpay
|
2
|
+
class Gateway
|
3
|
+
|
4
|
+
include Spree::RouteAccess
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
SixSaferpay.configure do |config|
|
8
|
+
config.success_url = options.fetch(:success_url)
|
9
|
+
config.fail_url = options.fetch(:fail_url)
|
10
|
+
|
11
|
+
# Allow config via ENV for static values
|
12
|
+
config.customer_id = options.fetch(:customer_id) { ENV.fetch('SIX_SAFERPAY_CUSTOMER_ID') }
|
13
|
+
config.terminal_id = options.fetch(:terminal_id) { ENV.fetch('SIX_SAFERPAY_TERMINAL_ID') }
|
14
|
+
config.username = options.fetch(:username) { ENV.fetch('SIX_SAFERPAY_USERNAME') }
|
15
|
+
config.password = options.fetch(:password) { ENV.fetch('SIX_SAFERPAY_PASSWORD') }
|
16
|
+
config.base_url = options.fetch(:base_url) { ENV.fetch('SIX_SAFERPAY_BASE_URL') }
|
17
|
+
config.css_url = options.fetch(:css_url) { ENV.fetch('SIX_SAFERPAY_CSS_URL') }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize_payment(order, payment_method)
|
22
|
+
initialize_response = SixSaferpay::Client.post(
|
23
|
+
interface_initialize_object(order, payment_method)
|
24
|
+
)
|
25
|
+
response(
|
26
|
+
true,
|
27
|
+
"Saferpay Initialize Checkout response: #{initialize_response.to_h}",
|
28
|
+
initialize_response,
|
29
|
+
)
|
30
|
+
rescue SixSaferpay::Error => e
|
31
|
+
handle_error(e, initialize_response)
|
32
|
+
end
|
33
|
+
|
34
|
+
def authorize(amount, saferpay_payment, options = {})
|
35
|
+
raise NotImplementedError, "must be implemented in PaymentPageGateway or TransactionGateway"
|
36
|
+
end
|
37
|
+
|
38
|
+
def inquire(saferpay_payment, options = {})
|
39
|
+
raise NotImplementedError, "must be implemented in PaymentPageGateway or TransactionGateway"
|
40
|
+
end
|
41
|
+
|
42
|
+
def purchase(amount, saferpay_payment, options = {})
|
43
|
+
capture(amount, saferpay_payment.transaction_id, options)
|
44
|
+
end
|
45
|
+
|
46
|
+
def capture(amount, transaction_id, options={})
|
47
|
+
transaction_reference = SixSaferpay::TransactionReference.new(transaction_id: transaction_id)
|
48
|
+
payment_capture = SixSaferpay::SixTransaction::Capture.new(transaction_reference: transaction_reference)
|
49
|
+
|
50
|
+
capture_response = SixSaferpay::Client.post(payment_capture)
|
51
|
+
|
52
|
+
response(
|
53
|
+
true,
|
54
|
+
"Saferpay Payment Capture response: #{capture_response.to_h}",
|
55
|
+
capture_response,
|
56
|
+
{ authorization: capture_response.capture_id }
|
57
|
+
)
|
58
|
+
|
59
|
+
rescue SixSaferpay::Error => e
|
60
|
+
handle_error(e, capture_response)
|
61
|
+
end
|
62
|
+
|
63
|
+
def void(transaction_id, options = {})
|
64
|
+
transaction_reference = SixSaferpay::TransactionReference.new(transaction_id: transaction_id)
|
65
|
+
payment_cancel = SixSaferpay::SixTransaction::Cancel.new(transaction_reference: transaction_reference)
|
66
|
+
|
67
|
+
cancel_response = SixSaferpay::Client.post(payment_cancel)
|
68
|
+
|
69
|
+
response(
|
70
|
+
true,
|
71
|
+
"Saferpay Payment Cancel response: #{cancel_response.to_h}",
|
72
|
+
cancel_response
|
73
|
+
)
|
74
|
+
rescue SixSaferpay::Error => e
|
75
|
+
handle_error(e, cancel_response)
|
76
|
+
end
|
77
|
+
|
78
|
+
def try_void(payment)
|
79
|
+
if payment.checkout? && payment.transaction_id
|
80
|
+
void(payment.transaction_id, originator: self)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# aliased to #refund for compatibility with solidus internals
|
85
|
+
def credit(amount, transaction_id, options = {})
|
86
|
+
refund(amount, transaction_id, options)
|
87
|
+
end
|
88
|
+
|
89
|
+
def refund(amount, transaction_id, options = {})
|
90
|
+
payment = Spree::Payment.find_by!(response_code: transaction_id)
|
91
|
+
refund_amount = Spree::Money.new(amount, currency: payment.currency)
|
92
|
+
|
93
|
+
saferpay_amount = SixSaferpay::Amount.new(value: refund_amount.cents, currency_code: payment.currency)
|
94
|
+
saferpay_refund = SixSaferpay::Refund.new(amount: saferpay_amount, order_id: payment.order.number)
|
95
|
+
capture_reference = SixSaferpay::CaptureReference.new(capture_id: payment.transaction_id)
|
96
|
+
|
97
|
+
payment_refund = SixSaferpay::SixTransaction::Refund.new(refund: saferpay_refund, capture_reference: capture_reference)
|
98
|
+
|
99
|
+
if refund_response = SixSaferpay::Client.post(payment_refund)
|
100
|
+
|
101
|
+
# actually capture the refund
|
102
|
+
capture(amount, refund_response.transaction.id, options)
|
103
|
+
end
|
104
|
+
|
105
|
+
rescue SixSaferpay::Error => e
|
106
|
+
handle_error(e, refund_response)
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
def interface_initialize_object(order, payment_method)
|
112
|
+
raise NotImplementedError, "Must be implemented in PaymentPageGateway or TransactionGateway"
|
113
|
+
end
|
114
|
+
|
115
|
+
def interface_initialize_params(order, payment_method)
|
116
|
+
amount = Spree::Money.new(order.total, currency: order.currency)
|
117
|
+
payment = SixSaferpay::Payment.new(
|
118
|
+
amount: SixSaferpay::Amount.new(value: amount.cents, currency_code: amount.currency.iso_code),
|
119
|
+
order_id: order.number,
|
120
|
+
description: order.number
|
121
|
+
)
|
122
|
+
|
123
|
+
billing_address = order.billing_address
|
124
|
+
billing_address = SixSaferpay::Address.new(
|
125
|
+
first_name: billing_address.first_name,
|
126
|
+
last_name: billing_address.last_name,
|
127
|
+
date_of_birth: nil,
|
128
|
+
company: nil,
|
129
|
+
gender: nil,
|
130
|
+
legal_form: nil,
|
131
|
+
street: billing_address.address1,
|
132
|
+
street2: billing_address.address2,
|
133
|
+
zip: billing_address.zipcode,
|
134
|
+
city: billing_address.city,
|
135
|
+
country_subdevision_code: nil,
|
136
|
+
country_code: billing_address.country.iso,
|
137
|
+
phone: nil,
|
138
|
+
email: nil,
|
139
|
+
)
|
140
|
+
shipping_address = order.shipping_address
|
141
|
+
delivery_address = SixSaferpay::Address.new(
|
142
|
+
first_name: shipping_address.first_name,
|
143
|
+
last_name: shipping_address.last_name,
|
144
|
+
date_of_birth: nil,
|
145
|
+
company: nil,
|
146
|
+
gender: nil,
|
147
|
+
legal_form: nil,
|
148
|
+
street: shipping_address.address1,
|
149
|
+
street2: shipping_address.address2,
|
150
|
+
zip: shipping_address.zipcode,
|
151
|
+
city: shipping_address.city,
|
152
|
+
country_subdevision_code: nil,
|
153
|
+
country_code: shipping_address.country.iso,
|
154
|
+
phone: nil,
|
155
|
+
email: nil,
|
156
|
+
)
|
157
|
+
payer = SixSaferpay::Payer.new(language_code: I18n.locale, billing_address: billing_address, delivery_address: delivery_address)
|
158
|
+
|
159
|
+
params = { payment: payment, payer: payer }
|
160
|
+
|
161
|
+
six_payment_methods = payment_method.enabled_payment_methods
|
162
|
+
params.merge!(payment_methods: six_payment_methods) unless six_payment_methods.blank?
|
163
|
+
|
164
|
+
params
|
165
|
+
end
|
166
|
+
|
167
|
+
def response(success, message, api_response, options = {})
|
168
|
+
GatewayResponse.new(success, message, api_response, options)
|
169
|
+
end
|
170
|
+
|
171
|
+
def handle_error(error, response)
|
172
|
+
# Call host error handler hook
|
173
|
+
SolidusSixSaferpay::ErrorHandler.handle(error, level: :error)
|
174
|
+
|
175
|
+
response(
|
176
|
+
false,
|
177
|
+
error.error_message,
|
178
|
+
response,
|
179
|
+
error_name: error.error_name
|
180
|
+
)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|