# 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.

<figure><img src="https://1088849411-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5ukgSPDBOdbQp4FYtbz1%2Fuploads%2FOPN0gEb5fqXYiRJa7pK8%2FScreenshot%202024-10-17%20at%207.58.22%E2%80%AFPM.png?alt=media&#x26;token=ffde5157-0d6e-45c0-8dce-f3f6b6b273fb" alt=""><figcaption></figcaption></figure>

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

Setup in-game purchases in the [config file](https://wiki.playgama.com/playgama/sdk/engines/setup#setup). 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.

<figure><img src="https://1088849411-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5ukgSPDBOdbQp4FYtbz1%2Fuploads%2FbsJLTAVUJz7DM1e7wXxI%2FScreenshot%202025-11-26%20at%209.51.44%E2%80%AFAM.png?alt=media&#x26;token=dac3b57f-4e55-4704-9769-891d33647f39" alt=""><figcaption></figcaption></figure>

<details>

<summary>Copy This Example</summary>

```
{"is-c3-clipboard-data":true,"type":"events","items":[{"eventType":"block","conditions":[{"id":"on-clicked","objectClass":"Button"}],"actions":[],"children":[{"eventType":"block","conditions":[{"id":"compare-two-values","objectClass":"System","parameters":{"first-value":"PlaygamaBridge.PlatformId","comparison":0,"second-value":"\"playgama\""}}],"actions":[{"type":"comment","text":"optional"},{"id":"add-action-parameter","objectClass":"PlaygamaBridge","parameters":{"key":"\"externalId\"","value":"\"<YOUR_ID>\""}}]},{"eventType":"block","conditions":[],"actions":[{"id":"payments-purchase","objectClass":"PlaygamaBridge","parameters":{"id":"\"test_product\""}}]}]},{"eventType":"block","conditions":[{"id":"on-payments-purchase-completed","objectClass":"PlaygamaBridge"}],"actions":[],"children":[{"eventType":"block","conditions":[{"id":"is-last-action-completed-successfully","objectClass":"PlaygamaBridge"}],"actions":[{"id":"log","objectClass":"Browser","parameters":{"type":"log","message":"\"Purchase completed, id: \" & PlaygamaBridge.PaymentsLastPurchasePropertyValue(\"id\")"}}]}]}]}
```

</details>

Each platform provides its own set of properties for a purchase (which you can access through `PaymentsLastPurchasePropertyValue`), 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.

```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

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

<figure><img src="https://1088849411-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5ukgSPDBOdbQp4FYtbz1%2Fuploads%2FG5KFSrFSG7sY30kTdOzf%2FScreenshot%202025-04-24%20at%2010.08.11%E2%80%AFAM.png?alt=media&#x26;token=c4dfa950-2a1f-47c6-879f-4c84a5f71b22" alt=""><figcaption></figcaption></figure>

<details>

<summary>Copy This Example</summary>

```
{"is-c3-clipboard-data":true,"type":"events","items":[{"eventType":"block","conditions":[{"id":"on-clicked","objectClass":"Button"}],"actions":[{"id":"payments-consume-purchase","objectClass":"PlaygamaBridge","parameters":{"id":"\"test_product\""}}]},{"eventType":"block","conditions":[{"id":"on-payments-consume-purchase-completed","objectClass":"PlaygamaBridge"}],"actions":[],"children":[{"eventType":"block","conditions":[{"id":"is-last-action-completed-successfully","objectClass":"PlaygamaBridge"}],"actions":[{"id":"log","objectClass":"Browser","parameters":{"type":"log","message":"\"Consume completed, id: \" & PlaygamaBridge.PaymentsLastPurchasePropertyValue(\"id\")"}}]}]}]}
```

</details>

#### 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.

<figure><img src="https://1088849411-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5ukgSPDBOdbQp4FYtbz1%2Fuploads%2FUgD5U0179EsDSfj5dzAF%2FScreenshot%202025-04-24%20at%2010.09.01%E2%80%AFAM.png?alt=media&#x26;token=a6ad8a39-bced-4ee9-afe2-73a2cc707c6a" alt=""><figcaption></figcaption></figure>

<details>

<summary>Copy Example</summary>

```
{"is-c3-clipboard-data":true,"type":"events","items":[{"eventType":"block","conditions":[{"id":"on-clicked","objectClass":"Button"}],"actions":[{"id":"payments-get-catalog","objectClass":"PlaygamaBridge"}]},{"eventType":"block","conditions":[{"id":"on-payments-get-catalog-completed","objectClass":"PlaygamaBridge"}],"actions":[],"children":[{"eventType":"block","conditions":[{"id":"compare-two-values","objectClass":"System","parameters":{"first-value":"PlaygamaBridge.PaymentsCatalogItemsCount","comparison":4,"second-value":"0"}}],"actions":[],"children":[{"eventType":"block","conditions":[{"id":"for","objectClass":"System","parameters":{"name":"\"items\"","start-index":"0","end-index":"PlaygamaBridge.PaymentsCatalogItemsCount - 1"}}],"actions":[{"id":"log","objectClass":"Browser","parameters":{"type":"log","message":"\"ID: \" & PlaygamaBridge.PaymentsCatalogItemPropertyValue(loopindex(\"items\"), \"id\")"}},{"id":"log","objectClass":"Browser","parameters":{"type":"log","message":"\"Price: \" & PlaygamaBridge.PaymentsCatalogItemPropertyValue(loopindex(\"items\"), \"price\")"}},{"id":"log","objectClass":"Browser","parameters":{"type":"log","message":"\"Price Currency Code: \" & PlaygamaBridge.PaymentsCatalogItemPropertyValue(loopindex(\"items\"), \"priceCurrencyCode\")"}},{"id":"log","objectClass":"Browser","parameters":{"type":"log","message":"\"Price Value: \" & PlaygamaBridge.PaymentsCatalogItemPropertyValue(loopindex(\"items\"), \"priceValue\")"}}]}]}]}]}
```

</details>

#### 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 %}

<figure><img src="https://1088849411-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5ukgSPDBOdbQp4FYtbz1%2Fuploads%2Fz4V8UIesl0BITmBTMVtZ%2FScreenshot%202025-04-24%20at%2010.09.50%E2%80%AFAM.png?alt=media&#x26;token=2a94fb17-2cbb-4e3a-bd7f-69db34cb0602" alt=""><figcaption></figcaption></figure>

<details>

<summary>Copy This Example</summary>

```
{"is-c3-clipboard-data":true,"type":"events","items":[{"eventType":"block","conditions":[{"id":"on-clicked","objectClass":"Button"}],"actions":[{"id":"payments-get-purchases","objectClass":"PlaygamaBridge"}]},{"eventType":"block","conditions":[{"id":"on-payments-get-purchases-completed","objectClass":"PlaygamaBridge"}],"actions":[],"children":[{"eventType":"block","conditions":[{"id":"compare-two-values","objectClass":"System","parameters":{"first-value":"PlaygamaBridge.PaymentsPurchasesCount","comparison":4,"second-value":"0"}}],"actions":[],"children":[{"eventType":"block","conditions":[{"id":"for","objectClass":"System","parameters":{"name":"\"purchases\"","start-index":"0","end-index":"PlaygamaBridge.PaymentsPurchasesCount - 1"}}],"actions":[{"id":"log","objectClass":"Browser","parameters":{"type":"log","message":"\"ID: \" & PlaygamaBridge.PaymentsPurchasePropertyValue(loopindex(\"purchases\"), \"id\")"}}]}]}]}]}
```

</details>
