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>
157 lines
7.4 KiB
C++
157 lines
7.4 KiB
C++
/*
|
|
catcrafts.net
|
|
Copyright (C) 2026 Catcrafts
|
|
|
|
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 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
|
|
// payment path and no credential that a third party can revoke.
|
|
//
|
|
// That is a scar, not a philosophy. The shop ran on a hosted payment provider
|
|
// until 2026-08-20, when that provider closed the account after a risk review,
|
|
// with no appeal and no reason beyond "outside our acceptance criteria". Every
|
|
// payment method died in one email: iDEAL, cards, the lot. Its rail
|
|
// implementation was removed once the decision proved final — keeping a dead
|
|
// integration alive costs a CI gate, a secret, and a steady trickle of
|
|
// confusion about which rail is actually serving.
|
|
//
|
|
// What that history is worth remembering FOR: a hosted rail can be switched
|
|
// off by someone else, and a self-hosted one cannot. The bank can still close
|
|
// the account, because every euro has to land somewhere, but it cannot decline
|
|
// a payment method while leaving the business running. That is the property
|
|
// the two current rails were chosen for, and the reason not to trade it away
|
|
// for convenience later.
|
|
|
|
module;
|
|
module Catcrafts.Server;
|
|
|
|
import std;
|
|
import Catcrafts.Shared;
|
|
|
|
namespace Catcrafts::Server {
|
|
|
|
namespace {
|
|
|
|
// ── the fake rail ─────────────────────────────────────────────────────
|
|
//
|
|
// Exists so the ENTIRE order lifecycle — checkout, storage, status page,
|
|
// reconciler, paid transition — runs in e2e with zero network. Payment links
|
|
// point at a made-up URL; CheckPaid answers true once a marker file exists,
|
|
// which the test creates when it wants "the customer has paid" to happen.
|
|
//
|
|
// It can stand in for EITHER slot, which is what lets the e2e suite drive the
|
|
// bank and crypto paths through the same machinery: what it proves is that the
|
|
// choice is carried from the form to the ledger to the poll, and that is
|
|
// rail-independent by design.
|
|
//
|
|
// Note what it is NOT for any more. Both live rails are self-hosted and render
|
|
// instructions rather than a button, and each has its own black-box coverage
|
|
// against the real implementation (ShouldSettleBankTransfers,
|
|
// ShouldSettleEurcOnTestnet). So the fake rail's remaining job is the parts
|
|
// that are about the SHOP rather than about a provider: the choice, the
|
|
// ledger, the reconciler, and the hosted-button branch that no live rail takes
|
|
// but the renderer still has to be able to draw.
|
|
|
|
class FakeRail final : public PaymentRail {
|
|
public:
|
|
FakeRail(std::filesystem::path marker, std::string name)
|
|
: marker_(std::move(marker)), name_(std::move(name)) {}
|
|
|
|
std::optional<PaymentLink> CreateLink(std::int64_t, const std::string&,
|
|
const std::string& redirectUrl) override {
|
|
static std::atomic<std::int64_t> counter{1};
|
|
PaymentLink link;
|
|
link.payId = std::format("fake-{}", counter.fetch_add(1));
|
|
// Checkout 303s the buyer to payUrl. The fake rail has no checkout to
|
|
// send anyone to, so it points at the order page itself — which keeps
|
|
// the browser flow usable in dev and the e2e redirect parseable.
|
|
link.payUrl = redirectUrl;
|
|
return link;
|
|
}
|
|
|
|
std::optional<PaidStatus> CheckPaid(const std::string&, std::int64_t) override {
|
|
std::error_code ec;
|
|
if (std::filesystem::exists(marker_, ec)) {
|
|
return PaidStatus{ PayState::Paid, "fake" };
|
|
}
|
|
PaidStatus out;
|
|
out.state = PayState::Pending;
|
|
out.method = "fake";
|
|
// "<marker>.seen" is the in-flight state: money visible on the
|
|
// network, finality still pending. It exists so the e2e suite can
|
|
// drive the order page's "your payment is on its way" notice the
|
|
// same way the marker itself drives "paid".
|
|
std::filesystem::path seenMarker = marker_;
|
|
seenMarker += ".seen";
|
|
out.seen = std::filesystem::exists(seenMarker, ec);
|
|
return out;
|
|
}
|
|
|
|
// The crypto slot's fake renders payment INSTRUCTIONS, like the real EURC
|
|
// rail, so the suites exercise the order page's self-hosted branch
|
|
// (address, window, the in-flight notice). The bank slot's fake keeps the
|
|
// BUTTON on purpose: no live rail takes that branch any more, and without
|
|
// one fake still drawing it, the renderer's hosted-payment path would go
|
|
// completely uncovered. Fixed values, so assertions can pin them.
|
|
std::optional<PayInstructions> Instructions(const std::string&,
|
|
std::int64_t totalMinor) const override {
|
|
if (name_ != "fake-crypto" || totalMinor <= 0) return std::nullopt;
|
|
PayInstructions out;
|
|
out.address = "0x" + std::string(40, 'f');
|
|
out.amount = Money::FormatMinor(totalMinor);
|
|
out.deadlineUnix =
|
|
std::chrono::duration_cast<std::chrono::seconds>(
|
|
std::chrono::system_clock::now().time_since_epoch()).count()
|
|
+ 24 * 3600;
|
|
PayChainOption chain;
|
|
chain.name = "fake-chain";
|
|
chain.contract = "0x" + std::string(40, 'f');
|
|
out.chains.push_back(std::move(chain));
|
|
return out;
|
|
}
|
|
|
|
std::string_view Name() const override { return name_; }
|
|
std::chrono::seconds PollInterval() const override { return std::chrono::seconds(1); }
|
|
|
|
private:
|
|
std::filesystem::path marker_;
|
|
std::string name_;
|
|
};
|
|
|
|
} // namespace
|
|
|
|
// The roster has one home, here. An unrecognised mode is "off" rather than an
|
|
// error, and the caller (main) is what refuses to start on a mode it did not
|
|
// expect — a rail that silently half-exists would be worse than either.
|
|
std::unique_ptr<PaymentRail> MakeRail(const RailConfig& config) {
|
|
// The fake rail keeps the slot's own name so the ledger, the startup line
|
|
// and the logs still say which half of the checkout ran in a test.
|
|
if (config.mode == "fake") {
|
|
return std::make_unique<FakeRail>(config.statePath, "fake");
|
|
}
|
|
if (config.mode == "fake-crypto") {
|
|
return std::make_unique<FakeRail>(config.statePath, "fake-crypto");
|
|
}
|
|
// The two live rails. Both can fail to construct for a reason other than a
|
|
// typo — a missing IBAN or beneficiary name, a chains file or address pool
|
|
// 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") {
|
|
// 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"
|
|
}
|
|
|
|
} // namespace Catcrafts::Server
|