Start typing to search...

Set up koji.json

In the first section of this tutorial, you will add the in-app purchase entitlement and define a price value that can be modified when someone customizes your game.

By the end of this section, you should feel comfortable:

  • Defining entitlements and customization values in koji.json.

Forking the game scaffold

Get started by cloning the Tower Stack game to your own app.

  1. Open the Tower Stack game listing.

  2. Click …​  Fork.

    A copy of the app is created in your Koji account, and the Project Details page for your new app is displayed.

  3. Click Open in Code Editor.

    The Koji editor opens with the game code loaded.

Note
The Koji editor is recommended for this tutorial, but you’re free to clone the newly created app to your local environment if you prefer.

Defining entitlements

First, you need to enable Koji’s in-app purchases feature for your new game scaffold.

Open the file koji.json, which is located in the root of the app. Find the following section of code.

...

"entitlements": {
    "InstantRemixing": true,
    "InstantRemixingNativeNavigation": true,
    "CustomMetadata": {
        "enabled": true,
        "metadata": {
        "title": "{{remixData.title}}",
        "description": "How high can you stack them?"
        }
    }
},

...

This code defines an entitlements object, which contains a number of properties that define how the application works on the Koji platform.

Add a new property called InAppPurchases, as follows.

"entitlements": {
    "InstantRemixing": true,
    "InstantRemixingNativeNavigation": true,
    "CustomMetadata": {
        "enabled": true,
        "metadata": {
        "title": "{{remixData.title}}",
        "description": "How high can you stack them?"
        }
    },
    "InAppPurchases": {
        "enabled": true,
        "products": [
            {
                "sku": "extraLives",
                "name": "Extra Lives",
                "price": "{{remixData.price}}",
                "isConsumable": true
            }
        ]
    }
},

InAppPurchases is defined as an object, and it contains an array of products. You’re only selling one product — extra lives — so you only have one product in the array. The product is defined as follows.

{
    "sku": "extraLives",
    "name": "Extra Lives",
    "price": "{{remixData.price}}",
    "isConsumable": true
}

Here’s a breakdown of the properties:

  • sku – Identifier used to look up the product when the user makes a purchase.

  • name – Product name that appears on the user’s receipt.

  • price – Price of the product in USD. This value is set to {{remixData.price}}, which means the price will use a custom value. You will define the custom value in the next step.

  • isConsumable – Feature that determines whether the product can be purchased more than once. This value is set to true, which allows the user to purchase the product multiple times.

Defining customization data

In koji.json, scroll down to the remixData object. This is where you define the values that users can modify when customizing the scaffold.

Add a price property and set it to 0.1 for now.

"remixData": {
    ...
    "price": 0.1
  },
Note
To register the product, the price value must be greater than 0 and you must deploy a build of your game. For example, by publishing it from the Koji editor. Registering the product will enable you to test purchases in the debugger, which you will do later in the tutorial.

Wrapping up

In this section, you set up the product and price information for extra lives in your game.

In the next section, you’ll create the menu that enables players to purchase more lives when they run out.