Monetising your Game with In-App Purchases

Welcome to the Facebook Instant Games SDK Tutorials. This series of tutorials covers many aspects of using the Facebook Instant Games SDK.

In this tutorial we will take a look at earning money from your game with in-app purchases using the Facebook Instant Games SDK.


Facebook Instant Games allows you to sell virtual products to your users on the Android and Web platforms (iOS is not currently supported).
In order to earn money from in-app purchases you must have created a verified business on Facebook. See for details.

You can add products to the In App Purchases section of the Instant Games product in the developer dashboard. Here you can specify product ID’s, names, descriptions, price and icons associated with your virtual products.

Note that you will also have to submit your in-app purchases for review in the review section of instant games. Do not launch your game until IAP’s have also been approved as they may not work.
Also note that users that have been added to the Testers section in the In App Purchases section of Instant games will not be charged for purchases, which is useful for testing.

Checking for Support

Before attempting to make any purchases in-game its best to check that in-app purchasing is available. You can do this by querying support by calling FBInstant.getSupportedAPIs():

var supportedAPIs = FBInstant.getSupportedAPIs();
if (supportedAPIs.includes("payments.purchaseAsync"))
    purchasingSupported = true;
Once you know that you have support you can begin working with in-app purchases.

You also need to ensure that payments are ready before using the API. You do this by subscribing to the payments.onReady event:
FBInstant.payments.onReady(function() {
    // Payments are ready

Getting Products

You can retrieve a list of your products and their details by calling FBInstant.payments.getCatalogAsync():

    // catalog contains an array of products
}).catch(function(err) {
    // There was an error

Each product has the following properties:

  • title string Product title
  • productID string Product ID
  • description string? Product description
  • imageURI string? A link to the products icon
  • price string Product price
  • priceCurrencyCode string Currency code for the product

Buying Products

You can allow the user to make a purchase of a specific item by calling FBInstant.payments.purchaseAsync():

    productID: product_id,
    developerPayload: payload,
    // Purchase success (purchaseToken is available in purchase)
}).catch(function(err) {
    // Purchase failed

When you make the call to purchaseAsync() the user is displayed a native dialog which shows the product summary. The user can at this point choose to accept or cancel the purchase. If the user cancels the purchase then purchaseAsync() will return with an error.

Consuming Purchases

Once a purchase has been made it is classed as unconsumed. To consume a product you can call FBInstant.payments.consumePurchaseAsync():

    // Product consumed
}).catch(function(e) {
    // Error occurred

purchase_token is returned by FBInstant.payments.purchaseAsync() as part of the purchase.

Getting Consumed Products

Products are by default unconsumed which means that the player still owns the products until they have been used. This is good for none consumable items such as extra game levels. Other products however such as currency are consumable and used as the player plays. The best way that I have found to deal with consumable products such as currency is to consume them straight after purchase. You can get a list of consumable products by calling FBInstant.payments.getPurchasesAsync():

    // purchases contains the list of unconsumed purchases
}).catch(function(error) {
    // Error occurred

Each purchase has the following properties:

  • developerPayload string? A developer-specified string, provided during the purchase of the product
  • paymentID string Purchase transaction ID
  • productID string Product ID
  • purchaseTime string Unix timestamp of purchase time
  • purchaseToken string A purchase token representing the purchase, can be used to consume the purchase
  • signedRequest SignedPurchaseRequest Server signed encoding of the purchase request

Leave a Reply