跳至主要内容

Unity SDK reference

The Aghanim Unity SDK that allows you to use the Checkout withing both your Android and iOS apps.

Android. Default browser
Android. Default browser

Android. Default browser

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.

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}");
}
);
ParameterTypeRequiredDescription
orderIdstringYesUnique ID for the Order.
onSuccessAction<Models.OrderRead>Yes if no errorCallback that is invoked on successful result.
onErrorAction<string>Yes if no successCallback 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.

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
}
);
ParameterTypeRequiredDescription
onSuccessAction<string[]>Yes if no errorCallback that is invoked on successful result.
onErrorAction<string>Yes if no successCallback 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.

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
}
);
ParameterTypeRequiredDescription
orderIdstringYesUnique ID for the Order.
onSuccessActionYes if no errorCallback that is invoked on successful result.
onErrorAction<string>Yes if no successCallback 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.

Aghanim.SetPlayerId(playerId);
ParameterTypeRequiredDescription
playerIdstringYesUnique 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.

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
}
);
ParameterTypeRequiredDescription
skusList<string>YesList of item SKUs to retrieve (max 50).
localeLocaleNoLocale for price formatting. Find the full list of supported locales in Checkout → Locales.
onSuccessAction<Item[]>Yes if no errorCallback that is invoked on successful result.
onErrorAction<string>Yes if no successCallback 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.

var items = new List<CheckoutItem>
{
new CheckoutItem("CRS-82500")
};
ParameterTypeRequiredDescription
skustringYesItem SKU from Dashboard.
namestringNoItem name from Dashboard.
descriptionstringNoItem description from Dashboard.
imageUrlstringNoItem image URL from Dashboard.
quantityintNoItem quantity.

Create redirect behavior

To choose the behavior of redirecting the player after they have completed the payment successfully, use the RedirectSettings method.

When the player has completed the payment, the SDK redirects them immediately to the deep link from backToGameUrl.

var redirectSettings = new RedirectSettings(
mode: RedirectMode.Immediate
);
ParameterTypeRequiredDescription
modeRedirectModeYesRedirect mode. Possible values: Immediate, Delayed, NoRedirect.
delaySecondsintYes if DelayedDelay in seconds. For Delayed mode, default is 5.

Create UI settings

To set the appearance mode for the Checkout, use the UiSettings method.

The SDK automatically detects and applies the appropriate appearance mode based on the system setting.

var uiSettings = new UiSettings(
mode: UiMode.Auto
);
ParameterTypeRequiredDescription
modeUiModeYesUI 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.

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.

var checkoutParams = new CheckoutParams(
items: items,
customMessage: "Holiday Sale!"
);
ParameterTypeRequiredDescription
itemsList<CheckoutItem>YesList of items.
metadataDictionary<string, string>NoMetadata structured as “key-value” pairs for tracking purposes.
priceTemplateIdstringNoPrice template ID from Get Price Points for localized pricing.
localestringNoLocale for item name and description localization. Find the full list of supported locales in Checkout → Locales.
customMessagestringNoMessage for Checkout page.
backToGameUrlstringNoDeep link URL to return player to app. Is auto-generated if not provided.
redirectSettingsRedirectSettingsNoPost-payment redirect behavior.
uiSettingsUiSettingsNoCheckout appearance settings.

Use Checkout launch mode

To launch the payment form, use the LaunchMode entity.

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.

LaunchMode.Default

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.

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.

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
}
);
ParameterTypeRequiredDescription
checkoutParamsCheckoutParamsYesCheckout configuration.
launchModeLaunchModeYesLaunch mode for Checkout.
onSuccessAction<string>YesCallback invoked with Order ID on successful Checkout launch.
onErrorAction<string>YesCallback 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.

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.

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
}
);
ParameterTypeRequiredDescription
orderIdstringYesID of the existing order to open.
launchModeLaunchModeYesLaunch mode for Checkout.
onSuccessAction<string>YesCallback invoked with Order ID on successful Checkout launch.
onErrorAction<string>YesCallback invoked with error message on failed Checkout launch.

FAQ

What platforms does your Unity SDK support?

The Unity SDK is available for both iOS and Android.

需要技术支持?
联系我们的集成技术团队: integration@aghanim.com