-
Notifications
You must be signed in to change notification settings - Fork 0
Payments: Getting Started
opera-pavelg edited this page Aug 20, 2024
·
1 revision
Use GxGames
singleton to access the platform API:
# Connecting signals to your custom handlers:
GxGames.payment_status_received.connect(your_status_signal_handler)
GxGames.payment_completed.connect(your_payment_signal_handler)
# Calling functions:
GxGames.get_full_version_payment_status()
GxGames.trigger_payment("some-id")
Here is the simple usage example. Assume that the game has a demo version with the last locations locked. They are available only in the paid version. The function check_full_version
is called from other parts of the game - for example, on initialisation or when the user reaches the first paid location. The function purchase_full_version
may be invoked on clicking a button.
# Your node with the game logic
extends Node
# The ID of the item to purchase. You should get this value from Dev Portal.
const ITEM_ID = "aosuhaoeucr-aoreuhaoleuhaou-aocruh"
# The last locations are available only in the paid version:
var is_last_locations_available = false
func _ready() -> void:
# Connecting signals:
GxGames.payment_status_received.connect(_on_payment_status_received)
GxGames.payment_completed.connect(_on_payment_completed)
func check_full_version() -> void:
# Block the UI
# ...
GxGames.get_full_version_payment_status()
func _on_payment_status_received(is_full_version_purchased: Boolean, error_codes: Array) -> void:
if error_codes.size() > 0:
# Handle the errors, unlock the UI
# ...
return
is_last_locations_available = is_full_version_purchased
# Unlock the UI
# ...
func purchase_full_version() -> void:
# Block the UI
# ...
GxGames.trigger_payment(ITEM_ID)
func _on_payment_completed(id: String) -> void:
if id != ITEM_ID:
# Something went wrong. Handle this error. Unlock the UI.
# ....
return
# Triggering the flow to check the full version - this is the only reliable way
# to check whether the payment was successful or not.
check_full_version()
Refer to GxGames API for the detailed explanations of the API.