bank: the order page offers a payto link and quotes one reference

The bank-transfer block on the order page now gives two ways to pay.
First a payto link (RFC 8905) that hands the IBAN, the amount, the
account-holder name and the order code to a payment app in one go, then
"Or do a manual transfer" with the same details as before.

The manual details list the order code as the Description and nothing
else. The page used to print the structured RF reference as well, with
a paragraph on which code goes in which field, and that read as two
codes for one payment. Matching never needed the RF form: the matcher
finds the CC- code anywhere in the remittance text, the RF form
included. OrderCryptoPay::structuredReference, which only fed that row,
is gone; CreditorReferenceFromToken stays, with its unit test.

The link is built in the view from the very values the manual details
print, so the two cannot disagree. Url() now lets payto: through, like
ethereum:, and the name is percent-encoded because Url() strips spaces.
ShouldSettleBankTransfers asserts the whole link, including that its
message is the reference the matcher looks for.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jorijn van der Graaf 2026-11-25 15:33:50 +01:00
commit dead3ed0cc
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
7 changed files with 84 additions and 38 deletions

View file

@ -1414,6 +1414,45 @@ SafeHtml MoneyRow(std::string_view label, std::int64_t minor) {
Escape(label), Escape(Money::FormatEuro(minor)));
}
// RFC 3986 percent-encoding for one URI query value: unreserved characters
// stay, every other byte becomes %XX. Byte-wise on purpose, so a non-ASCII
// account-holder name goes out as its UTF-8 bytes.
std::string PercentEncode(std::string_view s) {
static constexpr std::string_view kHex = "0123456789ABCDEF";
std::string out;
out.reserve(s.size() * 3);
for (const char ch : s) {
const auto c = static_cast<unsigned char>(ch);
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')
|| c == '-' || c == '.' || c == '_' || c == '~') {
out += ch;
} else {
out += '%';
out += kHex[c >> 4];
out += kHex[c & 0x0F];
}
}
return out;
}
// The bank-transfer instructions as one RFC 8905 payto URI, which a payment
// app that handles the scheme opens with every field filled in. Built from
// the very values the manual details print, so the two cannot disagree. The
// IBAN is compacted because a configured one may carry display spaces, and
// the BIC is left out: only a payer outside SEPA needs it, and the plain
// payto://iban/<IBAN> form is the one a handler is surest to parse.
std::string PaytoUri(std::string_view iban, std::int64_t totalMinor,
std::string_view receiver, std::string_view message) {
std::string compact;
for (const char c : iban) {
if (c >= 'a' && c <= 'z') compact += static_cast<char>(c - 'a' + 'A');
else if ((c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')) compact += c;
}
return std::format("payto://iban/{}?amount=EUR:{}&receiver-name={}&message={}",
compact, Money::FormatMinor(totalMinor),
PercentEncode(receiver), PercentEncode(message));
}
// The order status page. The token in the URL is the whole capability: no
// account, no login — bookmark the page. Rendered server-side only, because
// only the server knows the order; the shared fallback below covers the app.
@ -1548,8 +1587,13 @@ export RenderedPage RenderOrderStatus(const OrderView& o, std::string_view indic
// Both live rails are self-hosted and so both land in this branch;
// what separates them is which of these two blocks renders.
if (!pay.beneficiary.empty()) {
// Three fields, in the order a banking app asks for them, so the
// buyer can work straight down the page instead of hunting.
// Two ways to pay, quickest first. The payto link hands every
// field below to the buyer's payment app in one go, so nothing is
// retyped; the manual details are the same values for everyone
// whose app does not take such links.
//
// The manual fields are in the order a banking app asks for them,
// so the buyer can work straight down the page instead of hunting.
//
// The name comes FIRST and is labelled as exact on purpose. Every
// euro-area transfer is now name-checked against the IBAN, and a
@ -1557,33 +1601,33 @@ export RenderedPage RenderOrderStatus(const OrderView& o, std::string_view indic
// moment of paying. Telling them why the spelling looks odd is
// cheaper than losing the payment to a scary red banner.
//
// Both reference forms are offered because banks disagree about
// where a reference goes: those with a dedicated payment-reference
// field validate the RF form's check digits and refuse a mistyped
// one before the money moves, which is the safer path; the rest
// only have a free-text description, where the short code is what
// a human will actually copy correctly.
// One reference, the short order code, in the description field
// every bank has. The matcher finds it anywhere in that text.
// Offering the structured RF form as well, for banks with a
// separate reference field, left buyers unsure which code went
// where.
payBlock = Format(
R"(<section class="section">)"
R"(<h2 class="section__title">Pay by bank transfer</h2>)"
R"(<p>Transfer <strong>{}</strong> to this account:)"
R"(<p>Open this link in your payment app:</p>)"
R"(<p class="order__paylink"><a class="btn btn--primary"{}>Pay {}</a></p>)"
R"(<p>Or do a manual transfer of <strong>{}</strong> to this account:</p>)"
R"(<dl class="order__bank">)"
R"(<dt>Account holder</dt><dd><code class="order__address">{}</code></dd>)"
R"(<dt>IBAN</dt><dd><code class="order__address">{}</code></dd>)"
R"({})"
R"(<dt>Payment reference</dt><dd><code class="order__address">{}</code></dd>)"
R"(<dt>Description</dt><dd><code class="order__address">{}</code></dd>)"
R"(</dl>)"
R"({})"
R"(<p class="order__note">Please copy the the fields )"
R"(exactly as written above. If your bank )"
R"(has a separate field for a payment reference, use )"
R"(<strong>{}</strong> there, it is checked for typing errors. )"
R"(Otherwise put <strong>{}</strong> in the description. )"
R"(Without the reference the payment cannot be matched to your )"
R"(order. If you send too little, transfer the rest the same )"
R"(way and the order confirms once the total arrives.</p>)"
R"(<p class="order__note">Please copy the fields exactly as written )"
R"(above. Without the description the payment cannot be matched )"
R"(to your order. If you send too little, transfer the rest the )"
R"(same way and the order confirms once the total arrives.</p>)"
R"({})"
R"(</section>)",
Url("href", PaytoUri(pay.address, o.totalMinor, pay.beneficiary,
o.reference)),
Escape(Money::FormatEuro(o.totalMinor)),
Escape(Money::FormatEuro(o.totalMinor)),
Escape(pay.beneficiary),
Escape(pay.address),
@ -1595,12 +1639,8 @@ export RenderedPage RenderOrderStatus(const OrderView& o, std::string_view indic
R"(asks for it, usually outside Europe)</span></dt>)"
R"(<dd><code class="order__address">{}</code></dd>)",
Escape(pay.bic)),
Escape(pay.structuredReference.empty() ? o.reference
: pay.structuredReference),
indicativeLine,
Escape(pay.structuredReference.empty() ? o.reference
: pay.structuredReference),
Escape(o.reference),
indicativeLine,
windowLine);
} else {
payBlock = Format(