# Recover abandoned checkouts and payments

Discover the [checkout recovery reminder schedule](../operate/settings-catalogue.md#checkout_recovery_reminders) in the settings catalogue.

Let customers resume unpaid checkouts, request payment links, or replace
technically expired orders. Compose recovery on your server with your
authentication, routes, screens, localized messages, transport and schedules.

Commerce factories below use `@openlup/platform/commerce/server` in Node.
Install the complete native PostgreSQL catalogue. For maturity, consult the
[platform capability
reference](https://github.com/openlup/openlup/blob/openlup-core-v1.4.0/packages/platform/release-gates.json).
The native payment execution and recreation bindings described here use the
sandbox simulator. Their public query executors are structural and require no
database-driver types merely to import or compose these factories. Unconfigured
provider actions retain `native_prepared_attempt_store_unsupported`. The 0.42.0
source supplies a separate explicit card provider composition; see [provider adapters](../extend/provider-adapters.md#card-and-wallet-payment-template).

Recovery covers one-time purchases and eligible provisional initial subscription
checkouts, before a live subscription exists. Orders with a non-null
`subscriptionCycleId` belong to renewal recovery and refuse these checkout
flows.

## Issue a recovery token for an admitted checkout

Use `generateCheckoutRecoveryToken` and
`createPostgresCheckoutRecoveryTokenPort` only after your server has authorized
the purchase. Caller-supplied identifiers or email addresses are not authority.

Supply a dedicated `PostgresRoleFreeTransactionLane` through
`createPostgresRoleFreeTransactionLane` from `@openlup/platform/data`, with
effective service-role privileges. Methods own READ COMMITTED transactions. Keep
it separate from actor lanes and close it when finished. Missing privileges
produce `checkout_recovery_service_required`.

Call `issue({ orderId, rawToken, expiresAt })`. This adapter ignores `expiresAt`
and derives a bounded expiry from order creation, preserving database
sub-millisecond precision. It locks the order and contact, requiring
`pending_payment`, a contact and no renewal cycle. Ineligible orders or elapsed
deadlines produce `checkout_recovery_order_not_recoverable`. The contact need
not have a customer principal. Store the raw bearer securely and exclude it from
logs; the token table receives only its SHA-256 hash.

New service-issued links leave earlier checkout links live. Reusing the same
hash for the same eligible order returns the original token ID without
reactivating it. Actor-issued checkout links also preserve earlier links.
Renewal payment-case issuance uses its separate rotating issuer, serializing on
the pending order before revocation and insertion. Reusing a checkout hash for
another order produces `checkout_recovery_hash_conflict`.

Use `inspect(rawToken)` for presentation. It prioritizes revoked, expired,
consumed, then active state; consumption maps to `order_not_recoverable`,
unknown states to `unknown`. `validate(rawToken)` returns context only for an
active token on a pending order. PostgreSQL inspection adds `cadenceDays: number
| null`: initial subscription mode and cadence come from stored draft/quote
context and the provisional declaration; one-time cadence is null. Missing
required or contradictory subscription facts refuse, and browser fields supply
none of them. Paid confirmation may still be available through inspection.
Payment admission must recheck current facts. Inspection exposes no customer
email or arbitrary order reader and cannot execute or settle payment. Rehearsal
settlement cannot substitute for observations and verified ingress.

The adapter uses static errors: `checkout_recovery_service_required`,
`checkout_recovery_order_not_recoverable`, `checkout_recovery_hash_conflict`,
`checkout_recovery_response_invalid` and `checkout_recovery_storage_failed`.
Driver details, raw credentials and attached causes are excluded. Construction
installs no schema, grants, reminder producer, mail sender or automatic binding.

## Schedule reminders and expire abandoned checkouts

Create `createPostgresCheckoutRecoveryWaves(executor, policy)` with a restricted
service executor. Set `profile` to an identity unique to the selected mail
transport. Configure `firstOffsetSeconds`, `finalOffsetSeconds`,
`checkoutSeconds`, `recoverySeconds` and `activitySeconds` explicitly. The first
offset must precede the final offset, which must precede the checkout deadline;
durations must be positive integers. Invalid policies produce
`checkout_recovery_policy_invalid`.

Invoke `enqueue(limit, now)` with a UTC timestamp. It queues first and final
reminders for eligible pending checkouts, excluding recent payment activity and
known capture. The payload’s first/final content labels do not change when
you change the offsets; use the content contract in the
[API report](https://github.com/openlup/openlup/blob/openlup-core-v1.4.0/packages/platform/api/communications-contracts.api.md) rather than inferring labels from timing. Supply localized copy through
`createCheckoutRecoveryContentFactory` from
`@openlup/platform/communications/contracts`.

Wrap automatic-wave mail with `withCheckoutRecoverySendEvidence(emailPort,
recovery)` from `@openlup/platform/communications`. When the episode's effective
schedule has a first wave, the final wave requires a confirmed first-wave
acceptance receipt for the same delivery profile. A schedule with only a `last`
stage can send it without a predecessor. A processed outbox event alone is
insufficient. A captured transport's receipt proves acceptance by that
transport only. Never reuse its profile to claim
network delivery. The receipt fingerprint binds event, recipient reference,
template and delivery profile. The wrapper classifies the send outcome before
recording confirmed acceptance, leaving other mail methods and deduplication
unchanged. Receipt-write failure reaches the caller; preserve event idempotency
on retries.

Use `createCheckoutRecoveryWaveJob` from `@openlup/platform/composition` to bind
an enabled predicate, job name, lease duration, batch size and lazy `{ ledger,
enqueue }` binding. Its disabled path constructs no persistence; a refused lease
performs no enqueue. `createCheckoutRecoveryWaveHttpEntry` adds the
method/bearer guard using your secret reader. Register the endpoint and schedule
its invocation in your application.

Run the other operations separately:

- `expire(limit, now)` expires one-time pending orders only when native inventory
  reservation deadlines have elapsed, including retained inventory-sweeper
  evidence. It preserves known success, releases held reservations and captures
  a `commerce.checkout.expired` event atomically. Order age alone is insufficient.
- `sweepInitial(limit, olderThan, now)` compensates eligible provisional initial
  checkouts older than the supplied UTC cutoff. Prior payment attempts, external
  payment references or payment evidence block this sweep. The selection filters stable contact refusals before applying the limit,
  then locks and rechecks before compensation. It emits a recovery notice without
  ordinary cancellation mail. Compensation marks initial abandonment; it does
  not cancel a live subscription.
- `reconcile(limit, now)` adds missing expiry events for eligible expired orders
  and marked initial abandonment.

Expiry notices omit the token and token insertion when the order-based
`recoverySeconds` deadline has elapsed. Earlier links are retained. Expose
`subscriptionActivationAbandoned` in your expired-mail lifecycle reader only for
the durable sweep marker together with compensated activation.

## Install reminder stages and hours

Use `installCheckoutRecoveryReminderSchedule`, `readCheckoutRecoveryReminderSchedule`
and `CheckoutRecoveryScheduleChangeBlockedError` in `@openlup/platform/commerce/server`, with the
`CheckoutRecoveryReminderSchedule` type in `@openlup/platform/commerce/contracts`.
Apply the complete native catalogue, including the reminder installation outcome forward. Install
explicitly on your write-capable installation connection. The
`checkout_recovery_reminders` commerce setting contains a
nonblank `revision` and two nonempty arrays: `abandonedCart` admits `first`,
`gentle`, `last`; `checkoutRecovery` admits `first`, `last`. Each entry has exactly
`stage` and `afterHours`. Hours are strictly increasing positive integers up to
2147483647; stages cannot repeat and the final entry must be `last`. Extra or
missing keys, malformed JSON and invalid values refuse with
`checkout_recovery_reminder_schedule_invalid` before enqueue writes.

A reminder episode belongs to one order and one kind, either checkout recovery
or abandoned cart. The producer chooses timing in this order:

- **Pinned episode.** The pin supplies the stages, hours and effective offsets
  for follow-ups, even after a schedule change or removal.
- **New episode.** The first created wave pins the live timing. An installed
  schedule supplies the stages and hours. With no installed row, checkout
  recovery uses the host's offsets, with SQL defaults of 1 and 20 hours for
  omitted offsets, and abandoned carts use 1, 24 and 72 hours. A change therefore
  applies to episodes whose first wave is created afterward.
- **Older unpinned episode.** An episode with a preexisting wave and no pin uses
  live timing, including the same fallback when the row is absent. It receives
  no backfilled pin.

The read helper returns the installed schedule or the nominal schedule with
revision `default`. New payloads carry `stage` alongside `reminderHours`.
Renderers use the explicit stage; old payloads without it retain their previous
hour mapping and rendered bytes. Unknown stages refuse through the handler's
existing payload-error policy.

Custom hours retain `abandoned_<hours>h:<order-id>` and
`checkout_recovery:<hours>h:<order-id>` dedup keys. Default keys are unchanged.
Abandoned-cart event types remain the existing stage routes ending in
`1h`/`24h`/`72h`; their names do not describe custom timing. Nonfinal abandoned
waves occupy the window before the next configured wave; the final wave requires
the preceding configured stage's processed event when one exists. Checkout final
waves require confirmed acceptance of the first configured wave when one exists.
A schedule containing only `last` has no predecessor requirement. Enqueue result
counter names remain the legacy names, counted by stage.

After the reminder guard migration, creating a wave consumes that stage for the
order even if you later change its configured hour. A wave created under a
custom schedule still consumes its recorded stage after the schedule row is removed.
Checkout waves written before stage labels were added use the historical first
and last hour mapping.
An unlabeled wave at any other hour consumes both stages. While a schedule row
is installed, a compacted checkout wave consumes both stages because retention
removed its stage label. With no installed row, compacted checkout waves
use the historical hour mapping. Abandoned-cart stages remain identifiable
through their event types after compaction.

Use `READ COMMITTED` for reminder producers and schedule changes.
`REPEATABLE READ` and `SERIALIZABLE` refuse with
`checkout_recovery_schedule_isolation_unsupported`. An identical installation
replay succeeds at any isolation level and performs no write. Installing an
explicit schedule where none was stored counts as a change, even if it contains
the default values. An empty shop accepts its first install at `READ COMMITTED`.

On qualified profiles, run the installer as the declared migration owner.
Qualified migration status and apply refuse grants to roles outside the
selected profile with `outside_principal_references_selected_catalog`.

On the legacy profile, the function owner can delegate installation to a role
with settings-table read and write permissions. For a role named
`schedule_installer`, grant execution as follows:

```sql
GRANT EXECUTE ON FUNCTION public.commerce_install_checkout_recovery_reminder_schedule(text, jsonb),
  public.commerce_checkout_recovery_schedule_change_guard(jsonb, jsonb),
  public.commerce_checkout_recovery_reminder_schedule()
TO schedule_installer;
```

A changed install counts each blocking order once. Both blocker predicates
require an order in `pending_payment` and no pin for the wave's kind:

- **Checkout recovery.** The order has a checkout-recovery wave recognized by
  the stage classifier. Compacted waves count. Operator and buyer link events
  are outside this predicate. Order age does not affect it.
- **Abandoned cart.** The order has an abandoned-cart wave on the `1h`, `24h` or
  `72h` event route, at least one non-invalidated draft receipt and no settlement
  intent. The guard does not check current consent or enqueue eligibility.

A pin for one kind exempts only that kind. If neither predicate matches any
order, the guard allows the changed install.

Check this installer refusal with
`error instanceof CheckoutRecoveryScheduleChangeBlockedError`. Use
`error.blockingOrders` to display the count as a decimal string. The fixed
message is `checkout_recovery_schedule_change_blocked_open_episodes`, and
the original PostgreSQL error is available as `error.cause`. Direct SQL calls
retain SQLSTATE `55000`, the count in the message and the retry hint. Older
schemas without the outcome forward still return the original driver error.
After either refusal, roll back an explicit transaction before retrying.

For the named refusal, the starter's `./lifecycle up` reports the count, the
affected `checkoutRecoveryReminders` configuration and when to try again.

The current schedule stays in effect. Retry after the blocking orders are paid
or cancelled. An abandoned cart also stops blocking when all its draft receipts
are invalidated or it has a settlement intent.

The host checkout window, activity, consent and payment gates, and token expiry
still apply. For example, a 48-hour final checkout reminder needs a host window
longer than 48 hours. Keep the request-policy offsets valid even when an
installed schedule supplies timing.

If your legacy cart reminder job runs under its own database role, keep that
role's `EXECUTE` on `public.commerce_enqueue_abandoned_cart_reminders(integer)`.
After applying the episode pin migration, run this grant once as the database
owner. Replace `cart_runtime` with the role that runs the job.

```sql
GRANT EXECUTE ON FUNCTION public.commerce_enqueue_abandoned_cart_reminder_episodes(integer) TO cart_runtime;
```

The built-in runtime role already has the grant. The cart job can enqueue
without access to episode rows or settings. The TypeScript read helper still
needs settings `SELECT`.

If the role can call the entry point but lacks the helper grant, PostgreSQL
refuses before writing with SQLSTATE `42501` and message
`checkout_recovery_cart_runtime_grant_required`. The separate `HINT` is the
exact `GRANT EXECUTE` statement for the calling role, quoted as needed. Run
that statement as the database owner, then retry the job.

The native cart cron returns HTTP 502 with the message, a newline and the full
grant in `body.reason`. If it successfully records the failed run, the same
text appears in the run's `error` and `metadata.reason` fields in
`platform_job_runs`.

## Give an operator a payment link

Bind `createAdminCheckoutPaymentLinkHandler` to `authorizeAdmin`, `respond`,
`orderPort`, `tokenStore`, `policy` and commercial `validateRecreate`. Use
`createPostgresOperatorCheckoutLinkStore` with a restricted service executor
whose calls commit separately, preserving admission and completed effects after
failure. Do not wrap the entire command in one transaction. Choose explicit
policy lifetimes; neutral examples are `operatorLifetimeMs: 3600000` and
`recoveryWindowMs: 86400000`. Bind the same recovery window at redemption.
Construction installs no feature flag, scheduler or operator UI.

Authorize an active human administrator through your operator session; machine
and control principals refuse. Send a POST body containing `orderId` and
optional `delivery: "copy"` or `delivery: "email"`.

Pending orders qualify without repricing. For expired orders, supply canonical
technical-expiry, frozen quote and destination facts and bind
`validateRecreate`; the callback is optional in the API, so omission skips
commercial validation. Manual cancellation and renewal cycles do not qualify.
Persisted initial-checkout mode selects subscription mail copy without a native
cycle. Refusals include `order_not_found`, `order_paid`, `order_cancelled`,
`order_not_recoverable` and `order_changed`.

Set positive `operatorLifetimeMs` and `recoveryWindowMs` in `policy`, and use
the same recovery window at redemption. Expiry is the earlier of issuance plus
operator lifetime and order creation plus recovery window. An elapsed deadline
returns `order_not_recoverable` without inserting a token.

The command records admission, revokes same-order links, mints, optionally
queues email, then records the outcome and last stage: `none`, `revoked`,
`minted` or `email_queued`. Failed admission changes no token. A failed mint
after revocation can leave no live predecessor. Concurrent operators can leave
multiple live links; a later operator command revokes them, while
service/customer issuance preserves them.

`copy` is the default and returns the raw token with `emailQueued: false`.
`email` queues `commerce.checkout_recovery` with `operatorIssued: true`, source
`admin_payment_link`, and key `checkout_recovery:operator:<token-id>`.
Re-enqueue adds no second event; queue failure reports `UPSTREAM_UNAVAILABLE`.

## Add customer recovery entry points

For signed-in account recovery, bind `createCheckoutRecoveryStartHandler` to
`recoveryEnabled`, `authenticateUser`, `createPort`, `respond` and `lifetimeMs`.
Use `createPostgresCustomerCheckoutRecoveryStartPort` on that customer's actor
executor. PostgreSQL derives ownership from `auth.uid()`.

The POST body accepts exactly `{ orderId }` or `{ subscriptionId }`. For an
initial subscription checkout, use the provisional `activationId` as
`subscriptionId`. Selection uses the exact owned pending order or newest
eligible declaration order. An initial declaration or persisted subscription
checkout context selects subscription presentation without admitting renewals.
Flag and session checks precede port construction.

Set `lifetimeMs` explicitly to a positive safe integer at most `86400000`.
The deadline is order creation plus that lifetime, and the database rechecks it
after blocking writes, rolling them back if the deadline elapsed. A successful
start returns a fresh raw token for navigation and sends no mail. An elapsed
deadline or terminal checkout returns `recoverable: false` with `fresh_checkout`
or `customer_account` fallback. Earlier checkout tokens remain live until
expiry, payment or operator revocation.

For a buyer's “email me a payment link” action, bind
`createCheckoutPaymentLinkHandler` to your continuation codec and a lazy
`createPostgresBuyerCheckoutLinkPort` using a service executor. Only
`verifyCookieHeader` claims authorize the order and client. Missing, invalid or
expired cookies produce `continuation_missing` before persistence is
constructed; body identifiers and recipient addresses supply no authority.

The service issuer locks the order and admits pending non-renewal checkout only.
Configure the buyer port's `lifetimeMs` and positive `sendBucketMs`; neutral
examples are `86400000` and `600000`, respectively.
Bucket admission deduplicates the
`checkout_recovery:buyer:<order>:<bucket>` event and token atomically; a
duplicate inserts neither. Later buckets preserve earlier links. `{ sent: true
}` means queued or deduplicated; only the port's `queued` identifies a new
insertion. Neither response proves transport delivery. A terminal mint race
reports `order_not_recoverable`; other mint failures report `mint_failed`.

Route the reminder producers through
`createOutboxCheckoutRecoveryEmailHandler`, with the appropriate scoped
`authorize(eventId, claimToken)` gate: waves, operator store or buyer port. Each
gate checks its own event and authority. The operator gate requires its exact
token to remain live and bound to the claimed order and client; it cannot
replace the automatic-wave gate. Buyer events carry `buyerRequested: true` and
source `buyer_payment_link`. They bypass the fresh-payment-session courtesy
deferral, while missing or paid orders still suppress mail. Bind recipient
resolution, localization and transactional transport in your application.

## Inspect a link before showing recovery controls

Compose `createCheckoutRecoveryInspection` with the token port,
`createPostgresCheckoutRecoveryOrderPort` on a service executor,
`clientHasLiveOrPendingSubscription` and your commercial validation policy. Use
`createCheckoutRecoveryValidationPolicy({ supports, validation })` to reject
unsupported frozen content before commercial validation. Reuse `supports` for
recreation.

Call `inspect({ token, capabilities })` and render its decision:

| Result | What to show |
| --- | --- |
| `recoverable: true`, `recoveryKind: "retry_existing"` | Continue the current payable order |
| `recoverable: true`, `recoveryKind: "recreate_expired"` | Offer an independently authorized replacement command |
| `terminalStatus: "paid"` | Confirmation without payment controls, using `paidOrder` when available |
| `terminalStatus: "cancelled"` or `"order_changed"` | The returned account or fresh-checkout fallback |
| Other `recoverable: false` | The returned fallback |

Include `recreate_expired_order` in `capabilities` to opt into expired recovery.
Without it, clients retain fallback behavior and payable orders need not carry
`recoveryKind`. Expired tokens may expose validated expired context, but cannot
resume a pending replacement. Only `active` and `order_not_recoverable`
inspection states permit continuation; revoked, used or unknown authority
refuses before descendant reads. The order reader returns the bound original or
the root's latest-created descendant; both must match the token's client. An
initial subscription replacement requires a compensated declaration; inspection
reopens neither its predecessor nor a live subscription.

Include `resolve_active_payment` separately to invoke the injected payment
resolver. If no resolver is bound, that opt-in returns `awaiting_provider`.
Inspection performs no recovery writes and grants no payment authority.
Authorize and recheck later mutations independently.

## Recreate a technically expired checkout

Bind `createExpiredCheckoutRecoveryService` to an independently authorized
order/client. Supply `supports`, `quoteRequest`, quote and draft ports, recovery
writer, payment safety, runtime and compensation. Unsupported snapshots validate
as false and recreation returns `unavailable` before side effects.

Require a frozen quote, an owned destination and prior payment evidence.
`ExpiredCheckoutPaymentSafetyPort.verifyPriorPayment` must read the actual prior
payment object: success returns `paid`; confirmed terminal non-settlement with
matching money returns `safe`; missing, unknown, pending or failed reads return
`unavailable`. Absence of local success is insufficient. The sandbox binding is
`createPostgresSandboxExpiredCheckoutSafety` from `@openlup/platform/payments`.

Build opaque quote-request extensions from trusted persisted data. The service
passes persisted `pricingPolicy` and `offerVersion` to quoting and compares the
commercial fingerprint, excluding transient quote IDs and timestamps. Drift
returns `order_changed` before draft creation. Frozen offer evidence is
retained.

Fresh governed replacement is unavailable. The native draft owner returns
`catalog_admission_quote_authority_required` when that demand reaches it.
Existing payment-safety, unavailability and commercial-drift refusals still
apply before drafting. Eligible legacy recreation remains supported, including
sources with recorded promotion acceptance. Exact authenticated replacement
replay remains supported.

Wrap draft persistence with `createPostgresExpiredCheckoutDraftPort`; use
`createPostgresExpiredCheckoutRecoveryPort` for lineage. The stable key is
`checkout-recovery-recreate:<sourceOrderId>`. Replay preserves the accepted
draft when only quote identity changed. Preparation allows a unique immediate
replacement, including replay after compensation, and never reparents it.
Preparation locks source and replacement, checking payment evidence and the
recovery deadline after waiting for locks. Exact linked replay precedes fresh
admission checks.

Bind `createPostgresExpiredCheckoutRuntime` to a dedicated READ COMMITTED lane.
Bind `verifyPriorPayment`, reservation and payment callbacks to its executor,
using `createPostgresPurchaseReservationPort` from `@openlup/platform/inventory`
and the native simulator. Set `stockSourceKey`, `channelKey` and
`reservationLifetimeMs`. Use `checkoutRecoveryExecutionFingerprint` for
execution identity. Keep remote dispatch outside this transaction.

The runtime locks the source order before the replacement and source intent,
then rechecks prior payment before stock
or payment writes, even with an existing replacement intent. Racing source
success returns `paid` and triggers compensation. Recorded buyer snapshots are
preserved without inventing an absent `invoiceBuyerSnapshot` key. A nonempty
runtime snapshot takes precedence; recorded empty objects remain explicit. When
there is no snapshot, first-duty invoice capture can select the owned billing
profile/address and then the marked shipping fallback. Later profile edits do
not change captured buyer facts.

Initial recreation makes a new provisional declaration, leaving its predecessor
compensated and live subscriptions untouched. It creates no renewal cycle. Use
`createPostgresExpiredCheckoutCompensation` for guarded cancellation and
unstarted cleanup; dispatched or uncertain payments block cancellation. A
compensated replacement keeps its lineage and permits no sibling. Handle
`ExpiredCheckoutRecoveryError.reason`: `paid`, `order_changed` (including stock
refusal), `unavailable` or `execution_failed`. Other purchase profiles need
their own admitted runtime port. These factories supply no route, UI or token
issuer and establish no real-service qualification. A live subscription is
created only by a later successful captured-payment activation.

## Show payment recovery guidance from one snapshot

Compose `createPostgresPaymentRecoveryGuidancePort` with a service executor and
`normalizeSandboxPaymentRecoveryEvidence` from `@openlup/platform/payments`. Use
a fresh READ COMMITTED statement: one
`commerce_checkout_payment_guidance_snapshot` call reads status, provenance,
authority and evidence without materializing destinations, issuing tokens or
changing payment state. A draft receipt and frozen checkout context establish
one-time provenance; an initial subscription also needs its declaration.
Renewal-cycle orders are ineligible.

History probes a bounded number of attempts and evidence members, returning
attempts newest first. Overflow, contradictory proof or an oversized envelope
drops that attempt’s whole proof set and marks history incomplete. Observation
records and truth/readback source envelopes have bounded sizes; consult the
[API report](https://github.com/openlup/openlup/blob/openlup-core-v1.4.0/packages/platform/api/commerce-server-postgres.api.md) and its linked implementation
for the limits. Only correlated identity/outcome fields are projected; raw
source envelopes, request keys, token hashes and opaque authorization/method
references are excluded. Native states map to the Core attempt vocabulary and
Core derives the public actions. These observations establish neither
method-specific advice nor a reusable payment method.

Call `readAuthorizedPaymentRecovery` with a validated bearer or verified
continuation claims. Cookie claims bind journey/order/client/intent and must
match the snapshot's current attempt and rail. Token authority is rechecked in
the snapshot against the exact order/client, expiry, revocation and pending
state; earlier validation cannot bypass it. The token dependency needs only
`validate`. Fall back to the legacy reader for missing authority, read failure
or malformed data; a snapshot with dead authority carries null guidance.

Opt in with `X-Payment-Recovery-Guidance: 1` and preserve the legacy response
without it, as in the [status-handler
composition](https://github.com/openlup/openlup/blob/openlup-core-v1.4.0/server/domains/commerce/commercePaymentStatusHandler.ts).

Render returned actions without inferring method-specific advice: native
observations prove generic refusal, with method, operation and advice unknown.
Exactly linked capture suppresses refusal guidance and `projectGuidance` before
settlement converges, without declaring the order paid. Guidance authorizes no
new payment. Supply `projectGuidance` only to preserve your existing display
fallback; it cannot turn observed success into refusal advice. Exactly linked
capture suppresses advice even when its attempt falls outside returned history.

## Retry payment with a recovery token

Bind `createCheckoutRecoveryPayService` to
`createPostgresSandboxCheckoutRecoveryAttemptPort` from
`@openlup/platform/payments`, using a READ COMMITTED service executor. Wrap the
service with `withCheckoutRecoveryPaymentHold`, then pass it with the token and
order ports to `createCheckoutRecoveryTokenPay`.

Call `pay({ token, idempotencyKey, method, followLatest })`. Order and client
identity come from the token. Set `followLatest: true` only when you intend to
follow the recovery root's latest order: inspection must establish continuation
authority and original ownership. Expired inspection alone cannot pay a
replacement; use the separate recreation command.

Payment retry uses the existing order, intent and stock reservation. The native
reader's `pending` projection means a created intent; the attempt owner fences
unresolved dispatch under locks. Under order/intent locks, native admission
rechecks token expiry/revocation, checkout provenance, money and captured
observations. A capture blocks another dispatch before settlement converges.
Repeating the same key and fingerprint returns its attempt; changed method facts
under the same key refuse. After a terminal failure, use a fresh per-click key
to select another synthetic method.

Handle `CheckoutRecoveryPayError.kind`: `conflict` includes dead authority and
unrecoverable orders; `upstream_unavailable` includes in-flight or uncertain
execution. Known payment refusal remains a recoverable `failed` result. Invalid
local method facts roll back before dispatch, allowing correction. Money results
come from observations and verified ingress, never from a browser result or
rehearsal shortcut. The sandbox owner records dispatch atomically with attempt
creation, without a separate external preparation/finalization phase.

Inject hold reads, method classification, offered methods and first-purchase
evidence. A one-time order without a subscription is treated as a first
purchase; subscription context needs evidence that it was never live from your
first-purchase lookup. A matching hold withholds only orders created strictly
after it (`payment_method_withheld`). Recreated orders, foreign-root chains and
renewal cycles bypass holds. Your application owns control keys, the
offered-method policy and the hold trigger. Failed reads, unknown first-purchase
evidence or holding every offered method permit payment. Reuse this policy for
fresh inline retries.

## Retry the exact failed attempt inline

Compose `createCheckoutInlineRecovery` with your continuation codec and exact
cookie name, the atomic guidance port, order reader and
`createPostgresSandboxInlineRecoveryAttemptPort` from
`@openlup/platform/payments`. Supply `methodKeyFor` to map synthetic method
facts to explicit method keys, and `executionAllowed` for offered methods and
purchase contexts. Unknown identities refuse; opaque method references imply no
method or refusal category. Pass the same `hold` dependencies used for token
payment.

Call `retry` with the cookie header, journey/order/client/intent,
`expectedPaymentAttemptId`, `retryRequestId`, `executionRail`, `methodKey` and
`method`. The signed cookie must match the exact predecessor before durable
reads. A bearer header cannot authorize this path. A missing or mismatched
cookie produces `continuation_required`.

Fresh retry requires the exact failed attempt and failed intent on a payable
one-time or provisional initial checkout. Previously live subscriptions refuse.
Staying with the same method requires `change_instrument` or `correct_data`
without a method-wide prohibition; switching methods requires `change_method`.
`authenticate` alone is insufficient. Disallowed actions produce
`recovery_action_not_allowed`; host execution policy can refuse with
`recovery_execution_not_allowed`.

`checkoutInlineRecoveryTransitionKey(expectedPaymentAttemptId)` yields
`checkout-inline-recovery:<expectedPaymentAttemptId>`. Keep the retry nonce
(`retryRequestId`) and selected rail unchanged when retrying a lost response.
The native prepare key appends `:payment-execution:prepare-attempt`; its request
key and server-computed fingerprint bind transition, nonce and rail without a
separate nonce ledger. The native owner compares the exact predecessor under
locks and fences
cancellation and capture. Retry creates no order, intent or reservation.

Replay binds the replacement to the transition, nonce and rail, without
redispatch or fresh execution/hold policy. Method input adds no comparison.
Failed replacements return failure; live replacements permit action readback or
safe polling when readback lags. Native intent status may still describe the
previous refusal while its replacement is dispatched; the durable replacement
attempt supplies the processing result. Transient codes add no replay
comparison.

On every successful response, write the returned `setCookie` as the response's
`Set-Cookie` header and expose only `result` as the response body. The new
cookie binds the replacement attempt and rail. Reusing the old predecessor with
it refuses; a later failed replacement can become the next exact transition.
