Godot 4 · GDScript · Currency & store
buy_pack
Starts a real-money top-up: opens Stripe Checkout in the browser to credit currency.
Signature
buy_pack(pack_sku: String, success_url: String = "https://gamdato.com/topup/ok", cancel_url: String = "https://gamdato.com/topup/cancel", idempotency_key: String = "") -> voidWhat it does
POSTs /currency/topup/checkout (session-auth). On success the Stripe Checkout page is opened in the system browser (url carries the checkout link). After the player pays, the server credits the linked grant via a Stripe webhook; call get_balances() afterwards to see the new balance. error_code may be no_session / invalid_sku. Emits topup_started(false, "", …) immediately on no session or an empty pack_sku.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| pack_sku | String | required | The top-up pack SKU configured in the panel (e.g. "premium_pack"). |
| success_url | String | "https://gamdato.com/topup/ok" | Where Stripe redirects after a successful payment. Must be https:// (or http://localhost in dev). |
| cancel_url | String | "https://gamdato.com/topup/cancel" | Where Stripe redirects if the player cancels. Must be https:// (or http://localhost in dev). |
| idempotency_key | String | "" | Optional key to make retries safe; auto-generated if omitted. |
How to call it
Connect topup_started first, then call buy_pack(). Because crediting happens via webhook, refresh with get_balances() when the player returns to the game.
Result signal: topup_started(success: bool, url: String, error_code: String)
Example
Gamdato.topup_started.connect(_on_topup)
Gamdato.buy_pack("premium_pack")
func _on_topup(ok: bool, url: String, error_code: String) -> void:
if ok: print("checkout opened: %s" % url)
else: print("error: %s" % error_code)Use cases
- Sell a gem pack for real money via Stripe Checkout.
- Offer a starter bundle that tops up the player's soft currency.