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

# Native Apps Integration

> Integrate Stash Pay in native iOS and Android apps and custom game engines using the Stash Native SDK.

> [card] [Package repository](https://github.com/stashgg/stash-native)
>
> github.com/stashgg/stash-native

> [card] [Package Readme](https://github.com/stashgg/stash-native/blob/main/README.md)
>
> Detailed usage patterns.

## Requirements

* Android API 21+ (target/compile SDK 34)
* iOS 13.0+

## Install the SDK

**1. Android (AAR)**

1. Download the latest AAR from [stash-native releases](https://github.com/stashgg/stash-native/releases).
2. Add it to your Android project (for example in `libs/`).
3. Reference it in your app module:

```groovy theme={null}
dependencies {
  implementation files('libs/StashNative-<tag>.aar')
  implementation 'androidx.appcompat:appcompat:1.6.1'
  // Optional, recommended for Custom Tabs:
  // implementation 'androidx.browser:browser:1.7.0'
}
```

**2. iOS (XCFramework or SPM)**

Use one of the following:

* **XCFramework**: download `StashNative.xcframework.zip` from [releases](https://github.com/stashgg/stash-native/releases), add it to your project, then set it to **Embed & Sign**.
* **Swift Package Manager**: add `https://github.com/stashgg/stash-native.git` in Xcode (**File -> Add Packages...**).

## Presentation methods

The SDK lets you present Stash Pay checkout links using three modes: `openCard`, `openModal`, and `openBrowser`.
Just provide your generated checkout URL, and you can also pass an optional config object to customize the presentation and subscribe to callbacks.

![Stash Native presentation methods overview](https://raw.githubusercontent.com/stashgg/stash-native/refs/heads/main/.github/assets/presentations.png)

### `openCard` (Drawer/sheet)

Use this when you want an in-app checkout view with callbacks for success/failure/dismiss.

> [tab] Android (Java)
>
> ```java theme={null}
> StashNativeCard.CardConfig config = new StashNativeCard.CardConfig(); // or null
> StashNativeCard.getInstance().openCard(checkoutUrl, config);
> ```

> [tab] iOS (Swift)
>
> ```swift theme={null}
> let config = StashNativeCardConfig() // or nil
> StashNativeCard.sharedInstance().openCard(withURL: checkoutUrl, config: config)
> ```

> [tab] iOS (Objective-C)
>
> ```objc theme={null}
> StashNativeCardConfig *config = [[StashNativeCardConfig alloc] init]; // or nil
> [[StashNativeCard sharedInstance] openCardWithURL:checkoutUrl config:config];
> ```

### `openModal` (Centered modal)

Use this when you want a centered dialog style with the same callback model as `openCard`.

> [tab] Android (Java)
>
> ```java theme={null}
> StashNativeCard.ModalConfig config = new StashNativeCard.ModalConfig(); // or null
> StashNativeCard.getInstance().openModal(checkoutUrl, config);
> ```

> [tab] iOS (Swift)
>
> ```swift theme={null}
> let config = StashNativeModalConfig() // or nil
> StashNativeCard.sharedInstance().openModal(withURL: checkoutUrl, config: config)
> ```

> [tab] iOS (Objective-C)
>
> ```objc theme={null}
> StashNativeModalConfig *config = [[StashNativeModalConfig alloc] init]; // or nil
> [[StashNativeCard sharedInstance] openModalWithURL:checkoutUrl config:config];
> ```

### `openBrowser` (Safari View Controller / Chrome Custom Tabs)

Use this when you prefer a browser-based checkout (`SFSafariViewController` on iOS, Chrome Custom Tabs/system browser on Android).

> [tab] Android (Java)
>
> ```java theme={null}
> StashNativeCard.getInstance().openBrowser(checkoutUrl);
> ```

> [tab] iOS (Swift)
>
> ```swift theme={null}
> StashNativeCard.sharedInstance().openBrowser(withURL: checkoutUrl)
> // Optional on deeplink return:
> StashNativeCard.sharedInstance().closeBrowser()
> ```

> [tab] iOS (Objective-C)
>
> ```objc theme={null}
> [[StashNativeCard sharedInstance] openBrowserWithURL:checkoutUrl];
> // Optional on deeplink return:
> [[StashNativeCard sharedInstance] closeBrowser];
> ```

## Callbacks and verification

`openCard` and `openModal` use the same callback/delegate model. Typical events:

* Payment success
* Payment failure
* Dialog dismissed
* External payment started
* Opt-in response
* Page loaded
* Network error

> [!WARNING]
>
> Always verify purchases on your backend before granting items. Client callbacks should drive UX, not final entitlement decisions.

## Landscape and orientation notes

Use `forcePortrait` in card config if your host app is landscape-locked and checkout should appear in portrait.

* On Android, this opens a portrait checkout activity in the same app process.
* On iOS, the SDK unlocks portrait for its own checkout/browser windows.

For Android landscape projects, an optional backdrop API (`setBackdropBitmap` / `setBackdropBytes`) can reduce visual artifacts during rotation.

## Android keep-alive (optional)

For browser-based flows on memory-constrained devices, you can enable keep-alive:

```java theme={null}
StashNativeCard.getInstance().setKeepAliveEnabled(true);
StashNativeCard.KeepAliveConfig config = new StashNativeCard.KeepAliveConfig();
config.notificationTitle = "Payment in progress";
config.notificationText = "Tap to return to the app";
config.notificationIconResId = 0; // 0 = SDK default icon
StashNativeCard.getInstance().setKeepAliveConfig(config);
```

This starts a short foreground service during external browser checkout. Review Play Console declarations if you enable this mode.

## Detailed references

* Full SDK docs and examples: [stash-native README](https://github.com/stashgg/stash-native/blob/main/README.md)
* Platform and policy notes: [stash-native COMPATIBILITY.md](https://github.com/stashgg/stash-native/blob/main/COMPATIBILITY.md)
* Stash Pay backend integration flow: [/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.