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:
parent
25d991658f
commit
b43ab124a6
42 changed files with 1234 additions and 994 deletions
|
|
@ -213,6 +213,11 @@ namespace Nostro::App {
|
|||
} else {
|
||||
overview.state = LoadState::Loading;
|
||||
}
|
||||
// A link that waits for the accounts starts from the one chosen for pay links: where that could not be read
|
||||
// either, it is read again with them.
|
||||
if(waiting && checkout.state == LoadState::Failed) {
|
||||
LoadCheckout();
|
||||
}
|
||||
Fetch<std::vector<ConnectorSummary>>("overview", "Connectors", [](Client& bank, Client::Then<std::vector<ConnectorSummary>> then) { return bank.Connectors(std::move(then)); }, [this, again](Answer<std::vector<ConnectorSummary>> answer) {
|
||||
if(answer.Failed()) {
|
||||
OverviewFailed(Explain(answer.Error(), Operation::Load));
|
||||
|
|
@ -276,6 +281,10 @@ namespace Nostro::App {
|
|||
if(!Find(filtering)) {
|
||||
filtering.clear();
|
||||
}
|
||||
// A link's payment waited for this. Last, so that it finds the accounts and the pages as they now are.
|
||||
if(waiting) {
|
||||
TakeLink();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -400,10 +409,14 @@ namespace Nostro::App {
|
|||
if(answer.Failed()) {
|
||||
checkout.state = LoadState::Failed;
|
||||
checkout.problem = Explain(answer.Error(), Operation::Load);
|
||||
return;
|
||||
} else {
|
||||
checkout.value = std::move(answer.Get());
|
||||
checkout.state = LoadState::Loaded;
|
||||
}
|
||||
// A link's payment starts from this account, and waited to hear which it is, or that it cannot be read.
|
||||
if(waiting) {
|
||||
TakeLink();
|
||||
}
|
||||
checkout.value = std::move(answer.Get());
|
||||
checkout.state = LoadState::Loaded;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -575,6 +588,34 @@ namespace Nostro::App {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool App::Open(std::string_view link) {
|
||||
// Not from under a change, as no place is gone to from under one.
|
||||
if(changing) {
|
||||
return false;
|
||||
}
|
||||
Read<PaymentLink> read = ReadPaymentLink(link);
|
||||
if(!read.value) {
|
||||
// Said over wherever the user is, with nothing of the link in it: what a stranger wrote is not shown as
|
||||
// the app's own words. A link that waits is left waiting.
|
||||
Dialog problem;
|
||||
problem.kind = Dialog::Kind::Problem;
|
||||
problem.name = "link";
|
||||
problem.title = "This link cannot be opened";
|
||||
problem.text = {std::move(read.error)};
|
||||
problem.choices.push_back({"link.close", "Close", Ui::ButtonKind::Tonal, true, {}, [this] { Close(); }});
|
||||
Show(std::move(problem));
|
||||
return true;
|
||||
}
|
||||
Go(Place::Accounts);
|
||||
waiting = std::move(*read.value);
|
||||
// The form starts from the account the user chose for pay links to start from, so that is read if it was not.
|
||||
if(checkout.state == LoadState::Idle || checkout.state == LoadState::Failed) {
|
||||
LoadCheckout();
|
||||
}
|
||||
TakeLink();
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string App::Screen() const {
|
||||
static constexpr std::array<std::string_view, 3> places = {"accounts", "cards", "settings"};
|
||||
// The three steps of adding a connection are one name, as far as it has been gone: "add:bunq:key".
|
||||
|
|
@ -624,6 +665,57 @@ namespace Nostro::App {
|
|||
Push(Page::Request);
|
||||
}
|
||||
|
||||
// Tried when a link is opened, and again as the accounts and the account pay links start from are read: it goes
|
||||
// ahead once both are known, or the second is known not to be readable. It is safe to try again: a reading that
|
||||
// fails at once, as one without a system bus does, has tried it already by the time whoever asked for the reading
|
||||
// tries it, and then no link waits any more.
|
||||
void App::TakeLink() {
|
||||
if(!waiting || overview.state != LoadState::Loaded || checkout.state == LoadState::Loading) {
|
||||
return;
|
||||
}
|
||||
const PaymentLink link = std::move(*waiting);
|
||||
waiting.reset();
|
||||
// The user went elsewhere while the accounts were read, or is being told something: what they are doing is not
|
||||
// taken from under them for what a link asks. The link is theirs to open again.
|
||||
if(place != Place::Accounts || !stack.empty() || dialog.has_value()) {
|
||||
Tell("The link's payment was not opened: open the link again");
|
||||
return;
|
||||
}
|
||||
// No bank connected, or none whose accounts could be read: there is nothing to pay from, and no form to show.
|
||||
if(Accounts().empty()) {
|
||||
Dialog none;
|
||||
none.kind = Dialog::Kind::Problem;
|
||||
none.name = "link";
|
||||
none.title = "No account to pay from";
|
||||
none.text = {"This link asks for a payment, and there is no account to pay it from. Once your bank is connected and its accounts show here, open the link again."};
|
||||
none.choices.push_back({"link.close", "Close", Ui::ButtonKind::Tonal, true, {}, [this] { Close(); }});
|
||||
Show(std::move(none));
|
||||
return;
|
||||
}
|
||||
// From the account the user chose in the settings for pay links to start from. Without one, from the first
|
||||
// whose connection pays anybody: one that pays between the user's own accounts only could do no more than
|
||||
// save a draft.
|
||||
std::string from;
|
||||
if(checkout.state == LoadState::Loaded && checkout.value && Find(AccountKey(*checkout.value))) {
|
||||
from = AccountKey(*checkout.value);
|
||||
} else {
|
||||
for(const AccountRef& account : Accounts()) {
|
||||
if(!account.connection->ownAccountsOnly) {
|
||||
from = account.key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
payment.Fill(link);
|
||||
OpenPay(std::move(from));
|
||||
// Which account pays is the user's to say, and a link is where that is asked rather than assumed: the form
|
||||
// opens with its choice of accounts over it, the one it starts from marked, and a tap beside the choice keeps
|
||||
// that one. With one account there is nothing to choose, and the form opens as it is.
|
||||
if(Accounts().size() > 1) {
|
||||
picking = Picking::PayFrom;
|
||||
}
|
||||
}
|
||||
|
||||
// The pay form's button: what is filled in is checked, and sent. The app asks nothing more itself: a payment, a
|
||||
// schedule and a draft are each confirmed in the system's password dialog, which nostrod words from its own data,
|
||||
// and a draft is not paid until it is accepted, which is confirmed there once more.
|
||||
|
|
@ -1010,8 +1102,8 @@ namespace Nostro::App {
|
|||
Change<std::string>(Operation::RemoveConnection, "RemoveConnector", std::format("Removing {}", name), {}, [connector](Client& bank, Client::Then<std::string> then) { return bank.RemoveConnector(connector, std::move(then)); }, [this](std::string& removed) {
|
||||
dialog.reset();
|
||||
Tell(std::format("Removed {}", removed));
|
||||
// Its cards and its say at checkout went with it: the cards are read when they are next looked at, the
|
||||
// checkout's account now, the settings being where connections are removed from.
|
||||
// Its cards went with it, and it may have held the account pay links start from: the cards are read
|
||||
// when they are next looked at, that account now, the settings being where connections are removed from.
|
||||
cards = {};
|
||||
LoadCheckout();
|
||||
Refresh();
|
||||
|
|
@ -1094,11 +1186,11 @@ namespace Nostro::App {
|
|||
}
|
||||
|
||||
void App::ChooseCheckout(const std::string& key, const std::string& name) {
|
||||
Change<Account>(Operation::SetCheckoutAccount, "SetDefaultCheckoutAccount", std::format("Letting apps ask you to pay from {}", name), {}, [key](Client& bank, Client::Then<Account> then) { return bank.SetDefaultCheckoutAccount(key, std::move(then)); }, [this](Account& chosen) {
|
||||
Change<Account>(Operation::SetCheckoutAccount, "SetDefaultCheckoutAccount", std::format("Having pay links start from {}", name), {}, [key](Client& bank, Client::Then<Account> then) { return bank.SetDefaultCheckoutAccount(key, std::move(then)); }, [this](Account& chosen) {
|
||||
checkout.value = chosen;
|
||||
checkout.state = LoadState::Loaded;
|
||||
dialog.reset();
|
||||
Tell(std::format("Apps now ask you to pay from {}", chosen.name));
|
||||
Tell(std::format("Pay links now start from {}", chosen.name));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue