feat: open payto links on the pay form, and take the checkout over D-Bus out

An app could have nostrod pay an order: it called Pay of
net.catcrafts.Nostro1.Checkout on the system bus, and nostrod paid from
an account the user had chosen, after a dialog of its own. On 2026-11-22
the owner decided that a link takes its place. The app registers for
payto links (RFC 8905), so that an app or a website can hand one to the
desktop, and shows a link as its pay form filled in.

The link:

- The app's desktop entry takes the scheme (Exec=nostro-app %u,
  MimeType=x-scheme-handler/payto), and nostro-app takes an argument
  that is no option as a link: it overwrites it in argv and hands it to
  App::Open once the app has started.
- ReadPaymentLink (Nostro.App:Forms) reads payto://iban/<IBAN> with the
  options amount, receiver-name and message, and refuses a link rather
  than guess at it, in a sentence of the app's own with nothing of the
  link in it. Among what it refuses: an IBAN whose check digits do not
  hold, one of the three options given twice, instruction, a comma in
  the amount, and a name or a message with a code point that is Unshown,
  or Blank and no plain space.
- A link that is read waits until the accounts are read and
  DefaultCheckoutAccount has answered or failed, with a line on the
  accounts' page. Then App::TakeLink fills in the pay form, which says
  in a banner that a link filled it in, and with more than one account
  opens it under the choice of accounts that the form's From row has. A
  link pays nothing: the form's button sends, and polkit's dialog
  confirms as for any payment (design rule 12, and 14, which is new).
- Unshown and Blank are the two tables the worker's Shown() works from.
  They move into Nostro:Utils, where the app's reader asks them too.
  The move is within the library. The reader holds a link's name to
  those two and to no more of Shown(): a name with an & is read, and
  the dialog shows it with a + as it does any name.

The checkout:

- nostrod serves one interface under one bus name. Gone are
  net.catcrafts.Nostro1.Checkout with its XML and its activation file,
  the polkit action Checkout, the module Nostro.Checkout with
  --product=checkout, and the worker's record of orders. That changes
  the published contract after a release, 0.0.0, and design rule 10
  records it as the owner's decision.
- DefaultCheckoutAccount and SetDefaultCheckoutAccount keep their names
  and signatures. The account they keep is where a link's pay form
  starts: nostrod's dialog for choosing it says "have pay links start
  from", the app's setting reads "Pay links start from", and `nostro
  checkout account` prints "pay links start from".
- The D-Bus policy still lets nostrod own the old name: the nostrod of
  0.0.0 asks for it when it starts, and the system files can be newer
  than the Flatpak it runs from. install.sh removes the old name's
  activation file. A user's checkouts.cdb is read by nothing any more,
  and is left where it is.
- The Arch package stops installing the checkout's two files, and its
  pkgrel goes up to 2. Where makepkg -si finds a package of the version
  already built it installs that one again, which would bring the
  activation file back. The guide now says that pkgrel goes up with a
  change to what the package installs.
- Bus::Interface goes too: the worker called it in two places, to tell
  a call to the checkout from one to the main interface.

The review's own files follow. gate0 loses the build of
--product=checkout, and the three lens sections that named the checkout
no longer do, and ask about a link.

The README has "Pay links" in place of "Checkout for apps", and
AGENTS.consumer.md says what the app reads of a link. Its line on
lib/json.hpp no longer gives a release: the file is of none, and the
guide names its commit. The pay form and the accounts' page change only
by a banner each, shown while a link is in play, which
docs/screenshots/take.sh never has: the README's pictures stand.

Tests: ShouldValidateForms reads and refuses links and fills the form
from one. ShouldDriveTheApp opens links against a real nostrod on the
fake bus: before the accounts are known, with no account, with one and
with several, with the accounts known and the system bus gone, for a
second user whose first connection pays their own accounts only, one
that cannot be read, one whose name has an &, and through polkit's
dialog to the payment. It now counts nostrod's answers to hold that the
account pay links start from is read again once a connection is
removed: the check it had there passed without that.
ShouldHandleMoneyAndText holds the two tables at the ends of their
ranges. ShouldServeEveryUser holds that nostrod serves no checkout, that
the bus's policy lets an older nostrod own the old name, and the account
pay links start from. ShouldRunCommands holds the CLI's wording.

The review's gate0 passes at this commit: the version check, 17 tests,
the builds of the CLI, the library, nostrod, the fake system, the app
and its --debug-api build, and five lint runs that report nothing.
tests/coverage.sh reports lines, functions and regions at 100.00%.

Looked at on 2026-11-22 on the made-up system (run fake), on a desktop
(KWin at a scale of 1.85). At 420x760, at --scale 3 --size 360x760 and
at 1100x720 in the light look: a link's pay form under the choice of
accounts, the form after a tap beside that choice, and the accounts'
page while a link waits, its line above the rows that stand in for the
accounts (--bank-delay 10000). At 420x760: that line above what the
page says when the accounts cannot be read (--polkit deny) and above
the accounts themselves (--polkit slow, the link opened in the running
app), the settings' row and page for the account pay links start from,
the sheet for a link that cannot be read, and with --empty the sheet
for no account.
This commit is contained in:
Jorijn van der Graaf 2026-11-22 13:35:51 +01:00
commit b43ab124a6
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
42 changed files with 1234 additions and 994 deletions

View file

@ -2,8 +2,9 @@
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
// Nostro.App without nostrod: how money, days and the bank's capitals are worded (in a fixed time zone, so the
// expectations hold anywhere), what each form reads from what was typed and what it refuses, what every error
// nostrod can answer with is explained as, and what the app knows of each bank it can connect.
// expectations hold anywhere), what each form reads from what was typed and what it refuses, what a link that asks
// for a payment is read as and everything it is refused for, what every error nostrod can answer with is explained
// as, and what the app knows of each bank it can connect.
#include <stdlib.h>
#include <time.h>
@ -228,6 +229,182 @@ namespace {
Check(form.to.value.empty() && form.amount.value.empty() && form.when == When::Now && form.unit == 0 && form.day.value.empty() && !form.tried, "a cleared form is as new");
}
// A link that asks for a payment, as a website's pay button opens one: what is read from it, everything it is
// refused for, and the form it fills in. Whoever wrote the link chose every character of it.
void Linking() {
const std::string to = std::format("payto://iban/{}", iban);
const auto times = [](std::string_view text, std::size_t count) {
std::string repeated;
for(std::size_t i = 0; i < count; i++) {
repeated += text;
}
return repeated;
};
// The link with options after it.
const auto with = [&to](std::string_view options) { return std::format("{}?{}", to, options); };
struct Asked {
std::string link;
std::string name;
std::optional<std::int64_t> amount;
std::string description;
std::string_view what;
};
const std::vector<Asked> read = {
{to, "", std::nullopt, "", "an IBAN alone: how much and what for are the user's to say"},
{"PAYTO://IBAN/nl91abna0417164300", "", std::nullopt, "", "the scheme in capitals and the IBAN in small letters"},
{std::format("payto://iban/ABNANL2A/{}", iban), "", std::nullopt, "", "a bank's code of eight before the IBAN, which is left out"},
{std::format("payto://iban/ABNANL2AXXX/{}", iban), "", std::nullopt, "", "or one of eleven"},
{with(""), "", std::nullopt, "", "a question mark with nothing after it"},
{with("amount=EUR:12.50&receiver-name=Shop%20BV&message=Order%201234"), "Shop BV", 1250, "Order 1234", "who, how much and what for"},
{with("amount=EUR%3A12.5"), "", 1250, "", "the amount's colon as an escape, as a browser's own writer of queries has it"},
{with("amount=eur:12"), "", 1200, "", "the currency in small letters, and no cents"},
{with("amount=EUR:0012.50"), "", 1250, "", "zeros before it"},
{with("amount=EUR:999999999999.99"), "", 99999999999999, "", "the most a form takes"},
{with("message=a+b%2Bc"), "", std::nullopt, "a b+c", "a plus for a space, and an escaped one for a plus"},
{with("receiver-name=%20Bob%20"), "Bob", std::nullopt, "", "spaces around a name are not part of it"},
{with("message"), "", std::nullopt, "", "an option without a value says nothing"},
{with("AMOUNT=EUR:1&%6Dessage=x&Receiver-Name=Bob"), "Bob", 100, "x", "an option's name in capitals or as escapes is that option"},
{with("utm_source=mail&sender-name=Eve&flag&=x&&amount=EUR:5&"), "", 500, "", "what Nostro does not know is passed over, wherever it stands"},
{with("message=caf%C3%A9%20%E2%82%AC%20%F0%9F%98%80"), "", std::nullopt, "café € 😀", "characters of two, three and four bytes, as escapes"},
{with("receiver-name=Café René"), "Café René", std::nullopt, "", "or as they are"},
{with("receiver-name=Fish%20%26%20Chips%20%3CNL%3E&message=5%20%24(each)"), "Fish & Chips <NL>", std::nullopt, "5 $(each)", "an &, a <, a > and a $( are a name's and a description's to have: only the system's dialog shows a name otherwise"},
{std::format("{}?receiver-name={}&message={}", to, times("a", 70), times("b", 140)), times("a", 70), std::nullopt, times("b", 140), "a name of 70 characters and a description of 140"},
{std::format("{}?receiver-name={}&message={}", to, times("%C3%A9", 70), times("%E2%82%AC", 140)), times("é", 70), std::nullopt, times("€", 140), "counted in characters, not in bytes"},
};
for(const Asked& asked : read) {
const Read<PaymentLink> link = ReadPaymentLink(asked.link);
Check(link.value && link.error.empty() && link.value->iban == iban && link.value->name == asked.name && link.value->amount == asked.amount && link.value->currency == euro && link.value->description == asked.description, std::format("a link is read: {}", asked.what));
// What is read is what the form then holds, to the letter, and what its order asks nostrod for.
PaymentForm form;
form.Fill(link.value.value_or(PaymentLink()));
Check(form.linked && form.to.value == iban && form.name.value == asked.name && form.description.value == asked.description && ReadAmount(form.amount.value, euro).value == asked.amount, std::format("and fills the form in with just that: {}", asked.what));
}
constexpr std::string_view notOne = "It is not a link to pay an IBAN";
constexpr std::string_view noIban = "The IBAN in it is not a valid one";
constexpr std::string_view damaged = "something in it is there twice, or cannot be read";
constexpr std::string_view instruction = "a reference of a kind Nostro cannot send along";
constexpr std::string_view noAmount = "The amount in it cannot be read";
constexpr std::string_view noCurrency = "a currency Nostro does not pay in";
constexpr std::string_view notPlain = "holds what a payment cannot carry";
constexpr std::string_view tooLong = "is too long";
const std::vector<std::tuple<std::string, std::string_view, std::string_view>> refused = {
{"", notOne, "nothing"},
{"https://example.org/pay?to=MARK", notOne, "a web address"},
{"payto:iban/NL91ABNA0417164300", notOne, "a scheme without its slashes"},
{"payto://bic/ABNANL2A", notOne, "a bank's code and no account"},
{"payto://bitcoin/1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa", notOne, "something that is no IBAN"},
{"payto://user@iban/NL91ABNA0417164300", notOne, "a user before the kind of account"},
{"payto://pay/iban/NL91ABNA0417164300", notOne, "a kind of account that is none"},
{"nostro://iban/NL91ABNA0417164300", notOne, "a scheme of Nostro's own, which there is none of"},
{std::format(" {}", to), notOne, "a space before it"},
{std::format("{}#MARK", to), notOne, "a fragment"},
{with("message=a#MARK"), notOne, "a fragment after the options"},
{with(std::format("x={}", times("a", 4096))), notOne, "a link longer than any that asks for a payment"},
{std::format("payto://iban/ABNANL2/{}", iban), notOne, "a bank's code of seven"},
{std::format("payto://iban/ABNANL2AX/{}", iban), notOne, "one of nine"},
{std::format("payto://iban/ABNA-L2A/{}", iban), notOne, "one that is not letters and digits"},
{std::format("payto://iban//{}", iban), notOne, "an empty one"},
{"payto://iban/", noIban, "no IBAN"},
{"payto://iban/?amount=EUR:1", noIban, "no IBAN before the options"},
{"payto://iban/NL91ABNA0417164301", noIban, "an IBAN whose check digits do not hold"},
{"payto://iban/NL91%41BNA0417164300", noIban, "an escape in the IBAN"},
{"payto://iban/NL91 ABNA 0417 1643 00", noIban, "spaces in it"},
{"payto://iban/bob@example.org", noIban, "an e-mail address"},
{"payto://iban/+31612345678", noIban, "a phone number"},
{std::format("payto://iban/ABNANL2A/ABNANL2A/{}", iban), noIban, "two banks' codes"},
{"payto://iban/ABNANL2A/", noIban, "a bank's code and nothing after it"},
{with("amount=EUR:1&amount=EUR:2"), damaged, "two amounts"},
{with("amount=EUR:1&AMOUNT=EUR:1000"), damaged, "a second amount in capitals"},
{with("%61mount=EUR:1000&amount=EUR:1"), damaged, "a first amount behind an escape"},
{with("message=a&x=1&message=MARK"), damaged, "two descriptions"},
{with("receiver-name=a&receiver-name=MARK"), damaged, "two names"},
{with("message=100%"), damaged, "a percent sign that begins no escape"},
{with("message=MARK%4"), damaged, "an escape cut short"},
{with("receiver-name=%zzMARK"), damaged, "an escape that is no number"},
{with("receiver-name=%4zMARK"), damaged, "an escape that is half a number"},
{with("amount=EUR%3"), damaged, "an escape cut short in the amount"},
{with("instruction=RF18539007547034"), instruction, "a reference for the payee's bank to pass on"},
{with("instruction="), instruction, "an empty one"},
{with("instruction"), instruction, "one without a value"},
{with("INSTRUCTION=MARK"), instruction, "one in capitals"},
{with("amount=12.50"), noAmount, "an amount without its currency"},
{with("amount=EUR"), noAmount, "a currency without an amount"},
{with("amount=EUR:"), noAmount, "a currency and a colon"},
{with("amount="), noAmount, "an empty amount"},
{with("amount"), noAmount, "an amount without a value"},
{with("amount=EUR:12,50"), noAmount, "a comma for the point: twelve hundred and fifty by the letter of RFC 8905, twelve and a half to whoever wrote it"},
{with("amount=EUR:1,250.00"), noAmount, "a comma between the thousands"},
{with("amount=EUR:-1"), noAmount, "less than nothing"},
{with("amount=EUR:+1"), noAmount, "a plus, which reads as a space"},
{with("amount=EUR:%201"), noAmount, "a space"},
{with("amount=EUR:12."), noAmount, "a point with nothing after it"},
{with("amount=EUR:.5"), noAmount, "a point with nothing before it"},
{with("amount=EUR:1.2.3"), noAmount, "two points"},
{with("amount=EUR:1e3"), noAmount, "a power of ten"},
{with("amount=EUR:%D9%A1%D9%A2"), noAmount, "digits of another script"},
{with("amount=EUR:1.234"), noAmount, "more decimals than the euro has"},
{with("amount=EUR:0"), noAmount, "nothing"},
{with("amount=EUR:0.00"), noAmount, "nothing, to the cent"},
{with("amount=EUR:1234567890123"), noAmount, "more than a form takes"},
{with("amount=USD:1"), noCurrency, "another currency"},
{with("amount=Eur:1"), noCurrency, "a currency in neither capitals nor small letters"},
{with("amount=EURO:1"), noCurrency, "a currency's name"},
{with("amount=:1"), noCurrency, "no currency before the colon"},
{with("message=MARK%00"), notPlain, "a zero byte"},
{with("message=MARK%0AMARK"), notPlain, "a new line"},
{with("message=MARK%09"), notPlain, "a tab"},
{with("receiver-name=MARK%7F"), notPlain, "a delete"},
{with("receiver-name=MARK%C2%85"), notPlain, "a control of the second kind"},
{with("receiver-name=MA%E2%80%8BRK"), notPlain, "a space without a width"},
{with("receiver-name=%E2%80%AEMARK"), notPlain, "a mark that turns the text around"},
{with("receiver-name=MARK%C2%A0BV"), notPlain, "a space that is not the ordinary one"},
{with("message=MARK%C2%AD"), notPlain, "a soft hyphen"},
{with("message=%EF%BB%BFMARK"), notPlain, "a byte order mark"},
{with("message=%EE%80%80MARK"), notPlain, "a character of private use"},
{with("message=M%C1%81RK"), notPlain, "an A written in two bytes, which reads as one and is none"},
{with("message=%E0%80%AFMARK"), notPlain, "a slash written in three"},
{with("message=%F0%80%80%AFMARK"), notPlain, "and in four"},
{with("message=%ED%A0%80MARK"), notPlain, "half of a pair"},
{with("message=%F4%90%80%80MARK"), notPlain, "a character beyond the last there is"},
{with("message=MARK%F0%9F%BF%BE"), notPlain, "the last but one of the second plane, which is no character and which the bus refuses"},
{with("receiver-name=MARK%F3%AF%BF%BF"), notPlain, "and the last of the fifteenth"},
{with("message=%F8%88%80%80%80MARK"), notPlain, "five bytes, which begin no character"},
{with("message=MARK%C3"), notPlain, "a character cut short"},
{with("message=%FFMARK"), notPlain, "a byte that is in no character"},
{with("message=MARK%EF%BF%BD"), notPlain, "the mark that stands for what could not be read"},
{std::format("{}?receiver-name={}", to, times("a", 71)), tooLong, "a name of 71 characters"},
{std::format("{}?message={}", to, times("%C3%A9", 141)), tooLong, "a description of 141"},
};
for(const auto& [link, why, what] : refused) {
const Read<PaymentLink> none = ReadPaymentLink(link);
Check(!none.value && none.error.contains(why), std::format("a link is refused for {}: {}", what, why));
// Why it was refused is said in the app's own words: nothing of a stranger's link comes back in them.
Check(!none.error.contains("MARK") && !none.error.contains("NL91") && !none.error.contains("payto"), std::format("and what says so holds nothing of the link: {}", what));
}
// The form a link fills in: all of it the link's, in place of whatever was there, and none of it sent.
const Moment now = ParseLocalDate("2026-11-19 15:00");
PaymentForm form;
form.to.Set("bob@example.org");
form.description.Set("lunch");
form.when = When::Scheduled;
form.day.Set("2026-12-01");
form.unit = 3;
form.every.Set("2");
form.tried = true;
form.Fill(*ReadPaymentLink(with("amount=EUR:12.50&receiver-name=Shop%20BV&message=Order%201234")).value);
PaymentOrder order;
Check(!form.Check(euro, now, order).Any() && order.to.type == "IBAN" && order.to.value == iban && order.to.name == "Shop BV" && order.amount == 1250 && order.description == "Order 1234" && order.when == When::Now, "a link's form asks for what the link said, now");
Check(form.linked && !form.tried && form.day.value.empty() && form.unit == 0 && form.every.value.empty(), "with nothing left of what the form held before, and marked as a link's");
form.Fill(*ReadPaymentLink(to).value);
const PaymentForm::Errors errors = form.Check(euro, now, order);
Check(form.linked && form.amount.value.empty() && form.name.value.empty() && errors.amount == "Enter an amount" && errors.name == "The name of the account's holder", "a link that says no more than who is paid leaves the rest to the user");
form.Clear();
Check(!form.linked && form.to.value.empty(), "a cleared form is nobody's");
}
void Asking() {
RequestForm form;
RequestOrder order;
@ -428,6 +605,7 @@ int main() {
Words();
Reading();
Paying();
Linking();
Asking();
Filtering();
Connecting();