Payments
Supported Platforms





Platforms without support





To check for purchase support on a platform in the SDK, use the gp.payments.isAvailable
property.
// Checking for purchase support on a platform
if (gp.payments.isAvailable) {
// You can make purchases
}
Payment Rules
Stick to payments rules.
There are two types of payments: one-time and permanent.
Example of a one-time purchase:
- Buy 1000 gold
- Buy chest
- Restore Lives
One-time purchases must be consumed immediately.
An example of a permanent purchase:
- Disable ads
- VIP status
- Increase x5 reward per level
Constant purchases do not need to be consumed. As soon as the purchase is paid, it will always be visible to the user, until it is used up.
One-time purchase rules
// 1. Make purchase
await gp.payments.purchase({ tag: 'GOLD_1000' });
// 2. Give a reward
gp.player.add('gold', 1000);
// 3. Save player progess on server
await gp.player.sync();
// 4. Consume purchase
await gp.payments.consume({ tag: 'GOLD_1000' });
Permanent purchase rules
// 1. Make purchase
await gp.payments.purchase({ tag: 'VIP' });
// 2. Checking for purchase availability when needed
if (gp.payments.has('VIP')) {
// do something with VIP status
}
Platform setup
Yandex.Games
Setup
In the Yandex.Games console, fill in the list of products in accordance with the list of products in the GS control panel.
Testing
In the Yandex.Games console, you must specify your username as a tester.
VK Direct Games
Setup
You must fill in the "Callback URL" in the Payments section. Set: https://gamepush.com/api/vk/payments
Testing
In the Payments section, specify the tester's account.
VK Play
Setup
You must fill in the "Callback URL" in the Basic features section. Set: https://gamepush.com/api/vk_play/payments
Testing
You can test directly from your developer account. You can also add a tester account in the Accounts section. Purchases are tested through a test card, which is listed next to the Callback URL field in the Basic features section.
OK Games
Setup
You must fill in the "Callback URL" in application settings. Set: https://gamepush.com/api/ok/payments
Testing
Absent. Top up your account balance with a few OKs. Set your purchases at 1 OK. The price can be changed at any time in the panel.
SmartMarket
Setup
You must fill in the "Smartapp Webhook" in application settings. Set: https://gamepush.com/api/smartmarket/webhook
Testing
Absent. Payment by card. Set your purchases at 1 RUB. The price can be changed at any time in the panel.
Local testing
On the test domain, a test purchase form that imitates the platform order form is used. You do not need to upload the game to the platform to test it.
Purchase product
To purchase product, you need to pass an ID or Tag of product.
// Purchase by id
gp.payments.purchase({ id: 17541 });
// Purchase by tag
gp.payments.purchase({ tag: 'GOLD_1000' });
Purchase product events
// Purchase success
gp.payments.on('purchase', ({ product, purchase }) => {});
/**
* Error if purchase failed
* @type {
* 'player_not_found' |
* 'empty_id_or_tag' |
* 'product_not_found' |
* 'purchases_not_alloved_on_platform' |
* undefined
* }
*/
gp.payments.on('error:purchase', (error) => {});
Purchase with promises
const result = await gp.payments.purchase({ id: 17541 });
/**
* Product data
* @type {Product}
*/
result.product;
/**
* Purchase data
* @type {PlayerPurchase}
*/
result.purchase;
Consuming purchases
To use a purchase, you need to pass in a product ID or tag.
// Spending by ID
gp.payments.consume({ id: 17541 });
// Spending by Tag
gp.payments.consume({ tag: 'GOLD_1000' });
Purchase spend events
// Successfully used
gp.payments.on('consume', ({ product, purchase }) => {});
// Error while using
gp.payments.on('error:consume', (error) => {});
Spending method through promises
const result = await gp.payments.consume({ id: 17541 });
/**
* Product data
* @type {Product}
*/
result.product;
/**
* Purchase data
* @type {PlayerPurchase}
*/
result.purchase;
Getting a list of products
gp.payments.fetchProducts();
Get method via promises
const result = await gp.payments.fetchProducts();
// Answer result
const {
// Grocery list
products,
// Player shopping list
playerPurchases,
} = result;
Events when getting a shopping list
// Successfully received
gp.payments.on('fetchProducts', (result) => {});
// Errors by getting
gp.payments.on('error:fetchProducts', (error) => {});
Purchase fields
Field | Type | Description | Example |
---|---|---|---|
id | number | Purchase ID | 115 |
tag | string | Optional tag to help with selection. You can use it instead of ID | VIP |
name | string | Name translated into the user's language | VIP Status |
description | string | Description translated into the user's language | No ads, reward x2 |
icon | string | Link to icon size 256x256 | Link example |
iconSmall | string | Link to icon size 64x64 | Link example |
price | number | Purchase price | 199 |
currency | string | Currency code | YAN OK VOTE RUB GP |
currencySymbol | string | Currency symbol (translated into the user's language and formatted if needed) | Voice, Voices |
isSubscription | boolean | Purchase is a subscription | default false |
period | number | Subscription duration in days | 7 , 30 , 90 |
trialPeriod | number | The duration of the trial period in days (during this time, the user can cancel the subscription without debiting funds) | 0 , 3 , 7 , 30 |
Player Purchase Fields
Field | Type | Description | Example |
---|---|---|---|
productId | number | Purchase ID | 115 |
payload | Object | Data from the purchase on the platform (for example, order ID or token) | {"order_id": 213} |
createdAt | string | Date of purchase, format ISO 8601 UTC | 2022-12-01T04:52:26+0000 |
gift | boolean | The purchase was a gift from the game developer | false |
subscribed | boolean | Is the subscription for this purchase active? | true |
expiredAt | string | Subscription end date, format ISO 8601 UTC | 2022-12-01T04:52:26+0000 |
Error codes
Error | Error Description |
---|---|
player_not_found | Player not found |
empty_id_or_tag | Passed empty ID or purchase tag |
product_not_found | Purchase with this ID or tag was not found |
purchases_not_alloved_on_platform | Purchases are not available on this site |
undefined | Unexpected error (see console) |
Stay in Touch
Other documents of this chapter available Here. To get started, welcome to the Tutorials chapter.
GamePush Community Telegram
: @gs_community.
For your suggestions e-mail
: [email protected]
We Wish you Success!