In-game purchases
You can earn revenue by allowing users to make in-game purchases. For example, additional time to complete a level or accessories for a game character. To do this:
- Connect in-game purchases in the Yandex Games developer console.
- Configure the SDK to work with purchases.
Portal currency
Yan is the portal currency of the Yandex Games platform for paying for in-game purchases. Yan is stored in a single balance for all players, which can be topped up with bank cards. The exchange rate of Yan to rubles is dynamic.
For international payments, the Yan-to-currency coefficient will depend on the player's country.
You can top up your balance:
- in the catalog header;
- in the player's profile;
- during a purchase in the game.
Users can also receive Yan as a bonus for participating in promotions or purchasing fixed packs.
In-game purchases can be made by both authorized Yandex users and unauthenticated users. A user can log in directly during the game, including at the time of purchase.
The procedure and conditions for paying a license fee to the developer in connection with the introduction of the portal currency will not change.
Connection requirements
The requirements for connecting purchases depend on the country of residence of your legal entity.
- Russian Federation resident
- Non-Russian Federation resident
To set up and test purchases, you need to sign the "Act of transfer of non-exclusive rights to use the Game".
After adding purchases and publishing a game draft, send a request for the act form to games-partners@yandex-team.com. In the letter, be sure to specify the name and identifier (ID) of the game.
In response to your letter, you will receive a form of "Act of transfer of non-exclusive rights to use the Game". You need to fill out, sign, and send a scan (or a high-quality photo) in response to our letter.
Only after receiving the signed act, you can set up and test in-game purchases.
After adding purchases and publishing a game draft, send a request to connect purchases to games-partners@yandex-team.com. In the letter, be sure to specify the name and identifier (ID) of the game, as well as the country of residence of your legal entity.
Purchase process
You can activate an in-game purchase using the following method:
ysdk.payments.create_purchase(callback, options)
callback
— function — the callback of the called method. It looks like this:
function(self, purchase: table|nil, signature: string|nil): nil
purchase: table
— purchase information. Contains properties:product_id: string
— product identifier.purchase_token: string
— token for using the purchase.developer_payload: string|nil
— additional purchase data.
signature: string|nil
— purchase data and signature for player authenticity verification.
options
— method parameters. Contains properties:
id: string
— product identifier that you set in the developer console.developer_payload: string
— optional parameter. Additional purchase information that you want to pass to your server (will be passed in the signature parameter).signed: boolean|nil
— optional parameter. Designed to protect the game from fraud.
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 the player has already made, use the method:
ysdk.payments.getPurchases(
callback: function,
options : {
signed: boolean|nil
}
)
callback
— function — the callback of the called method. It looks like this:
function(self, purchase: Purchase[]|nil, signature: string|nil): nil
Purchase
— purchase information. Contains properties:product_id: string
— product identifier.purchase_token: string
— token for using the purchase.developer_payload: string|nil
— additional purchase data.
signature: string|nil
— purchase data and signature for player authenticity verification.
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 a catalog of all items
To get a list of available purchases and their cost, use the method
ysdk.payments.getCatalog()
.
ysdk.payments.getCatalog(callback: function)
callback
— function — the callback of the called method. It looks like this:
function(self, products: Product[]|nil): nil
products: table[]
— item information. 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 a purchase and crediting in-game currency
There are two types of purchases — permanent (for example, disabling ads) and consumable (for example, in-game currency).
To process permanent purchases, use the ysdk.payments.get_purchases()
method.
To process consumable purchases, use the ysdk.payments.consume_purchase()
method.
ysdk.payments.consume_purchase(purchase_token: string)
After calling the ysdk.ayments.consume_purchase()
method, the processed purchase is
deleted without the possibility of recovery. Therefore, first modify the player's data
using the ysdk.player.set_stats()
or ysdk.player.increment_stats()
methods, 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