주요 콘텐츠로 건너뛰기

Android SDK reference

The Aghanim Android SDK that allows you to use the Checkout withing your Android app.

Native UI
Native UI

Native UI

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.

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
}
}

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.

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
}
}

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 items.get or items.getAsync method. The method returns items created in SKU Management → Items with prices localized based on the player's region.

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

Create Checkout item

To create an item representation, use the CheckoutItem method. The item should be already created in SKU Management → Items.

import com.aghanim.android.sdk.checkout.core.api.models.CheckoutItem

val checkoutItem = CheckoutItem(
sku = "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.

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

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
)
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 Native UI launch mode. Since the Checkout doesn’t use a browser to launch, no need to pass backToGameUrl.

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
)
ParameterTypeRequiredDescription
itemsList<CheckoutItem>YesList of items.
metadataMap<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.

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.

The launch mode uses the Native UI that has full control over the players’ experience.

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
}
}
ParameterTypeRequiredDescription
contextActivityYesCurrent Activity.
checkoutParamsCheckoutParamsYesCheckout configuration.

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.

The launch mode uses the Native UI that has full control over the players' experience.

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
}
}
ParameterTypeRequiredDescription
contextActivityYesCurrent Activity.
orderIdStringYesID of the existing order to open.

도움이 필요하세요?
통합팀에 문의하십시오 integration@aghanim.com