Problem/Motivation

  • The gateway's configuration has no config schema.
  • Every balances#update notification 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 is balance_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#update also 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-SHA256 ends 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 to X-Delivery-Id) as the payment's remote ID, and skip a deposit that is already recorded. Load the order with OrderStorage::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 QuickPayLinkEvent subscriber set, such as a down payment), or when the order is fully paid. Set checkout_step to complete and 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.
Command icon 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

valic created an issue. See original summary.

valic’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.