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

# Unity Opt-in Dialog

> Learn how to implement payment channel selection opt-in dialogs in your Unity project using the Stash Pay Unity SDK.

Use `OpenPopup()` to display payment channel selection opt-in dialogs in your Unity project. This allows players to choose between native IAP and Stash Pay payment methods.

## Before you begin

This guide assumes you have already set up the Stash Pay Unity SDK. If you haven't, see the [Unity integration guide](https://docs.stash.gg/guides/stash-pay/ios-android-integration/unity.md) first.

## Opening an Opt-in Popup

Use `OpenPopup()` for payment channel selection opt-in dialogs. Always handle the `OnOptinResponse` event:

```csharp title="Opening an Opt-in Popup" theme={null}
using StashPopup;

void ShowPaymentChannelSelection()
{
    // Subscribe to opt-in response
    StashPayCard.Instance.OnOptinResponse += OnChannelSelected;
    
    StashPayCard.Instance.OpenPopup(
        "https://your-site.com/pay/channel-selection",
        dismissCallback: () => {
            // Unsubscribe when popup closes
            StashPayCard.Instance.OnOptinResponse -= OnChannelSelected;
        }
    );
}

void OnChannelSelected(string channel)
{
    // Receives "native_iap" or "stash_pay"
    string paymentMethod = channel.ToUpper();
    
    // Save user preference
    PlayerPrefs.SetString("PaymentMethod", paymentMethod);
    PlayerPrefs.Save();
    
    Debug.Log($"User selected: {paymentMethod}");
}
```

> [!NOTE]
>
> Use `OpenPopup()` exclusively for payment channel selection opt-in flows. For checkout flows, use `OpenCheckout()` instead.

## Configuring Popup Size

`OpenPopup()` supports optional custom size configuration. By default, it uses platform-specific default sizing. You can customize the size using `PopupSizeConfig`:

```csharp title="Custom Popup Size Configuration" theme={null}
var customSize = new PopupSizeConfig
{
    portraitWidthMultiplier = 0.9f,      // 90% of base width in portrait
    portraitHeightMultiplier = 1.2f,     // 120% of base height in portrait
    landscapeWidthMultiplier = 1.4f,     // 140% of base width in landscape
    landscapeHeightMultiplier = 0.85f    // 85% of base height in landscape
};

StashPayCard.Instance.OpenPopup(
    url,
    dismissCallback: OnDismiss,
    customSize: customSize
);
```

**Note:** The popup automatically adjusts its size when the device rotates between portrait and landscape orientations. Custom multipliers are applied relative to the calculated base size (which depends on device type and screen dimensions).

## API Reference

### Methods

**`OpenPopup(string url, Action onDismiss = null, Action onSuccess = null, Action onFailure = null, PopupSizeConfig? customSize = null)`**
Opens Stash opt-in and other remote Stash dialogs in a centered modal popup. Size can be customized using `PopupSizeConfig`. If not provided, uses platform-specific default sizing.

### Events

**`OnOptinResponse`** (event Action\<string>)

* Fired when user selects a payment channel in opt-in popup. Receives `"native_iap"` or `"stash_pay"`.

### Types

**`PopupSizeConfig`** (struct)

* `portraitWidthMultiplier` (float) - Width multiplier for portrait orientation
* `portraitHeightMultiplier` (float) - Height multiplier for portrait orientation
* `landscapeWidthMultiplier` (float) - Width multiplier for landscape orientation
* `landscapeHeightMultiplier` (float) - Height multiplier for landscape orientation

**Note:** Each platform (iOS and Android) has its own default sizing. When `customSize` is not provided, the platform-specific defaults are used.


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