/* 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 callback shadow's verdict: what Nostro's reader makes of a bank callback // beside what our own parser made of it (ShadowCallbackVerdict). Temporary, // like the shadow itself. // // Three things are held here, and the third is the one that must not regress: // // * AGREE is said when, and only when, the id, the amount and the reference // are the same in both readings. Those are what settlement rests on. // * Each way the two can part is said in words that tell them apart: Nostro // refusing a body ours reads, reading none where ours does, reading one // where ours does not, and reading another value. // * NOTHING OF THE BODY COMES OUT. The verdict goes to the server's log, and // a callback holds the payer's name and IBAN and may repeat the secret // address it was posted to. Every verdict this suite produces is searched // for the values its bodies carry. // // The bodies are made up. Their shape is bunq's own sample of a MUTATION // callback (bunq/sdk_python, tests/assets/NotificationUrlJsons/Mutation.json), // which is also what Nostro's reader was written against. Whether bunq still // writes one like it is exactly what the shadow is in production to find out, // and no suite can. import std; import Catcrafts.Shared; import Catcrafts.Server; using namespace Catcrafts; namespace { int failures = 0; void Check(bool ok, std::string_view what, std::string_view got = {}) { if (ok) return; ++failures; std::println(std::cerr, "FAIL: {}{}{}", what, got.empty() ? "" : " got: ", got); } // Not real accounts, and not the shop's: see ShouldSettleBankTransfers. constexpr std::string_view kOwnIban = "NL00TEST0123456789"; constexpr std::string_view kOtherIban = "NL00OTHR0000000002"; // Every value below that a verdict must never repeat. constexpr std::string_view kSecrets[] = { "SECRETMARK", "CC-2B6457", "4155999", "570", "24.95", "NL00", "Payer", "shop.invalid", "bad type", }; struct Sent { std::string_view id = "4155999"; std::string_view type = "EBA_SCT"; std::string_view description = "CC-2B6457"; std::string_view value = "570.43"; std::string_view account = kOwnIban; // the payment's own side }; // A callback as bunq's sample has one: the envelope with the address it was // sent to, and a Payment with both sides on it. std::string Callback(const Sent& s) { return std::format(R"({{ "NotificationUrl": {{ "target_url": "https://shop.invalid/hooks/SECRETMARK", "category": "MUTATION", "event_type": "MUTATION_CREATED", "object": {{"Payment": {{ "id": {}, "created": "2026-11-25 10:15:30.498520", "updated": "2026-11-25 10:15:30.498520", "monetary_account_id": 42, "amount": {{"currency": "EUR", "value": "{}"}}, "description": "{}", "type": "{}", "alias": {{"iban": "{}", "display_name": "SECRETMARK Shop", "country": "NL"}}, "counterparty_alias": {{"iban": "NL00PAYR0000000001", "display_name": "SECRETMARK Payer", "country": "NL"}} }}}} }} }})", s.id, s.value, s.description, s.type, s.account); } // The four members our own parser reads, and nothing else: the shape this // repo's suites have always used for a callback, which Nostro's reader // refuses for what it lacks. constexpr std::string_view kReduced = R"({ "NotificationUrl": { "category": "MUTATION", "object": {"Payment": { "id": 4155999, "type": "EBA_SCT", "description": "CC-2B6457", "amount": {"currency": "EUR", "value": "570.43"} }} } })"; std::vector verdicts; // The verdict on `body`, with our own parser's reading of the same body, as // the server calls it. std::string Verdict(std::string_view body, std::string_view ownIban = kOwnIban, std::string_view bank = "bunq") { const std::optional ours = Server::ParseBunqCallback(body); verdicts.push_back(Server::ShadowCallbackVerdict(bank, body, ours, ownIban)); return verdicts.back(); } void Equal(const std::string& got, std::string_view want, std::string_view what) { Check(got == want, what, got); } void Has(const std::string& got, std::string_view part, std::string_view what) { Check(got.find(part) != std::string::npos, what, got); } } // namespace int main() { // ── the two readings agree ──────────────────────────────────────── Equal(Verdict(Callback({})), "AGREE in method=sepa account=ours event=transactions", "an incoming transfer on the shop's account reads the same both ways"); Equal(Verdict(Callback({}), "nl00 test 0123 4567 89"), "AGREE in method=sepa account=ours event=transactions", "the shop's IBAN is compared as a person wrote it down"); Equal(Verdict(Callback({ .account = kOtherIban })), "AGREE in method=sepa account=other event=transactions", "a payment on another account is said to be on another account"); Equal(Verdict(Callback({}), ""), "AGREE in method=sepa account=unknown event=transactions", "with no account named, whose it is on is not guessed"); Equal(Verdict(Callback({ .value = "-24.95" })), "AGREE out method=sepa account=ours event=transactions", "money going out keeps its sign in both readings"); // ── the method, which may differ without the readings differing ─── Equal(Verdict(Callback({ .type = "IDEAL" })), "AGREE in method=ideal account=ours event=transactions", "iDEAL"); Equal(Verdict(Callback({ .type = "BUNQ" })), "AGREE in method=bunq account=ours event=transactions", "between two bunq accounts"); Equal(Verdict(Callback({ .type = "MASTERCARD", .value = "-24.95" })), "AGREE out method ours=MASTERCARD nostro=card account=ours event=transactions", "a card payment, which ours passes through and Nostro names, is still AGREE"); Equal(Verdict(Callback({ .type = "ADYEN" })), "AGREE in method=ADYEN account=ours event=transactions", "a type neither table has is the bank's own word in both"); Equal(Verdict(Callback({ .type = "" })), "AGREE in method=bank account=ours event=transactions", "no type at all is 'bank' in both"); { const std::string v = Verdict(Callback({ .type = "bad type!" })); Has(v, "method=?", "a type that is no bank's word is not printed"); Has(v, "AGREE in ", "and the readings still agree"); } // ── Nostro refuses what ours reads ──────────────────────────────── // // The outcome the shadow is in production to rule out, or to find. { const std::string v = Verdict(kReduced); Has(v, "DIFFER nostro refused what ours reads as a payment: ", "the four members ours reads are not enough for Nostro's reader"); } { const std::string v = Verdict(Callback({ .account = "" })); Has(v, "DIFFER nostro refused what ours reads as a payment: ", "a payment that does not say which account it is on is refused"); Has(v, "which account", "and the refusal says that is why"); } { // Past what Nostro reads at all, with a payment ours still decodes. std::string big = Callback({}); const std::size_t at = big.find("\"category\""); big.insert(at, std::format("\"padding\": \"{}\", ", std::string(70000, 'x'))); const std::string v = Verdict(big); Has(v, "DIFFER nostro refused what ours reads as a payment: ", "a body past Nostro's limit is refused"); Check(v.size() < 400, "and the verdict stays one line's worth", v); } Has(Verdict(Callback({}), kOwnIban, "nobank"), "DIFFER nostro refused what ours reads as a payment: ", "a bank Nostro was not built with reads nothing"); // ── one reads a payment where the other reads none ──────────────── { // Two things under `object`: ours looks for the Payment among them, // Nostro takes a callback to be about one thing. std::string two(kReduced); const std::size_t at = two.rfind("}}"); two.insert(at + 1, R"(, "Other": {})"); Equal(Verdict(two), "DIFFER nostro reads no payment in it (event=transactions), ours does", "a second object beside the payment"); } { verdicts.push_back(Server::ShadowCallbackVerdict("bunq", Callback({}), std::nullopt, kOwnIban)); Equal(verdicts.back(), "DIFFER nostro reads a payment, ours does not (in account=ours event=transactions)", "a payment only Nostro reads"); } // ── both read a payment, and not the same one ───────────────────── { const std::string body = Callback({}); const std::optional ours = Server::ParseBunqCallback(body); Check(ours.has_value(), "our parser reads the sample's shape"); if (ours) { Server::BankCredit other = *ours; other.amountMinor += 1; verdicts.push_back(Server::ShadowCallbackVerdict("bunq", body, other, kOwnIban)); Equal(verdicts.back(), "DIFFER id=same amount=DIFFERENT reference=same in method=sepa " "account=ours event=transactions", "another amount"); other = *ours; other.id = "1"; verdicts.push_back(Server::ShadowCallbackVerdict("bunq", body, other, kOwnIban)); Has(verdicts.back(), "DIFFER id=DIFFERENT amount=same reference=same ", "another id"); other = *ours; other.reference = "something else"; verdicts.push_back(Server::ShadowCallbackVerdict("bunq", body, other, kOwnIban)); Has(verdicts.back(), "DIFFER id=same amount=same reference=DIFFERENT ", "another reference"); } } // ── neither reads a payment ─────────────────────────────────────── for (const std::string_view none : { std::string_view(""), std::string_view("not json"), std::string_view("SECRETMARK"), std::string_view(R"({"SECRETMARK": 1})"), std::string_view(R"({"NotificationUrl": {}})") }) { Has(Verdict(none), "AGREE neither reads a payment (nostro: ", std::format("a body that is no callback: '{}'", none.substr(0, 16))); } Equal(Verdict(R"({"NotificationUrl": {"category": "REQUEST", "event_type": "REQUEST_INQUIRY_CREATED", "object": {"RequestInquiry": {"id": 7}}}})"), "AGREE no payment in it (event=bunq:REQUEST)", "a callback about something that is no payment"); // ── and none of it says anything a body carried ─────────────────── Check(verdicts.size() >= 25, "the verdicts above were all collected", std::format("{}", verdicts.size())); for (const std::string& v : verdicts) { for (const std::string_view secret : kSecrets) { Check(v.find(secret) == std::string::npos, std::format("a verdict repeats '{}' from a body", secret), v); } Check(v.find('\n') == std::string::npos, "a verdict is one line", v); } if (failures != 0) { std::println(std::cerr, "{} check(s) failed", failures); return 1; } std::println("ShouldCompareCallbackReaders: all checks passed"); return 0; }