Skip to content

Payments: Getting Started

opera-pavelg edited this page Sep 3, 2024 · 4 revisions

Use the following functions from GxGames to access the platform API:

// Calling functions:
GxGames.TriggerPayment("test-id", callback);
GxGames.GetFullVersionPaymentStatus(callback)

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 CheckFullVersion is called from other parts of the game - for example, on initialisation or when the user reaches the first paid location. The function PurchaseFullVersion may be invoked on clicking a button.

// Your class with the game logic
public sealed class PaymentsManager
{
    // The ID of the item to purchase. You should get this value from Dev Portal.
    const string ITEM_ID = "aosuhaoeucr-aoreuhaoleuhaou-aocruh"    

    // The last locations are available only in the paid version:
    private bool isLastLocationsAvailable = false

    public void CheckFullVersion()
    {
        // Block the UI
        // ...

        GxGames.GetFullVersionPaymentStatus((data, isOk, errorCodes) =>
        {
            if (errorCodes.Length > 0)
            {
                // Handle the errors, unlock the UI.
                // ...

                return;
            }

            isLastLocationsAvailable = data.isFullVersionPurchased;
            // Unlock the UI.
            // ...
        });
    }

    public void PurchaseFullVersion()
    {
        // Block the UI
        // ...

        GxGames.TriggerPayment(ITEM_ID, (id) =>
        {
            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.
            CheckFullVersion();
        });
    }
}

Refer to GxGames API for the detailed explanations of the API.

Clone this wiki locally