spree_adyen 0.11.0 → 6.0.6
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 +221 -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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0cb7735c1cd9ccaf42449366708188e9103c43336a9a6d585341c4de76162bf1
|
|
4
|
+
data.tar.gz: df796b561616b73d541346da8c0921e4e16e65e078c843d8fe702d86c3bb565d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b8a60500f6b456b829e233a3bdf17b18f1049c42e708a533e13192306ee6dc4f3b295217ce0bd81e3857c292056f4f63878043923da3c341b61d3bc9d6d42a89
|
|
7
|
+
data.tar.gz: d5899c051f9dbbb218b07418664247ca507d7ca09f81557213b439b9bd0ed8a2dbe5f527c7930f7bb5530698d9a12d38bff70ceffdc4fd4f6d0b3028ec3cbc83
|
data/LICENSE
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2026 Vendo
|
|
3
|
+
Copyright (c) 2026-present, Vendo Sp. z o.o., Vendo Connect Inc.
|
|
4
4
|
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
6
11
|
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
8
14
|
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
|
@@ -1,59 +1,17 @@
|
|
|
1
1
|
# Spree Adyen
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Adyen payments for [Spree Commerce](https://spreecommerce.org): cards, wallets
|
|
4
|
+
and local payment methods through Adyen's Sessions flow and Drop-in, on the
|
|
5
|
+
Spree payment session API.
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
1. Add this extension to your Gemfile with this line:
|
|
8
|
-
|
|
9
|
-
```ruby
|
|
10
|
-
bundle add spree_adyen
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
2. Run the install generator
|
|
14
|
-
|
|
15
|
-
```ruby
|
|
16
|
-
bundle exec rails g spree_adyen:install
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
3. Restart your server
|
|
20
|
-
|
|
21
|
-
If your server was running, restart it so that it can find the assets properly.
|
|
22
|
-
|
|
23
|
-
## Developing
|
|
24
|
-
|
|
25
|
-
1. Create a dummy app
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
bundle update
|
|
29
|
-
bundle exec rake test_app
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
2. Add your new code
|
|
33
|
-
3. Run tests
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
bundle exec rspec
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
When testing your applications integration with this extension you may use it's factories.
|
|
40
|
-
Simply add this require statement to your spec_helper:
|
|
7
|
+
Add the gem to your Spree application:
|
|
41
8
|
|
|
42
9
|
```ruby
|
|
43
|
-
|
|
10
|
+
gem 'spree_adyen'
|
|
44
11
|
```
|
|
45
12
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
```shell
|
|
49
|
-
bundle exec gem bump -p -t
|
|
50
|
-
bundle exec gem release
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
For more options please see [gem-release README](https://github.com/svenfuchs/gem-release)
|
|
54
|
-
|
|
55
|
-
## Contributing
|
|
13
|
+
The gateway registers itself. Add an Adyen payment method in the admin and
|
|
14
|
+
enter your API key, merchant account and, for live, the live URL prefix.
|
|
56
15
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
pull request.
|
|
16
|
+
See the [Adyen guide](https://spreecommerce.org/docs/integrations/payments/adyen)
|
|
17
|
+
for setup and the storefront.
|
data/Rakefile
CHANGED
|
@@ -1,26 +1,15 @@
|
|
|
1
|
-
require '
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
require 'rake/testtask'
|
|
4
4
|
require 'rspec/core/rake_task'
|
|
5
|
-
require 'spree/testing_support/
|
|
5
|
+
require 'spree/testing_support/common_rake'
|
|
6
6
|
|
|
7
7
|
RSpec::Core::RakeTask.new
|
|
8
8
|
|
|
9
|
-
task :
|
|
10
|
-
if Dir['spec/dummy'].empty?
|
|
11
|
-
Rake::Task[:test_app].invoke
|
|
12
|
-
Dir.chdir('../../')
|
|
13
|
-
end
|
|
14
|
-
Rake::Task[:spec].invoke
|
|
15
|
-
end
|
|
9
|
+
task default: :spec
|
|
16
10
|
|
|
17
|
-
desc
|
|
11
|
+
desc "Generates a dummy app for testing"
|
|
18
12
|
task :test_app do
|
|
19
13
|
ENV['LIB_NAME'] = 'spree_adyen'
|
|
20
|
-
Rake::Task['
|
|
21
|
-
install_admin: true
|
|
22
|
-
)
|
|
23
|
-
system({ 'BUNDLE_GEMFILE' => File.expand_path('Gemfile', __dir__) }, 'rails g spree_posts:install')
|
|
24
|
-
system({ 'BUNDLE_GEMFILE' => File.expand_path('Gemfile', __dir__) }, 'rails g spree_legacy_product_properties:install')
|
|
25
|
-
system({ 'BUNDLE_GEMFILE' => File.expand_path('Gemfile', __dir__) }, 'rails g spree_legacy_api_v2:install')
|
|
14
|
+
Rake::Task['common:test_app'].invoke
|
|
26
15
|
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module SpreeAdyen
|
|
2
|
+
class ConfigureJob < BaseJob
|
|
3
|
+
# Safe to replay: configuration finds what is already in place.
|
|
4
|
+
retry_on StandardError, wait: :polynomially_longer, attempts: 5
|
|
5
|
+
# Must come after `retry_on StandardError` so DeserializationError lands in discard.
|
|
6
|
+
discard_on ActiveJob::DeserializationError
|
|
7
|
+
|
|
8
|
+
def perform(payment_method_id)
|
|
9
|
+
# Locked on load: two saves in a row queue two jobs, and both would
|
|
10
|
+
# otherwise create a webhook for the same URL.
|
|
11
|
+
Spree::PaymentMethod.transaction do
|
|
12
|
+
payment_method = Spree::PaymentMethod.lock.find_by(id: payment_method_id)
|
|
13
|
+
next unless payment_method.is_a?(SpreeAdyen::Gateway)
|
|
14
|
+
|
|
15
|
+
SpreeAdyen::Configure.call(payment_method)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
module SpreeAdyen
|
|
2
|
+
module MaintenanceTasks
|
|
3
|
+
# Gives Adyen payments taken under the 5.x gem the 6.0 shape:
|
|
4
|
+
#
|
|
5
|
+
# - a payment from 5.x's legacy checkout, whose response code its webhook
|
|
6
|
+
# rewrote to the PSP reference, gets that reference in
|
|
7
|
+
# metadata['adyen_psp_reference'], where captures, cancels, refunds and
|
|
8
|
+
# the dashboard link read it. Its response code stays, since no session
|
|
9
|
+
# links to it;
|
|
10
|
+
# - a payment-session payment, keyed on the session id with no PSP
|
|
11
|
+
# reference anywhere, cannot be recovered: Adyen has no lookup from a
|
|
12
|
+
# session id. It is counted and logged by id, to handle in Adyen;
|
|
13
|
+
# - the capture and cancellation references 5.x kept in custom fields move
|
|
14
|
+
# to the capture event and the payment's metadata, and the values go;
|
|
15
|
+
# - a payment left in 5.x's capture_pending or void_pending is marked done,
|
|
16
|
+
# since Adyen will not send its outcome again.
|
|
17
|
+
class MigratePayments < Spree::MaintenanceTask
|
|
18
|
+
CAPTURE_FIELD = 'adyen.capture_psp_reference'.freeze
|
|
19
|
+
CANCELLATION_FIELD = 'adyen.cancellation_psp_reference'.freeze
|
|
20
|
+
|
|
21
|
+
supports_dry_run
|
|
22
|
+
|
|
23
|
+
def collection
|
|
24
|
+
gateway_ids = Spree::PaymentMethod.unscoped.where(type: 'SpreeAdyen::Gateway').select(:id)
|
|
25
|
+
Spree::Payment.unscoped.where(payment_method_id: gateway_ids).where.not(response_code: [nil, '']).order(:id)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# One transaction per payment, so a retry after a failure never finds a
|
|
29
|
+
# capture event written without the status change that goes with it.
|
|
30
|
+
def process(payment)
|
|
31
|
+
payment.transaction do
|
|
32
|
+
capture_reference = payment.get_custom_field(CAPTURE_FIELD)&.value.presence&.to_s
|
|
33
|
+
changed = record_psp_reference(payment)
|
|
34
|
+
changed |= move_custom_fields(payment)
|
|
35
|
+
changed |= finish_pending_status(payment, capture_reference)
|
|
36
|
+
tally(:unchanged) unless changed
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# The two custom field definitions belong to merchants' data, so they go
|
|
41
|
+
# once no value is left.
|
|
42
|
+
def after_complete
|
|
43
|
+
return if dry_run?
|
|
44
|
+
|
|
45
|
+
Spree::CustomFieldDefinition.where(namespace: 'adyen', key: %w[capture_psp_reference cancellation_psp_reference]).
|
|
46
|
+
find_each { |definition| definition.destroy if definition.custom_fields.none? }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
def record_psp_reference(payment)
|
|
52
|
+
return false if payment.metadata['adyen_psp_reference'].present?
|
|
53
|
+
|
|
54
|
+
if session_payment?(payment)
|
|
55
|
+
Rails.logger.warn("[spree_adyen] migrate_adyen_payments: payment #{payment.id} has no PSP reference; handle it in Adyen")
|
|
56
|
+
tally(:unrecoverable)
|
|
57
|
+
return true
|
|
58
|
+
end
|
|
59
|
+
if dry_run?
|
|
60
|
+
tally(:would_convert)
|
|
61
|
+
return true
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
payment.update_columns(metadata: payment.metadata.merge('adyen_psp_reference' => payment.response_code), updated_at: Time.current)
|
|
65
|
+
tally(:converted)
|
|
66
|
+
true
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def session_payment?(payment)
|
|
70
|
+
Spree::PaymentSession.unscoped.exists?(payment_method_id: payment.payment_method_id, external_id: payment.response_code)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def move_custom_fields(payment)
|
|
74
|
+
capture_field = payment.get_custom_field(CAPTURE_FIELD)
|
|
75
|
+
cancellation_field = payment.get_custom_field(CANCELLATION_FIELD)
|
|
76
|
+
return false if capture_field.nil? && cancellation_field.nil?
|
|
77
|
+
|
|
78
|
+
if dry_run?
|
|
79
|
+
tally(:would_move_references)
|
|
80
|
+
return true
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
if capture_field
|
|
84
|
+
capture_event = payment.capture_events.where(transaction_id: nil).order(:id).last
|
|
85
|
+
capture_event&.update_columns(transaction_id: capture_field.value.to_s, updated_at: Time.current)
|
|
86
|
+
capture_field.destroy
|
|
87
|
+
end
|
|
88
|
+
if cancellation_field
|
|
89
|
+
references = Array(payment.metadata['adyen_cancel_references']) | [cancellation_field.value.to_s]
|
|
90
|
+
payment.update_columns(metadata: payment.metadata.merge('adyen_cancel_references' => references), updated_at: Time.current)
|
|
91
|
+
cancellation_field.destroy
|
|
92
|
+
end
|
|
93
|
+
tally(:moved_references)
|
|
94
|
+
true
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Adyen's acceptance is counted as done for these legacy rows only.
|
|
98
|
+
def finish_pending_status(payment, capture_reference)
|
|
99
|
+
status = payment.read_attribute(:status)
|
|
100
|
+
return false unless status.in?(%w[capture_pending void_pending])
|
|
101
|
+
|
|
102
|
+
Rails.logger.warn("[spree_adyen] migrate_adyen_payments: payment #{payment.id} was #{status}; marked done, check it in Adyen")
|
|
103
|
+
if dry_run?
|
|
104
|
+
tally(:would_mark_done)
|
|
105
|
+
return true
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
if status == 'capture_pending'
|
|
109
|
+
payment.capture_events.create!(amount: payment.amount, status: 'completed',
|
|
110
|
+
transaction_id: capture_reference || payment.metadata['adyen_psp_reference'])
|
|
111
|
+
payment.update_columns(status: 'completed', updated_at: Time.current)
|
|
112
|
+
else
|
|
113
|
+
payment.update_columns(status: 'void', updated_at: Time.current)
|
|
114
|
+
end
|
|
115
|
+
refresh_owner(payment)
|
|
116
|
+
tally(:marked_done)
|
|
117
|
+
true
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# The column writes skip the payment events that keep the order's paid
|
|
121
|
+
# total and payment status current, so they are refreshed here instead.
|
|
122
|
+
def refresh_owner(payment)
|
|
123
|
+
owner = payment.owner
|
|
124
|
+
owner.refresh_payment_total! if owner.respond_to?(:refresh_payment_total!)
|
|
125
|
+
owner.update_statuses! if owner.is_a?(Spree::Order)
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
@@ -1,59 +1,66 @@
|
|
|
1
1
|
module Spree
|
|
2
|
+
# Stored under this name in `type` columns since 5.x, so it is kept.
|
|
2
3
|
class PaymentSessions::Adyen < PaymentSession
|
|
3
|
-
|
|
4
|
-
ios: 'iOS',
|
|
5
|
-
android: 'Android',
|
|
6
|
-
web: 'Web'
|
|
7
|
-
}.freeze
|
|
8
|
-
|
|
9
|
-
# Adyen-specific accessors from external_data
|
|
10
|
-
def adyen_id
|
|
11
|
-
external_id
|
|
12
|
-
end
|
|
13
|
-
|
|
4
|
+
# @return [String, nil] what Drop-in loads the session with
|
|
14
5
|
def session_data
|
|
15
6
|
external_data&.dig('session_data')
|
|
16
7
|
end
|
|
17
8
|
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
# Whether Spree made the session payable; after that its amount is fixed.
|
|
10
|
+
def payable?
|
|
11
|
+
ActiveModel::Type::Boolean.new.cast(external_data&.dig('payable')) || false
|
|
20
12
|
end
|
|
21
13
|
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
# What the session asked Adyen for at creation, so a webhook is mapped by
|
|
15
|
+
# it rather than by the method's setting when the webhook arrives.
|
|
16
|
+
def manual_capture?
|
|
17
|
+
ActiveModel::Type::Boolean.new.cast(external_data&.dig('manual_capture')) || false
|
|
24
18
|
end
|
|
25
19
|
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
# Nothing reaches the webhook path to build it from, so the source is
|
|
21
|
+
# attached by apply_settlement_metadata from the report instead.
|
|
22
|
+
def payment_source_for_settlement
|
|
23
|
+
nil
|
|
28
24
|
end
|
|
29
25
|
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
# Records the PSP reference and the variant, and attaches the source the
|
|
27
|
+
# report describes. Never merges the raw report.
|
|
28
|
+
#
|
|
29
|
+
# @param payment [Spree::Payment] unsaved
|
|
30
|
+
# @param metadata [Hash] SpreeAdyen::Result#to_h
|
|
31
|
+
def apply_settlement_metadata(payment, metadata)
|
|
32
|
+
result = SpreeAdyen::Result.from_h(metadata)
|
|
33
|
+
payment.metadata = payment.metadata.merge(
|
|
34
|
+
'adyen_psp_reference' => result.psp_reference, 'adyen_variant' => result.variant
|
|
35
|
+
).compact
|
|
36
|
+
payment.source = settlement_source(result)
|
|
32
37
|
end
|
|
33
38
|
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
# The PSP reference, written on the capture event of a payment that settles
|
|
40
|
+
# as captured, so a late CAPTURE_FAILED finds it.
|
|
41
|
+
def capture_reference_for_settlement(payment)
|
|
42
|
+
payment.metadata['adyen_psp_reference']
|
|
36
43
|
end
|
|
37
44
|
|
|
38
|
-
|
|
39
|
-
return unless persisted?
|
|
40
|
-
return payment if payment.present?
|
|
45
|
+
private
|
|
41
46
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
payment_method: payment_method,
|
|
45
|
-
response_code: external_id
|
|
46
|
-
).first
|
|
47
|
+
def settlement_source(result)
|
|
48
|
+
return if result.psp_reference.blank?
|
|
47
49
|
|
|
48
|
-
|
|
50
|
+
if SpreeAdyen::Variants.card?(result.variant)
|
|
51
|
+
return payment_method.credit_card_from(result, customer: customer) if result.stored_payment_method_id.present? && customer
|
|
49
52
|
|
|
50
|
-
|
|
51
|
-
payment_method: payment_method,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
skip_source_requirement: true
|
|
53
|
+
return SpreeAdyen::PaymentSources::Card.create!(
|
|
54
|
+
payment_method: payment_method, customer: customer, gateway_payment_profile_id: result.psp_reference,
|
|
55
|
+
adyen_variant: result.variant, brand: SpreeAdyen::Variants.card_brand(result.variant),
|
|
56
|
+
last_digits: result.card_summary, wallet: SpreeAdyen::Variants.wallet(result.variant)
|
|
55
57
|
)
|
|
56
58
|
end
|
|
59
|
+
|
|
60
|
+
SpreeAdyen::Variants.source_class(result.variant).create!(
|
|
61
|
+
payment_method: payment_method, customer: customer, gateway_payment_profile_id: result.psp_reference,
|
|
62
|
+
adyen_variant: result.variant
|
|
63
|
+
)
|
|
57
64
|
end
|
|
58
65
|
end
|
|
59
66
|
end
|
|
@@ -1,29 +1,5 @@
|
|
|
1
1
|
module Spree
|
|
2
|
+
# Stored under this name in `type` columns since 5.x, so it is kept.
|
|
2
3
|
class PaymentSetupSessions::Adyen < PaymentSetupSession
|
|
3
|
-
delegate :preferred_client_key, to: :payment_method
|
|
4
|
-
|
|
5
|
-
def adyen_id
|
|
6
|
-
external_id
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def session_data
|
|
10
|
-
external_data&.dig('session_data')
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def client_key
|
|
14
|
-
preferred_client_key
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def channel
|
|
18
|
-
external_data&.dig('channel') || Spree::PaymentSessions::Adyen::AVAILABLE_CHANNELS[:web]
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def return_url
|
|
22
|
-
external_data&.dig('return_url')
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def successful?
|
|
26
|
-
status == 'completed'
|
|
27
|
-
end
|
|
28
4
|
end
|
|
29
5
|
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
module SpreeAdyen
|
|
2
|
+
# Adyen's integer amounts, in the decimals Adyen publishes per currency
|
|
3
|
+
# (https://docs.adyen.com/development-resources/currency-codes), which are
|
|
4
|
+
# leading over ISO 4217: CLP and ISK take two decimals, CVE and IDR none. An
|
|
5
|
+
# amount Adyen cannot represent raises, naming the rule, rather than being
|
|
6
|
+
# rounded to a sum other than the one Spree records.
|
|
7
|
+
module Amounts
|
|
8
|
+
module_function
|
|
9
|
+
|
|
10
|
+
ZERO_DECIMAL = %w[CVE DJF GNF IDR JPY KMF KRW PYG RWF UGX VND VUV XAF XOF XPF].freeze
|
|
11
|
+
THREE_DECIMAL = %w[BHD IQD JOD KWD LYD OMR TND].freeze
|
|
12
|
+
TWO_DECIMAL = %w[
|
|
13
|
+
AED ALL AMD AOA ARS AUD AWG AZN BAM BBD BDT BMD BND BOB BRL BSD BWP BYN BZD CAD CHF CLP CNH CNY COP CRC
|
|
14
|
+
CUP CZK DKK DOP DZD EGP ETB EUR FJD FKP GBP GEL GHS GIP GMD GTQ GYD HKD HNL HTG HUF ILS INR ISK JMD KES
|
|
15
|
+
KGS KHR KYD KZT LAK LKR MAD MDL MKD MMK MNT MOP MRU MUR MVR MWK MXN MYR MZN NAD NGN NIO NOK NPR NZD PAB
|
|
16
|
+
PEN PGK PHP PKR PLN QAR RON RSD RUB SAR SBD SCR SEK SGD SHP SLE SOS SRD STN SVC SZL THB TOP TRY TTD TWD
|
|
17
|
+
TZS UAH USD UYU UZS VEF WST XCD XCG YER ZAR ZMW
|
|
18
|
+
].freeze
|
|
19
|
+
|
|
20
|
+
class UnsupportedAmount < Spree::Core::GatewayError; end
|
|
21
|
+
|
|
22
|
+
# @param currency [String]
|
|
23
|
+
# @return [Boolean] whether Adyen takes the currency
|
|
24
|
+
def supported?(currency)
|
|
25
|
+
!decimals_for(currency).nil?
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# @param amount [BigDecimal, Spree::Money]
|
|
29
|
+
# @param currency [String]
|
|
30
|
+
# @return [Integer] minor units as Adyen expects them
|
|
31
|
+
# @raise [UnsupportedAmount] for a currency Adyen does not take, or an
|
|
32
|
+
# amount finer than its decimals
|
|
33
|
+
def to_adyen(amount, currency)
|
|
34
|
+
code = currency.to_s.upcase
|
|
35
|
+
decimals = decimals_for!(code)
|
|
36
|
+
amount = amount.to_d
|
|
37
|
+
units = amount * (10**decimals)
|
|
38
|
+
raise UnsupportedAmount, "Adyen takes #{code} with #{decimals} decimals, got #{amount.to_s('F')}" unless units.frac.zero?
|
|
39
|
+
|
|
40
|
+
units.to_i
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# @param units [Integer] as Adyen reports them
|
|
44
|
+
# @param currency [String]
|
|
45
|
+
# @return [BigDecimal]
|
|
46
|
+
def from_adyen(units, currency)
|
|
47
|
+
BigDecimal(units.to_s) / (10**decimals_for!(currency))
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# The `amount` object Adyen's requests take.
|
|
51
|
+
#
|
|
52
|
+
# @return [Hash]
|
|
53
|
+
def to_adyen_amount(amount, currency)
|
|
54
|
+
{ value: to_adyen(amount, currency), currency: currency.to_s.upcase }
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def decimals_for!(currency)
|
|
58
|
+
decimals_for(currency) || raise(UnsupportedAmount, "Adyen does not take #{currency.to_s.upcase}")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def decimals_for(currency)
|
|
62
|
+
code = currency.to_s.upcase
|
|
63
|
+
return 0 if ZERO_DECIMAL.include?(code)
|
|
64
|
+
return 3 if THREE_DECIMAL.include?(code)
|
|
65
|
+
|
|
66
|
+
2 if TWO_DECIMAL.include?(code)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|