Android SDK reference
The Aghanim Android SDK that allows you to use the Checkout withing your Android app.
Integration
To integrate the SDK, see its prerequisites and the detailed instruction on Integrate → Android.
Method reference
Get unconsumed Orders
To know what Orders have been paid for but not granted yet, use the getUnconsumed or getUnconsumedAsync method.
- Coroutines
- Async callbacks
- Kotlin
import com.aghanim.android.sdk.common.api.result.ApiResult
import android.util.Log
when (val unconsumedResult = aghanim.orders.getUnconsumed()) {
is ApiResult.Success -> {
// Player has paid but not granted items from orders
val unconsumedOrderIds = unconsumedResult.value
// TODO: Save order IDs for further consuming and granting
}
is ApiResult.Failure -> {
// Log debug information for troubleshooting
Log.e("Orders", "Failed to get unconsumed orders: ${unconsumedResult.error}")
// TODO: Handle error
}
}
- Kotlin
import com.aghanim.android.sdk.common.api.callbacks.OrderListCallback
import com.aghanim.android.sdk.common.api.result.ApiError
import android.util.Log
aghanim.orders.getUnconsumedAsync(
callback = object : OrderListCallback {
override fun onSuccess(orderIds: List<String>) {
// Player has paid but not granted items from orders
val unconsumedOrderIds = orderIds
// TODO: Save order IDs for further consuming and granting
}
override fun onError(failure: ApiError) {
// Log debug information for troubleshooting
Log.e("Orders", "Failed to get unconsumed orders: ${failure.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 consume or consumeAsync method.
- Coroutines
- Async callbacks
- Kotlin
import com.aghanim.android.sdk.common.api.result.ApiResult
import android.util.Log
when (val consumeResult = aghanim.orders.consume(orderId)) {
is ApiResult.Success -> {
// Paid orders are marked as consumed
Log.d("Orders", "Order $orderId is successfully consumed")
// TODO: Grant items in order to player
}
is ApiResult.Failure -> {
// Log debug information for troubleshooting
Log.e("Orders", "Failed to consume order: ${consumeResult.error}")
// TODO: Handle error
}
}
- Kotlin
import com.aghanim.android.sdk.common.api.callbacks.ConsumeCallback
import com.aghanim.android.sdk.common.api.result.ApiError
import android.util.Log
aghanim.orders.consumeAsync(
orderId = orderId,
callback = object : ConsumeCallback {
override fun onSuccess() {
// Paid orders are marked as consumed
Log.d("Orders", "Order $orderId is successfully consumed")
// TODO: Grant items in order to player
}
override fun onError(failure: ApiError) {
// Log debug information for troubleshooting
Log.e("Orders", "Failed to consume order: ${failure.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.
- Kotlin
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 items.get or items.getAsync method. The method returns items created in SKU Management → Items with prices localized based on the player's region.
- Coroutines
- Async callbacks
- Kotlin
import com.aghanim.android.sdk.common.api.result.ApiResult
import android.util.Log
when (val result = aghanim.items.get(
skus = listOf("your-item-sku"),
)) {
is ApiResult.Success -> {
val items = result.value
items.forEach { item ->
// Use item.name, item.price.display, item.imageUrl to populate your store
Log.d("Items", "${item.name}: ${item.price.display}")
}
}
is ApiResult.Failure -> {
// Log debug information for troubleshooting
Log.e("Items", "Failed to get items: ${result.error}")
// TODO: Handle error
}
}
- Kotlin
import com.aghanim.android.sdk.common.api.callbacks.ItemsCallback
import com.aghanim.android.sdk.common.api.models.item.Item
import com.aghanim.android.sdk.common.api.result.ApiError
import android.util.Log
aghanim.items.getAsync(
skus = listOf("your-item-sku"),
locale = null,
callback = object : ItemsCallback {
override fun onSuccess(items: List<Item>) {
items.forEach { item ->
// Use item.name, item.price.display, item.imageUrl to populate your store
Log.d("Items", "${item.name}: ${item.price.display}")
}
}
override fun onError(failure: ApiError) {
// Log debug information for troubleshooting
Log.e("Items", "Failed to get items: ${failure.debugMessage}")
// 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<List<Item>> | Yes if no error | Callback that is invoked on successful result. |
onError | Action<ApiError> | Yes if no success | Callback that is invoked on failed result. |
| 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. |
Create Checkout item
To create an item representation, use the CheckoutItem method. The item should be already created in SKU Management → Items.
- Kotlin
import com.aghanim.android.sdk.checkout.core.api.models.CheckoutItem
val checkoutItem = CheckoutItem(
sku = "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.
- Kotlin
import com.aghanim.android.sdk.common.api.models.order.RedirectSettings
import com.aghanim.android.sdk.common.api.models.order.RedirectMode
val redirectSettings = 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.
- Kotlin
import com.aghanim.android.sdk.common.api.models.order.RedirectSettings
import com.aghanim.android.sdk.common.api.models.order.RedirectMode
val redirectSettings = 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.
- Kotlin
import com.aghanim.android.sdk.common.api.models.order.RedirectSettings
import com.aghanim.android.sdk.common.api.models.order.RedirectMode
val redirectSettings = RedirectSettings(
mode = RedirectMode.NO_REDIRECT
)
| 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.
- Kotlin
import com.aghanim.android.sdk.checkout.core.api.models.UiSettings
import com.aghanim.android.sdk.checkout.core.api.models.UiMode
val uiSettings = UiSettings(
mode = UiMode.AUTO
)
The SDK forces dark mode appearance for the Checkout UI.
- Kotlin
import com.aghanim.android.sdk.checkout.core.api.models.UiSettings
import com.aghanim.android.sdk.checkout.core.api.models.UiMode
val uiSettings = UiSettings(
mode = UiMode.DARK
)
The SDK forces light mode appearance for the Checkout UI.
- Kotlin
import com.aghanim.android.sdk.checkout.core.api.models.UiSettings
import com.aghanim.android.sdk.checkout.core.api.models.UiMode
val uiSettings = 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.
- Native UI
- Others
Creating Checkout params is simpler for the Native UI launch mode. Since the Checkout doesn’t use a browser to launch, no need to pass backToGameUrl.
- Kotlin
import com.aghanim.android.sdk.checkout.core.api.models.CheckoutParams
import com.aghanim.android.sdk.common.api.models.common.Locale
val checkoutParams = CheckoutParams(
items = listOf(checkoutItem),
customMessage = "Holiday Sale!",
locale = null
)
Creating Checkout params is slightly different for the In-app browser and Default browser launch modes. Since the Checkout launches in the browser, you should pass backToGameUrl.
- Kotlin
import com.aghanim.android.sdk.checkout.core.api.models.CheckoutParams
import com.aghanim.android.sdk.common.api.models.common.Locale
val checkoutParams = CheckoutParams(
items = listOf(checkoutItem),
customMessage = "Holiday Sale!",
backToGameUrl = "https://<YOUR_DOMAIN>/checkout-complete",
locale = null
)
| Parameter | Type | Required | Description |
|---|---|---|---|
items | List<CheckoutItem> | Yes | List of items. |
metadata | Map<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. |
Launch Checkout
To launch the Checkout process, use the startCheckout or startWebCheckout method. The method creates an order from the provided checkout params and opens the Checkout UI. Returns ApiResult<String> where the success value is the Order ID.
- Native UI
- In-app browser
- Default browser
The launch mode uses the Native UI that has full control over the players’ experience.
- Kotlin
import com.aghanim.android.sdk.checkout.ui.api.startCheckout
import com.aghanim.android.sdk.common.api.result.ApiResult
import android.util.Log
when (val result = aghanim.startCheckout(
context = context,
checkoutParams = checkoutParams,
)) {
is ApiResult.Success -> {
// Order is created and checkout has launched successfully
val orderId = result.value
// TODO: Save order ID for further granting or tracking
}
is ApiResult.Failure -> {
// Log debug information for troubleshooting
Log.e("Checkout", "Failed to launch Checkout: ${result.error}")
// TODO: Show user-friendly error message to player
}
}
| Parameter | Type | Required | Description |
|---|---|---|---|
context | Activity | Yes | Current Activity. |
checkoutParams | CheckoutParams | Yes | Checkout configuration. |
The launch mode creates the seamless players’ experience via Custom Tabs.
- Kotlin
import com.aghanim.android.sdk.checkout.web.api.startWebCheckout
import com.aghanim.android.sdk.checkout.web.api.models.LaunchMode
import com.aghanim.android.sdk.common.api.result.ApiResult
import android.util.Log
when (val result = aghanim.startWebCheckout(
context = context,
checkoutParams = checkoutParams,
launchMode = LaunchMode.InAppBrowser,
)) {
is ApiResult.Success -> {
// Order is created and checkout has launched successfully
val orderId = result.value
// TODO: Save order ID for further granting or tracking
}
is ApiResult.Failure -> {
// Log debug information for troubleshooting
Log.e("Checkout", "Failed to launch Checkout: ${result.error}")
// TODO: Show user-friendly error message to player
}
}
| Parameter | Type | Required | Description |
|---|---|---|---|
context | Activity | Yes | Current Activity. |
checkoutParams | CheckoutParams | Yes | Checkout configuration. |
launchMode | LaunchMode | Yes | Launch mode for Checkout. |
The launch mode works in the player default browser. Use the mode when you want to redirect the player outside your app.
- Kotlin
import com.aghanim.android.sdk.checkout.web.api.startWebCheckout
import com.aghanim.android.sdk.checkout.web.api.models.LaunchMode
import com.aghanim.android.sdk.common.api.result.ApiResult
import android.util.Log
when (val result = aghanim.startWebCheckout(
context = context,
checkoutParams = checkoutParams,
launchMode = LaunchMode.DefaultBrowser,
)) {
is ApiResult.Success -> {
// Order is created and checkout has launched successfully
val orderId = result.value
// TODO: Save order ID for further granting or tracking
}
is ApiResult.Failure -> {
// Log debug information for troubleshooting
Log.e("Checkout", "Failed to launch Checkout: ${result.error}")
// TODO: Show user-friendly error message to player
}
}
| Parameter | Type | Required | Description |
|---|---|---|---|
context | Activity | Yes | Current Activity. |
checkoutParams | CheckoutParams | Yes | Checkout configuration. |
launchMode | LaunchMode | Yes | Launch mode for Checkout. |
Present Checkout
To present the Checkout UI for an existing order, use the presentCheckout or presentWebCheckout method. Use this when you have an order ID from server-to-server order creation or when resuming a previously abandoned checkout.
- Native UI
- In-app browser
- Default browser
The launch mode uses the Native UI that has full control over the players' experience.
- Kotlin
import com.aghanim.android.sdk.checkout.ui.api.presentCheckout
import com.aghanim.android.sdk.common.api.result.ApiResult
import android.util.Log
when (val result = aghanim.presentCheckout(
context = context,
orderId = orderId,
)) {
is ApiResult.Success -> {
// Checkout has launched successfully for the existing order
val presentedOrderId = result.value
}
is ApiResult.Failure -> {
// Log debug information for troubleshooting
Log.e("Checkout", "Failed to present Checkout: ${result.error}")
// TODO: Show user-friendly error message to player
}
}
| Parameter | Type | Required | Description |
|---|---|---|---|
context | Activity | Yes | Current Activity. |
orderId | String | Yes | ID of the existing order to open. |
The launch mode creates the seamless players' experience via Custom Tabs.
- Kotlin
import com.aghanim.android.sdk.checkout.web.api.presentWebCheckout
import com.aghanim.android.sdk.checkout.web.api.models.LaunchMode
import com.aghanim.android.sdk.common.api.result.ApiResult
import android.util.Log
when (val result = aghanim.presentWebCheckout(
context = context,
orderId = orderId,
launchMode = LaunchMode.InAppBrowser,
)) {
is ApiResult.Success -> {
// Checkout has launched successfully for the existing order
val presentedOrderId = result.value
}
is ApiResult.Failure -> {
// Log debug information for troubleshooting
Log.e("Checkout", "Failed to present Checkout: ${result.error}")
// TODO: Show user-friendly error message to player
}
}
| Parameter | Type | Required | Description |
|---|---|---|---|
context | Activity | Yes | Current Activity. |
orderId | String | Yes | ID of the existing order to open. |
launchMode | LaunchMode | Yes | Launch mode for Checkout. |
The launch mode works in the player default browser. Use the mode when you want to redirect the player outside your app.
- Kotlin
import com.aghanim.android.sdk.checkout.web.api.presentWebCheckout
import com.aghanim.android.sdk.checkout.web.api.models.LaunchMode
import com.aghanim.android.sdk.common.api.result.ApiResult
import android.util.Log
when (val result = aghanim.presentWebCheckout(
context = context,
orderId = orderId,
launchMode = LaunchMode.DefaultBrowser,
)) {
is ApiResult.Success -> {
// Checkout has launched successfully for the existing order
val presentedOrderId = result.value
}
is ApiResult.Failure -> {
// Log debug information for troubleshooting
Log.e("Checkout", "Failed to present Checkout: ${result.error}")
// TODO: Show user-friendly error message to player
}
}
| Parameter | Type | Required | Description |
|---|---|---|---|
context | Activity | Yes | Current Activity. |
orderId | String | Yes | ID of the existing order to open. |
launchMode | LaunchMode | Yes | Launch mode for Checkout. |
도움이 필요하세요?
통합팀에 문의하십시오 integration@aghanim.com





