# 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., removing ads) 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.

```gdscript
Bridge.payments.is_supported
```

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

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

{% tabs %}
{% tab title="Godot 3.x" %}

```gdscript
func _ready():
    var id = "test_product" # id you specified in the config file
    var options = { } # optional
    Bridge.payments.purchase(id, options, funcref(self, "_on_purchase_completed"))

func _on_purchase_completed(success, purchase):
    print(success)
    print(purchase)
```

{% endtab %}

{% tab title="Godot 4.x" %}

```gdscript
func _ready():
    var id = "test_product" # id you specified in the config file
    var options = { } # optional
    Bridge.payments.purchase(id, options, Callable(self, "_on_purchase_completed"))

func _on_purchase_completed(success, purchase):
    print(success)
    print(purchase)
```

{% endtab %}
{% endtabs %}

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` and `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;
#  }
```

#### Consumable <a href="#consumable" id="consumable"></a>

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

{% tabs %}
{% tab title="Godot 3.x" %}

```gdscript
func _ready():
    var id = "test_product" # id you specified in the config file
    Bridge.payments.consume_purchase(id, funcref(self, "_on_consume_completed"))

func _on_consume_completed(success, purchase):
    print(success)
    print(purchase)
```

{% endtab %}

{% tab title="Godot 4.x" %}

```gdscript
func _ready():
    var id = "test_product" # id you specified in the config file
    Bridge.payments.consume_purchase(id, Callable(self, "_on_consume_completed"))

func _on_consume_completed(success, purchase):
    print(success)
    print(purchase)
```

{% endtab %}
{% endtabs %}

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

{% tabs %}
{% tab title="Godot 3.x" %}

```gdscript
func _ready():
    Bridge.payments.get_catalog(funcref(self, "_on_get_catalog_completed"))

func _on_get_catalog_completed(success, catalog):
    print(success)
    
    for item in catalog:
        print("ID: " + str(item.id))
        print("Price: " + str(item.price))
        print("Price Currency Code: " + str(item.priceCurrencyCode))
        print("Price Value: " + str(item.priceValue))
```

{% endtab %}

{% tab title="Godot 4.x" %}

```gdscript
func _ready():
    Bridge.payments.get_catalog(Caallable(self, "_on_get_catalog_completed"))

func _on_get_catalog_completed(success, catalog):
    print(success)
    
    for item in catalog:
        print("ID: " + str(item.id))
        print("Price: " + str(item.price))
        print("Price Currency Code: " + str(item.priceCurrencyCode))
        print("Price Value: " + str(item.priceValue))
```

{% endtab %}
{% endtabs %}

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

{% tabs %}
{% tab title="Godot 3.x" %}

```gdscript
func _ready():
    Bridge.payments.get_purchases(funcref(self, "_on_get_purchases_completed"))

func _on_get_purchases_completed(success, purchases):
    print(success)
    
    for purchase in purchases:
        print("ID: " + str(purchase.id))
```

{% endtab %}

{% tab title="Godot 4.x" %}

```gdscript
func _ready():
    Bridge.payments.get_purchases(Callable(self, "_on_get_purchases_completed"))

func _on_get_purchases_completed(success, purchases):
    print(success)
    
    for purchase in purchases:
        print("ID: " + str(purchase.id))
```

{% endtab %}
{% endtabs %}
