Payments

Working with payments is implemented via connector.payments interface.

Supported Platforms

  • Yandex Games
  • VK Games
  • OK Games
  • Kongregate
  • Crazy Games
  • Facebook Instant Games
  • Android
  • iOS
  • Amazon
  • Microsoft Store
  • MSN
  • Facebook
  • Fotostrana
  • Mobage
  • SP Mobage
  • My World
  • Rustore
  • Samsung
  • Draugiem
  • Plinga
  • Mygames
  • Wortal

You can check whether payments are supported on platform with

if (connector.payments.isAvailable) {
  // Payments are supported
}

Purchase product

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

const result = await connector.payments.purchase({ id: "gold" });
if (result) {
  // Purchase is successful
  console.log(result.product, result.purchase);
}

Purchase product events

// Purchase is successful
connector.payments.on("purchase", ({ purchase, product } => {});

// Purchase failed
// Error types
//  "purchase_already_open"
//  "product_not_found"
//  "login_failed
//  "email_required"
//  "invalid_email"
//  "purchase_timeout"
//  "purchase_canceled_by_user"
//  "purchase_unknown_error"
connector.payments.on("error:purchase", (error => {});

Consume product

To use a purchase, you need to pass in a purchase object

const result = await connector.payments.consume(purchase);
if (result) {
  // consume is successful
  console.log(result.product, result.purchase);
}

Consume product events

// Consume is successful
connector.payments.on("consume", ({ purchase, product } => {});

// Consume failed
// Error types
//  "consume_unknown_error"
connector.payments.on("error:consume", (error => {});

Getting products

// Get a list of all products
const products = connector.payments.products;

// Get a specific product by ID or Tag
const product = connector.payments.getProduct("gold");

Restore not consumed purchases

You can request for not consumed consumable purchases.

const purchase = await connector.payments.restore()
if (purchase) {
  // process and consume purchase
}

Or subscribe to on restore event to receive not consumed purchases.

connector.payments.on("restore", (purchase) => {
  const success = await connector.payments.consume(purchase);
  if (success) {
    // Consume success
  }
});

Members

(static) products :Array.<Payments.Product>

Returns a list of available products

Type:

(static) isAvailable :Boolean

Are payments supported on this platform

Type:
  • Boolean

(static) isLoginRequired :Boolean

Whether a user needs to be logged in to make a payment

Type:
  • Boolean

(static) isEmailRequired :Boolean

Whether an email needs to be provided to make a payment

Type:
  • Boolean

(static) isSubscriptionsAvailable :Boolean

Are subscriptions supported on this platform

Type:
  • Boolean

Methods

(static) purchase(options) → {Promise.<Payments.PurchaseResult>}

Purchase product by provided ID or Tag

Parameters:
NameTypeDescription
optionsobject

Options

Properties
NameTypeDescription
idstring

Product ID

tagstring

Product Tag

emailstring

Email

contextobject

Context

Returns:
Type: 
Promise.<Payments.PurchaseResult>

(static) consume(purchase) → {Promise.<Payments.PurchaseResult>}

Consume purchase

Parameters:
NameTypeDescription
purchasePayments.Purchase

Purchase

Returns:
Type: 
Promise.<Payments.PurchaseResult>

(static) getProduct(productIdOrTag) → {Payments.Product}

Returns product by provided ID or Tag

Parameters:
NameTypeDescription
productIdOrTagstring

Product ID or Tag

Returns:
Type: 
Payments.Product

Type Definitions

Purchase

Properties
NameTypeDescription
paymentIdstring

Purchase ID

userIdstring

User ID

productIdstring

Product ID

sourcestring

Platform source

methodstring

Payment method

pricenumber

Price in local currency

realPricenumber

Real price paid by the user in USD, can be used for statistics

currencystring

Currency code

typestring

Purchase type

payloadobject

Platform-specific data e.g. payment token

Product

Properties
NameTypeDescription
itemIdstring

Item ID

productIdstring

Product ID

pricenumber

Price in local currency

currencystring

Currency code

priceUSDnumber

Price in USD

textPricestring

Text price

PurchaseResult

Type:
  • Object
Properties
NameTypeDescription
purchasePayments.Purchase

Purchase

productPayments.Product

Product

Events

purchase

Properties
NameTypeDescription
resultPayments.PurchaseResult

Purchase result

error:purchase

Properties
NameTypeDescription
errorstring

Error

consume

Properties
NameTypeDescription
errorPayments.PurchaseResult

Error

error:consume

Properties
NameTypeDescription
errorstring

Error

restore

Properties
NameTypeDescription
purchasePayments.Purchase

Purchase