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

# Web Apps & WebGL

> Integrate Stash Pay in websites, web apps, and WebGL games using the Stash Pay web SDK.

> [card] [Repository](https://github.com/stashgg/stash-web)
>
> github.com/stashgg/stash-web

> [card] [NPM Package](https://www.npmjs.com/package/@stashgg/stash-pay)
>
> @stashgg/stash-pay

> [card] [Playground](https://pay-playground.stashpreview.com/)
>
> Live config and callback playground.

## Install the SDK

```bash theme={null}
npm install @stashgg/stash-pay
```

The package supports three integration modes from one install:

* React component (`@stashgg/stash-pay`)
* Framework-agnostic API (`@stashgg/stash-pay/vanilla`)
* Script-tag UMD bundle (`window.StashPay.open(...)`)

## Presentation modes

### React component

Use this when checkout state is controlled by your app UI and component lifecycle.

```tsx theme={null}
import { StashPay } from '@stashgg/stash-pay';
import '@stashgg/stash-pay/styles';

<StashPay
  isOpen={isOpen}
  checkoutUrl={checkoutUrl}
  onSuccess={(e) => console.log('paid', e.orderId)}
  onFailure={(e) => console.log('failed', e.message)}
  onClose={() => setIsOpen(false)}
/>
```

### Vanilla API

Use this when you want framework-agnostic control.

```ts theme={null}
import { open } from '@stashgg/stash-pay/vanilla';
import '@stashgg/stash-pay/styles';

open({
  checkoutUrl,
  onSuccess: (e) => console.log('paid', e.orderId),
  onFailure: (e) => console.log('failed', e.message),
  onClose: () => console.log('closed')
});
```

### Script-tag UMD (WebGL-friendly)

Use this in plain HTML or embedded game contexts (including Unity WebGL pages).

```html theme={null}
<script src="https://unpkg.com/@stashgg/stash-pay@2/dist/umd/stash-pay.umd.global.js"></script>
<script>
  window.StashPay.open({
    checkoutUrl: "https://test.stashpreview.com/",
    onSuccess: (e) => console.log('paid', e.orderId),
    onFailure: (e) => console.log('failed', e.message),
    onClose: () => console.log('closed')
  });
</script>
```

## Available parameters

The SDK options are shared across React, vanilla, and UMD integrations (except where noted).

| Option | Type | Default | Notes |
| :- | :- | :- | :- |
| `checkoutUrl` | `string` | — | Required checkout URL from your backend. |
| `isOpen` *(React only)* | `boolean` | — | Required in React component mode; controls visibility. |
| `checkoutTheme` | `'light' \| 'dark'` | — | Forwards `theme` to checkout page (different from host card theming). |
| `position` | `'bottom-sheet' \| 'center-modal' \| 'side-panel-right' \| 'side-panel-left'` | `'bottom-sheet'` | Layout preset. |
| `width` | `string \| number` | — | Override preset width. |
| `height` | `string \| number` | — | Override preset height. |
| `zIndex` | `number` | `2147483000` | Host layer z-index. |
| `portalTarget` / `container` | `HTMLElement` | `document.body` | Mount target element. |
| `showCloseButton` | `boolean` | `true` | Show/hide close button. |
| `showDragBar` | `boolean` | `true` on bottom-sheet, else `false` | Bottom-sheet drag indicator. |
| `dismissOnBackdropClick` | `boolean` | `true` | Close on backdrop click. |
| `dismissOnEscape` | `boolean` | `true` | Close on Esc key. |
| `autoCloseOnSuccess` | `boolean` | `true` | Fires callback before close. |
| `autoCloseOnFailure` | `boolean` | `true` | Auto-close after failure event. |
| `backdrop` | `{ blur?, color?, opacity?, hidden? }` | — | Backdrop styling/visibility overrides. |
| `theme` | `StashPayTheme` | — | Per-instance CSS variable overrides. |
| `animationDuration` | `number` | `300` | Animation duration in ms. |
| `ariaLabel` | `string` | `'Stash Pay checkout'` | Dialog accessibility label. |
| `iframe` | `StashPayIframeOptions` | — | Iframe behavior and security options. |
| `injectStyles` | `boolean` | UMD: `true`, otherwise `false` | Runtime style injection toggle. |
| `cspNonce` | `string` | — | Nonce for injected style tag. |
| `onOpen` / `onClose` / `onReady` / `onError` / `onSuccess` / `onFailure` / `onProcessing` | function | — | Lifecycle and payment callbacks. |

> [!NOTE]
>
> For the full and always up-to-date API surface, refer to the package docs on npm: [@stashgg/stash-pay](https://www.npmjs.com/package/@stashgg/stash-pay).

## Open checkout from websites and WebGL shells

For web games and launcher-style web surfaces, keep checkout orchestration at the page shell level:

1. Request checkout URL from your backend
2. Open Stash Pay from React, vanilla API, or UMD bridge
3. Handle callbacks for UX updates
4. Confirm final purchase state on backend before granting entitlements

For WebGL, the most common pattern is the UMD entry point from the host page and event handoff between game runtime and page JavaScript.

## Playground and implementation testing

Use the [Stash Pay Playground](https://pay-playground.stashpreview.com/) to:

* test checkout URL behavior quickly
* validate config changes and visual options
* inspect callback events in real time

## Detailed references

* Repository and sample app: [stash-web](https://github.com/stashgg/stash-web)
* SDK package details: [@stashgg/stash-pay on npm](https://www.npmjs.com/package/@stashgg/stash-pay)
* Interactive playground: [pay-playground.stashpreview.com](https://pay-playground.stashpreview.com/)
* Backend flow reference: [/guides/stash-pay/integration](https://docs.stash.gg/guides/stash-pay/integration.md)


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