Skip to main content

Payments

Process players' one-time payments.

Supported Platforms

  • Yandex Games
  • VK Games
  • VK Play
  • OK Games
  • Kongregate
  • SmartMarket
  • Google Play
  • Android (alternative stores)
  • Web (custom site)
  • Platforms without support
  • CrazyGames
  • GamePix
  • GameDistribution
  • GameMonetize
  • WG Playground
  • PlayDeck
  • To check for purchase support on a platform in the SDK, use the ss.payments.isAvailable property.

    // Checking for purchase support on a platform
    if (ss.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
    tip

    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 ss.payments.purchase({ tag: 'GOLD_1000' });

    // 2. Give a reward
    ss.player.add('gold', 1000);

    // 3. Save player progess on server
    await ss.player.sync();

    // 4. Consume purchase
    await ss.payments.consume({ tag: 'GOLD_1000' });

    Permanent purchase rules

    // 1. Make purchase
    await ss.payments.purchase({ tag: 'VIP' });

    // 2. Checking for purchase availability when needed
    if (ss.payments.has('VIP')) {
    // do something with VIP status
    }

    Purchase product

    +1-3 Request

    To purchase product, you need to pass an ID or Tag of product.

    // Purchase by id
    ss.payments.purchase({ id: 17541 });

    // Purchase by tag
    ss.payments.purchase({ tag: 'GOLD_1000' });

    Purchase product events

    // Purchase success
    ss.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
    * }
    */
    ss.payments.on('error:purchase', (error) => {});

    Purchase with promises

    const result = await ss.payments.purchase({ id: 17541 });

    /**
    * Product data
    * @type {Product}
    */
    result.product;

    /**
    * Purchase data
    * @type {PlayerPurchase}
    */
    result.purchase;

    Consuming purchases

    +1 Request

    To use a purchase, you need to pass in a product ID or tag.

    // Spending by ID
    ss.payments.consume({ id: 17541 });

    // Spending by Tag
    ss.payments.consume({ tag: 'GOLD_1000' });

    Purchase spend events

    // Successfully used
    ss.payments.on('consume', ({ product, purchase }) => {});

    // Error while using
    ss.payments.on('error:consume', (error) => {});

    Spending method through promises

    const result = await ss.payments.consume({ id: 17541 });

    /**
    * Product data
    * @type {Product}
    */
    result.product;

    /**
    * Purchase data
    * @type {PlayerPurchase}
    */
    result.purchase;

    Lists of Products and Purchases

    FREE

    Lists are loaded at the start of the game and are available immediately after SDK initialization.

    Get the list of products:

    ss.payments.products;

    Get the list of the player's purchases:

    ss.payments.purchases;

    Getting a list of products

    FREE Deprecated
    ss.payments.fetchProducts();

    Get method via promises

    const result = await ss.payments.fetchProducts();

    // Answer result
    const {
    // Grocery list
    products,
    // Player shopping list
    playerPurchases
    } = result;

    Events when getting a shopping list

    // Successfully received
    ss.payments.on('fetchProducts', (result) => {});

    // Errors by getting
    ss.payments.on('error:fetchProducts', (error) => {});

    Purchase fields

    FieldTypeDescriptionExample
    idnumberPurchase ID115
    tagstringOptional tag to help with selection. You can use it instead of IDVIP
    namestringName translated into the user's languageVIP Status
    descriptionstringDescription translated into the user's languageNo ads, reward x2
    iconstringLink to icon size 256x256Link example
    iconSmallstringLink to icon size 64x64Link example
    pricenumberPurchase price199
    currencystringCurrency codeYAN OK VOTE RUB SS
    currencySymbolstringCurrency symbol (translated into the user's language and formatted if needed)Voice, Voices
    isSubscriptionbooleanPurchase is a subscriptiondefault false
    periodnumberSubscription duration in days7, 30, 90
    trialPeriodnumberThe 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

    FieldTypeDescriptionExample
    productIdnumberPurchase ID115
    payloadObjectData from the purchase on the platform (for example, order ID or token){"order_id": 213}
    createdAtstringDate of purchase, format ISO 8601 UTC2022-12-01T04:52:26+0000
    giftbooleanThe purchase was a gift from the game developerfalse
    subscribedbooleanIs the subscription for this purchase active?true
    expiredAtstringSubscription end date, format ISO 8601 UTC2022-12-01T04:52:26+0000

    Error codes

    ErrorError Description
    player_not_foundPlayer not found
    empty_id_or_tagPassed empty ID or purchase tag
    product_not_foundPurchase with this ID or tag was not found
    purchases_not_alloved_on_platformPurchases are not available on this site
    undefinedUnexpected error (see console)

    Stay in Touch

    Other documents of this chapter available Here. To get started, welcome to the Tutorials chapter.

    SpellSync Community Telegram: @spellsync.

    For your suggestions e-mail: [email protected]

    We Wish you Success!