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
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>
This commit is contained in:
parent
36a635fd48
commit
33ce8f45d8
24 changed files with 1218 additions and 2385 deletions
|
|
@ -6,8 +6,7 @@ The source code of this website is made available for viewing purposes only.
|
|||
No permission is granted to copy, modify, distribute, or create derivative works.
|
||||
*/
|
||||
|
||||
// The payment-rail roster, the fake rail the suites run on, and the one money
|
||||
// parser both real rails share.
|
||||
// The payment-rail roster and the fake rail the suites run on.
|
||||
//
|
||||
// Every rail this shop has is SELF-HOSTED: a bank transfer to its own account,
|
||||
// or EURC to an address it generated itself. There is no hosted provider in the
|
||||
|
|
@ -36,38 +35,6 @@ import Catcrafts.Shared;
|
|||
|
||||
namespace Catcrafts::Server {
|
||||
|
||||
std::optional<std::int64_t> ParseAmountToMinor(std::string_view s) {
|
||||
// Exactly: 1*DIGIT ["." 1*2DIGIT]. Anything else — signs, exponents,
|
||||
// spaces, thousands separators — is rejected. Money parsing has no
|
||||
// "probably fine" mode.
|
||||
//
|
||||
// Shared because every amount that arrives from outside comes as a decimal
|
||||
// string: the bank quotes "57.38", and the crypto rail's own decoding
|
||||
// reduces to the same question. The sign is deliberately NOT accepted here
|
||||
// (see ParseSignedAmountToMinor, which peels it off first) so that a stray
|
||||
// minus can never quietly halve a total.
|
||||
if (s.empty() || s.size() > 15) return std::nullopt;
|
||||
std::int64_t units = 0;
|
||||
std::size_t i = 0;
|
||||
if (s[i] < '0' || s[i] > '9') return std::nullopt;
|
||||
for (; i < s.size() && s[i] >= '0' && s[i] <= '9'; ++i) {
|
||||
units = units * 10 + (s[i] - '0');
|
||||
}
|
||||
std::int64_t cents = 0;
|
||||
if (i < s.size()) {
|
||||
if (s[i] != '.') return std::nullopt;
|
||||
++i;
|
||||
const std::size_t fracStart = i;
|
||||
for (; i < s.size() && s[i] >= '0' && s[i] <= '9'; ++i) {
|
||||
cents = cents * 10 + (s[i] - '0');
|
||||
}
|
||||
const std::size_t digits = i - fracStart;
|
||||
if (i != s.size() || digits == 0 || digits > 2) return std::nullopt;
|
||||
if (digits == 1) cents *= 10;
|
||||
}
|
||||
return units * 100 + cents;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// ── the fake rail ─────────────────────────────────────────────────────
|
||||
|
|
@ -175,39 +142,13 @@ std::unique_ptr<PaymentRail> MakeRail(const RailConfig& config) {
|
|||
// that will not load — and both return nullptr there, which main reports
|
||||
// as a rail that could not load rather than as an unknown one.
|
||||
if (config.mode == "transfer") {
|
||||
// Which credit source depends on where the operator chose to keep the
|
||||
// bank key. With BUNQ_API_KEY set here, this process reads the account
|
||||
// itself — simpler, and strictly worse, because that key can move
|
||||
// money and this process is reachable from the internet. Without it,
|
||||
// the rail reads the credits file that `--pull-credits` fills from a
|
||||
// trusted machine, and this host holds nothing that can spend.
|
||||
std::unique_ptr<CreditSource> credits;
|
||||
if (const char* key = std::getenv("BUNQ_API_KEY"); key && *key) {
|
||||
std::println(std::cerr,
|
||||
"transfer: WARNING — reading the bank directly with "
|
||||
"BUNQ_API_KEY present in this process. A bunq key can "
|
||||
"initiate payments and bunq has no read-only scope, so this "
|
||||
"host now holds a credential that can spend the account. The "
|
||||
"intended shape is `--pull-credits` on a trusted machine "
|
||||
"writing the credits file this rail reads.");
|
||||
BunqConfig bunq;
|
||||
bunq.apiKey = key;
|
||||
bunq.iban = config.transferIban;
|
||||
if (const char* v = std::getenv("BUNQ_PERMITTED_IPS"); v) {
|
||||
bunq.permittedIps = v;
|
||||
}
|
||||
if (const char* v = std::getenv("BUNQ_STATE"); v && *v) {
|
||||
bunq.statePath = v;
|
||||
} else {
|
||||
bunq.statePath = config.transferCreditsPath;
|
||||
bunq.statePath += ".bunq-context.json";
|
||||
}
|
||||
credits = MakeBunqCreditSource(bunq);
|
||||
if (!credits) return nullptr;
|
||||
} else {
|
||||
credits = MakeFileCreditSource(config.transferCreditsPath);
|
||||
}
|
||||
return MakeTransferRail(config, std::move(credits));
|
||||
// The rail reads the credits file, and nothing else. This process
|
||||
// holds no bank credential: the file is filled by the bank's callback
|
||||
// (HandleBankCallback) and by tools/pull-and-ship-credits.sh, which
|
||||
// asks the bank from a trusted machine and ships the result here. A
|
||||
// key that can read a bank account can as a rule also pay from it, so
|
||||
// none belongs on a host that is reachable from the internet.
|
||||
return MakeTransferRail(config, MakeFileCreditSource(config.transferCreditsPath));
|
||||
}
|
||||
if (config.mode == "eurc") return MakeEurcRail(config);
|
||||
return nullptr; // "off"
|
||||
|
|
|
|||
Loading…
Reference in a new issue