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.

let options = { }

switch (bridge.platform.id) {
    case 'yandex':
        options = {
            id: 'PRODUCT_ID' // ID from catalog
        }
        break
    case 'facebook':
        options = {
            productID: 'PRODUCT_ID' // ID from catalog
        }
        break
}

bridge.payments.purchase(options)
    .then((purchase) => {
        // success
        switch (bridge.platform.id) {
            case 'yandex':
                console.log('Product ID: ' + purchase.productID)
                console.log('Purchase Token: ' + purchase.purchaseToken)
                break
            case 'facebook':
                console.log('Product ID: ' + purchase.productID)
                console.log('Purchase Token: ' + purchase.purchaseToken)
                break
        }
    })
    .catch(error => {
        // error
    })

Consume Purchase

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

let options = { }

switch (bridge.platform.id) {
    case 'yandex':
        options = {
            purchaseToken: 'PURCHASE_TOKEN' // token
        }
    case 'facebook':
        options = {
            purchaseToken: 'PURCHASE_TOKEN' // token
        }
        break
}

bridge.payments.consumePurchase(options)
    .then(() => {
        // success
    })
    .catch(error => {
        // error
    })

Catalog of All Items

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

bridge.payments.getCatalog()
    .then(catalogItems => {
        // success
        switch (bridge.platform.id) {
            case 'yandex':
                catalogItems.forEach(catalogItem => {
                    console.log('ID: ' + catalogItem.id)
                    console.log('Title: ' + catalogItem.title)
                    console.log('Description: ' + catalogItem.description)
                    console.log('Image URI: ' + catalogItem.imageURI)
                    console.log('Price: ' + catalogItem.price)
                    console.log('Price Currency Code: ' + catalogItem.priceCurrencyCode)
                    console.log('Price Currency Image: ' + catalogItem.priceCurrencyImage)
                    console.log('Price Value: ' + catalogItem.priceValue)
                })
                break
            case 'facebook:
                catalogItems.forEach(catalogItem => {
                    console.log('ID: ' + catalogItem.productID)
                    console.log('Title: ' + catalogItem.title)
                    console.log('Description: ' + catalogItem.description)
                    console.log('Image URI: ' + catalogItem.imageURI)
                    console.log('Price: ' + catalogItem.price)
                    console.log('Price Currency Code: ' + catalogItem.priceCurrencyCode)
                    console.log('Price Amount: ' + catalogItem.priceAmount)
                })
                break
        }
    })
    .catch(error => {
        // error
    })

List of Purchased Items

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

bridge.payments.getPurchases()
    .then(purchases => {
        // success
        switch (bridge.platform.id) {
            case 'yandex':
                purchases.forEach(purchase => {
                    console.log('Product ID: ' + purchase.productID)
                    console.log('Purchase Token: ' + purchase.purchaseToken)
                })
            case 'facebook':
                purchase.forEach(purchase => {
                    console.log('Product ID: ' + purchase.productID)
                    console.log('Purchase Token: ' + purchase.purchaseToken)
                })  
                break
        }
    })
    .catch(error => {
        // error
    })

Last updated