Commit graph catcrafts.net/server/implementations/Catcrafts.Server-Transfer.cpp
Author SHA1 Message Date
3c61116531
bank: a payment is spent once
A payer could place several orders and send one transfer naming all of
them. Each order looked for its own reference, found it, and saw the
full amount, so every order settled on one payment: three EUR 5 orders
on a single EUR 5 credit, reproduced. The rail logged "settle this one
by hand" and settled each of them. The README called it a known
limitation; it was a way to pay once for several orders.

The rail now records which payment settled which order, by the bank's
id, in <credits>.claims, before it reports the order paid, and a claimed
payment is left out of every other order's sum. The record cannot live
in the credits file, which the pull replaces every hour. It is read back
at start. If it cannot be written the rail settles nothing and says why;
if it is there and cannot be read the rail does not start. A claims
file that ends mid-line gets its line break before the next claim, or
that claim would be lost at the next start and the payment free again.

It does not rest on what a description looks like, because the payer
writes it. The "also quotes another reference" flag stays as a pointer
in the log and decides nothing: a name followed by a date has the same
shape. A payer who really sends one transfer for two orders gets the
first settled and the other by hand, with one line in the journal.

One payment is also counted once however many lines of the credits file
carry its id. Two lines are not meant to happen and were reproduced all
the same (one callback delivered on two connections at once passed the
id check twice), and summed they settle an order on half its price. The
callback's look-then-append is now under a lock as well.

ShouldMatchBankTransfers drives the matcher and the rail itself across
a restart, a torn claims file, an unreadable one and a duplicated line;
ShouldSettleBankTransfers shows over HTTP that one of three orders
settles.

Found in the security review of 2026-11-26; the torn claims file and
the duplicate line by the adversarial review of the first fix.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
2026-11-26 11:05:35 +01:00
33ce8f45d8
bank: Nostro reads the bank's callback, and the shop's bunq code is gone
All checks were successful
Deploy / build-deploy (push) Successful in 7m20s
The shadow run of 36a635f had Nostro's ReadCallback read a real
callback beside our own parser on 2026-11-25, for order CC-BCD155: the
same id, amount and reference, on the shop's own account. So the reader
takes over, and what this repo carried of bunq goes: the callback
parser, the payment-type table, the API client with its RSA signing,
`--pull-credits`, the mode that read the bank from the server with an
API key, and tools/register-bunq-webhook.sh.

The server now knows no bank. Catcrafts.Server-BankCallback.cpp is the
one unit that imports Nostro.Money: ReadBankCallback has a body read
and says what it comes to, CreditMethodFor says how a payment arrived.
Which bank it is is configuration: --banks= in project.cpp for what the
build can read, BANK_CALLBACK_BANK on the server for what arrives.

What changes for a running shop:

- The endpoint is configured with BANK_CALLBACK_PATH and
  BANK_CALLBACK_BANK; BUNQ_WEBHOOK_PATH is no longer read. Without the
  bank's name, or without TRANSFER_IBAN, the endpoint stays off and the
  startup log says so: one that answered 200 and credited nothing would
  look like working. Production's payments.env got both names before
  this was pushed.
- Only a payment on TRANSFER_IBAN is credited. A bank posts to whatever
  address any of its customers registered, so a callback about someone
  else's account can be the bank's own. Until now a payment in a
  callback was credited whichever account it was on.
- `via` says `internal` for a payment from another account at the bank
  itself, where it said `bunq`, and `card` where it would have said
  `MASTERCARD`. A kind without a word is still passed on as the bank
  wrote it, now only where that is a plain word.
- Every callback leaves one line in the log, `bank callback: credited
  ...` or `bank callback: nothing credited: <why>`, with nothing of the
  body in it beyond the credit.
- A line of the credits file may carry the bank's kind and the bank
  (`"bank":"bunq","kind":"EBA_SCT/SCT"`) in place of `method`, put into
  the ledger's words when the file is read. The pull script ships those
  and takes the bank's name from nostrod, so it holds no table of a
  bank's words either.

Also gone, with their last user: ParseAmountToMinor, PullCreditsInto
and the explicit -lcrypto (Crafter.Network names what it needs).

ShouldReadBankCallbacks replaces ShouldParseBunqPayments and
ShouldCompareCallbackReaders: what a callback comes to for each shape,
each method, the account and the sign, and that no note repeats
anything a body carried. ShouldReceiveBankCallbacks posts to the real
endpoint: an order settles from a callback, one from another account
quoting the same order does not pay for it, and a server without the
bank's name has no endpoint.

Built from scratch and run in a copy of this tree with crafter-build
6.4.1: the server and the wasm bundle build, and every suite passes but
ShouldServePostPages, which fails there for want of mirrored post media
and passed in CI on the commit before this. A dry run of the pull
script against nostrod gave 19 credits with their kinds.

Not tried: a real callback through the new handler, and `nostro
callbacks` against the registration that is in place, which was made
with the script this removes. deploy/README.md has the new setup.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-25 15:08:42 +01:00
aaa7a8ce99 bank tranfer fix
All checks were successful
Deploy / build-deploy (push) Successful in 3m11s
2026-08-20 23:33:50 +02:00
df91762271 Replaced mollie
All checks were successful
Deploy / build-deploy (push) Successful in 3m47s
2026-08-20 20:15:47 +02:00