spree-bank_payments 5.2.0 → 6.0.0
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/CHANGELOG.md +201 -0
- data/README.md +275 -115
- data/Rakefile +39 -1
- data/app/controllers/concerns/spree/bank_payments/release_on_other_method.rb +56 -0
- data/app/controllers/spree/api/v3/admin/bank_payments/accounts_controller.rb +135 -0
- data/app/controllers/spree/api/v3/admin/bank_payments/health_controller.rb +44 -0
- data/app/controllers/spree/api/v3/admin/bank_payments/orders_controller.rb +44 -0
- data/app/controllers/spree/api/v3/admin/bank_payments/payment_methods_controller.rb +32 -0
- data/app/controllers/spree/api/v3/admin/bank_payments/resource_controller.rb +40 -0
- data/app/controllers/spree/api/v3/admin/bank_payments/transfers_controller.rb +179 -0
- data/app/jobs/spree/bank_payments/expire_sessions_job.rb +67 -57
- data/app/jobs/spree/bank_payments/poll_job.rb +59 -0
- data/app/jobs/spree/bank_payments/send_reminders_job.rb +4 -1
- data/app/mailers/spree/bank_payments/instructions_mailer.rb +7 -4
- data/app/models/spree/bank_payments/account_data.rb +8 -3
- data/app/models/spree/bank_payments/adjusters/discount.rb +99 -0
- data/app/models/spree/bank_payments/bank_account.rb +3 -0
- data/app/models/spree/bank_payments/base.rb +8 -0
- data/app/models/spree/bank_payments/current.rb +10 -0
- data/app/models/spree/bank_payments/gateway.rb +315 -75
- data/app/models/spree/bank_payments/incoming_transfer.rb +5 -0
- data/app/models/spree/bank_payments/reconciler_state.rb +10 -0
- data/app/models/spree/bank_payments/reconcilers/base.rb +26 -1
- data/app/models/spree/bank_payments/reconcilers/manual.rb +4 -2
- data/app/models/spree/payment_sessions/bank_transfer.rb +80 -9
- data/app/serializers/spree/api/v3/admin/bank_payments/bank_account_serializer.rb +23 -0
- data/app/serializers/spree/api/v3/admin/bank_payments/incoming_transfer_serializer.rb +48 -0
- data/app/serializers/spree/api/v3/admin/bank_payments/payment_session_serializer.rb +21 -0
- data/app/serializers/spree/api/v3/admin/bank_payments/suggestion_serializer.rb +40 -0
- data/app/services/spree/bank_payments/apply_transfer.rb +74 -45
- data/app/services/spree/bank_payments/guard_capture.rb +17 -0
- data/app/services/spree/bank_payments/health_reporter.rb +124 -0
- data/app/services/spree/bank_payments/ignore_transfer.rb +37 -0
- data/app/services/spree/bank_payments/ingest_transfer.rb +16 -4
- data/app/services/spree/bank_payments/migrate_legacy_accounts.rb +5 -1
- data/app/services/spree/bank_payments/migrate_legacy_discounts.rb +82 -0
- data/app/services/spree/bank_payments/record_manual_transfer.rb +115 -0
- data/app/services/spree/bank_payments/release_selection.rb +58 -0
- data/app/services/spree/bank_payments/settle_at_completion.rb +35 -0
- data/app/services/spree/bank_payments/suggest_matches.rb +7 -3
- data/app/services/spree/bank_payments/sync_accounts.rb +2 -1
- data/app/subscribers/spree/bank_payments/instructions_mailer_subscriber.rb +29 -0
- data/app/subscribers/spree/bank_payments/order_placed_subscriber.rb +31 -0
- data/app/views/spree/bank_payments/instructions_mailer/instructions.html.erb +5 -5
- data/app/views/spree/bank_payments/instructions_mailer/reminder.html.erb +6 -6
- data/config/initializers/spree.rb +50 -56
- data/config/locales/en.yml +22 -0
- data/config/routes.rb +23 -15
- data/db/migrate/20260817000007_add_health_to_reconciler_states.rb +7 -0
- data/db/migrate/20260817000008_add_pooled_to_bank_accounts.rb +5 -0
- data/lib/spree/bank_payments/api_fields.rb +39 -0
- data/lib/spree/bank_payments/events.rb +36 -0
- data/lib/spree/bank_payments/factories.rb +10 -5
- data/lib/spree/bank_payments/testing_support/reconciler_shared_examples.rb +4 -0
- data/lib/spree/bank_payments/version.rb +2 -2
- data/lib/spree/bank_payments.rb +27 -57
- data/lib/tasks/spree_bank_payments.rake +9 -0
- metadata +33 -65
- data/app/controllers/spree/admin/bank_accounts_controller.rb +0 -134
- data/app/controllers/spree/admin/bank_transfers_controller.rb +0 -287
- data/app/models/spree/bank_payments/adjuster/discount.rb +0 -55
- data/app/models/spree/bank_payments/payment_decorator.rb +0 -22
- data/app/services/spree/bank_payments/apply_discount.rb +0 -154
- data/app/views/spree/admin/bank_accounts/_form.html.erb +0 -33
- data/app/views/spree/admin/bank_accounts/edit.html.erb +0 -3
- data/app/views/spree/admin/bank_accounts/index.html.erb +0 -71
- data/app/views/spree/admin/bank_accounts/new.html.erb +0 -3
- data/app/views/spree/admin/bank_transfers/index.html.erb +0 -75
- data/app/views/spree/admin/bank_transfers/new.html.erb +0 -46
- data/app/views/spree/admin/payment_methods/configuration_guides/_spree_bank_payments.html.erb +0 -52
- data/app/views/spree/admin/payment_methods/descriptions/_spree_bank_payments.html.erb +0 -4
- data/app/views/spree/bank_payments/_order_instructions.html.erb +0 -82
- data/app/views/spree/bank_payments/admin/_order_panel.html.erb +0 -55
- data/app/views/spree/checkout/payment/_spree_bank_payments.html.erb +0 -13
- data/lib/spree/bank_payments/subscribers.rb +0 -42
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 691381c2f0df4208b375a5d717b71965f00ce2151104ad709efa8ccc4267b3bc
|
|
4
|
+
data.tar.gz: 8e65b580952f031b481730037abcee943117eedc0e529716667e9791103aefa5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 16c6e9ffe0a561e23da7d9a2c28a62f8738476f775b965a87cf73f2d4ea24413fcf5c0ec84c8d35d406080d912ef4df854161474c3986b1706d5983ff0aee20d
|
|
7
|
+
data.tar.gz: 8c1378d1095f1d0f826cf2772e5ce041a40df623d1980db99bda60a01c7843066176d0c535456f70cff9cd577aeeaadfc55d3491d99b81f49f66b91e44cb24f3
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,207 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project are documented in this file.
|
|
4
4
|
|
|
5
|
+
## 6.0.0
|
|
6
|
+
|
|
7
|
+
Spree 6 support. The major version tracks Spree's, so 6.x supports Spree 6.
|
|
8
|
+
Spree 5.6 stays on 5.3.x, on the `5-3-stable` branch. To upgrade, see
|
|
9
|
+
[docs/upgrading-5-to-6.md](docs/upgrading-5-to-6.md).
|
|
10
|
+
|
|
11
|
+
### Requirements
|
|
12
|
+
|
|
13
|
+
- Spree `~> 6.0` and Ruby 3.3 or newer. The 5.x releases do not install on
|
|
14
|
+
Spree 6.
|
|
15
|
+
- The `spree_admin` dependency is gone: Spree 6 has no Rails admin.
|
|
16
|
+
|
|
17
|
+
### Removed
|
|
18
|
+
|
|
19
|
+
- **The Rails admin screens**: the unmatched-transfers queue, the "record a
|
|
20
|
+
received transfer" form, the bank accounts screen, the sidebar entry, the
|
|
21
|
+
order panel partial and the payment method configuration guide. Spree 6's
|
|
22
|
+
dashboard plugin replaces them (see "The dashboard" below).
|
|
23
|
+
- **The Rails storefront partials** (the checkout payment partial and
|
|
24
|
+
`spree/bank_payments/_order_instructions`). A storefront reads the quote
|
|
25
|
+
from the Store API instead.
|
|
26
|
+
- `Gateway#bank_details` (deprecated in 5.2.0), `#method_type`,
|
|
27
|
+
`#description_partial_name`, `#configuration_guide_partial_name` and
|
|
28
|
+
`#auto_capture?`.
|
|
29
|
+
- `Spree::BankPayments.gateway_type_names` and `.gateway_scope`.
|
|
30
|
+
|
|
31
|
+
### The dashboard
|
|
32
|
+
|
|
33
|
+
- **A Spree dashboard plugin**, `@aypex-io/spree-bank-payments-dashboard` on
|
|
34
|
+
npm, released with the gem at the same version. `pnpm add` it in the
|
|
35
|
+
dashboard app and the next build picks it up. It brings back the 5.x
|
|
36
|
+
screens: the unmatched-transfers queue under Orders, each transfer's
|
|
37
|
+
possible matches with Apply and Ignore, recording a received transfer, the
|
|
38
|
+
bank accounts screen, a Bank transfer card on the order page and the
|
|
39
|
+
payment method's setup guide.
|
|
40
|
+
- **Applying a transfer for a different amount asks first.** The Admin API
|
|
41
|
+
answers 422 `amount_mismatch`, with both amounts, until the request
|
|
42
|
+
confirms with `confirm_mismatch`.
|
|
43
|
+
- **Accounts can be added by hand** from the dashboard, for the `manual`
|
|
44
|
+
reconciler. Sync from provider is offered only for a provider's
|
|
45
|
+
reconciler, as in 5.x.
|
|
46
|
+
- **An Admin API** under `/api/v3/admin/bank_payments`: transfers (list,
|
|
47
|
+
show, suggestions, record, apply, ignore), the store's bank transfer
|
|
48
|
+
payment methods, each one's accounts (list, create, update, delete, sync
|
|
49
|
+
plan, sync) and reconciler health, and an order's bank transfer. Transfers and accounts have prefixed ids,
|
|
50
|
+
`btxfr_` and `bacct_`.
|
|
51
|
+
- **A Bank transfers permission** for staff roles (`read_bank_payments`,
|
|
52
|
+
`write_bank_payments`): read to see the queue, write to act on it.
|
|
53
|
+
|
|
54
|
+
### Checkout
|
|
55
|
+
|
|
56
|
+
- **The gateway is session-based** and its API type is `bank_transfer`.
|
|
57
|
+
Creating a payment session quotes the cart: a fresh reference, the amount
|
|
58
|
+
due after the discount, the deadline and the bank details, under
|
|
59
|
+
`external_data.bank_transfer`, which a client cannot write. Completing the
|
|
60
|
+
session re-quotes, then leaves a pending payment carrying the reference, so
|
|
61
|
+
Spree places the order unpaid (`payment_status` `authorized`).
|
|
62
|
+
- **Changing the cart after choosing bank transfer** re-quotes it, up to the
|
|
63
|
+
moment the order is placed: completing the session re-quotes, and so does
|
|
64
|
+
completing the cart, under Spree's lock. The quote, the pending payment and
|
|
65
|
+
the order total are always equal.
|
|
66
|
+
- **A released, expired or completed session cannot be completed again**
|
|
67
|
+
(or updated): the Store API answers 422, so an order is never placed
|
|
68
|
+
against a reference nothing will match.
|
|
69
|
+
- **Switching to another payment method releases bank transfer first.**
|
|
70
|
+
Before the Store API creates another method's session or payment, or
|
|
71
|
+
updates or completes one created earlier, the bank transfer session is
|
|
72
|
+
cancelled, its payment voided and the discount recalculated away, so the
|
|
73
|
+
other method charges the full total. A request Spree refuses releases
|
|
74
|
+
nothing. A bank transfer session the buyer never completed is released when
|
|
75
|
+
the cart completes, so an order is never placed on a discount bank transfer
|
|
76
|
+
is not paying.
|
|
77
|
+
- **Spree holds dispatch of an unpaid bank transfer order** unless staff
|
|
78
|
+
force it: the gateway captures at checkout, so its pending payment does not
|
|
79
|
+
count as money staff have taken charge of collecting. `authorize` and
|
|
80
|
+
`purchase` refuse, and the dashboard offers no Capture: Spree's capture
|
|
81
|
+
workflow refuses a bank transfer payment unless a transfer is being applied
|
|
82
|
+
to it. Money moves only when a transfer is reconciled.
|
|
83
|
+
- **The Store API shows the quote**: a bank transfer payment, on the cart and
|
|
84
|
+
on the order, carries a `bank_transfer` field with the reference, amount,
|
|
85
|
+
deadline and bank details. The payment method carries
|
|
86
|
+
`bank_transfer.discount_percent` and `expiry_days`.
|
|
87
|
+
|
|
88
|
+
### Discount
|
|
89
|
+
|
|
90
|
+
- Written as one `manual` `Spree::Discount` per line item, found by
|
|
91
|
+
`metadata.source = "spree_bank_payments"`, through an adjuster registered in
|
|
92
|
+
`Spree.adjusters`. The figures do not change: 3% off a 20% VAT-inclusive
|
|
93
|
+
100.00 line records 16.17 VAT, and a 20% promotion plus 3% is 23%. Shares
|
|
94
|
+
round to the currency's own minor unit.
|
|
95
|
+
|
|
96
|
+
### Reconciliation and expiry
|
|
97
|
+
|
|
98
|
+
- A transfer settles through `Spree.payment_capture_workflow`, so Spree
|
|
99
|
+
records the capture and publishes `payment.captured`. Under the order's
|
|
100
|
+
lock it re-checks that the session is still open and the order still
|
|
101
|
+
placed, so a second transfer racing the first queues rather than being
|
|
102
|
+
marked applied with nothing captured.
|
|
103
|
+
- **Only placed orders reconcile automatically.** A transfer quoting a
|
|
104
|
+
reference from a checkout that was never placed queues for a person, and is
|
|
105
|
+
never suggested; it is not used to place the cart.
|
|
106
|
+
- `parse_webhook_event` ingests the transfer and returns `nil`, so Spree's
|
|
107
|
+
webhook workflow has nothing to settle a second time.
|
|
108
|
+
- An unpaid placed order past its deadline is cancelled through
|
|
109
|
+
`Spree.order_cancel_workflow`, which releases its stock and voids the
|
|
110
|
+
payment, with a staff note. A cancel Spree refuses, or one that raises,
|
|
111
|
+
leaves the session open and reports `bank_transfer.expiry_failed`, and the
|
|
112
|
+
run carries on with the next session. A session whose checkout was never
|
|
113
|
+
placed is expired silently.
|
|
114
|
+
- An order counts as paid when its `payment_status` is `paid`, `overcharged`,
|
|
115
|
+
`partially_refunded` or `refunded`: it is never cancelled for an unpaid
|
|
116
|
+
transfer, and a transfer for it queues for a person.
|
|
117
|
+
- **Upgrading:** Spree's own upgrade writes each 5.x bank transfer discount as
|
|
118
|
+
a 0.00 surcharge. Run `bin/rails spree_bank_payments:upgrade:legacy_discounts`
|
|
119
|
+
after `spree:upgrade` to restore them as discounts; otherwise the next
|
|
120
|
+
re-sum of such an order raises its total by the discount.
|
|
121
|
+
|
|
122
|
+
### Events and email
|
|
123
|
+
|
|
124
|
+
- **Instructions are sent when the order is placed**, not when the session is
|
|
125
|
+
created, and the payment window starts then. Reminders go only to placed
|
|
126
|
+
orders.
|
|
127
|
+
- Every event is declared. The operational ones
|
|
128
|
+
(`reconciler_unhealthy`, `expiry_failed`, `reconciler_health.*`) are
|
|
129
|
+
declared `webhook: false`: their payloads carry error text.
|
|
130
|
+
- Events are published under the gateway's store, so they reach webhook
|
|
131
|
+
endpoints from the background jobs too.
|
|
132
|
+
- **Payloads use string keys and prefixed ids** (`ps_...`, `pm_...`), and the
|
|
133
|
+
customer-facing payload adds `order_id`, `discount_percent` and
|
|
134
|
+
`bank_details`. A subscriber reading `payload[:payment_session_id]` must
|
|
135
|
+
read `payload['payment_session_id']`.
|
|
136
|
+
- The default mailer is `Spree::BankPayments::InstructionsMailerSubscriber`,
|
|
137
|
+
registered through `Spree.subscribers`. 5.x subscribed blocks from
|
|
138
|
+
`to_prepare`, which on Spree 6 stopped every one of Spree's own subscribers
|
|
139
|
+
from registering. `InstructionsMailer` takes the session's prefixed id.
|
|
140
|
+
|
|
141
|
+
## 5.3.0
|
|
142
|
+
|
|
143
|
+
### Upgrading from 5.2.0
|
|
144
|
+
|
|
145
|
+
Adds columns, so this is not gem-bump-only:
|
|
146
|
+
|
|
147
|
+
```sh
|
|
148
|
+
bin/rails spree_bank_payments:install:migrations
|
|
149
|
+
bin/rails db:migrate
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
**Run the migration before or with the deploy, never after.** `Gateway#health`
|
|
153
|
+
reads `reconciler_state.health_status`, and it is now on the checkout path.
|
|
154
|
+
In a rolling deploy, any pod running 5.3.0 against the 5.2.0 schema raises
|
|
155
|
+
`NoMethodError` on `health_status` for every non-Manual gateway — a checkout
|
|
156
|
+
500 for the whole window between the code going out and the migration landing.
|
|
157
|
+
The columns are additive and nullable, so 5.2.0 pods are perfectly happy
|
|
158
|
+
against the 5.3.0 schema; migrate first and the window does not exist.
|
|
159
|
+
|
|
160
|
+
**A revoked consent means unpaid orders stop expiring.** `ExpireSessionsJob`
|
|
161
|
+
gates on `reconciler_healthy?` and refuses to cancel while it cannot see the
|
|
162
|
+
bank, which is correct — cancelling orders customers have already paid for is
|
|
163
|
+
the worse failure. But `:consent_revoked` is by definition a state that never
|
|
164
|
+
resolves on its own, so from the moment it is reported, unpaid orders and the
|
|
165
|
+
stock they reserve accumulate until a human re-authorises the provider. Alert
|
|
166
|
+
on `reason="consent_revoked"` and treat it as a page, not a ticket.
|
|
167
|
+
|
|
168
|
+
### Added
|
|
169
|
+
|
|
170
|
+
**Three-state reconciler health.** `Reconcilers::Base#health` returns `:ok`,
|
|
171
|
+
`:transient` or `:consent_revoked`. A boolean could not separate a retryable
|
|
172
|
+
provider outage from a dead authorisation, and the two need different responses:
|
|
173
|
+
`:transient` keeps offering at checkout, because those transfers still arrive
|
|
174
|
+
and reconcile once the provider returns, while `:consent_revoked` withdraws the
|
|
175
|
+
payment method, because nothing will ever reconcile against it.
|
|
176
|
+
|
|
177
|
+
**Backward compatible.** A reconciler written against 5.1.1 or 5.2.0, overriding
|
|
178
|
+
only `#healthy?`, works unmodified — `#health` derives from it. A reconciler
|
|
179
|
+
overriding only `#health` gets `#healthy?` derived in turn.
|
|
180
|
+
|
|
181
|
+
**Health transition logging, owned by core.** Logged on transition and at most
|
|
182
|
+
hourly thereafter, with a stable `event=` key so alert rules never depend on
|
|
183
|
+
prose. `:transient` logs WARN, `:consent_revoked` logs ERROR, recovery logs INFO.
|
|
184
|
+
`bank_transfer.reconciler_health.unhealthy` and
|
|
185
|
+
`bank_transfer.reconciler_health.recovered` are also published through
|
|
186
|
+
`Spree::Events`. They sit under the same `bank_transfer.` prefix as every other
|
|
187
|
+
event this gem publishes, so `Spree::Events.subscribe('bank_transfer.*', …)` —
|
|
188
|
+
the pattern the README documents — receives them.
|
|
189
|
+
|
|
190
|
+
Note these are distinct from the flat `bank_transfer.reconciler_unhealthy`
|
|
191
|
+
published by `ExpireSessionsJob`, which is unchanged: that one says the expiry
|
|
192
|
+
job declined to cancel anything, this pair reports the reconciler's own health.
|
|
193
|
+
|
|
194
|
+
The `reason` is drawn from a closed enum — `ok`, `provider_error`,
|
|
195
|
+
`consent_revoked`, `unknown` — and unrecognised values collapse to `unknown`.
|
|
196
|
+
It is never built from an exception message or a response body. The enum is
|
|
197
|
+
deliberately only what core can actually emit: widening it later is
|
|
198
|
+
non-breaking, narrowing it is not.
|
|
199
|
+
|
|
200
|
+
**`pooled` on bank accounts.** Carried from `AccountData` through `SyncAccounts`.
|
|
201
|
+
A pooled account shares its coordinates with other customers of the provider, so
|
|
202
|
+
the payment reference is the only thing separating two payers. Auto-apply has
|
|
203
|
+
always required an exact reference match; `spec/services/spree/bank_payments/pooled_account_matching_spec.rb`
|
|
204
|
+
now locks that invariant explicitly.
|
|
205
|
+
|
|
5
206
|
## 5.2.0
|
|
6
207
|
|
|
7
208
|
### Upgrading from 5.1.1
|