Skip to content

Store

Beta

The store module is currently in beta. This is an invite only feature. If you are interested in using it, please get in touch with us.

The store module offers a simplified way to sell in-game items. It can work alongside your existing Xsolla integration. Using the buyItem method is required in order to enable in-app purchases on the CrazyGames mobile app. The method is also supported on the web.

Getting started

The module can be accessed like this:

window.CrazyGames.SDK.store;

The module can be accessed like this:

CrazySDK.Store;

Consult the Demo

For a demo, please consult the CrazySDK/Demo/StoreModule scene. You can run it directly in the Unity editor.

🟥 Not supported by the GameMaker SDK.

🟥 Not supported by the Construct SDK.

🟥 Not supported by the Godot SDK.

🟥 Not supported by the Cocos SDK.

Buying an item

Call buyItem with the item ID configured in your Xsolla project. The method opens the Xsolla Pay Station widget and resolves once the purchase is completed. Only one purchase can be in progress at a time.

try {
    const result = await window.CrazyGames.SDK.store.buyItem("your_item_id");
    console.log("Purchase completed", result); // { itemId: "your_item_id" }
    // the item can now be found in the Xsolla inventory
} catch (e) {
    console.log("Purchase error", e);
}

Warning

A successful buyItem call means the payment flow completed, but you should always confirm ownership on your back-end (or via the Xsolla inventory API) before granting valuable items. Never rely solely on the client-side result to unlock content.

Errors

The buyItem method rejects with a StoreError, for example:

{
    "code": "purchaseCancelled",
    "message": "The purchase was cancelled."
}

Possible error codes:

  • userNotAuthenticated - the user must be signed in to make a purchase
  • purchaseInitFailed - something went wrong while initiating the purchase with Xsolla
  • purchaseInProgress - a purchase is already in progress, wait for it to finish before starting a new one
  • purchaseCancelled - the user closed the payment widget without completing the purchase
  • unexpectedError - an unexpected error occurred (for example a network issue, or the payment widget failed to load)
  • other

Call BuyItem with the item ID configured in your Xsolla project. The method opens the Xsolla Pay Station widget and invokes the callback once the purchase is completed. Only one purchase can be in progress at a time.

CrazySDK.Store.BuyItem(
    "your_item_id",
    (error, result) =>
    {
        if (error != null)
        {
            Debug.LogError("Purchase error: " + error);
            return;
        }
        Debug.Log("Purchase completed: " + result);
        // the item can now be found in the Xsolla inventory
    }
);
// or
try
{
    var result = await CrazySDK.Store.BuyItemAsync("your_item_id");
    Debug.Log("Purchase completed: " + result);
}
catch (SdkError e)
{
    Debug.LogError("Purchase error (async): " + e);
}

Warning

A successful BuyItem call means the payment flow completed, but you should always confirm ownership on your back-end (or via the Xsolla inventory API) before granting valuable items. Never rely solely on the client-side result to unlock content.

Errors

The callback receives an SdkError as the first parameter (it is null when the purchase succeeds). The async version throws the SdkError instead.

Possible error codes:

  • userNotAuthenticated - the user must be signed in to make a purchase
  • purchaseInitFailed - something went wrong while initiating the purchase with Xsolla
  • purchaseInProgress - a purchase is already in progress, wait for it to finish before starting a new one
  • purchaseCancelled - the user closed the payment widget without completing the purchase
  • unexpectedError - an unexpected error occurred (for example a network issue, or the payment widget failed to load)
  • other

🟥 Not supported by the GameMaker SDK.

🟥 Not supported by the Construct SDK.

🟥 Not supported by the Godot SDK.

🟥 Not supported by the Cocos SDK.

Sandbox mode

While developing, enable sandbox mode so purchases run against Xsolla's test environment, allowing you to buy items with fake money.

window.CrazyGames.SDK.store.setSandbox(true);

While developing, enable sandbox mode so purchases run against Xsolla's test environment, allowing you to buy items with fake money.

CrazySDK.Store.SetSandbox(true);

🟥 Not supported by the GameMaker SDK.

🟥 Not supported by the Construct SDK.

🟥 Not supported by the Godot SDK.

🟥 Not supported by the Cocos SDK.

Local Testing

When the SDK is in the local environment (on 127.0.0.1 or localhost), buyItem always simulates a successful purchase and setSandbox only logs the new value.

When you are running the game in the editor, BuyItem returns a hard-coded response and SetSandbox only logs the new value.

You can customize the response returned by BuyItem with the Buy Item Response field in the CrazySDK/Resources/CrazyGamesSettings object. The available values are:

  • Success - returns a successful PurchaseResult for the requested item ID
  • PurchaseCancelled - returns the purchaseCancelled error
  • UserLoggedOut - returns the userNotAuthenticated error
  • UnexpectedError - returns the unexpectedError error

🟥 Not supported by the GameMaker SDK.

🟥 Not supported by the Construct SDK.

🟥 Not supported by the Godot SDK.

🟥 Not supported by the Cocos SDK.

Ask AI