Unity SDK reference
The Aghanim Unity SDK that allows you to use the Checkout withing both your Android and iOS apps.
Integration
To integrate the SDK, see its prerequisites and the detailed instruction on Integrate → Unity.
Method reference
The SDK provides direct access to the Aghanim API through the Aghanim entity.
Get Order
To get Order details, use the GetOrder method.
- C#
Aghanim.GetOrder(
orderId: "order_123",
onSuccess: (order) => {
Debug.Log($"Order ID: {order.id}");
Debug.Log($"Player ID: {order.player_id}");
Debug.Log($"Total price: {order.price_minor_unit} {order.currency}");
},
onError: (error) => {
Debug.LogError($"Failed to get order: {error}");
}
);
| Parameter | Type | Required | Description |
|---|---|---|---|
orderId | string | Yes | Unique ID for the Order. |
onSuccess | Action<Models.OrderRead> | Yes if no error | Callback that is invoked on successful result. |
onError | Action<string> | Yes if no success | Callback that is invoked on failed result. |
Get unconsumed Orders
To know what Orders have been paid for but not granted yet, use the GetUnconsumedOrders method.
- C#
Aghanim.GetUnconsumedOrders(
onSuccess: (response) =>
{
// Player has paid but not granted items from orders
var unconsumedOrderIds = response.Orders;
// TODO: Save order IDs for further consuming and granting
},
onError: (error) =>
{
// Log debug information for troubleshooting
Debug.LogError($"Payment failed: {error.debugMessage}");
// TODO: Handle error
}
);
| Parameter | Type | Required | Description |
|---|---|---|---|
onSuccess | Action<string[]> | Yes if no error | Callback that is invoked on successful result. |
onError | Action<string> | Yes if no success | Callback that is invoked on failed result. |
Consume paid Order
To let the SDK acknowledge that you have granted the items the player has purchased via an Order, use the ConsumeOrder method.
- C#
Aghanim.ConsumeOrder(
orderId: orderId,
onSuccess: (response) =>
{
// Paid orders are marked as consumed
Debug.LogError($"Payment failed: {$orderId}");
// TODO: Grant items in order to player
},
onError: (error) =>
{
// Log debug information for troubleshooting
Debug.LogError($"Payment failed: {error.debugMessage}");
// TODO: Handle error
}
);
| Parameter | Type | Required | Description |
|---|---|---|---|
orderId | string | Yes | Unique ID for the Order. |
onSuccess | Action | Yes if no error | Callback that is invoked on successful result. |
onError | Action<string> | Yes if no success | Callback that is invoked on failed result. |
Set player ID
To set the player ID once for the current SDK instance, use the SetPlayerId method. The SDK will use the ID in all following method calls.
- C#
Aghanim.SetPlayerId(playerId);
| Parameter | Type | Required | Description |
|---|---|---|---|
playerId | string | Yes | Unique ID for the player. |
Get items
To retrieve items with localized prices, use the GetItems method. The method returns items created in SKU Management → Items with prices localized based on the player's region.
- C#
Aghanim.GetItems(
skus: new List<string> { "your-item-sku" },
onSuccess: (items) =>
{
foreach (var item in items)
{
// Use item.Name, item.Price.Display, item.ImageUrl to populate your store
Debug.Log($"{item.Name}: {item.Price.Display}");
}
},
onError: (error) =>
{
// Log debug information for troubleshooting
Debug.LogError($"Failed to get items: {error}");
// TODO: Handle error
}
);
| Parameter | Type | Required | Description |
|---|---|---|---|
skus | List<string> | Yes | List of item SKUs to retrieve (max 50). |
locale | Locale | No | Locale for price formatting. Find the full list of supported locales in Checkout → Locales. |
onSuccess | Action<Item[]> | Yes if no error | Callback that is invoked on successful result. |
onError | Action<string> | Yes if no success | Callback that is invoked on failed result. |
Create Checkout item
To create an item representation, use the CheckoutItem method. The item should be already created in SKU Management → Items.
- C#
var items = new List<CheckoutItem>
{
new CheckoutItem("CRS-82500")
};
| Parameter | Type | Required | Description |
|---|---|---|---|
sku | string | Yes | Item SKU from Dashboard. |
name | string | No | Item name from Dashboard. |
description | string | No | Item description from Dashboard. |
imageUrl | string | No | Item image URL from Dashboard. |
quantity | int | No | Item quantity. |
Create redirect behavior
To choose the behavior of redirecting the player after they have completed the payment successfully, use the RedirectSettings method.
- Immediate
- Delayed
- No redirect
When the player has completed the payment, the SDK redirects them immediately to the deep link from backToGameUrl.
- C#
var redirectSettings = new RedirectSettings(
mode: RedirectMode.Immediate
);
When the player has completed the payment, the SDK shows the screen for the successful payment and then redirects the player to the deep link from backToGameUrl.
- C#
var redirectSettings = new RedirectSettings(
mode: RedirectMode.Delayed,
delaySeconds: 5
);
When the player has completed the payment, they stay on the screen for the successful payment. To exit it, they manually close it or navigate away. After, you should redirect them to the deep link from backToGameUrl by yourself.
- C#
var redirectSettings = new RedirectSettings(
mode: RedirectMode.NoRedirect
);
| Parameter | Type | Required | Description |
|---|---|---|---|
mode | RedirectMode | Yes | Redirect mode. Possible values: Immediate, Delayed, NoRedirect. |
delaySeconds | int | Yes if Delayed | Delay in seconds. For Delayed mode, default is 5. |
Create UI settings
To set the appearance mode for the Checkout, use the UiSettings method.
- Auto
- Dark
- Light
The SDK automatically detects and applies the appropriate appearance mode based on the system setting.
- C#
var uiSettings = new UiSettings(
mode: UiMode.Auto
);
The SDK forces dark mode appearance for the Checkout UI.
- C#
var uiSettings = new UiSettings(
mode: UiMode.Dark
);
The SDK forces light mode appearance for the Checkout UI.
- C#
var uiSettings = new UiSettings(
mode: UiMode.Light
);
| Parameter | Type | Required | Description |
|---|---|---|---|
mode | UiMode | Yes | UI mode. Possible values: Auto, Dark, Light. |
Create Checkout params
To create Checkout params, a representation of what the player sees on the payment form, use the CheckoutParams method.
- Default
- Others
Creating Checkout params is simpler for the Default launch mode. Since the Checkout doesn’t use a browser to launch, no need to pass backToGameUrl.
- C#
var checkoutParams = new CheckoutParams(
items: items,
customMessage: "Holiday Sale!"
);
Creating Checkout params is slightly different for the In-app browser, Default browser, and Custom per platform launch modes. Since the Checkout launches in the browser, you should pass backToGameUrl.
- C#
var checkoutParams = new CheckoutParams(
items: items,
customMessage: "Holiday Sale!",
backToGameUrl: "https://<YOUR_DOMAIN>/checkout-complete"
);
| Parameter | Type | Required | Description |
|---|---|---|---|
items | List<CheckoutItem> | Yes | List of items. |
metadata | Dictionary<string, string> | No | Metadata structured as “key-value” pairs for tracking purposes. |
priceTemplateId | string | No | Price template ID from Get Price Points for localized pricing. |
locale | string | No | Locale for item name and description localization. Find the full list of supported locales in Checkout → Locales. |
customMessage | string | No | Message for Checkout page. |
backToGameUrl | string | No | Deep link URL to return player to app. Is auto-generated if not provided. |
redirectSettings | RedirectSettings | No | Post-payment redirect behavior. |
uiSettings | UiSettings | No | Checkout appearance settings. |
Use Checkout launch mode
To launch the payment form, use the LaunchMode entity.
- Default
- In-app browser
- Default browser
- Custom per platform
For Android, the Default launch mode uses the Native UI that has full control over the players’ experience.
For iOS, the Default launch mode uses the Internal Browser.
- C#
LaunchMode.Default
For Android and iOS, the In-app browser launch mode creates the seamless players’ experience via Android Custom Tabs and iOS SFSafariViewController.
- C#
LaunchMode.InAppBrowser
For Android and iOS, the Default browser launch mode works in the player default browser. Use the mode when you want to redirect the player outside your app.
- C#
LaunchMode.DefaultBrowser
You can use different launch modes for each platform.
- C#
var launchMode = new LaunchMode(
android: LaunchMode.Android.NativeUI,
ios: LaunchMode.IOS.InternalBrowser
);
| Parameter | Type | Required | Description |
|---|---|---|---|
android | LaunchMode.Android | Yes | Launch mode for Android platform. Possible values: NativeUI, InternalBrowser, DefaultBrowser. |
ios | LaunchMode.IOS | Yes | Launch mode for iOS platform. Possible values: InternalBrowser, DefaultBrowser. |
Start Checkout
To start the Checkout process, use the StartCheckout method. The method creates an order from the provided checkout params and opens the Checkout UI. On success, you receive the Order ID. On failure, you receive an error with debug information.
- Default
- In-app browser
- Default browser
- Custom per platform
For Android, the Default launch mode uses the Native UI that has full control over the players’ experience.
For iOS, the Default launch mode uses the Internal Browser.
- C#
Aghanim.StartCheckout(
checkoutParams,
LaunchMode.Default,
onSuccess: (orderId) =>
{
// Order is created and checkout has launched successfully
// TODO: Save order ID for further granting or tracking
},
onError: (error) =>
{
// Log debug information for troubleshooting
Debug.LogError($"Failed to launch Checkout: {error}");
// TODO: Show user-friendly error message to player
}
);
For Android and iOS, the In-app browser launch mode creates the seamless players’ experience via Android Custom Tabs and iOS SFSafariViewController.
- C#
Aghanim.StartCheckout(
checkoutParams,
LaunchMode.InAppBrowser,
onSuccess: (orderId) =>
{
// Order is created and checkout has launched successfully
// TODO: Save order ID for further granting or tracking
},
onError: (error) =>
{
// Log debug information for troubleshooting
Debug.LogError($"Failed to launch Checkout: {error}");
// TODO: Show user-friendly error message to player
}
);
For Android and iOS, the Default browser launch mode works in the player default browser. Use the mode when you want to redirect the player outside your app.
- C#
Aghanim.StartCheckout(
checkoutParams,
LaunchMode.DefaultBrowser,
onSuccess: (orderId) =>
{
// Order is created and checkout has launched successfully
// TODO: Save order ID for further granting or tracking
},
onError: (error) =>
{
// Log debug information for troubleshooting
Debug.LogError($"Failed to launch Checkout: {error}");
// TODO: Show user-friendly error message to player
}
);
You can use different launch modes for each platform.
- C#
Aghanim.StartCheckout(
checkoutParams,
launchMode,
onSuccess: (orderId) =>
{
// Order is created and checkout has launched successfully
// TODO: Save order ID for further granting or tracking
},
onError: (error) =>
{
// Log debug information for troubleshooting
Debug.LogError($"Failed to launch Checkout: {error}");
// TODO: Show user-friendly error message to player
}
);
| Parameter | Type | Required | Description |
|---|---|---|---|
checkoutParams | CheckoutParams | Yes | Checkout configuration. |
launchMode | LaunchMode | Yes | Launch mode for Checkout. |
onSuccess | Action<string> | Yes | Callback invoked with Order ID on successful Checkout launch. |
onError | Action<string> | Yes | Callback invoked with error message on failed Checkout launch. |
Present Checkout
To present the Checkout UI for an existing order, use the PresentCheckout method. Use this when you have an order ID from server-to-server order creation or when resuming a previously abandoned checkout.
- Default
- In-app browser
- Default browser
- Custom per platform
For Android, the Default launch mode uses the Native UI that has full control over the players' experience.
For iOS, the Default launch mode uses the Internal Browser.
- C#
Aghanim.PresentCheckout(
orderId,
LaunchMode.Default,
onSuccess: (orderId) =>
{
// Checkout has launched successfully for the existing order
},
onError: (error) =>
{
// Log debug information for troubleshooting
Debug.LogError($"Failed to present Checkout: {error}");
// TODO: Show user-friendly error message to player
}
);
For Android and iOS, the In-app browser launch mode creates the seamless players' experience via Android Custom Tabs and iOS SFSafariViewController.
- C#
Aghanim.PresentCheckout(
orderId,
LaunchMode.InAppBrowser,
onSuccess: (orderId) =>
{
// Checkout has launched successfully for the existing order
},
onError: (error) =>
{
// Log debug information for troubleshooting
Debug.LogError($"Failed to present Checkout: {error}");
// TODO: Show user-friendly error message to player
}
);
For Android and iOS, the Default browser launch mode works in the player default browser. Use the mode when you want to redirect the player outside your app.
- C#
Aghanim.PresentCheckout(
orderId,
LaunchMode.DefaultBrowser,
onSuccess: (orderId) =>
{
// Checkout has launched successfully for the existing order
},
onError: (error) =>
{
// Log debug information for troubleshooting
Debug.LogError($"Failed to present Checkout: {error}");
// TODO: Show user-friendly error message to player
}
);
You can use different launch modes for each platform.
- C#
Aghanim.PresentCheckout(
orderId,
launchMode,
onSuccess: (orderId) =>
{
// Checkout has launched successfully for the existing order
},
onError: (error) =>
{
// Log debug information for troubleshooting
Debug.LogError($"Failed to present Checkout: {error}");
// TODO: Show user-friendly error message to player
}
);
| Parameter | Type | Required | Description |
|---|---|---|---|
orderId | string | Yes | ID of the existing order to open. |
launchMode | LaunchMode | Yes | Launch mode for Checkout. |
onSuccess | Action<string> | Yes | Callback invoked with Order ID on successful Checkout launch. |
onError | Action<string> | Yes | Callback invoked with error message on failed Checkout launch. |
FAQ
需要技术支持?
联系我们的集成技术团队: integration@aghanim.com









