Overview
The GameRamp SDK tracks IAPs across iOS and Android platforms, and enables GameRamp ML models to personalize the in-app experience.
Store Products
Fetch and display available products from the app store
Purchase Tracking
Handle purchase flows with success and failure callbacks
Personalization
Improve in-game player experience using GameRamp ML models
Fetching Store Products
Retrieve available products from the app store to display in your shop.
Gameramp.FetchStoreProducts(
Action<StoreProducts> onSuccess,
Action<string> onError
);
Implementation
void LoadShop() {
Gameramp.FetchStoreProducts(
(products) => {
foreach (var sku in products.activeSkus) {
Debug.Log($"{sku.name} ({sku.skuId}) - {sku.price}");
// Display in your shop UI
CreateShopItem(sku);
}
},
(error) => {
Debug.LogError($"Failed to fetch products: {error}");
// Show error to user
}
);
}
Initiating Purchases
Start the purchase flow for a specific product.
Gameramp.InitiatePurchase(
string productId,
Action<Purchase> onSuccess,
Action<string> onFailed
);
Parameters
The SKU ID of the product to purchase
Callback when purchase completes successfully
Callback when purchase fails with error message
Implementation Examples
public void BuyProduct(string skuId) {
Gameramp.InitiatePurchase(
skuId,
onSuccess: (purchase) => {
Debug.Log($"Purchase successful: {purchase.productId}");
// Grant the purchased item
GrantPurchase(purchase.productId);
},
onFailed: (error) => {
Debug.LogError($"Purchase failed: {error}");
// Show error to user
ShowPurchaseError(error);
}
);
}
Purchase Events
Subscribe to global purchase events for centralized handling.
// Subscribe to events
Gameramp.OnPurchaseCompleted += HandlePurchaseCompleted;
Gameramp.OnPurchaseFailed += HandlePurchaseFailed;
// Unsubscribe when done
Gameramp.OnPurchaseCompleted -= HandlePurchaseCompleted;
Gameramp.OnPurchaseFailed -= HandlePurchaseFailed;
Event Implementation
public class IAPManager : MonoBehaviour {
void OnEnable() {
// Subscribe to events
Gameramp.OnPurchaseCompleted += OnPurchaseCompleted;
Gameramp.OnPurchaseFailed += OnPurchaseFailed;
}
void OnDisable() {
// Unsubscribe to prevent memory leaks
Gameramp.OnPurchaseCompleted -= OnPurchaseCompleted;
Gameramp.OnPurchaseFailed -= OnPurchaseFailed;
}
void OnPurchaseCompleted(Purchase purchase) {
Debug.Log($"Global: Purchase completed - {purchase.productId}");
// Track analytics
Analytics.TrackPurchase(purchase.productId, purchase.price);
// Save purchase
SavePurchase(purchase);
}
void OnPurchaseFailed(string error) {
Debug.LogError($"Global: Purchase failed - {error}");
// Track failure
Analytics.TrackPurchaseFailure(error);
}
}
Product Types
Consumable
Non-Consumable
Subscription
Items that can be purchased multiple times (coins, gems, lives)// Example consumable products
"com.game.coins_100" // 100 coins
"com.game.coins_500" // 500 coins
"com.game.energy_refill" // Energy refill
Testing IAP
Always test IAP in sandbox/test environments before production release.
Testing Checklist
Troubleshooting
- Verify product IDs match exactly with store setup
- Check internet connection
- Ensure store agreements are signed
- Wait for products to propagate (can take hours)
Purchase Fails Immediately
Receipt Validation Issues
- Ensure server endpoints are configured
- Check network connectivity
- Verify receipt format is correct
- Look for server-side validation logs
Best Practices
Clear Pricing
Always show clear, localized prices before purchase
Purchase Feedback
Provide immediate visual/audio feedback on purchase
Error Handling
Show user-friendly error messages for failures
Receipt Storage
Save purchase receipts for verification
Next Steps