> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stash.gg/llms.txt
> Use this file to discover all available pages before exploring further.

# Payment Flow

> Understand where the money moves in a Real-time Catalog purchase, why ConfirmPayment is required rather than optional, and which checks only your backend can enforce.

On a [Real-time Catalog](https://docs.stash.gg/guides/stash-webshop/catalog/real-time-catalog.md) integration, your backend owns the catalog: pricing, availability, and per-player limits are all computed by you, at the moment Stash asks. That makes [`ConfirmPayment`](https://docs.stash.gg/api/egress/purchase/confirmpayment) required rather than optional. It is the only point in the flow where Stash shows you a purchase that is still in progress and lets you decline it before the payment is captured.

This page covers web shop purchases, both from the cart and from Buy Now. The same `ConfirmPayment` contract applies when the same backend also powers Stash Pay checkout links; see [Stash Pay High-Level Flow](https://docs.stash.gg/guides/stash-pay/flow.md) for that surface.

`RegisterPayment`, `ConfirmPayment`, and the pre-flight checks on this page apply only to the Real-time Catalog. A [managed catalog](https://docs.stash.gg/guides/stash-webshop/catalog/managed-catalog.md) purchase skips them: Stash authorizes and captures the payment, then your backend grants the items from the `PURCHASE_SUCCEEDED` webhook. See [Granting from the webhook](https://docs.stash.gg/guides/stash-webshop/integration.md#granting-from-the-webhook).

## Where the Money Is at Each Step

**1. Authorize**

Stash asks the player's bank to check and reserve the funds. The money is held, not taken.

**2. RegisterPayment**

If you implement it, Stash calls your backend to register the purchase intent so you can reserve inventory. This step is optional and it is not the decision point.

**3. ConfirmPayment**

Stash calls your backend and waits. The funds are already held, so your response decides whether they are taken or released. This is the decision point.

**4. Capture**

Stash requests the capture that draws the held funds. It runs only after your backend returns success.

**5. PURCHASE\_SUCCEEDED**

Stash queues the webhook as soon as the capture request is accepted.

```mermaid theme={null}
sequenceDiagram
actor Player
participant Stash
participant Bank
participant GameBackend

Player->>Stash: Complete Payment
Stash->>Bank: Authorize
Bank-->>Stash: Funds held
opt If implemented
Stash->>GameBackend: RegisterPayment
GameBackend-->>Stash: Reserved
end
Stash->>GameBackend: ConfirmPayment
alt Success
GameBackend-->>Stash: 200 OK with results
Stash->>Bank: Capture
Stash->>GameBackend: PURCHASE_SUCCEEDED
else Declined or failed
GameBackend-->>Stash: Error, or 200 with no results
Stash->>Bank: No capture, hold released or expires
end
```

> [!NOTE]
>
> **`PURCHASE_SUCCEEDED` marks the capture request, not settlement.** Stash sends the event as soon as the payment provider accepts the capture, and settlement happens asynchronously after that. Read the event as "the purchase completed and capture was requested", not as a settlement receipt.

## `ConfirmPayment` Is Required

Stash calls `ConfirmPayment` on every Real-time Catalog purchase. There is no shop configuration that skips it, and no response that means "Stash should decide".

* **Success is a non-empty `results` array.** `ConfirmPayment` has no status field. Returning the granted results in the body is how your backend says yes.
* **A `200` with an empty or absent `results` array is a failure.** It confirmed nothing, so Stash treats it the same as an error response rather than as a silent success.
* **Every failure looks the same to Stash.** A deliberate rejection, an unhandled `500`, a timeout, and a malformed body are all handled identically.

When the call does not succeed, Stash does not capture. The authorization is released or left to expire at the payment provider and the player is not charged, so the bad case is "not charged, not granted" rather than "charged, not granted". A payment method that settles at authorization has no hold to release: its funds moved when the payment was authorized, so reversing that purchase takes a refund. If you implement the [`RegisterPayment`](https://docs.stash.gg/api/egress/purchase/registerpayment) and [`CancelPayment`](https://docs.stash.gg/api/egress/purchase/cancelpayment) pair, Stash also calls `CancelPayment` on the cart flow so you can release the reservation you took.

> [!WARNING]
>
> Because a failure and a rejection are indistinguishable to Stash, an outage in your `ConfirmPayment` handler reads as a shop-wide refusal to sell. Respond `200 OK` with your granted results unless you specifically do not want Stash to take the money.

## The Catalog Read Before Checkout Is a Snapshot

Stash reads your catalog once more just before checkout. For a cart purchase it reads when the player starts checkout, as it creates the payment. For a Buy Now purchase it reads when the player taps Buy Now, before the checkout opens. Stash validates that the items still resolve and takes the price, the item's `expiration`, and its `maxPurchasable` from that read. The read is a snapshot of what your server said, not a reservation:

* **Nothing holds stock between the read and the charge.** No reservation is taken at catalog-read time on either side. A player can sit on the checkout page, and the same allowance can be spent elsewhere in the meantime.
* **The read can be served from cache.** It goes through the same catalog path as any other read, so the [catalog cache](https://docs.stash.gg/guides/stash-webshop/catalog/real-time-catalog/caching.md) applies to it.

## Stash Keeps No Ledger of Your Limits

`maxPurchasable` is the player's remaining allowance as your server computed it at read time. For the items your catalog returns, Stash keeps no count of its own and never decrements the value: it checks the purchase against what the pre-checkout read returned.

Stash runs two pre-flight checks, both on values from that pre-checkout read rather than on a fresh read when the purchase is confirmed:

| Check | Cart purchase | Buy Now purchase |
| - | - | - |
| Item expiry | Refuses to create the payment if the item's `expiration` has already been reached, and rejects the purchase if it has been reached by the time Stash would call `ConfirmPayment` (allowing a [checkout grace period](#checkout-grace-period) if one is agreed for your shop) | Refuses to open the checkout if the item's `expiration` has already been reached, and rejects the purchase if it has been reached by the time Stash would call `ConfirmPayment` (allowing a [checkout grace period](#checkout-grace-period) if one is agreed for your shop) |
| Remaining allowance | Rejects a quantity greater than `maxPurchasable` when the payment is created, and checks the same value again before Stash calls `ConfirmPayment` | Rejects a quantity greater than `maxPurchasable` before the checkout opens, and does not check it again |

A rejected pre-flight check fails the purchase before Stash calls `RegisterPayment` or `ConfirmPayment`, and Stash does not capture the payment.

These checks catch the obvious stale cases cheaply. They are not a substitute for your own check, because each value is only as fresh as the read it came from.

### Checkout Grace Period

By default, a purchase that completes at or after the item's `expiration` is rejected, even when the player started checkout before it. Stash can agree a checkout grace period with you for your shop. With one in place, a purchase that reached checkout before `expiration` can still complete for up to that long after it:

* `ConfirmPayment` can arrive after the item's `expiration`. Approve it if you want those purchases to complete; declining it works as for any other purchase.
* A player still cannot start checkout on an item once its `expiration` has been reached.
* The grace period applies to purchase packs the same way, using the pack's `expiration`.

## What Only Your Backend Can Enforce

Anything that depends on your live state has to be enforced in `ConfirmPayment`, because that is the last moment before the charge at which you are consulted:

* **Limits shared across several offers.** Stash sees a per-item `maxPurchasable`, not a budget spanning a bundle, an offer chain, or a campaign.
* **Stock that is also sellable elsewhere.** Anything a player can also buy in-game or on another surface can be consumed between the catalog read and the charge.
* **Per-player caps and eligibility.** Daily caps, cooldowns, progression gates, and anti-abuse rules all live in your systems.
* **Anything priced or gated on live state.** If the answer can change between the catalog read and the charge, the catalog snapshot cannot hold it.

> [!WARNING]
>
> Do not treat [`RegisterPayment`](https://docs.stash.gg/api/egress/purchase/registerpayment) as the enforcement point. It is a reservation hint that helps you lock inventory across multiple clients, it is optional, and Stash can be configured to skip it. `ConfirmPayment` is the call that gates the money.

## Next Steps

> [card] [Real-time Catalog](https://docs.stash.gg/guides/stash-webshop/catalog/real-time-catalog.md)
>
> Setup, authentication, and configuration for the Real-time Catalog integration, with links to its other pages.

> [card] [ConfirmPayment API Reference](https://docs.stash.gg/api/egress/purchase/confirmpayment.md)
>
> Full request and response schema for the confirm endpoint.

> [card] [CancelPayment API Reference](https://docs.stash.gg/api/egress/purchase/cancelpayment.md)
>
> Release a reservation after a purchase does not complete.

> [card] [Stash Pay High-Level Flow](https://docs.stash.gg/guides/stash-pay/flow.md)
>
> The same payment sequence as it applies to Stash Pay checkout links.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.