// SPDX-License-Identifier: LGPL-3.0-only // SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® export module Nostro.Checkout; import std; // Checkout: how a shop app has the user's nostro pay an order, and nothing else of nostro. nostrod pays the order from // the account the user chose for checkouts, once the user has confirmed it at a password prompt that shows the order and // that account; the app never names nor sees an account, and learns only the payment's id. A module of its own, so // `--product=checkout` builds it without nostro's bank code, OpenSSL, Crafter.Network or Crafter.DB: it needs libsystemd // alone. Apps in other languages use packaging/dbus/net.catcrafts.Nostro1.Checkout.xml instead. using namespace std::string_view_literals; export namespace Nostro::Checkout { // String views of literals, so `.data()` is NUL-terminated as sd-bus wants it. inline constexpr std::string_view busName = "net.catcrafts.Nostro1.Checkout"; inline constexpr std::string_view objectPath = "/net/catcrafts/Nostro1"; inline constexpr std::string_view interfaceName = "net.catcrafts.Nostro1.Checkout"; // Pay(payeeIban, payeeName, amount, currency, reference, options) -> (paymentId, results): the arguments' signature, // the reply's, and their names, each ended by a NUL. inline constexpr std::string_view payArguments = "ssxssa{sv}"; inline constexpr std::string_view payReply = "ta{sv}"; inline constexpr std::string_view payNames = "payeeIban\0payeeName\0amount\0currency\0reference\0options\0paymentId\0results\0"sv; // The errors an app tells apart, besides org.freedesktop.DBus.Error.AccessDenied (the system's policy refused), // ServiceUnknown (no nostro) and InteractiveAuthorizationRequired. nostrod's other interface uses the same names. inline constexpr std::string_view errorCancelled = "net.catcrafts.Nostro1.Error.Cancelled"; // the user did not confirm: nothing was paid inline constexpr std::string_view errorNoCheckoutAccount = "net.catcrafts.Nostro1.Error.NoCheckoutAccount"; // the user has no account to pay checkouts from inline constexpr std::string_view errorInvalidArgument = "net.catcrafts.Nostro1.Error.InvalidArgument"; // refused before anything was paid inline constexpr std::string_view errorBank = "net.catcrafts.Nostro1.Error.Bank"; // the bank refused inline constexpr std::string_view errorFailed = "net.catcrafts.Nostro1.Error.Failed"; // anything else // An order to pay. struct Order { std::string payeeIban; // who is paid: an IBAN, the only kind of payee checkout pays std::string payeeName; // their name, as the bank and the prompt show it std::int64_t amount = 0; // in the currency's smallest unit: 1250 is 12.50 std::string currency = "EUR"; // ISO 4217 std::string reference; // the order's own number: the payment's description, and what tells orders apart }; // What became of an order. struct Paid { std::uint64_t paymentId = 0; // the bank's id of the payment bool repeated = false; // paid before, by an earlier call with the same order: nothing was paid now }; // An error nostrod answered with, by its D-Bus name: errorBank, org.freedesktop.DBus.Error.AccessDenied, ... struct Error : std::runtime_error { std::string name; Error(std::string name, const std::string& message); }; // The user did not confirm the order: nothing was paid. struct Cancelled : Error { using Error::Error; }; // The user has no account to pay checkouts from (`nostro checkout account ` chooses one): nothing was paid. struct NoCheckoutAccount : Error { using Error::Error; }; // Has the user's nostro pay `order`, and waits for it: for nostrod to start, for the user to read the order and // confirm it with their password, and for the bank, up to `timeout`; so call it off the UI thread. An order is paid // once: the same payee and reference again, after a timeout or a crash, answers with the first payment // (Paid::repeated), or waits for it while the user is still at the prompt, and the same reference with another // amount is refused. Throws Cancelled, NoCheckoutAccount, std::invalid_argument for text that is not UTF-8, and // Error for the rest; an Error named org.freedesktop.DBus.Error.ServiceUnknown means nostro is not installed. Paid Pay(const Order& order, std::chrono::seconds timeout = std::chrono::minutes(10)); }