fix(checkout): return the customer to the merchant when payment is detected

A merchant that supplies `redirectURL` and `redirectAutomatically` is asking for its
customer back, and the moment to do that is detection rather than final depth. The
payment is already irreversible from the payer's side, and the merchant's own page is
where an order status belongs. Waiting for the confirmation target instead parks the
customer on a payment page for as long as the coin takes.

Only the classic style acted on those fields, and it held its own copy of the rule. The
standard style had no automatic return at all, and its way back appeared only once the
invoice was confirmed. Both styles now render one shared component, so the rule lives in
one place, and the return appears as soon as the payment is seen. The receipt still
waits for confirmation, because that is when there is a settled payment to describe.

Also ignores the tsbuildinfo a typecheck leaves behind.
This commit is contained in:
jwinterm
2026-09-05 10:50:02 -04:00
parent ad6121582e
commit 4fdac75ba3
4 changed files with 80 additions and 23 deletions
+20 -7
View File
@@ -6,6 +6,7 @@ import InvoicePaymentDetails from "../../../components/invoice-payment-details";
import InvoiceStatusAutoRefresh from "../../../components/invoice-status-auto-refresh";
import { formatRelativeTime } from "../../../components/relative-time";
import StatusRefreshButton from "../../../components/status-refresh-button";
import BtcpayAutoReturn from "../../../components/btcpay-auto-return";
export const dynamic = "force-dynamic";
export const metadata: Metadata = {
@@ -149,7 +150,12 @@ export default async function BtcpayModalInvoicePage({
const isBtcpayInvoice = Boolean(invoice.btcpay_amount && invoice.btcpay_currency);
const useClassicCheckout =
isBtcpayInvoice && invoice.btcpay_checkout_style === "btcpay_classic";
const shouldShowBtcpayActions = isBtcpayInvoice && invoice.status === "confirmed";
// The merchant's own order page is where a customer belongs once the payment has been seen, so
// the way back appears at detection. The receipt still waits for the confirmation target, because
// that is the point at which there is a settled payment to write one about.
const shouldShowBtcpayActions =
isBtcpayInvoice &&
(invoice.status === "payment_detected" || invoice.status === "confirmed");
const checkoutContinueAvailable =
!isBtcpayInvoice &&
invoice.status === "confirmed" &&
@@ -257,6 +263,11 @@ export default async function BtcpayModalInvoicePage({
) : null}
</div>
<BtcpayAutoReturn
status={invoice.status}
redirectUrl={invoice.btcpay_redirect_url ?? null}
redirectAutomatically={invoice.btcpay_redirect_automatically ?? null}
/>
<div className="mt-5">
<InvoicePaymentDetails
address={invoice.address}
@@ -270,12 +281,14 @@ export default async function BtcpayModalInvoicePage({
</div>
{shouldShowBtcpayActions ? (
<div className="mt-6 grid gap-3">
<a
className="inline-flex items-center justify-center rounded-full bg-sage px-6 py-3 text-sm font-semibold text-cream shadow-[0_14px_22px_rgba(93,122,106,0.25)] transition hover:-translate-y-0.5"
href={`/i/${encodeURIComponent(invoiceId)}/receipt`}
>
View receipt
</a>
{invoice.status === "confirmed" ? (
<a
className="inline-flex items-center justify-center rounded-full bg-sage px-6 py-3 text-sm font-semibold text-cream shadow-[0_14px_22px_rgba(93,122,106,0.25)] transition hover:-translate-y-0.5"
href={`/i/${encodeURIComponent(invoiceId)}/receipt`}
>
View receipt
</a>
) : null}
{invoice.btcpay_redirect_url ? (
<a
className="inline-flex items-center justify-center rounded-full border border-stroke bg-white px-6 py-3 text-sm font-semibold text-sage transition hover:bg-cream"