> ## 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.

# High-Level Flow

> Learn how Stash Pay's purchase flow works and discover three integration patterns for granting purchases based on your existing infrastructure.

This article walks through three Stash Pay integration patterns and when to use each one, based on:

* Your game-specific technical requirements and limitations.
* Your backend architecture (async/event-based vs. synchronous).
* Your preferred in-game purchase-granting behavior.

## Initial Setup

**1. Set up Stash Pay instance**

To set up Stash Pay, contact the Stash team. After onboarding, you'll receive access to **Stash Studio**, our developer portal. Your game instance (including payment processing) will be created for you so you can begin the integration.

**2. Get your API key**

Once you have your Stash Studio instance all set up, the only prerequisite is creating your first API key. You'll use this key to call Stash Pay API endpoints from your game backend. Specifically, you'll need an Ingress API key for the `GetPaymentEvent` endpoint, and an Egress API key for the `ConfirmPayment` endpoint.

## Core Checkout Flow (Common to All Options)

All three options share the same basic checkout flow:

**1. Requesting Checkout**

From your game backend, request a checkout session via the Stash API.

**2. Get Checkout URL**

Receive a customized checkout URL and a **checkout link order ID** (UUID) from Stash. Store this ID on your backend, associated with the player and the pending purchase.

**3. Show Checkout**

Display the checkout to the player via redirect, popup, or in-app browser. The player reviews the purchase and completes payment using the configured payment methods.

While these three steps are always consistent, the way you finalize the purchase and grant items can vary.

## Where the Money Is at Each Step

Every Stash Pay purchase runs the same payment sequence, whichever granting flow you choose. The sequence tells you what has already happened to the player's money by the time your backend hears from Stash.

**1. Authorize**

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

**2. Grant (ConfirmPayment pattern only)**

Stash calls your backend here and waits for your response. The funds are already held at this point, so your response decides whether they are taken or released. The other two patterns have no step here.

**3. Capture**

Stash requests the capture that draws the held funds. On the `ConfirmPayment` pattern, capture runs only after your backend returns success.

**4. 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 GameServer

Player->>Stash: Complete Payment
Stash->>Bank: Authorize
Bank-->>Stash: Funds held
opt ConfirmPayment pattern only
Stash->>GameServer: ConfirmPayment
GameServer-->>Stash: 200 OK with granted items
end
Stash->>Bank: Capture
Stash->>GameServer: PURCHASE_SUCCEEDED
```

> [!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.

Not every payment method has a separate capture step. Some settle at authorization, and which ones do depends on the method and on the provider processing it. The sequence above is otherwise unchanged, but there is no hold to release: the funds moved when the payment was authorized, so reversing such a purchase takes a refund. Standard card payments follow the authorize-then-capture sequence. If the behaviour of a specific method matters to your integration, check with your Stash engineering partner.

## Choosing Your Granting Flow

Select the pattern that best matches your backend architecture and reward-granting requirements. The three differ mainly in **when they fire relative to the charge**, and only one of them lets your server reject a purchase:

| Pattern | When it fires | Direction | Can your server reject? | Best for |
| - | - | - | - | - |
| [`ConfirmPayment`](https://docs.stash.gg/api/egress/purchase/confirmpayment) | After the funds are held, before they are captured | Stash calls your server | **Yes.** See the warning in that tab. | Inventory limits, purchase caps, multi-client locking |
| `PURCHASE_SUCCEEDED` webhook | After capture is requested | Stash calls your server | No | Backends that process events asynchronously through queues, workers, or jobs |
| [`GetPaymentEvent`](https://docs.stash.gg/api/ingress/payments/getpaymentevent) | After the purchase completes, when you ask for it | Your server calls Stash | No | Showing rewards in the client immediately after purchase |

> [!NOTE]
>
> **This is an integration-time choice, not a runtime one.** Which delivery mechanism a shop uses is fixed when the shop is configured, not selected per purchase. A single shop uses one of these patterns rather than switching between them, so treat the table above as a decision you make once per integration.

> [tab] Webhook
>
> **Async post-purchase.** Stash captures the payment and then sends your backend a `PURCHASE_SUCCEEDED` event. Your server has no say in whether the charge goes through.
>
> **Direction:** Stash → Game (your backend exposes a webhook endpoint).
>
> **Best for:** Backends that already process events via queues, workers, or background jobs. Rewards may appear slightly after purchase.
>
> **Flow:**
>
> **Step 1**
>
> Player completes checkout.
>
> **Step 2**
>
> Stash authorizes the payment, then captures it.
>
> **Step 3**
>
> Stash queues a
>
> `PURCHASE_SUCCEEDED`
>
> webhook to your backend.
>
> **Step 4**
>
> Your backend consumes the event, runs game logic, and grants rewards.
>
> ```mermaid theme={null}
> sequenceDiagram
> actor Player
> participant GameClient
> participant GameServer
> participant Stash
>
> Player->>Stash: Complete Payment
> Stash->>Stash: Authorize, then Capture
> Stash->>GameServer: PURCHASE_SUCCEEDED Webhook
> GameServer->>GameServer: Process Event (async)
> GameServer->>GameServer: Grant Rewards
> ```
>
> > [!WARNING]
> >
> > **Delivery is queued, not guaranteed.** Stash hands the event to a delivery queue and retries a failed delivery, but a purchase never fails because its webhook could not be delivered, and there is no way to ask Stash to replay an event that never landed. On this pattern the webhook is your only delivery signal, so make your handler idempotent and reconcile missed events with [`GetPaymentEvent`](https://docs.stash.gg/api/ingress/payments/getpaymentevent). See [Webhook Retries and Idempotency](https://docs.stash.gg/guides/get-started/stash-webhooks/retries.md).
>
> For full implementation details see the [Webhook guides](https://docs.stash.gg/guides/get-started/stash-webhooks/overview.md).

> [tab] Payment Lookup
>
> **Synchronous post-purchase.** Your backend asks Stash for the final payment status as soon as the purchase completes.
>
> This is a targeted lookup, not a background poll. The trigger is the client's completion signal, which depends on how you present the checkout: the `onSuccess` prop or option on [web](https://docs.stash.gg/guides/stash-pay/web-integration/web-apps.md); the `successCallback` argument of `OpenCard` or `OpenModal` (for example `successCallback: OnSuccess`) in [Unity](https://docs.stash.gg/guides/stash-pay/ios-android-integration/unity.md); and, in browser presentation modes such as `openBrowser`, the deep link that returns the player to your game, since those modes have no success callback (see [Presentation Options](https://docs.stash.gg/guides/stash-pay/ios-android-integration/presentation-options.md)). Your backend already holds the checkout link order ID from creating the link, so it can look the purchase up as soon as the client reports completion.
>
> **Direction:** Game → Stash (your backend calls [`GetPaymentEvent`](https://docs.stash.gg/api/ingress/payments/getpaymentevent)).
>
> **Best for:** Games where the client needs to show rewards immediately, or backends designed for synchronous request-response patterns without incoming webhooks.
>
> **Flow:**
>
> **Step 1**
>
> Player completes checkout.
>
> **Step 2**
>
> The client receives the completion signal (the SDK success callback, or the deep-link return in browser modes) and notifies your backend.
>
> **Step 3**
>
> Your backend calls
>
> [`GetPaymentEvent`](https://docs.stash.gg/api/ingress/payments/getpaymentevent)
>
> with the purchase ID.
>
> **Step 4**
>
> Stash returns the final payment status.
>
> **Step 5**
>
> Your backend grants rewards and returns updated state to the client.
>
> ```mermaid theme={null}
> sequenceDiagram
> actor Player
> participant GameClient
> participant GameServer
> participant Stash
>
> Player->>Stash: Complete Payment
> Stash-->>GameClient: Success Callback or Deep Link Return
> GameClient->>GameServer: Check Purchase Status
> GameServer->>Stash: GetPaymentEvent
> Stash-->>GameServer: Payment Status
> GameServer->>GameServer: Grant Rewards
> GameServer-->>GameClient: Updated Player State
> ```
>
> See the [`GetPaymentEvent` API Reference](https://docs.stash.gg/api/ingress/payments/getpaymentevent) for request/response details.

> [tab] Confirm Payment
>
> **Validation between the hold and the charge.** Stash authorizes the payment first, then calls your backend with [`ConfirmPayment`](https://docs.stash.gg/api/egress/purchase/confirmpayment) and waits for your response. Capture runs only after you return success.
>
> By the time you see the call, the player's funds are already held but not taken. That is what makes this the only one of the three patterns where your server can **reject** a purchase: the bad case is "not charged, not granted" rather than "charged, not granted". It grants items during the same call, and it fires earliest of the three.
>
> **Direction:** Stash → Game (your backend exposes the [`ConfirmPayment`](https://docs.stash.gg/api/egress/purchase/confirmpayment) endpoint).
>
> **Best for:** Games with per-player inventory limits, multi-client purchase locking, or any validation that must happen before a purchase is finalized.
>
> **Flow:**
>
> **Step 1**
>
> Player completes checkout.
>
> **Step 2**
>
> Stash authorizes the payment. The funds are held.
>
> **Step 3**
>
> Stash sends a
>
> `ConfirmPayment`
>
> request to your backend.
>
> **Step 4**
>
> Your backend validates the purchase (inventory, caps, locks), grants the items, and returns them in the response body.
>
> **Step 5**
>
> Stash captures the payment and queues a
>
> `PURCHASE_SUCCEEDED`
>
> webhook.
>
> **There is no approve field.** Your server signals success by returning `200 OK` with the granted results in the body. A `200` whose `results` array is empty or absent confirms nothing and counts as a failure, not a success. Your server rejects by returning an HTTP `4xx` status, optionally with a `decline` object in the body naming a `PurchaseConfirmationStatus`. Where the checkout supports it, Stash uses that status to show the player the specific reason; otherwise the player sees a generic failure. See the [`ConfirmPayment` API Reference](https://docs.stash.gg/api/egress/purchase/confirmpayment).
>
> > [!WARNING]
> >
> > **Any failure response fails the purchase.** Stash treats every non-success response the same way, whether it is a deliberate rejection, an unhandled `500`, a timeout, a malformed body, or a `200` with no results. When that happens Stash does not capture: the authorization is released or left to expire at the payment provider, and the player is not charged. A payment method that settles at authorization has no hold to release, so reversing that purchase takes a refund.
> >
> > Respond `200 OK` with your granted results unless you specifically do not want Stash to take the money.
>
> ```mermaid theme={null}
> sequenceDiagram
> actor Player
> participant GameClient
> participant GameServer
> participant Stash
>
> Player->>Stash: Complete Payment
> Stash->>Stash: Authorize (funds held)
> Stash->>GameServer: ConfirmPayment Request
> GameServer->>GameServer: Validate & Grant Items
> GameServer-->>Stash: 200 OK with granted items
> Stash->>Stash: Capture Payment
> ```
>
> For the full request/response schema see the [`ConfirmPayment` API Reference](https://docs.stash.gg/api/egress/purchase/confirmpayment).


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