Problem/Motivation
- The gateway's configuration has no config schema.
- Every
balances#updatenotification creates a completed payment. Wise resends a notification it got no 200 for, and sends one per webhook subscription, so one deposit can be recorded several times. The payment's remote ID isbalance_id, the ID of the balance account, which is the same for every deposit. - The order is placed whatever amount arrived, so a partial deposit places it.
- Debits count as deposits.
balances#updatealso fires for money going out (transaction_type: debit); a payment made from the account with a numeric reference records a payment for, and places, the order with that ID. - Any
is_numeric()reference ("12.5", "1e3") loads an order. Every site on a Wise account receives every deposit, so when sites share an account, a deposit for one site's order 42 pays another site's order 42. - A deposit in another currency than the order's is recorded, and summing the order's payments then throws
CurrencyMismatchException. - A request without
X-Signature-SHA256ends in a TypeError (500). An invalid signature is answered 200 and not logged, so a wrong public key drops payments silently. - Test notifications (
X-Test-Notification: true) are processed like real ones. - The pay link asks for the order total, not its balance, with six decimals ("243.750000"), and its description is not URL-encoded.
Proposed resolution
- Add
config/schema/commerce_wise.schema.yml. - Handle only credits with a positive amount. Answer 200 to debits, test notifications and references that name no order, and do nothing with them.
- Use
data.step_id(falling back toX-Delivery-Id) as the payment's remote ID, and skip a deposit that is already recorded. Load the order withOrderStorage::loadForUpdate(), so deliveries arriving together are handled one after the other. - Do not record a deposit in another currency than the order's; log it.
- Place a draft order only when the deposit covers what the pay link asks for (the order's balance, or what a
QuickPayLinkEventsubscriber set, such as a down payment), or when the order is fully paid. Setcheckout_steptocompleteand unlock it, as checkout does. A smaller deposit is recorded and the order stays in checkout. A deposit for a placed order only adds a payment. - Add an optional "Reference prefix" setting (e.g.
SHOP-42); a reference without it names no order. Without a prefix, only a plain number matches. - Answer a missing or invalid signature with 403 and log a warning.
- Make the pay link ask for the order's balance, rounded and without trailing zeros, with the query URL-encoded.
- Add kernel tests.
- API changes:
QuickPayInterface::getReferencePrefix();QuickPay::createPayment(OrderInterface $order, Price $amount, ?string $remote_id); payments' remote ID is now Wise's step ID.
Issue fork commerce_wise-3637383
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
valic