Unity SDK for U.CASH Pay: an in-app pay button and a checkout helper for Unity games and apps. Non-custodial funds always settle directly to the merchant's own configured receive addresses inside their pay.u.cash store. This SDK never touches, holds, or custodies funds.
The store Cloud Token used here is publishable: it is safe to embed in a client build or browser webview, the same way you would embed a Stripe publishable key. It can only be used to create checkouts that pay the merchant, never to withdraw.
UcashPay.HostedCheckoutUrl(options)builds a client-side hosted pay link (no network call, safe from the browser).UcashPay.CreateCheckout(options, cb)creates a server-side tracked checkout viaUnityEngine.Networkingand returns the hosted payment URL plus the transaction id. Idempotent perexternal_reference.UcashPayButtonMonoBehaviour: drop it on a UI Button, set the Cloud Token in the inspector, and clicking opens the pay page.- WebGL interop included so the pay page opens in a new browser tab in WebGL builds.
In Unity: Window -> Package Manager -> + -> Add package from git URL... and paste:
https://github.com/UdotCASH/unity-ucashpay.git#v0.1.0
Clone this repo, then Package Manager -> + -> Add package from disk... and select the package.json at the repo root.
openupm add com.ucash.ucashpay
Requires Unity 2019.4 or newer.
- Add a UI Button to your canvas.
- Attach the
UcashPayButtoncomponent. - Fill in Cloud Token (your store token), Amount, Currency (default
USD), and optionally Title, External Reference, Redirect URL. - Wire the
Buttonreference (or leave it blank; the component auto-binds to aButtonon the same GameObject). - At runtime, clicking the button opens
https://pay.u.cash/embed.php?....
using Ucash.Pay;
var options = new CheckoutOptions
{
cloud = "st_your_store_cloud_token", // publishable
amount = "19.99",
currency = "USD",
title = "Sword of Uprising",
externalReference = "order_" + System.Guid.NewGuid(),
redirect = "https://yourgame.example/return"
};
string payUrl = UcashPay.HostedCheckoutUrl(options);
Application.OpenURL(payUrl);This builds:
https://pay.u.cash/embed.php?cloud=st_...&amount=19.99¤cy=USD&title=...&external_reference=...&redirect=...
No server secret is required. The Cloud token is publishable and safe to ship in a client build.
CreateCheckout POSTs to https://pay.u.cash/payment/ajax.php with idempotent=1 so the same externalReference never creates duplicate transactions. The Cloud token is publishable, but because this registers a transaction row it is typically called from a server route or a trusted host.
using System.Collections;
using Ucash.Pay;
using UnityEngine;
public class CheckoutDemo : MonoBehaviour
{
public void Buy()
{
StartCoroutine(RunCheckout());
}
private IEnumerator RunCheckout()
{
var options = new CheckoutOptions
{
cloud = "st_your_store_cloud_token",
amount = "19.99",
currency = "USD",
title = "Sword of Uprising",
externalReference = "order_1234",
redirect = "https://yourgame.example/return"
};
CheckoutResult result = default;
yield return UcashPay.CreateCheckout(options, r => result = r);
if (result.success)
{
Debug.Log("Pay URL: " + result.paymentUrl);
Debug.Log("Transaction id: " + result.transactionId);
Application.OpenURL(result.paymentUrl);
}
else
{
Debug.LogWarning("Checkout failed: " + result.error);
}
}
}The response JSON is { success: true, response: [paymentUrl, transactionId, ...] }. The SDK picks the array element that starts with http(s):// as the payment URL.
| Field | Required | Notes |
|---|---|---|
cloud |
yes | Store Cloud Token. Publishable. |
amount |
yes | Fiat amount as a string, e.g. "10.50". |
currency |
no | Defaults to "USD". |
title |
no | Shown on the pay page. |
externalReference |
no | Your order id. Reuse to deduplicate a tracked checkout. |
redirect |
no | URL the user lands on after paying. |
| Field | Meaning |
|---|---|
success |
true when the API responded success. |
paymentUrl |
Hosted payment URL to present to the user. |
transactionId |
pay.u.cash transaction id, when present. |
response |
Raw response payload (for debugging). |
error |
Human-readable error when success is false. |
httpStatus |
HTTP status code from the request. |
- Sign up at pay.u.cash, then click the verification link in the email.
- Set receive addresses under Settings -> Addresses (raw address, ENS, Unstoppable Domains, or FIO).
- Create a store under Account -> Stores and copy its Store Cloud Token (use the store-level token, not the account-wide one).
- For fiat cards, connect your own Stripe under Settings -> Payment processors.
- No automatic crypto recurring billing. U.CASH Pay checkouts are one-time payments initiated by the user. Unity-side auto-recurring billing is not supported by the protocol today. If you need subscriptions, gate them on your own server by re-issuing a new
CreateCheckoutper cycle and let the user approve each one. CreateCheckoutis a network call. Use it from a coroutine on a MonoBehaviour. The hostedHostedCheckoutUrlpath is a pure string build with no network dependency and is the recommended client-side path.- JsonUtility cannot map a heterogeneous top-level array, so the SDK scans the response for the first
http(s)://element as the payment URL. This matches the documented response shape but is intentionally defensive.
- Non-custodial. Funds settle directly to the merchant's receive addresses configured in pay.u.cash.
- The Cloud token is publishable (safe in the browser / client build). It can only create checkouts that pay the merchant.
- The merchant's payout keys, wallet secrets, and account-wide credentials are never exposed to or required by this SDK.
MIT. See LICENSE.