Skip to main content

Unity In-App Purchase

The package uses Google Play Billing on Android and StoreKit on iOS through the native SDKs. The Alogame backend verifies each purchase and delivers it to your game server, as described in Mobile IAP.

Grant items from your server, not from the client result

The client result tells the player what happened. Items are granted by your game server when the Alogame backend delivers the verified purchase to it.

Purchase​

C#
var gameData = new GameData
{
ServerId = "1",
RoleId = "10001",
ServerName = "S1",
RoleName = "Hero",
Level = 12,
};

try
{
PurchaseResult result = await AlogamePayment.Purchase("gold_100", gameData);
Debug.Log($"Purchased {result.ProductId}");
}
catch (AlogameSdkException e)
{
Debug.Log($"Purchase not completed: [{e.Error.Code}] {e.Message}"); // cancelled, billing error, ...
}

GameData carries the role the purchase is for. Send the same values you passed to SetGameRole.

Recover interrupted purchases​

Call RestorePurchases after the player enters the game and the role is known. It re-verifies purchases that were paid but interrupted by a crash or a network failure.

C#
RestoreResult restore = await AlogamePayment.RestorePurchases(gameData);
bool pending = await AlogamePayment.HasPendingPurchases();

Product details​

C#
List<ProductDetails> products = await AlogamePayment.QueryProducts(new[] { "gold_100", "gold_500" });
// ProductId, Title, Price (formatted), PriceAmountMicros, Currency

Platform differences​

AndroidiOS
PurchaseResult.TransactionIdGoogle order idnull (the native purchase flow does not return it)
GameData.ServerIdmust be numericany string

How the native side stores, retries and deduplicates a purchase is the same as on Android and iOS.