In-Game Purchases

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.

Bridge.payments.isSupported

Check if getting catalog is supported.

Bridge.payments.isGetCatalogSupported

Check if getting purchases list is supported.

Bridge.payments.isGetPurchasesSupported

Check if purchase consuming is supported.

Bridge.payments.isConsumePurchaseSupported

Purchase

Allow players to buy items or upgrades in your game to enhance their gameplay experience.

private void Start()
{
    var options = new Dictionary<string, object>();

    switch (Bridge.platform.id)
    {
        case "yandex":
            options.Add("id", "PRODUCT_ID");
            break;
        case "facebook":
            options.Add("prodcutID", "PRODUCT_ID");
            break;
    }

    Bridge.payments.Purchase(options, OnPurchaseCompleted);
}

private void OnPurchaseCompleted(bool success)
{
    Debug.Log(success);
}

Consume Purchase

Consume purchased items, such as in-game currency, once they are used, to manage inventory and player progression.

private void Start()
{
    var options = new Dictionary<string, object>();

    switch (Bridge.platform.id)
    {
        case "yandex":
            options.Add("purchaseToken", "PURCHASE_TOKEN");
            break;
        case "facebook":
            options.Add("purchaseToken", "PURCHASE_TOKEN");
            break;
    }

    Bridge.payments.ConsumePurchase(options, OnConsumePurchaseCompleted);
}

private void OnConsumePurchaseCompleted(bool success)
{
    Debug.Log(success);
}

Catalog of All Items

Retrieve a list of all available in-game items that players can purchase to display in the game store.

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)
    {
        switch (Bridge.platform.id)
        {
            case "yandex":
                foreach (var item in catalog)
                {
                    Debug.Log("ID: " + item["id"]);
                    Debug.Log("Title: " + item["title"]);
                    Debug.Log("Description: " + item["description"]);
                    Debug.Log("Image URI: " + item["imageURI"]);
                    Debug.Log("Price: " + item["price"]);
                    Debug.Log("Price Currency Code: " + item["priceCurrencyCode"]);
                    Debug.Log("Price Currency Image: " + item["priceCurrencyImage"]);
                    Debug.Log("Price Value: " + item["priceValue"]);
                }
                break;
            case "facebook":
                foreach (var item in catalog)
                {
                    Debug.Log("ID: " + item["productID"]);
                    Debug.Log("Title: " + item["title"]);
                    Debug.Log("Description: " + item["description"]);
                    Debug.Log("Image URI: " + item["imageURI"]);
                    Debug.Log("Price: " + item["price"]);
                    Debug.Log("Price Currency Code: " + item["priceCurrencyCode"]);
                    Debug.Log("Price Currency Image: " + item["priceCurrencyImage"]);
                    Debug.Log("Price Amount: " + item["priceAmount"]);
                }
                break;
        }
    }
}

List of Purchased Items

Retrieve a list of items that the player has purchased to manage their inventory and provide access to purchased content.

Don't call SDK methods that require a callback (like Bridge.payments.GetPurchases) when starting the game in Awake. Call them in Start.

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)
    {
        switch (Bridge.platform.id)
        {
            case "yandex":
                foreach (var purchase in purchases)
                {
                    Debug.Log("Product ID: " + purchase["productID"]);
                    Debug.Log("Purchase Token: " + purchase["purchaseToken"]);
                }
                break;
            case "facebook":
                foreach (var purchase in purchases)
                {
                    Debug.Log("Product ID: " + purchase["productID"]);
                    Debug.Log("Purchase Token: " + purchase["purchaseToken"]);
                }
                break;
        }
    }
}

Last updated