spree_adyen 0.11.0 → 6.0.7
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/LICENSE +16 -4
- data/README.md +9 -51
- data/Rakefile +7 -18
- data/app/jobs/spree_adyen/base_job.rb +1 -1
- data/app/jobs/spree_adyen/configure_job.rb +19 -0
- data/app/maintenance_tasks/spree_adyen/maintenance_tasks/migrate_payments.rb +129 -0
- data/app/models/spree/payment_sessions/adyen.rb +42 -35
- data/app/models/spree/payment_setup_sessions/adyen.rb +1 -25
- data/app/models/spree_adyen/amounts.rb +69 -0
- data/app/models/spree_adyen/gateway/payment_sessions.rb +228 -98
- data/app/models/spree_adyen/gateway/payment_setup_sessions.rb +36 -136
- data/app/models/spree_adyen/gateway/webhooks.rb +142 -0
- data/app/models/spree_adyen/gateway.rb +275 -399
- data/app/models/spree_adyen/payment_sources/ach_direct_debit.rb +1 -13
- data/app/models/spree_adyen/payment_sources/affirm.rb +1 -13
- data/app/models/spree_adyen/payment_sources/afterpay.rb +1 -13
- data/app/models/spree_adyen/payment_sources/alipay.rb +1 -15
- data/app/models/spree_adyen/payment_sources/alipay_hk.rb +1 -13
- data/app/models/spree_adyen/payment_sources/alma.rb +1 -13
- data/app/models/spree_adyen/payment_sources/ancv.rb +1 -13
- data/app/models/spree_adyen/payment_sources/atome.rb +1 -13
- data/app/models/spree_adyen/payment_sources/bacs.rb +1 -13
- data/app/models/spree_adyen/payment_sources/bancontact.rb +1 -15
- data/app/models/spree_adyen/payment_sources/bank_transfer.rb +1 -13
- data/app/models/spree_adyen/payment_sources/base.rb +9 -1
- data/app/models/spree_adyen/payment_sources/benefit.rb +1 -13
- data/app/models/spree_adyen/payment_sources/billie.rb +1 -13
- data/app/models/spree_adyen/payment_sources/bizum.rb +1 -13
- data/app/models/spree_adyen/payment_sources/blik.rb +1 -11
- data/app/models/spree_adyen/payment_sources/boleto.rb +1 -13
- data/app/models/spree_adyen/payment_sources/card.rb +14 -0
- data/app/models/spree_adyen/payment_sources/cash_app_afterpay.rb +1 -13
- data/app/models/spree_adyen/payment_sources/cashapp.rb +1 -13
- data/app/models/spree_adyen/payment_sources/clearpay.rb +1 -13
- data/app/models/spree_adyen/payment_sources/dana.rb +1 -13
- data/app/models/spree_adyen/payment_sources/doku.rb +1 -15
- data/app/models/spree_adyen/payment_sources/duitnow.rb +1 -13
- data/app/models/spree_adyen/payment_sources/eps.rb +1 -15
- data/app/models/spree_adyen/payment_sources/fastlane.rb +1 -15
- data/app/models/spree_adyen/payment_sources/fpx.rb +1 -15
- data/app/models/spree_adyen/payment_sources/gcash.rb +1 -15
- data/app/models/spree_adyen/payment_sources/gift_cards.rb +1 -15
- data/app/models/spree_adyen/payment_sources/giropay.rb +1 -15
- data/app/models/spree_adyen/payment_sources/grabpay.rb +1 -15
- data/app/models/spree_adyen/payment_sources/ideal.rb +1 -11
- data/app/models/spree_adyen/payment_sources/klarna.rb +1 -28
- data/app/models/spree_adyen/payment_sources/oney.rb +1 -9
- data/app/models/spree_adyen/payment_sources/online_banking_czech_republic.rb +1 -11
- data/app/models/spree_adyen/payment_sources/online_banking_poland.rb +1 -11
- data/app/models/spree_adyen/payment_sources/pay_by_bank.rb +1 -11
- data/app/models/spree_adyen/payment_sources/paypal.rb +1 -11
- data/app/models/spree_adyen/payment_sources/paypo.rb +1 -11
- data/app/models/spree_adyen/payment_sources/paysafecard.rb +1 -11
- data/app/models/spree_adyen/payment_sources/rate_pay_direct_debit.rb +1 -11
- data/app/models/spree_adyen/payment_sources/riverty.rb +1 -11
- data/app/models/spree_adyen/payment_sources/samsung_pay.rb +1 -11
- data/app/models/spree_adyen/payment_sources/scalapay.rb +1 -9
- data/app/models/spree_adyen/payment_sources/sepa_direct_debit.rb +1 -11
- data/app/models/spree_adyen/payment_sources/trustly.rb +1 -11
- data/app/models/spree_adyen/payment_sources/unknown.rb +1 -15
- data/app/models/spree_adyen/payment_sources/wechat_pay.rb +1 -11
- data/app/models/spree_adyen/result.rb +155 -0
- data/app/models/spree_adyen/variants.rb +230 -0
- data/app/presenters/spree_adyen/application_info_presenter.rb +4 -4
- data/app/presenters/spree_adyen/session_presenter.rb +153 -0
- data/app/services/spree_adyen/configure.rb +121 -0
- data/app/subscribers/spree_adyen/capture_held_payments_subscriber.rb +41 -0
- data/config/locales/en.yml +21 -6
- data/lib/generators/spree_adyen/install/install_generator.rb +12 -12
- data/lib/spree_adyen/engine.rb +6 -70
- data/lib/spree_adyen/factories.rb +1 -3
- data/lib/spree_adyen/testing_support/factories/gateway_factory.rb +10 -17
- data/lib/spree_adyen/testing_support/factories/payment_session_factory.rb +18 -34
- data/lib/spree_adyen.rb +5 -30
- data/lib/tasks/configure_adyen_gateways.rake +39 -0
- metadata +35 -177
- data/app/assets/config/spree_adyen_manifest.js +0 -5
- data/app/controllers/spree_adyen/apple_pay_domain_verification_controller.rb +0 -11
- data/app/controllers/spree_adyen/payment_sessions_controller.rb +0 -67
- data/app/controllers/spree_adyen/store_controller_decorator.rb +0 -9
- data/app/controllers/spree_adyen/webhooks_controller.rb +0 -46
- data/app/helpers/spree_adyen/base_helper.rb +0 -18
- data/app/javascript/spree_adyen/application.js +0 -17
- data/app/javascript/spree_adyen/controllers/checkout_adyen_controller.js +0 -80
- data/app/javascript/spree_adyen/controllers/redirect_adyen_controller.js +0 -35
- data/app/jobs/spree_adyen/add_allowed_origin_job.rb +0 -24
- data/app/jobs/spree_adyen/webhooks/process_authorisation_event_job.rb +0 -10
- data/app/jobs/spree_adyen/webhooks/process_cancellation_event_job.rb +0 -10
- data/app/jobs/spree_adyen/webhooks/process_capture_event_job.rb +0 -10
- data/app/models/spree_adyen/base.rb +0 -6
- data/app/models/spree_adyen/custom_domain_decorator.rb +0 -17
- data/app/models/spree_adyen/order_decorator.rb +0 -23
- data/app/models/spree_adyen/payment_decorator.rb +0 -66
- data/app/models/spree_adyen/payment_method_decorator.rb +0 -15
- data/app/models/spree_adyen/payment_session.rb +0 -121
- data/app/models/spree_adyen/payment_sources/apple_pay.rb +0 -19
- data/app/models/spree_adyen/payment_sources/bcmc.rb +0 -17
- data/app/models/spree_adyen/payment_sources/bcmc_mobile.rb +0 -17
- data/app/models/spree_adyen/payment_sources/ebanking_fi.rb +0 -19
- data/app/models/spree_adyen/payment_sources/eft_directdebit_ca.rb +0 -19
- data/app/models/spree_adyen/payment_sources/eftpos_australia.rb +0 -19
- data/app/models/spree_adyen/payment_sources/elo.rb +0 -19
- data/app/models/spree_adyen/payment_sources/givex.rb +0 -19
- data/app/models/spree_adyen/payment_sources/gopay_wallet.rb +0 -19
- data/app/models/spree_adyen/payment_sources/grabpay_paylater.rb +0 -19
- data/app/models/spree_adyen/payment_sources/hipercard.rb +0 -19
- data/app/models/spree_adyen/payment_sources/kakaopay.rb +0 -19
- data/app/models/spree_adyen/payment_sources/kcp_naverpay.rb +0 -19
- data/app/models/spree_adyen/store_decorator.rb +0 -17
- data/app/presenters/spree_adyen/address_presenter.rb +0 -21
- data/app/presenters/spree_adyen/cancel_payload_presenter.rb +0 -31
- data/app/presenters/spree_adyen/capture_payload_presenter.rb +0 -36
- data/app/presenters/spree_adyen/checkout_presenter.rb +0 -51
- data/app/presenters/spree_adyen/payment_sessions/request_payload_presenter.rb +0 -140
- data/app/presenters/spree_adyen/payment_setup_sessions/request_payload_presenter.rb +0 -81
- data/app/presenters/spree_adyen/payments/request_payload_presenter.rb +0 -85
- data/app/presenters/spree_adyen/refund_payload_presenter.rb +0 -38
- data/app/presenters/spree_adyen/webhook_payload_presenter.rb +0 -28
- data/app/presenters/spree_adyen/webhooks/credit_card_presenter.rb +0 -43
- data/app/services/spree_adyen/gateways/add_allowed_origin.rb +0 -36
- data/app/services/spree_adyen/gateways/configuration.rb +0 -41
- data/app/services/spree_adyen/gateways/configure.rb +0 -60
- data/app/services/spree_adyen/payment_sessions/find_or_create.rb +0 -51
- data/app/services/spree_adyen/payment_sessions/process_with_result.rb +0 -49
- data/app/services/spree_adyen/payment_setup_sessions/create_source_from_result.rb +0 -71
- data/app/services/spree_adyen/payment_setup_sessions/handle_authorisation.rb +0 -48
- data/app/services/spree_adyen/webhooks/actions/create_source.rb +0 -112
- data/app/services/spree_adyen/webhooks/actions/find_or_create_credit_card.rb +0 -33
- data/app/services/spree_adyen/webhooks/event.rb +0 -104
- data/app/services/spree_adyen/webhooks/event_processors/authorisation_event_processor.rb +0 -69
- data/app/services/spree_adyen/webhooks/event_processors/cancellation_event_processor.rb +0 -49
- data/app/services/spree_adyen/webhooks/event_processors/capture_event_processor.rb +0 -48
- data/app/services/spree_adyen/webhooks/handle_event.rb +0 -43
- data/app/services/spree_adyen/webhooks/standard_hmac_validator.rb +0 -37
- data/app/views/layouts/spree_adyen/default.html.erb +0 -14
- data/app/views/spree/admin/payment_methods/configuration_guides/_spree_adyen.html.erb +0 -14
- data/app/views/spree/admin/payment_methods/custom_form_fields/_spree_adyen.html.erb +0 -18
- data/app/views/spree/admin/payment_methods/descriptions/_spree_adyen.html.erb +0 -12
- data/app/views/spree/admin/payments/source_forms/_spree_adyen.html.erb +0 -7
- data/app/views/spree/checkout/payment/_spree_adyen.html.erb +0 -40
- data/app/views/spree_adyen/_drop_in.html.erb +0 -12
- data/app/views/spree_adyen/_head.html.erb +0 -2
- data/app/views/spree_adyen/payment_sessions/redirect.html.erb +0 -5
- data/config/importmap.rb +0 -7
- data/config/initializers/spree.rb +0 -34
- data/config/initializers/spree_permitted_attributes.rb +0 -5
- data/config/routes.rb +0 -35
- data/db/migrate/20250630150000_setup_spree_adyen_models.rb +0 -17
- data/db/migrate/20250811140113_add_channel_to_adyen_payment_sessions.rb +0 -10
- data/db/migrate/20250813152608_add_return_url_to_spree_adyen_payment_sessions.rb +0 -15
- data/lib/spree_adyen/configuration.rb +0 -42
- data/lib/spree_adyen/testing_support/factories/payment_setup_session_factory.rb +0 -15
- data/lib/spree_adyen/version.rb +0 -7
- data/lib/spree_api_v2/spree/api/v2/storefront/adyen/base_controller.rb +0 -21
- data/lib/spree_api_v2/spree/api/v2/storefront/adyen/payment_sessions_controller.rb +0 -72
- data/lib/spree_api_v2/spree_adyen/api/v2/storefront/payment_session_serializer.rb +0 -21
- data/vendor/javascript/@adyen--adyen-web.js +0 -4
- data/vendor/stylesheets/adyen.css +0 -106
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
module SpreeAdyen
|
|
2
|
-
module Webhooks
|
|
3
|
-
class ProcessCaptureEventJob < SpreeAdyen::BaseJob
|
|
4
|
-
def perform(payload)
|
|
5
|
-
event = SpreeAdyen::Webhooks::Event.new(event_data: payload)
|
|
6
|
-
SpreeAdyen::Webhooks::EventProcessors::CaptureEventProcessor.new(event).call
|
|
7
|
-
end
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
module SpreeAdyen
|
|
2
|
-
module CustomDomainDecorator
|
|
3
|
-
def self.prepended(base)
|
|
4
|
-
base.after_commit :add_adyen_allowed_origin
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def add_adyen_allowed_origin
|
|
8
|
-
return if store.adyen_gateway.blank?
|
|
9
|
-
|
|
10
|
-
SpreeAdyen::AddAllowedOriginJob.perform_later(id, store.adyen_gateway.id, 'custom_domain')
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
if defined?(Spree::CustomDomain)
|
|
16
|
-
Spree::CustomDomain.prepend(SpreeAdyen::CustomDomainDecorator)
|
|
17
|
-
end
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
module SpreeAdyen
|
|
2
|
-
module OrderDecorator
|
|
3
|
-
def self.prepended(base)
|
|
4
|
-
base.has_many :adyen_payment_sessions, class_name: 'SpreeAdyen::PaymentSession', dependent: :destroy
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def outdate_payment_sessions
|
|
8
|
-
return unless SpreeAdyen::Config[:use_legacy_adyen_payment_sessions]
|
|
9
|
-
|
|
10
|
-
adyen_payment_sessions
|
|
11
|
-
.where.not(currency: currency).or(adyen_payment_sessions.where.not(amount: total_minus_store_credits))
|
|
12
|
-
.with_status(:initial)
|
|
13
|
-
.each(&:destroy)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def can_create_adyen_payment_session?
|
|
17
|
-
state.in?(%w[confirm payment])
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
Spree::Order.prepend(SpreeAdyen::OrderDecorator)
|
|
23
|
-
Spree::Order.register_update_hook :outdate_payment_sessions
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
module SpreeAdyen
|
|
2
|
-
module PaymentDecorator
|
|
3
|
-
def self.prepended(base)
|
|
4
|
-
base.state_machine.event :started_processing do
|
|
5
|
-
transition from: [:checkout, :pending, :completed, :processing, :capture_pending, :void_pending], to: :processing
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
base.state_machine.event :pend_capture do
|
|
9
|
-
transition from: [:pending, :processing, :checkout], to: :capture_pending
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
base.state_machine.event :pend_void do
|
|
13
|
-
transition from: [:pending, :processing, :checkout], to: :void_pending
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def capture!(amount = nil)
|
|
18
|
-
if payment_method.adyen? && !capture_pending?
|
|
19
|
-
request_capture!(amount)
|
|
20
|
-
else
|
|
21
|
-
super(amount)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def void_transaction!
|
|
26
|
-
if payment_method.adyen? && !void_pending?
|
|
27
|
-
request_void!
|
|
28
|
-
else
|
|
29
|
-
super
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
# Takes the amount in cents to request a capture of the payment.
|
|
34
|
-
# This is used instead of #capture! for Adyen that sends the capture result via a webhook.
|
|
35
|
-
def request_capture!(amount = nil)
|
|
36
|
-
return true if completed? || capture_pending?
|
|
37
|
-
|
|
38
|
-
amount ||= money.amount_in_cents
|
|
39
|
-
|
|
40
|
-
protect_from_connection_error do
|
|
41
|
-
response = payment_method.request_capture(amount, response_code, gateway_options)
|
|
42
|
-
handle_response(response, :pend_capture, :failure)
|
|
43
|
-
end
|
|
44
|
-
rescue Spree::Core::GatewayError
|
|
45
|
-
failure!
|
|
46
|
-
raise
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
# Sends a request to void the payment.
|
|
50
|
-
# This is used instead of #void_transaction! for Adyen that sends the void result via a webhook.
|
|
51
|
-
def request_void!
|
|
52
|
-
return true if void? || void_pending?
|
|
53
|
-
|
|
54
|
-
started_processing!
|
|
55
|
-
protect_from_connection_error do
|
|
56
|
-
response = payment_method.request_void(response_code, source, gateway_options)
|
|
57
|
-
handle_response(response, :pend_void, :failure)
|
|
58
|
-
end
|
|
59
|
-
rescue Spree::Core::GatewayError
|
|
60
|
-
failure!
|
|
61
|
-
raise
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
Spree::Payment.prepend(SpreeAdyen::PaymentDecorator)
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
module SpreeAdyen
|
|
2
|
-
module PaymentMethodDecorator
|
|
3
|
-
ADYEN_TYPE = 'SpreeAdyen::Gateway'.freeze unless const_defined?(:ADYEN_TYPE)
|
|
4
|
-
|
|
5
|
-
def self.prepended(base)
|
|
6
|
-
base.scope :adyen, -> { where(type: ADYEN_TYPE) }
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def adyen?
|
|
10
|
-
type == ADYEN_TYPE
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
Spree::PaymentMethod.prepend(SpreeAdyen::PaymentMethodDecorator)
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
module SpreeAdyen
|
|
2
|
-
class PaymentSession < Base
|
|
3
|
-
AVAILABLE_CHANNELS = {
|
|
4
|
-
ios: 'iOS',
|
|
5
|
-
android: 'Android',
|
|
6
|
-
web: 'Web'
|
|
7
|
-
}.freeze
|
|
8
|
-
|
|
9
|
-
acts_as_paranoid
|
|
10
|
-
#
|
|
11
|
-
# Associations
|
|
12
|
-
#
|
|
13
|
-
belongs_to :order, class_name: 'Spree::Order'
|
|
14
|
-
belongs_to :payment_method, class_name: 'Spree::PaymentMethod'
|
|
15
|
-
belongs_to :user, class_name: Spree.user_class.name, optional: true
|
|
16
|
-
|
|
17
|
-
#
|
|
18
|
-
# Attributes
|
|
19
|
-
#
|
|
20
|
-
attribute :skip_expiration_date_validation, :boolean, default: false
|
|
21
|
-
|
|
22
|
-
#
|
|
23
|
-
# Validations
|
|
24
|
-
#
|
|
25
|
-
validates :order, :payment_method, presence: true
|
|
26
|
-
validates :adyen_id, uniqueness: true, presence: true
|
|
27
|
-
validates :adyen_data, :status, :expires_at, presence: true
|
|
28
|
-
validates :amount, presence: true, numericality: { greater_than: 0 }
|
|
29
|
-
validates :currency, presence: true
|
|
30
|
-
validates :channel, presence: true, inclusion: { in: AVAILABLE_CHANNELS.values }
|
|
31
|
-
validates :return_url, presence: true
|
|
32
|
-
|
|
33
|
-
validate :amount_cannot_be_greater_than_payment_allowed_amount
|
|
34
|
-
validate :currency_matches_order_currency
|
|
35
|
-
validate :expiration_date_cannot_be_in_the_past_or_later_than_24_hours, on: :create, unless: :skip_expiration_date_validation
|
|
36
|
-
|
|
37
|
-
scope :not_expired, -> { where('expires_at > ?', DateTime.current) }
|
|
38
|
-
|
|
39
|
-
state_machine :status, initial: :initial do
|
|
40
|
-
event :pending do
|
|
41
|
-
transition %i[initial] => :pending
|
|
42
|
-
end
|
|
43
|
-
event :complete do
|
|
44
|
-
transition %i[pending initial] => :completed
|
|
45
|
-
end
|
|
46
|
-
event :cancel do
|
|
47
|
-
transition %i[pending initial] => :canceled
|
|
48
|
-
end
|
|
49
|
-
event :refuse do
|
|
50
|
-
transition %i[pending initial] => :refused
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
#
|
|
55
|
-
# Callbacks
|
|
56
|
-
#
|
|
57
|
-
before_validation :set_amount_from_order
|
|
58
|
-
before_validation :set_currency_from_order
|
|
59
|
-
before_validation :set_default_channel, on: :create, if: -> { channel.blank? }
|
|
60
|
-
before_validation :set_return_url, on: :create, if: -> { return_url.blank? }
|
|
61
|
-
before_validation :create_session_in_adyen, on: :create
|
|
62
|
-
|
|
63
|
-
#
|
|
64
|
-
# Delegations
|
|
65
|
-
#
|
|
66
|
-
delegate :store, :currency, to: :order
|
|
67
|
-
|
|
68
|
-
private
|
|
69
|
-
|
|
70
|
-
def set_amount_from_order
|
|
71
|
-
self.amount ||= order&.total_minus_store_credits
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def set_currency_from_order
|
|
75
|
-
self.currency = order&.currency
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def set_default_channel
|
|
79
|
-
self.channel = AVAILABLE_CHANNELS[:web]
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def set_return_url
|
|
83
|
-
return if order.blank?
|
|
84
|
-
|
|
85
|
-
self.return_url = "#{order.store.storefront_url}/adyen/payment_sessions/redirect"
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def expiration_date_cannot_be_in_the_past_or_later_than_24_hours
|
|
89
|
-
errors.add(:expires_at, "can't be in the past") if expires_at.present? && expires_at < DateTime.current
|
|
90
|
-
|
|
91
|
-
return unless expires_at.present? && expires_at > 24.hours.from_now
|
|
92
|
-
|
|
93
|
-
errors.add(:expires_at, "can't be more than 24 hours from now")
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
def currency_matches_order_currency
|
|
97
|
-
errors.add(:currency, 'must match order currency') if currency != order&.currency
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
def amount_cannot_be_greater_than_payment_allowed_amount
|
|
101
|
-
return if order.nil?
|
|
102
|
-
|
|
103
|
-
allowed_payment_amount = order.total_minus_store_credits - order.payment_total
|
|
104
|
-
errors.add(:amount, "can't be greater than allowed payment amount of #{allowed_payment_amount}") if amount > allowed_payment_amount
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def create_session_in_adyen
|
|
108
|
-
return if adyen_id.present?
|
|
109
|
-
|
|
110
|
-
response = payment_method.create_adyen_session(amount, order, channel, return_url)
|
|
111
|
-
return unless response.success?
|
|
112
|
-
|
|
113
|
-
self.adyen_id = response.params['id']
|
|
114
|
-
self.adyen_data = response.params['sessionData']
|
|
115
|
-
self.expires_at = response.params['expiresAt']
|
|
116
|
-
rescue Spree::Core::GatewayError
|
|
117
|
-
# Let validations handle missing adyen_id, adyen_data, expires_at
|
|
118
|
-
nil
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
module SpreeAdyen
|
|
2
|
-
module PaymentSources
|
|
3
|
-
class ApplePay < ::Spree::PaymentSource
|
|
4
|
-
store_accessor :public_metadata, :payment_data, :payment_method, :transaction_identifier
|
|
5
|
-
|
|
6
|
-
def actions
|
|
7
|
-
%w[credit void capture]
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def self.display_name
|
|
11
|
-
'Apple Pay'
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def display_payment_info
|
|
15
|
-
"Apple Pay: #{payment_method}"
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
module SpreeAdyen
|
|
2
|
-
module PaymentSources
|
|
3
|
-
class Bcmc < ::Spree::PaymentSource
|
|
4
|
-
def actions
|
|
5
|
-
%w[credit void]
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def self.display_name
|
|
9
|
-
'Bancontact card'
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def display_payment_info
|
|
13
|
-
'Bancontact card'
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
module SpreeAdyen
|
|
2
|
-
module PaymentSources
|
|
3
|
-
class BcmcMobile < ::Spree::PaymentSource
|
|
4
|
-
def actions
|
|
5
|
-
%w[credit void]
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def self.display_name
|
|
9
|
-
'Bancontact mobile'
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def display_payment_info
|
|
13
|
-
'Bancontact mobile'
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
module SpreeAdyen
|
|
2
|
-
module PaymentSources
|
|
3
|
-
class EbankingFi < ::Spree::PaymentSource
|
|
4
|
-
store_accessor :public_metadata, :payment_reference
|
|
5
|
-
|
|
6
|
-
def actions
|
|
7
|
-
%w[credit void]
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def self.display_name
|
|
11
|
-
'Online Banking Finland'
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def display_payment_info
|
|
15
|
-
"Online Banking Finland: #{payment_reference}"
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
module SpreeAdyen
|
|
2
|
-
module PaymentSources
|
|
3
|
-
class EftDirectdebitCa < ::Spree::PaymentSource
|
|
4
|
-
store_accessor :public_metadata, :payment_reference
|
|
5
|
-
|
|
6
|
-
def actions
|
|
7
|
-
%w[credit void]
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def self.display_name
|
|
11
|
-
'PAD Canada'
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def display_payment_info
|
|
15
|
-
"PAD Canada: #{payment_reference}"
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
module SpreeAdyen
|
|
2
|
-
module PaymentSources
|
|
3
|
-
class EftposAustralia < ::Spree::PaymentSource
|
|
4
|
-
store_accessor :public_metadata, :payment_reference
|
|
5
|
-
|
|
6
|
-
def actions
|
|
7
|
-
%w[credit void]
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def self.display_name
|
|
11
|
-
'eftpos'
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def display_payment_info
|
|
15
|
-
"eftpos: #{payment_reference}"
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
module SpreeAdyen
|
|
2
|
-
module PaymentSources
|
|
3
|
-
class Elo < ::Spree::PaymentSource
|
|
4
|
-
store_accessor :public_metadata, :payment_reference
|
|
5
|
-
|
|
6
|
-
def actions
|
|
7
|
-
%w[credit void]
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def self.display_name
|
|
11
|
-
'Elo'
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def display_payment_info
|
|
15
|
-
"Elo: #{payment_reference}"
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
module SpreeAdyen
|
|
2
|
-
module PaymentSources
|
|
3
|
-
class Givex < ::Spree::PaymentSource
|
|
4
|
-
store_accessor :public_metadata, :payment_reference
|
|
5
|
-
|
|
6
|
-
def actions
|
|
7
|
-
%w[credit void]
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def self.display_name
|
|
11
|
-
'Givex'
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def display_payment_info
|
|
15
|
-
"Givex: #{payment_reference}"
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
module SpreeAdyen
|
|
2
|
-
module PaymentSources
|
|
3
|
-
class GopayWallet < ::Spree::PaymentSource
|
|
4
|
-
store_accessor :public_metadata, :payment_reference
|
|
5
|
-
|
|
6
|
-
def actions
|
|
7
|
-
%w[credit void]
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def self.display_name
|
|
11
|
-
'GoPay'
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def display_payment_info
|
|
15
|
-
"GoPay: #{payment_reference}"
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
module SpreeAdyen
|
|
2
|
-
module PaymentSources
|
|
3
|
-
class GrabpayPaylater < ::Spree::PaymentSource
|
|
4
|
-
store_accessor :public_metadata, :payment_reference
|
|
5
|
-
|
|
6
|
-
def actions
|
|
7
|
-
%w[credit void]
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def self.display_name
|
|
11
|
-
'GrabPay PayLater'
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def display_payment_info
|
|
15
|
-
"GrabPay PayLater: #{payment_reference}"
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
module SpreeAdyen
|
|
2
|
-
module PaymentSources
|
|
3
|
-
class Hipercard < ::Spree::PaymentSource
|
|
4
|
-
store_accessor :public_metadata, :payment_reference
|
|
5
|
-
|
|
6
|
-
def actions
|
|
7
|
-
%w[credit void]
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def self.display_name
|
|
11
|
-
'Hipercard'
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def display_payment_info
|
|
15
|
-
"Hipercard: #{payment_reference}"
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
module SpreeAdyen
|
|
2
|
-
module PaymentSources
|
|
3
|
-
class Kakaopay < ::Spree::PaymentSource
|
|
4
|
-
store_accessor :public_metadata, :payment_reference
|
|
5
|
-
|
|
6
|
-
def actions
|
|
7
|
-
%w[credit void]
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def self.display_name
|
|
11
|
-
'KakaoPay'
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def display_payment_info
|
|
15
|
-
"KakaoPay: #{payment_reference}"
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
module SpreeAdyen
|
|
2
|
-
module PaymentSources
|
|
3
|
-
class KcpNaverpay < ::Spree::PaymentSource
|
|
4
|
-
store_accessor :public_metadata, :payment_reference
|
|
5
|
-
|
|
6
|
-
def actions
|
|
7
|
-
%w[credit void]
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def self.display_name
|
|
11
|
-
'Naverpay'
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def display_payment_info
|
|
15
|
-
"Naverpay: #{payment_reference}"
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
module SpreeAdyen
|
|
2
|
-
module StoreDecorator
|
|
3
|
-
def adyen_gateway
|
|
4
|
-
@adyen_gateway ||= payment_methods.adyen.active.last
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def handle_code_changes
|
|
8
|
-
super
|
|
9
|
-
|
|
10
|
-
return if adyen_gateway.blank?
|
|
11
|
-
|
|
12
|
-
SpreeAdyen::AddAllowedOriginJob.perform_later(id, adyen_gateway.id)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
Spree::Store.prepend(SpreeAdyen::StoreDecorator)
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
module SpreeAdyen
|
|
2
|
-
class AddressPresenter
|
|
3
|
-
def initialize(address)
|
|
4
|
-
@address = address
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def to_h
|
|
8
|
-
{
|
|
9
|
-
city: address['citystring'],
|
|
10
|
-
country: Spree::Country.find_by(name: address['countrystring']),
|
|
11
|
-
zipcode: address['postalCodestring'],
|
|
12
|
-
address1: address['streetstring'],
|
|
13
|
-
address2: address['houseNumberOrNamestring']
|
|
14
|
-
}
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
private
|
|
18
|
-
|
|
19
|
-
attr_reader :address
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
module SpreeAdyen
|
|
2
|
-
class CancelPayloadPresenter
|
|
3
|
-
REFERENCE_SUFFIX = 'cancel'.freeze
|
|
4
|
-
|
|
5
|
-
def initialize(payment:, payment_method:)
|
|
6
|
-
@payment = payment
|
|
7
|
-
@order = payment.order
|
|
8
|
-
@payment_method = payment_method
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def to_h
|
|
12
|
-
{
|
|
13
|
-
reference: reference,
|
|
14
|
-
merchantAccount: payment_method.preferred_merchant_account
|
|
15
|
-
}.merge!(SpreeAdyen::ApplicationInfoPresenter.new.to_h)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
private
|
|
19
|
-
|
|
20
|
-
attr_reader :payment, :order, :payment_method
|
|
21
|
-
|
|
22
|
-
def reference
|
|
23
|
-
[
|
|
24
|
-
order.number,
|
|
25
|
-
payment_method.id,
|
|
26
|
-
payment.response_code,
|
|
27
|
-
REFERENCE_SUFFIX
|
|
28
|
-
].join('_')
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
module SpreeAdyen
|
|
2
|
-
class CapturePayloadPresenter
|
|
3
|
-
REFERENCE_SUFFIX = 'capture'.freeze
|
|
4
|
-
|
|
5
|
-
def initialize(amount_in_cents:, payment:, payment_method:)
|
|
6
|
-
@amount_in_cents = amount_in_cents
|
|
7
|
-
@payment = payment
|
|
8
|
-
@order = payment.order
|
|
9
|
-
@payment_method = payment_method
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def to_h
|
|
13
|
-
{
|
|
14
|
-
amount: {
|
|
15
|
-
value: amount_in_cents,
|
|
16
|
-
currency: payment.currency
|
|
17
|
-
},
|
|
18
|
-
reference: reference,
|
|
19
|
-
merchantAccount: payment_method.preferred_merchant_account
|
|
20
|
-
}.merge!(SpreeAdyen::ApplicationInfoPresenter.new.to_h)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
private
|
|
24
|
-
|
|
25
|
-
attr_reader :amount_in_cents, :payment, :order, :payment_method
|
|
26
|
-
|
|
27
|
-
def reference
|
|
28
|
-
[
|
|
29
|
-
order.number,
|
|
30
|
-
payment_method.id,
|
|
31
|
-
payment.response_code,
|
|
32
|
-
REFERENCE_SUFFIX
|
|
33
|
-
].join('_')
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
module SpreeAdyen
|
|
2
|
-
# use this serializer to configure the Adyen Drop-in component
|
|
3
|
-
# https://docs.adyen.com/online-payments/build-your-integration/sessions-flow/?platform=Web&integration=Drop-in&version=6.18.1&tab=embed_script_and_stylesheet_1_2#configure
|
|
4
|
-
class CheckoutPresenter
|
|
5
|
-
def initialize(payment_session)
|
|
6
|
-
@payment_session = payment_session
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def to_json(*_args)
|
|
10
|
-
@to_json ||= to_h.to_json
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def to_h
|
|
14
|
-
@to_h ||= {
|
|
15
|
-
session: {
|
|
16
|
-
id: payment_session.adyen_id,
|
|
17
|
-
sessionData: payment_session.adyen_data
|
|
18
|
-
},
|
|
19
|
-
environment: payment_session.payment_method.environment,
|
|
20
|
-
|
|
21
|
-
amount: {
|
|
22
|
-
value: Spree::Money.new(payment_session.amount, currency: currency).cents,
|
|
23
|
-
currency: currency
|
|
24
|
-
},
|
|
25
|
-
countryCode: country_iso,
|
|
26
|
-
locale: locale,
|
|
27
|
-
clientKey: payment_session.payment_method.preferred_client_key,
|
|
28
|
-
showPayButton: true
|
|
29
|
-
}
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
private
|
|
33
|
-
|
|
34
|
-
attr_reader :payment_session
|
|
35
|
-
|
|
36
|
-
delegate :currency, :order, to: :payment_session
|
|
37
|
-
delegate :store, :user, to: :order
|
|
38
|
-
|
|
39
|
-
def locale
|
|
40
|
-
order.try(:locale) || 'en-US'
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def country_iso
|
|
44
|
-
address&.country_iso || store.default_country_iso || 'US'
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def address
|
|
48
|
-
@address ||= order.bill_address || order.ship_address || user&.bill_address || user&.ship_address
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|