Payment
AlogamePayment wraps the native SDK's in-app purchase flow — Google Play
Billing on Android, StoreKit on iOS — with server-side receipt verification
handled for you.
purchase() is the one real games use — it triggers the native SDK's
full purchase UI/flow and verify, on both platforms. queryProducts,
restorePurchases, and hasPendingPurchases are supported but see less
real-world use; reach for them only if your game needs that specific flow.
Purchase
import { AlogamePayment } from 'alogame-sdk';
const result = await AlogamePayment.purchase('com.oeg.game.pack1', {
serverId: 'server-01',
roleId: 'role-12345',
roleName: 'DragonSlayer', // optional
level: 42, // optional
});
if (result.success) {
// Payment verified by the OEG server. Item delivery is performed by your
// game server via the OEG entitlement webhook — do NOT grant items
// locally from this callback. Refresh player inventory from your game server.
}
// On failure, purchase() rejects — wrap the call in try/catch.
A resolved result.success only confirms the Alogame backend verified the
receipt. It is not a signal to grant items from the client. Item
entitlement is performed by your game server, which receives a delivery
callback from the Alogame backend after verification. Your game server must
implement the Mobile IAP server APIs — see
Server Integration → Mobile IAP.
What happens per platform
| Step | Android | iOS |
|---|---|---|
| UI | Native SDK opens its own IAP screen (showPayment) | StoreKit's system purchase sheet |
| Verify | Same Alogame server verification as the native SDK | Same Alogame server verification as the native SDK |
| Crash recovery | Pending purchase persisted, recovered via restorePurchases | Same |
gameData (serverId/roleId/level/extInfo) is recommended on every call — the
server verification endpoint uses it for entitlement attribution.
Restore pending purchases
Call after the player enters the game, once gameData is known. Re-verifies
any purchase that was interrupted by a crash or network failure.
const result = await AlogamePayment.restorePurchases({
serverId: 'server-01',
roleId: 'role-12345',
});
if (result.success) {
// Pending purchase verified and delivered — refresh inventory
}
Check for pending purchases
Synchronous-feeling check (no network call) for whether the current user has anything awaiting server verification — useful to show a "restore" button only when relevant.
const hasPending = await AlogamePayment.hasPendingPurchases();
Query product details
const products = await AlogamePayment.queryProducts([
'com.oeg.game.pack1',
'com.oeg.game.pack2',
]);
products.forEach((p) => {
console.log(p.productId, p.price, p.currency);
});
On iOS this calls StoreKit 2 directly (Product.products(for:)) since the
native SDK has no standalone query method there — devices on iOS 13/14 will
get a rejection. Android has no such restriction.
Reference
PurchaseResult
interface PurchaseResult {
success: boolean;
productId?: string;
transactionId?: string;
}
ProductDetails
interface ProductDetails {
productId: string;
price?: string; // formatted, e.g. "$4.99"
priceAmountMicros?: number; // Android only
currency?: string;
title?: string;
description?: string;
}