# In-Game Purchases

Enable players to purchase items, upgrades, or currency within your game to enhance their experience and generate revenue.

There are two types of purchases — permanent (e.g., ad removal) and consumable (e.g., in-game coins).

#### Support <a href="#support-1" id="support-1"></a>

Check if in-game purchases are supported to offer items or upgrades within the game.

```javascript
playgama_bridge_payments_is_supported()
```

#### Setup <a href="#purchase" id="purchase"></a>

Setup in-game purchases in the [config file](/playgama/sdk/engines/gamemaker/setup.md#config). For each product add an `id` and fill in the information for the required platforms, example for one product:

```json
{
    ...    
    "payments": [
        {
            "id": "test_product",
            "playgama": {
                "amount": 1 // int price in Gam
            },
            "playdeck": {
                "amount": 1, // int price in Telegram Stars
                "description": "TEST PRODUCT"
            }
        }
    ]
}
```

#### Purchase <a href="#purchase" id="purchase"></a>

Allow players to buy items or upgrades in your game to enhance their gameplay experience.

```javascript
var options = { }
playgama_bridge_payments_purchase("test_product", json_stringify(options)) // id you specified in the config file

// callback via Async Social Event
if async_load[? "type"] == "playgama_bridge_payments_purchase_callback" {
    if async_load[? "success"] {
        var purchase = json_parse(async_load[? "data"])
        var productId = purchase.id
        // your logic here
    }
}
```

Each platform provides its own set of properties for a purchase, so make sure to check the official documentation of the specific platform you are targeting.

Use `purchase` data to verify the purchase. Currently, the Playgama API verification only supports `playgama`, `msn` and `microsoft_store` platforms.&#x20;

```bash
curl -X POST "https://playgama.com/api/bridge/v1/verify" \
  -H "Content-Type: application/json" \
  -d '{"platform":"<PLATFORM_ID>","type":"purchase","data":{ <...purchase> }}'

#  Response:
#  {
#    success: boolean;
#    errorMessage?: string;

#    -- purchase --
#    orderId?: string;
#    productId?: string;
#    externalId?: string;
#  }
```

#### Consume Purchase <a href="#consume-purchase" id="consume-purchase"></a>

Consume purchased items, such as in-game currency, once they are used, to manage inventory and player progression.

```javascript
playgama_bridge_payments_consume_purchase("test_product") // id you specified in the config file

// callback via Async Social Event
if async_load[? "type"] == "playgama_bridge_payments_consume_purchase_callback" {
    if async_load[? "success"] {
        var purchase = json_parse(async_load[? "data"])
        var productId = purchase.id
        // your logic here
    }
}
```

#### Catalog of All Items <a href="#catalog-of-all-items" id="catalog-of-all-items"></a>

Retrieve a list of all available in-game items that players can purchase to display in the game store.

```javascript
playgama_bridge_payments_get_catalog()

// callback via Async Social Event
if async_load[? "type"] == "playgama_bridge_payments_get_catalog_callback" {
    if async_load[? "success"] {
        var catalog = json_parse(async_load[? "data"])
        for (var i = 0; i < array_length(catalog); i += 1)
	{
	    var catalogItem = catalog[i]
            var prodcutId = catalogItem.id
            var price = catalogItem.price
            var priceCurrencyCode = catalogItem.priceCurrencyCode
            var priceValue = catalogItem.priceValue
            // your logic here
	}
    }
}
```

#### List of Purchased Items <a href="#list-of-purchased-items" id="list-of-purchased-items"></a>

Retrieve a list of items that the player has purchased to manage their inventory and provide access to purchased content.

{% hint style="warning" %}
If the user loses internet connection when making an in-game purchase, the purchase might remain unprocessed. To avoid this, check for unprocessed purchases using this method (e.g., each time the game is launched).
{% endhint %}

```javascript
playgama_bridge_payments_get_purchases()

// callback via Async Social Event
if async_load[? "type"] == "playgama_bridge_payments_get_purchases_callback" {
    if async_load[? "success"] {
        var purchases = json_parse(async_load[? "data"])
        for (var i = 0; i < array_length(purchases); i += 1)
	{
	    var purchase = purchases[i]
            var productId = purchase.id
            // your logic here
	}
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.playgama.com/playgama/sdk/engines/gamemaker/in-game-purchases.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
