In-game purchases

You can generate revenue by offering users the option to make in-game purchases. For example, they can buy extra time for completing a level or accessories for their character. To do this:

Portal currency

Yan is the portal currency of the Yandex Games platform used for in-game purchases. This currency is stored on the player's account balance. A player can top up their balance with a bank card and use it for all their games. The exchange rate of the portal currency to rubles is dynamic.

Note

For international payments, the exchange rate of the portal currency to the national currency depends on the player's country.

Players can top up their balance:

  • In the catalog header.
  • In the player profile.
  • When making an in-game purchase.

Users can also earn the portal currency as bonus rewards for participating in promos or purchasing fixed packages.

Both authorized and unauthorized Yandex users can make in-game purchases. Users can log in directly during the game, including at the time of making a purchase.

The introduction of the portal currency will not affect the terms and conditions for paying the licensing revenue.

Connection Conditions

Requirements for integrating purchases depend on the residency of your legal entity.

To set up and test purchases, it is necessary to sign the "Deed of Transfer of Non-exclusive Rights to Use the Game".

After adding purchases and publishing the game draft, send an email requesting the form of the deed to games-partners@yandex-team.com. Be sure to include the name and identifier (ID) of the game in your email.

In response to your email, a form of the "Deed of Transfer of Non-exclusive Rights to Use the Game" will be sent. You need to fill out, sign, and send back a scan (or a good quality photo) in reply to our email.

Only after receiving the signed deed can in-game purchases be set up and tested.

After adding purchases and publishing the game draft, send an email requesting the activation of purchases to games-partners@yandex-team.com. Make sure to include the name and identifier (ID) of the game, as well as the country of residency of your legal entity in the email.

Purchase Process

You can activate an in-app purchase using the following method:

ysdk.payments.create_purchase(callback, options)

callback — function — callback of the invoked method. It looks like:

function(self, purchase: table|nil, signature: string|nil): nil
  • purchase: table — purchase information. Contains the properties:
    • product_id: string — product ID.
    • purchase_token: string — a token for consuming the purchase.
    • developer_payload: string|nil — additional purchase data.
  • signature: string|nil — purchase data and signature for authenticating the player.

options — method parameters. Contains properties:

  • id: string — product ID set in the Games Console.
  • developer_payload: string — optional parameter. Additional purchase data that you want to send to your server (transferred in the signature parameter).
  • signed: boolean|nil — an optional parameter. It is intended to protect the game from exploits.

Example

function buy_item(id)
  ysdk.payments.create_purchase(
    function(self, purchase, signature)
      if purchase then
        print(purchase.product_id, signature)
      end
    end,
    { id, signed = true }
  )
end

Getting a list of purchased items

To find out what purchases a player has already made, use the method:

ysdk.payments.getPurchases(
    callback: function,
    options : {
        signed: boolean|nil
    }
)

callback — function — callback of the called method. It looks like:

function(self, purchase: Purchase[]|nil, signature: string|nil): nil
  • Purchase — purchase information. Contains the properties:

    • product_id: string — product ID.
    • purchase_token: string — a token for consuming the purchase.
    • developer_payload: string|nil — additional purchase data.
  • signature: string|nil — purchase data and signature for player authentication.

Example

function display_puchases()
  ysdk.payments.get_purchases(function(self, purchases)
    if purchases then
      for k, v in pairs(purchases) do print(k, v) end
    end
  end)
end

Getting the catalog of all products

To get a list of available purchases and their cost, use the ysdk.payments.getCatalog() method.

ysdk.payments.getCatalog(callback: function)

callback — function — callback of the called method. It looks like:

function(self, products: Product[]|nil): nil
  • products: table[] — information about products. Contains properties:
products = [
    {
        id: string,
        title: string,
        description: string,
        image_uri: string,
        price: string,
        price_value: string,
        price_currency_code: string,
        price_currency_image: {
            small: string,
            medium: string,
            svg: string
        }
    },
    ...
]

Example

function display_shop()
  ysdk.payments.get_catalog(function(self, products)
    if products then
      for k, v in pairs(products) do print(v.title, v.price, v.description) end
    end
  end)
end

Processing purchases and crediting in-game currency

There are two types of purchases: non-consumables (such as for disabling ads) and consumables (such as for buying in-game currency).

To process non-consumable purchases, use the method ysdk.payments.get_purchases().

To process consumable purchases, use the method ysdk.payments.consume_purchase().

ysdk.payments.consume_purchase(purchase_token: string)

Alert

After calling the ysdk.payments.consume_purchase() method, the processed purchase is permanently deleted. To account for this, you should first modify the player data using the ysdk.player.set_stats() or ysdk.player.increment_stats() method and then process the purchase.

Example

function buy_item(id)
  ysdk.payments.create_purchase(
    function(self, purchase)
      if purchase then
        ysdk.payments.consume_puchase(purchase.purchase_token)
      end
    end,
    { id }
  )
end

Repository