Mobile games have two payment problems that crypto solves structurally: store commission on virtual currency, and chargebacks on digital goods. A crypto checkout moves the payment to a browser or wallet app, where the fee is cents and the transfer is final.

What it does not solve is trust in the client. A Unity build can be decompiled and a secret extracted in minutes, so the signing key stays on your server. Always.

The flow

  1. 1

    Client asks your backend

    POST /shop/checkout with the SKU and the player’s opaque id. The backend creates a GaaPay order and returns a checkout URL.

  2. 2

    Client opens the URL

    Application.OpenURL on mobile, or an in-game browser view. The player picks chain and asset there.

  3. 3

    Backend receives the webhook

    It verifies the signature, marks the order paid, and grants the SKU to the player id.

  4. 4

    Client refreshes

    On app resume, poll your backend for entitlement state. Never infer a purchase from the return URL alone.

Client code (C#)

Shop.cs
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;

public class Shop : MonoBehaviour {
    [System.Serializable] class Checkout { public string checkout_url; }

    public IEnumerator Buy(string sku) {
        var body = JsonUtility.ToJson(new BuyRequest { sku = sku, player = PlayerId() });
        using var req = new UnityWebRequest(BackendUrl + "/shop/checkout", "POST");
        req.uploadHandler = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(body));
        req.downloadHandler = new DownloadHandlerBuffer();
        req.SetRequestHeader("Content-Type", "application/json");
        yield return req.SendWebRequest();

        if (req.result != UnityWebRequest.Result.Success) {
            Debug.LogError(req.error);
            yield break;
        }
        var checkout = JsonUtility.FromJson<Checkout>(req.downloadHandler.text);
        Application.OpenURL(checkout.checkout_url);
    }
}
The secret test: if sk_live_ appears anywhere in the Unity project or its build output, the integration is already broken. Search the build folder before shipping.

Backend grant

The backend creates the order with merchant_order_ref = <your order id> and stores player_id in metadata (opaque, no email or phone). On a verified payment.succeeded, it grants the SKU exactly once — the event id is the idempotency key.

On app resume the client calls GET /shop/entitlements?player=...; that endpoint reads your database, not the payment provider, so a forged return URL grants nothing.

Game-specific pitfalls

  • Platform rules differ. Virtual currency inside a mobile store may be subject to store billing rules; web shops, physical goods and PC builds are different categories. Check the policy for your store and category before shipping.
  • Do not grant on Application.OpenURL return. The player can close the browser without paying, and the return URL is user-controlled.
  • Handle the app being killed mid-payment. The webhook is the source of truth; entitlement is restored on next launch.
  • Keep the player id opaque. A Unity client can send anything; never let it send an email or a display name into payment metadata.

Unity questions

Can I sign requests inside Unity?

Technically yes, practically no. A client-side secret is a published secret; the only safe pattern is a backend that signs.

Does this work on iOS and Android?

Opening a checkout in the system browser works on both. Whether an external checkout is permitted for your product category depends on store policy, not on the SDK.

How do I test it?

Point the client at your staging backend with sandbox keys, then use the sandbox’s simulated success. The client flow is identical.

Read the server-side guide first

The backend pattern is the same as the Node/Python guide: sign, create, verify.

Node guide