commit 82bde503a45abaee86f80161aadfa44d22dd4719
parent 42537cfe934c7914036ac3ea66f6112af10eb634
Author: Florian Dold <dold@taler.net>
Date: Thu, 26 Nov 2026 04:16:32 +0100
wallet-webui: keep the template form open after a merchant rejection
Keep the entered details editable after a rejection, including the
currency when the merchant allows a choice. Reopen checkout when the
inbox has an order ID. If the outcome is unknown, offer a link to
history and block another submission.
Diffstat:
4 files changed, 429 insertions(+), 61 deletions(-)
diff --git a/packages/wallet-webui/src/routes/App.tsx b/packages/wallet-webui/src/routes/App.tsx
@@ -204,6 +204,8 @@ import {
import {
cancelTransactionBeforeCompleting,
restoreActionGateReason,
+ submitTemplateOrder,
+ uncertainTemplateOrder,
unsupportedQrCodeHint,
withdrawalTransferResultHint,
} from "./action-model.js";
@@ -3259,6 +3261,9 @@ function ActionRoute() {
const [detail, setDetail] = useState<string>();
const [actionError, setActionError] = useState<ErrorPresentation>();
const [canRetry, setCanRetry] = useState(false);
+ const [unknownTemplate, setUnknownTemplate] = useState(false);
+ const activeEntry = useRef<string>();
+ const preparing = useRef<string>();
const parsed = useMemo(
() => (entry ? TalerUris.parse(entry.uri) : undefined),
[entry],
@@ -3285,11 +3290,25 @@ function ActionRoute() {
setDetail(undefined);
setActionError(undefined);
setCanRetry(false);
+ setUnknownTemplate(false);
void platform.actionInbox
.get(params?.id ?? "")
.then((value) => {
if (!active) return;
+ activeEntry.current = value?.id;
setEntry(value);
+ if (value?.templateOrder && value.templateOrder !== "started") {
+ navigate(`/pay/${value.templateOrder}/${value.id}`, {
+ replace: true,
+ });
+ return;
+ }
+ if (value?.templateOrder === "started") {
+ setActionError(uncertainTemplateOrder());
+ setUnknownTemplate(true);
+ setState("error");
+ return;
+ }
const uri = value && TalerUris.parse(value.uri);
if (
value &&
@@ -3309,6 +3328,7 @@ function ActionRoute() {
});
return () => {
active = false;
+ activeEntry.current = undefined;
};
}, [params?.id, platform, navigate]);
const discard = () => {
@@ -3319,10 +3339,12 @@ function ActionRoute() {
navigate("/");
};
const prepare = async () => {
- if (!entry || !parsed) return;
+ if (!entry || !parsed || preparing.current === entry.id) return;
+ preparing.current = entry.id;
setState("working");
setActionError(undefined);
setCanRetry(false);
+
try {
if (Result.isError(parsed)) {
if (parsedPayto && Result.isOk(parsedPayto)) {
@@ -3340,6 +3362,7 @@ function ActionRoute() {
WalletApiOperation.CheckPayForTemplate,
{ talerPayTemplateUri: entry.uri },
);
+ if (activeEntry.current !== entry.id) return;
if (Result.isError(checked)) {
setActionError(
walletCoreError(
@@ -3356,26 +3379,29 @@ function ActionRoute() {
contract.template_type === TemplateType.FIXED_ORDER &&
(!contract.amount || !contract.summary)
) {
- navigate(`/pay-template/${entry.id}`);
+ navigate(`/pay-template/${entry.id}`, { replace: true });
return;
}
- const result = await progressRequest.callAndInvalidate(
- WalletApiOperation.PreparePayForTemplateV2,
- { talerPayTemplateUri: entry.uri },
- ["transactions"],
- );
- if (Result.isError(result)) {
- setActionError(
- walletCoreError(
- result.detail,
- /* Translators: wallet-core is the background wallet engine; keep the component name unchanged. */ i18n.str`Wallet-core could not prepare this payment template.`,
+ const result = await submitTemplateOrder(
+ platform.actionInbox,
+ entry.id,
+ () =>
+ progressRequest.callAndInvalidate(
+ WalletApiOperation.PreparePayForTemplateV2,
+ { talerPayTemplateUri: entry.uri },
+ ["transactions"],
),
- );
- setCanRetry(true);
+ i18n.str`The merchant could not prepare this order.`,
+ );
+ if (activeEntry.current !== entry.id) return;
+ if ("error" in result) {
+ setActionError(result.error);
+ setCanRetry(result.retryable);
+ setUnknownTemplate(!result.retryable);
setState("error");
return;
}
- navigate(`/pay/${result.value.transactionId}/${entry.id}`);
+ navigate(`/pay/${result.transactionId}/${entry.id}`, { replace: true });
return;
} else if (parsed.value.type === TalerUriAction.WithdrawExchange) {
navigate(`/withdraw-exchange/${entry.id}`);
@@ -3478,13 +3504,20 @@ function ActionRoute() {
return;
}
} catch (error) {
- if (!isProgressRequestCancelled(error)) {
- setActionError(
- errorFromException(error, i18n.str`Action preparation failed`),
- );
- setCanRetry(true);
- setState("error");
+ if (activeEntry.current !== entry.id) return;
+ if (isProgressRequestCancelled(error)) {
+ setState("ready");
+ return;
}
+ const failure = errorFromException(
+ error,
+ i18n.str`Action preparation failed`,
+ );
+ setActionError(failure);
+ setCanRetry(true);
+ setState("error");
+ } finally {
+ if (preparing.current === entry.id) preparing.current = undefined;
}
};
if (
@@ -3515,6 +3548,9 @@ function ActionRoute() {
}
source={entry?.source}
error={actionError}
+ onViewHistory={
+ unknownTemplate ? () => navigate("/transactions") : undefined
+ }
detail={
detail ??
(parsed && Result.isOk(parsed)
@@ -4045,19 +4081,43 @@ function PaymentTemplateRoute() {
const [, navigate] = useLocation();
const { controller: progressRequest } = useWalletProgress(connection);
const [data, setData] = useState<TemplateRouteData>();
+ const [attempt, setAttempt] = useState(0);
+ const [submitError, setSubmitError] = useState<ErrorPresentation>();
+ const [unknownOutcome, setUnknownOutcome] = useState(false);
+ const activeAction = useRef<string>();
+ const submitting = useRef<string>();
const [loading, setLoading] = useState(true);
const [working, setWorking] = useState(false);
const [error, setError] = useState<ErrorPresentation>();
const actionId = params?.actionId ?? "";
useEffect(() => {
let active = true;
+ activeAction.current = actionId;
+ setLoading(true);
+ setError(undefined);
+ setData(undefined);
+ setSubmitError(undefined);
+ setUnknownOutcome(false);
+ setWorking(false);
void (async () => {
try {
const entry = await platform.actionInbox.get(actionId);
+ if (!active) return;
if (!entry)
throw Error(
i18n.str`This payment template expired or was already completed.`,
);
+ if (entry.templateOrder && entry.templateOrder !== "started") {
+ navigate(`/pay/${entry.templateOrder}/${actionId}`, {
+ replace: true,
+ });
+ return;
+ }
+ if (entry.templateOrder === "started") {
+ setSubmitError(uncertainTemplateOrder());
+ setUnknownOutcome(true);
+ return;
+ }
const parsed = TalerUris.parse(entry.uri);
if (
Result.isError(parsed) ||
@@ -4095,8 +4155,7 @@ function PaymentTemplateRoute() {
const requiredCurrency =
fixed?.currency ??
checked.value.templateDetails.required_currency ??
- contract.currency ??
- defaultCurrency;
+ contract.currency;
const currencies = requiredCurrency
? [requiredCurrency]
: Array.from(new Set(checked.value.supportedCurrencies));
@@ -4108,8 +4167,16 @@ function PaymentTemplateRoute() {
setData({
uri: entry.uri,
currencies,
- initialCurrency: requiredCurrency ?? currencies[0],
- initialAmount: fixed?.value ?? defaultAmount?.value ?? "",
+ initialCurrency:
+ requiredCurrency ??
+ (defaultCurrency && currencies.includes(defaultCurrency)
+ ? defaultCurrency
+ : currencies[0]),
+ initialAmount:
+ fixed?.value ??
+ (defaultAmount && currencies.includes(defaultAmount.currency)
+ ? defaultAmount.value
+ : ""),
initialSummary:
contract.summary ??
checked.value.templateDetails.editable_defaults?.summary ??
@@ -4122,7 +4189,9 @@ function PaymentTemplateRoute() {
: {}),
});
} catch (cause) {
- if (active && !isProgressRequestCancelled(cause))
+ if (active && isProgressRequestCancelled(cause))
+ setError(localError(i18n.str`Payment lookup cancelled.`));
+ else if (active)
setError(
errorFromException(
cause,
@@ -4135,16 +4204,18 @@ function PaymentTemplateRoute() {
})();
return () => {
active = false;
+ activeAction.current = undefined;
};
- }, [actionId, platform, progressRequest]);
+ }, [actionId, platform, progressRequest, attempt]);
const cancel = () => {
void completeActionBestEffort(platform.actionInbox, actionId);
navigate("/");
};
const review = async (values: PaymentTemplateValues) => {
- if (!data) return;
+ if (!data || submitting.current === actionId || unknownOutcome) return;
+ submitting.current = actionId;
setWorking(true);
- setError(undefined);
+ setSubmitError(undefined);
const templateParams: TemplateParams = {
...(data.amountEditable
? { amount: `${values.currency}:${values.amount}` as AmountString }
@@ -4152,28 +4223,31 @@ function PaymentTemplateRoute() {
...(data.summaryEditable ? { summary: values.summary } : {}),
};
try {
- const result = await progressRequest.callAndInvalidate(
- WalletApiOperation.PreparePayForTemplateV2,
- { talerPayTemplateUri: data.uri, templateParams },
- ["transactions"],
- );
- if (Result.isError(result)) {
- setError(
- walletErrorHint(
- result.detail,
- i18n.str`The merchant rejected these payment details.`,
+ const result = await submitTemplateOrder(
+ platform.actionInbox,
+ actionId,
+ () =>
+ progressRequest.callAndInvalidate(
+ WalletApiOperation.PreparePayForTemplateV2,
+ { talerPayTemplateUri: data.uri, templateParams },
+ ["transactions"],
),
- );
+ );
+ if (activeAction.current !== actionId) return;
+ if ("error" in result) {
+ setUnknownOutcome(!result.retryable);
+ setSubmitError(result.error);
} else {
- navigate(`/pay/${result.value.transactionId}/${actionId}`);
+ navigate(`/pay/${result.transactionId}/${actionId}`, { replace: true });
}
} catch (cause) {
- if (!isProgressRequestCancelled(cause))
- setError(
- errorFromException(cause, i18n.str`Payment preparation failed`),
- );
+ if (activeAction.current !== actionId) return;
+ setSubmitError(
+ errorFromException(cause, i18n.str`Payment preparation failed`),
+ );
} finally {
- setWorking(false);
+ if (submitting.current === actionId) submitting.current = undefined;
+ if (activeAction.current === actionId) setWorking(false);
}
};
return (
@@ -4181,6 +4255,10 @@ function PaymentTemplateRoute() {
loading={loading}
working={working}
error={error}
+ submitError={submitError}
+ unknownOutcome={unknownOutcome}
+ onRetryLoad={() => setAttempt((n) => n + 1)}
+ onViewHistory={() => navigate("/transactions")}
currencies={data?.currencies ?? []}
initialCurrency={data?.initialCurrency ?? ""}
initialAmount={data?.initialAmount ?? ""}
diff --git a/packages/wallet-webui/src/screens/ActionScreen.tsx b/packages/wallet-webui/src/screens/ActionScreen.tsx
@@ -71,6 +71,7 @@ export function ActionScreen(props: {
onCancel: () => void;
onBack?: () => void;
onRetry?: () => void;
+ onViewHistory?: () => void;
onDiscard?: () => void;
}) {
return (
@@ -90,6 +91,11 @@ export function ActionScreen(props: {
}
/>
<div class="mt-5 flex flex-wrap gap-3">
+ {props.onViewHistory && (
+ <Button
+ onClick={props.onViewHistory}
+ >{i18n.str`View transaction history`}</Button>
+ )}
{props.onRetry && (
<Button onClick={props.onRetry}>{i18n.str`Retry`}</Button>
)}
diff --git a/packages/wallet-webui/src/screens/PaymentTemplateScreen.tsx b/packages/wallet-webui/src/screens/PaymentTemplateScreen.tsx
@@ -5,7 +5,12 @@ import { Card } from "../ui/Card.js";
import { ErrorCard } from "../ui/ErrorCard.js";
import type { ErrorPresentation } from "../ui/error.js";
import { i18n } from "../i18n/runtime.js";
-import { positiveAmountValue } from "../routes/money-flow-model.js";
+import { useLanguage } from "../i18n/LanguageProvider.js";
+import {
+ positiveAmountValue,
+ localizedAmountInput,
+ amountInputHint,
+} from "../routes/money-flow-model.js";
export interface PaymentTemplateValues {
currency: string;
@@ -17,6 +22,10 @@ export function PaymentTemplateScreen(props: {
loading: boolean;
working: boolean;
error?: ErrorPresentation;
+ submitError?: ErrorPresentation;
+ unknownOutcome?: boolean;
+ onRetryLoad?: () => void;
+ onViewHistory?: () => void;
currencies: string[];
initialCurrency: string;
initialAmount: string;
@@ -28,19 +37,28 @@ export function PaymentTemplateScreen(props: {
onReview: (values: PaymentTemplateValues) => void;
onCancel: () => void;
}) {
+ const { language } = useLanguage();
+ const initialAmount = localizedAmountInput(props.initialAmount, language);
const [currency, setCurrency] = useState(props.initialCurrency);
- const [amount, setAmount] = useState(props.initialAmount);
+ const [amount, setAmount] = useState(initialAmount);
const [summary, setSummary] = useState(props.initialSummary);
useEffect(() => {
setCurrency(props.initialCurrency);
- setAmount(props.initialAmount);
+ setAmount(initialAmount);
setSummary(props.initialSummary);
- }, [props.initialAmount, props.initialCurrency, props.initialSummary]);
- const normalizedAmount = positiveAmountValue(currency, amount);
- const valid = Boolean(normalizedAmount) && Boolean(summary.trim());
+ }, [initialAmount, props.initialCurrency, props.initialSummary]);
+ const normalizedAmount = props.amountEditable
+ ? positiveAmountValue(currency, amount, undefined, language)
+ : props.initialAmount;
+ const submittingBlocked = props.working || props.unknownOutcome;
+ const valid =
+ Boolean(normalizedAmount) && Boolean(summary.trim()) && !submittingBlocked;
const amountInput = useRef<HTMLInputElement>(null);
const summaryInput = useRef<HTMLInputElement>(null);
- const formShown = !props.loading && !props.error;
+ const formShown =
+ !props.loading &&
+ !props.error &&
+ (!props.unknownOutcome || props.currencies.length > 0);
// Focus the first field the merchant left for the payer to fill in; the
// form only appears once the template has loaded.
useFocusScope({
@@ -58,9 +76,12 @@ export function PaymentTemplateScreen(props: {
<button
type="button"
onClick={props.onCancel}
+ disabled={props.working}
aria-label={
// Translators: Accessible label for closing a merchant-defined payment-template form.
- i18n.str`Cancel payment template`
+ props.unknownOutcome
+ ? i18n.str`Back to wallet`
+ : i18n.str`Cancel payment template`
}
class="grid h-11 w-11 place-items-center rounded-full text-2xl hover:bg-secondaryContainer"
>
@@ -81,7 +102,22 @@ export function PaymentTemplateScreen(props: {
<p role="status">{i18n.str`Loading payment template…`}</p>
</Card>
)}
- {props.error && <ErrorCard error={props.error} />}
+ {props.error && (
+ <ErrorCard error={props.error}>
+ {props.onRetryLoad && (
+ <Button onClick={props.onRetryLoad}>{i18n.str`Retry`}</Button>
+ )}
+ </ErrorCard>
+ )}
+ {props.submitError && (
+ <ErrorCard error={props.submitError}>
+ {props.unknownOutcome && props.onViewHistory && (
+ <Button
+ onClick={props.onViewHistory}
+ >{i18n.str`View transaction history`}</Button>
+ )}
+ </ErrorCard>
+ )}
{formShown && (
<form
class="space-y-5"
@@ -100,7 +136,9 @@ export function PaymentTemplateScreen(props: {
<span class="mb-1 block text-sm font-medium">{i18n.str`Currency`}</span>
<select
disabled={
- !props.currencyEditable || props.currencies.length < 2
+ submittingBlocked ||
+ !props.currencyEditable ||
+ props.currencies.length < 2
}
value={currency}
onChange={(event) => setCurrency(event.currentTarget.value)}
@@ -119,7 +157,7 @@ export function PaymentTemplateScreen(props: {
<input
ref={amountInput}
inputMode="decimal"
- disabled={!props.amountEditable}
+ disabled={submittingBlocked || !props.amountEditable}
value={amount}
onInput={(event) => setAmount(event.currentTarget.value)}
class="min-h-11 min-w-0 flex-1 rounded-l-xl border-0 bg-transparent px-3 outline-none disabled:opacity-70"
@@ -129,7 +167,9 @@ export function PaymentTemplateScreen(props: {
</span>
</div>
{amount && !normalizedAmount && (
- <span class="mt-1 block text-sm text-error">{i18n.str`Enter an amount greater than zero.`}</span>
+ <span class="mt-1 block text-sm text-error">
+ {amountInputHint(language)}
+ </span>
)}
</label>
<label class="block">
@@ -141,7 +181,7 @@ export function PaymentTemplateScreen(props: {
</span>
<input
ref={summaryInput}
- disabled={!props.summaryEditable}
+ disabled={submittingBlocked || !props.summaryEditable}
value={summary}
onInput={(event) => setSummary(event.currentTarget.value)}
class="min-h-11 w-full rounded-xl border border-outline bg-surface px-3 disabled:opacity-70"
@@ -161,8 +201,13 @@ export function PaymentTemplateScreen(props: {
<Button
tone="secondary"
onClick={props.onCancel}
- >{i18n.str`Cancel`}</Button>
- <Button type="submit" disabled={!valid || props.working}>
+ disabled={props.working}
+ >
+ {props.unknownOutcome
+ ? i18n.str`Back to wallet`
+ : i18n.str`Cancel`}
+ </Button>
+ <Button type="submit" disabled={!valid}>
{props.working ? i18n.str`Preparing…` : i18n.str`Review payment`}
</Button>
</div>
diff --git a/packages/wallet-webui/test/payment-entry.test.tsx b/packages/wallet-webui/test/payment-entry.test.tsx
@@ -31,6 +31,7 @@ import {
demoActionUris,
} from "../src/testing/demo-wallet.js";
import type { ActionEntry } from "../src/api/contracts.js";
+import { HostDisconnectedError } from "../src/api/rpc.js";
import { SessionStorageActionStore } from "../src/platform/action-inbox.js";
import { makePwaPlatform } from "../src/platform/adapters.js";
@@ -302,6 +303,244 @@ test("leaving payment preparation cannot navigate back to review", async () => {
}
});
+test("editable template defaults, corrected rejection, and uncertain order creation", async () => {
+ const h = await harness("paste");
+ const uri = "taler://pay-template/shop.example/template";
+ const original = h.services.connection.client.callForResult;
+ let posts = 0;
+ let checks = 0;
+ h.services.connection.client.callForResult = async (operation, request) => {
+ if (operation === WalletApiOperation.CheckPayForTemplate) {
+ if (++checks === 1)
+ throw TalerError.fromDetail(
+ TalerErrorCode.WALLET_CORE_REQUEST_CANCELLED,
+ {},
+ );
+ return Result.of({
+ templateDetails: {
+ template_contract: { template_type: TemplateType.FIXED_ORDER },
+ editable_defaults: { amount: "CHF:4.5", summary: "Lunch" },
+ },
+ supportedCurrencies: ["CHF", "EUR"],
+ availableBalances: [],
+ }) as never;
+ }
+ if (operation === WalletApiOperation.PreparePayForTemplateV2) {
+ if (++posts === 1)
+ throw new HostDisconnectedError("wallet offline", "", "not-sent");
+ if (posts === 2)
+ throw TalerError.fromUncheckedDetail({
+ code: TalerErrorCode.GENERIC_UNEXPECTED_REQUEST_ERROR,
+ requestMethod: "POST",
+ httpStatusCode: 409,
+ errorResponse: {
+ code: TalerErrorCode.MERCHANT_POST_USING_TEMPLATES_NO_SUMMARY,
+ },
+ });
+ throw new HostDisconnectedError(
+ "order response lost",
+ "order",
+ "unknown",
+ );
+ }
+ return original(operation, request);
+ };
+ try {
+ await h.pasteLink(uri);
+ const button = (name: string) =>
+ h.view.getByRole("button", { name, exact: true }) as HTMLButtonElement;
+ const click = (name: string) => h.act(() => button(name).click());
+ await h.waitFor(() => assert.ok(button("Continue")));
+ await click("Continue");
+ await h.waitFor(() => assert.ok(!button("Continue").disabled));
+ assert.equal(checks, 1);
+ await click("Continue");
+ await h.waitFor(() => assert.ok(!button("Review payment").disabled));
+ const currency = h.view.getByRole("combobox") as HTMLSelectElement;
+ assert.deepEqual(
+ Array.from(currency.options, (option) => option.value),
+ ["CHF", "EUR"],
+ );
+ assert.equal(currency.disabled, false);
+ assert.equal(currency.value, "CHF");
+ await click("Review payment");
+ await h.waitFor(() =>
+ assert.ok(h.view.getByText("Payment preparation failed")),
+ );
+ assert.equal(button("Review payment").disabled, false);
+ await click("Review payment");
+ await h.waitFor(() =>
+ assert.ok(
+ h.view.getByText("The merchant rejected these payment details."),
+ ),
+ );
+ assert.equal(button("Review payment").disabled, false);
+ assert.equal(
+ (h.view.getByDisplayValue("Lunch") as HTMLInputElement).disabled,
+ false,
+ );
+ await click("Review payment");
+ await h.waitFor(() =>
+ assert.match(
+ h.view.getByRole("alert").textContent ?? "",
+ /merchant may already have created/,
+ ),
+ );
+ assert.ok(button("Review payment").disabled);
+ assert.equal(h.view.queryByRole("button", { name: "Cancel" }), null);
+ assert.equal(
+ h.view.queryByRole("button", { name: "Cancel payment template" }),
+ null,
+ );
+ assert.equal(posts, 3);
+ await click("View transaction history");
+ await h.waitFor(() => assert.equal(h.dom.location.hash, "#/transactions"));
+ await h.act(() => h.dom.history.back());
+ await h.waitFor(() =>
+ assert.match(
+ h.view.getByRole("alert").textContent ?? "",
+ /merchant may already have created/,
+ ),
+ );
+ await h.remount();
+ await h.waitFor(() =>
+ assert.match(
+ h.view.getByRole("alert").textContent ?? "",
+ /merchant may already have created/,
+ ),
+ );
+ assert.equal(
+ h.view.queryByRole("button", { name: "Review payment" }),
+ null,
+ );
+ assert.equal(posts, 3);
+ } finally {
+ await h.close();
+ }
+});
+
+test("a fixed template action stays guarded after history navigation", async () => {
+ const h = await harness("paste");
+ const original = h.services.connection.client.callForResult;
+ let posts = 0;
+ h.services.connection.client.callForResult = async (operation, request) => {
+ if (operation === WalletApiOperation.CheckPayForTemplate) {
+ return Result.of({
+ templateDetails: {
+ template_contract: {
+ template_type: TemplateType.FIXED_ORDER,
+ amount: "CHF:3",
+ summary: "Lunch",
+ },
+ },
+ supportedCurrencies: ["CHF"],
+ availableBalances: [],
+ }) as never;
+ }
+ if (operation === WalletApiOperation.PreparePayForTemplateV2) {
+ posts++;
+ throw Error("Response lost");
+ }
+ return original(operation, request);
+ };
+ try {
+ await h.pasteLink("taler://pay-template/shop.example/fixed");
+ await h.waitFor(() =>
+ assert(h.view.getByRole("button", { name: "Continue" })),
+ );
+ await h.act(() => h.view.getByRole("button", { name: "Continue" }).click());
+ await h.waitFor(() =>
+ assert(h.view.getByRole("button", { name: "View transaction history" })),
+ );
+ await h.act(() =>
+ h.view.getByRole("button", { name: "View transaction history" }).click(),
+ );
+ await h.waitFor(() => assert.equal(h.dom.location.hash, "#/transactions"));
+ await h.act(() => h.dom.history.back());
+ await h.waitFor(() =>
+ assert.match(
+ h.view.getByRole("alert").textContent ?? "",
+ /merchant may already have created/,
+ ),
+ );
+ await h.remount();
+ await h.waitFor(() =>
+ assert.match(
+ h.view.getByRole("alert").textContent ?? "",
+ /merchant may already have created/,
+ ),
+ );
+ assert.equal(h.view.queryByRole("button", { name: "Continue" }), null);
+ assert.equal(h.view.queryByRole("button", { name: "Retry" }), null);
+ assert.equal(posts, 1);
+ } finally {
+ await h.close();
+ }
+});
+
+test("a free fixed-price template accepts a summary and its old routes reopen the checkout", async () => {
+ const h = await harness("paste");
+ const original = h.services.connection.client.callForResult;
+ let posts = 0;
+ h.services.connection.client.callForResult = async (operation, request) => {
+ if (operation === WalletApiOperation.CheckPayForTemplate)
+ return Result.of({
+ templateDetails: {
+ template_contract: {
+ template_type: TemplateType.FIXED_ORDER,
+ amount: "CHF:0",
+ },
+ editable_defaults: { summary: "Lunch" },
+ },
+ supportedCurrencies: ["CHF"],
+ availableBalances: [],
+ }) as never;
+ if (operation === WalletApiOperation.PreparePayForTemplateV2) {
+ posts++;
+ assert.deepEqual(
+ (request as { templateParams: unknown }).templateParams,
+ { summary: "Lunch" },
+ );
+ return original(WalletApiOperation.PreparePayForUriV2, {
+ talerPayUri: demoActionUris.payment,
+ }) as never;
+ }
+ return original(operation, request);
+ };
+ try {
+ await h.pasteLink("taler://pay-template/shop.example/template");
+ await h.waitFor(() =>
+ assert(h.view.getByRole("button", { name: "Continue" })),
+ );
+ const actionRoute = h.dom.location.hash;
+ await h.act(() => h.view.getByRole("button", { name: "Continue" }).click());
+ await h.waitFor(() =>
+ assert(h.view.getByRole("button", { name: "Review payment" })),
+ );
+ const formRoute = h.dom.location.hash;
+ const length = h.dom.history.length;
+ await h.act(() =>
+ h.view.getByRole("button", { name: "Review payment" }).click(),
+ );
+ await h.waitFor(() =>
+ assert.match(h.dom.location.hash, /^#\/pay\/txn:payment:/),
+ );
+ const checkout = h.dom.location.hash;
+ assert.equal(h.dom.history.length, length);
+ await h.act(() => h.dom.history.back());
+ await h.waitFor(() => assert.equal(h.dom.location.hash, "#/enter"));
+ for (const route of [actionRoute, formRoute]) {
+ await h.act(() => {
+ h.dom.location.hash = route;
+ });
+ await h.waitFor(() => assert.equal(h.dom.location.hash, checkout));
+ }
+ assert.equal(posts, 1);
+ } finally {
+ await h.close();
+ }
+});
+
test("unsupported contact links explain the limitation when opened", async () => {
const h = await harness("paste");
try {