---
updatedAt: 2026-04-13T18:07:36.000Z
agentTools:
  projectIndex: https://docs.kongregate.com/llms.txt
---

# Dynamic Purchasing

## Dynamic Purchasing API

The Dynamic Purchasing API allows users to purchase virtual items in your game. The API includes both client and server-side components. This API differs from the standard virtual goods API in the fact that you do not have to pre-define your items. Instead, our servers will contact yours to request item definitions.

> 🚧 Test carefully
>
> If you are selling in-app purchases you must thoroughly test your game prior to submission. We will reject games for incorrect implementation.
>
> Please also be sure to update your Game Description to include that the game includes in-app purchases

Here is a basic summary of how the API works. We will go into more detail about each part later on.

* You make a client API call to initiate a dynamic purchase and pass in an `order_info` string.
* [`purchaseItemsRemote`](https://docs.kongregate.com/docs/client-api-mtx-purchaseitemsremote) for web games
* We create an `ItemOrder` in our database with an `id` and your `order_info` string.
* Our servers call back to yours to request item definitions for the given `ItemOrder`
* The information received from your servers (name, description, icon, price) are displayed to the user in the shopping cart.
* Once the user confirms the purchase, we call back to your servers once again.
* Your servers award the user their virtual goods.

### Setup

In order to use this API, your game must have the an API callback URL set. If you haven't done this already you can do so by editing your web game in the <Anchor label="Developer Portal" target="_blank" href="https://kongregatedevelopers.zendesk.com/hc/en-us/articles/44394671315469">Developer Portal</Anchor>  (or by appending /edit to your game name - e.g.  `https://www.kongregate.com/games/YourName/YourGame/edit`).

We will cover the specific calls that will be made to that endpoint later.

Once the [client API is loaded](https://docs.kongregate.com/docs/client-api-introduction), you can access the virtual goods functions from the `mtx` object on the web API, for example `kongregate.mtx.purchaseItemsRemote`.

### Requesting a Purchase

You may bring up the "purchase items" dialog box by using the [purchaseItemsRemote](https://docs.kongregate.com/docs/client-api-mtx-purchaseitemsremote) method on the `mtx` API object for web. The dialog box will call back to your servers to request item definitions for the "order info" string that you pass into this function.

### Handling the item\_order\_request callback

This callback will be issued as a [signed request](https://docs.kongregate.com/docs/concepts-signed-requests) to your API callback URL when an order needs to be defined. The request will have the following parameters once decoded/verified:

* **event** - `item_order_request`.
* **game\_id** - The game\_id.
* **buyer\_id** - The id of the user making the purchase.
* **recipient\_id** - The id of the user to receive the items.
* **order\_id** - A unique order id for this order in our database.
* **order\_info** - The order info string you passed into `purchaseItemsRemote`.

Here is an example of the decoded JSON parameters received for an `item_order_request` with the `order_info` set to 'sword':

```json
{
  "event":"item_order_request",
  "game_id":10000,
  "buyer_id":765,
  "recipient_id":765,
  "order_id":12345,
  "order_info":"sword"
}
```

Your callback should render a JSON object with a single element `items` which is an array of item definitions. Each item needs to have the following elements, all of which are required and cannot be blank.

* **name** - The name of the item.
* **description** - The description of the item (255 character max).
* **price** - The price of the item in Kreds for web (integer) or USD for Kartridge (floating point)
* **image\_url** - A URL to an icon of the item. This icon will be rendered at 40x40 pixels.

Here is an example valid JSON response for the above callback:

```json JSON (web)
{
  "items":
  [
    {
      "name":"Awesome Sword",
      "description":"A really neat sword!",
      "price":10,
      "image_url":"https://media.giphy.com/media/3o85xFGXZQIC29z74Q/giphy.gif"
    }
  ]
}
```

Once you deliver this JSON payload back to our servers, the items will be displayed to the user and they can confirm the purchase.

### Handling the item\_order\_placed callback

This callback will be issued as a [signed request](https://docs.kongregate.com/docs/concepts-signed-requests) to your API callback URL when a user has confirmed an order. The request will have the following parameters once decoded/verified:

* **event** - `item_order_placed`
* **game\_id** - The game\_id.
* **buyer\_id** - The id of the user making the purchase.
* **recipient\_id** - The id of the user to receive the items.
* **order\_id** - A unique order id for this order in our database.
* **order\_info** - The order info string you passed into `purchaseItemsRemote`

Here is an example of the decoded JSON parameters received for an `item_order_placed` with the `order_info` set to 'sword':

```json
{
  "event":"item_order_placed",
  "game_id":10000,
  "buyer_id":765,
  "recipient_id":765,
  "order_id":12345,
  "order_info":"sword"
}
```

At this point you should render a JSON response object with a single attribute `state`. You may either set `state` to `completed` or `canceled`. If you cancel the order the user's Kreds will be refunded and they will be notified via private message. If you wish to complete the order, you should render the `completed` status and award the user their virtual items at this point. Here is an example of a valid `completed` JSON response:

```json
{"state":"completed"}
```

### Example

An basic PHP example can be found [here.](http://cdn1.kongregate.com/assets/files/0000/4388/dynamic-item-flow.zip) It demonstrates how to decode/verify the signed request and handle the various required callbacks for this flow.