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 IAP Integration guide first.
Opening an Opt-in Popup
Use OpenPopup() for payment channel selection opt-in dialogs. Always handle the OnOptinResponse event:
using StashPopup;
void ShowPaymentChannelSelection()
{
// Subscribe to opt-in response
StashPayCard.Instance.OnOptinResponse += OnChannelSelected;
StashPayCard.Instance.OpenPopup(
"https://your-site.com/payment-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}");
}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:
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 orientationportraitHeightMultiplier(float) - Height multiplier for portrait orientationlandscapeWidthMultiplier(float) - Width multiplier for landscape orientationlandscapeHeightMultiplier(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.
How is this guide?
Customize the Checkout Appearance
Learn how to customize the colors and brand assets of your Stash Pay checkout page to match your game or webshop branding. Follow these steps to ensure visual consistency and improve the user experience.
About Stash Webshop
Learn about Stash Webshop - a direct-to-consumer platform that extends your in-game store to the web. Deliver live, personalized game offers to players through a branded webshop with managed or unified catalog integration modes.