Enable players to purchase items, upgrades, or currency within your game to enhance their experience and generate revenue.
There are two types of purchases — permanent (e.g., ad removal) and consumable (e.g., in-game coins).
Support
Check if in-game purchases are supported to offer items or upgrades within the game.
Copy Bridge.payments.isSupported
Setup
Setup in-game purchases in the . For each product add a commonId
and fill in the information for the required platforms, example for one product:
Copy {
...
"payments": [
{
"commonId": "test_product",
"yandex": {
"id": "YANDEX_ID_HERE"
},
"facebook": {
"productID": "FACEBOOK_ID_HERE"
},
"msn": {
"productId": "MSN_ID_HERE"
},
"playgama": {
"amount": 1 // price in Golden Fennec
},
"qa_tool": {
"id": "QA_TOOL_ID_HERE",
"amount": 1 // price in Golden Fennec
},
"playdeck": {
"amount": 1, // price in Telegram Stars
"description": "TEST PRODUCT"
}
}
]
}
Purchase
Allow players to buy items or upgrades in your game to enhance their gameplay experience.
Copy private void Start()
{
var commonId = "test_product"; // commonId you specified in the config file
Bridge.payments.Purchase(commonId, OnPurchaseCompleted);
}
private void OnPurchaseCompleted(bool success, Dictionary<string, string> purchase)
{
Debug.Log($"OnPurchaseCompleted, success: {success}");
}
Consume Purchase
Consume purchased items, such as in-game currency, once they are used, to manage inventory and player progression.
Copy private void Start()
{
var commonId = "test_product"; // commonId you specified in the config file
Bridge.payments.ConsumePurchase(commonId, OnConsumePurchaseCompleted);
}
private void OnConsumePurchaseCompleted(bool success)
{
Debug.Log($"OnConsumePurchaseCompleted, success: {success}");
}
Catalog of All Items
Retrieve a list of all available in-game items that players can purchase to display in the game store.
Copy private void Start()
{
Bridge.payments.GetCatalog(OnGetCatalogCompleted);
}
private void OnGetCatalogCompleted(bool success, List<Dictionary<string, string>> catalog)
{
Debug.Log($"OnGetCatalogCompleted, success: {success}, items:");
if (success)
{
foreach (var item in catalog)
{
Debug.Log("Common ID: " + item["commonId"]);
Debug.Log("Price: " + item["price"]);
Debug.Log("Price Currency Code: " + item["priceCurrencyCode"]);
Debug.Log("Price Value: " + item["priceValue"]);
}
}
}
List of Purchased Items
Retrieve a list of items that the player has purchased to manage their inventory and provide access to purchased content.
If the user loses internet connection when making an in-game purchase, the purchase might remain unprocessed. To avoid this, check for unprocessed purchases using this method (e.g., each time the game is launched).
Copy private void Start()
{
Bridge.payments.GetPurchases(OnGetPurchasesCompleted);
}
private void OnGetPurchasesCompleted(bool success, List<Dictionary<string, string>> purchases)
{
Debug.Log($"OnGetPurchasesCompleted, success: {success}, items:");
if (success)
{
foreach (var purchase in purchases)
{
Debug.Log("Common ID: " + purchase["commonId"]);
}
}
}
Don't call SDK methods that require a callback (like Bridge.payments.GetPurchases
) when starting the game in Awake
. Call them in Start
.