Referencia de funciones
Godot 4 · GDScript · Currency & store
purchase
Spends in-game currency to buy a shop item (server validates the balance).
Asynchronous (result via signal)
Signature
purchase(sku: String, idempotency_key: String = "") -> voidWhat it does
POSTs /currency/purchase (session-auth). The server checks the balance and deducts atomically, applying the item's grant rules. On success result carries the RPC payload (balances, ledger_ids, …). error_code may be insufficient_funds / already_owned / item_not_found / no_session / invalid_sku. Emits purchase_completed(false, sku, {}, …) immediately on no session or an empty sku.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| sku | String | required | The item SKU configured in the panel. |
| idempotency_key | String | "" | Optional key to make retries safe so the player is never charged twice; auto-generated if omitted. |
How to call it
Connect purchase_completed first, then call purchase(). Pass your own idempotency_key if you retry the same purchase.
Result signal: purchase_completed(success: bool, sku: String, result: Dictionary, error_code: String)
Example
Gamdato.purchase_completed.connect(_on_purchase)
Gamdato.purchase("sword_skin")
func _on_purchase(ok: bool, sku: String, result: Dictionary, error_code: String) -> void:
if ok: print("bought %s. balances: %s" % [sku, result.balances])
else: print("failed: %s" % error_code)Use cases
- Buy a cosmetic with soft currency.
- Spend coins or gems on a power-up or unlock.