Core Concepts
The concepts you need to integrate StagePay, including apps (merchants), the tid transaction ID, the transaction state machine, minor-unit amounts, and beta/real environments.
Apps (merchants)
In StagePay, the unit that accepts payments is an app. Usually one game or one service is one app. Each app has its own settings:
| Item | Description |
|---|---|
appId | App identifier (a 24-character hexadecimal string, e.g. 6650f0c2a1b2c3d4e5f60718). Used when opening the checkout |
| Products | Price per productId (per currency). The payment amount is always determined by the product price registered on the server |
| PG connections | The PGs and payment methods the app uses, plus PG credentials |
| Callback URLs | The merchant server addresses that receive payment completion notices — purchaseRealUrl (production), purchaseTestUrl (test), callbackUrl (shared fallback) |
webhookSecret | HMAC key for callback signatures (whsec_ + 64 hexadecimal characters). Created and reissued in the console |
apiKey | App API key for v1 compatibility. Used in the callback's Authorization: Bearer header and in the refund API's X-Api-Key |
| REST API keys | Keys for REST API v1 (sk_... key ID + secret). Supports scopes, IP allowlist, and expiry |
allowCustomPrice | Whether price overrides are allowed (default false) |
There are three kinds of keys
webhookSecret (callback signature verification), the app apiKey (refund API, v1 compatibility), and REST API keys (keyId:secret) serve different purposes. Keep all of them on the server only, and never put them in a client (game client, app, or browser).
Transactions and transaction IDs (tid)
Each payment request is one transaction, identified by a unique ID issued by StagePay, the tid.
- Example format:
KCP-20260101090000123456-a1b2c3-9f8e7d6c— a string that starts with the PG code. The format may change, so store it as an opaque string (we recommend allowing up to 128 characters). - Starting with v2, a transaction is created first in the
pendingstate at the time of the payment request. You can also look up incomplete transactions in the console and the REST API. - The ID issued by the PG is stored separately as
pgTid(e.g. KCPtno, Stripe PaymentIntent ID). You may need it when calling the refund API. - The v1 callback field
orderIdhas the same value astid.
Transaction state machine
┌──────────► failed
│
pending ───┼──────────► cancelled
│
├──────────► expired
│
└──────────► success ──┬──► partial_refunded ──► refunded
└──────────────────────► refunded| State | Meaning | Callback |
|---|---|---|
pending | Payment request created, waiting for the customer to pay | — |
success | PG server verification complete, payment confirmed | payment.succeeded |
failed | Payment failed (declined, error) | — |
cancelled | Cancelled by the customer | — |
expired | Payment validity period elapsed (USDT, etc.) | — |
partial_refunded | Partially refunded | payment.refunded |
refunded | Fully refunded | payment.refunded |
A state transition succeeds atomically, exactly once in the database (even if pending → success is attempted twice concurrently, it is applied only once). Callbacks are sent only when a transition actually occurs, so a re-sent or forged-and-replayed PG webhook never produces a duplicate grant callback.
Amounts: minor units
The amount StagePay uses for settlement and aggregation is amountMinor, an integer in the smallest currency unit (minor unit). This eliminates floating-point calculation errors.
| Currency | Decimal places (exponent) | Display amount → amountMinor |
|---|---|---|
| KRW, JPY, IDR, VND, TWD, CLP | 0 | ₩12,000 → 12000 |
| USD, EUR, SGD, MYR, THB, PHP, BRL, MXN, etc. | 2 | $9.99 → 999 |
| USDT | 6 | 10.5 USDT → 10500000 |
amountis the major-unit value for display (e.g.9.99) and is sent alongside for v1 compatibility. UseamountMinorandcurrencyfor comparing and storing amounts.- TWD has 2 decimal places under ISO 4217, but StagePay treats it as 0 decimal places in line with PG practice.
- Never add amounts in different currencies. Aggregation and settlement are always done per currency.
const EXPONENT: Record<string, number> = { KRW: 0, JPY: 0, TWD: 0, USD: 2, EUR: 2, USDT: 6 };
// Convert via strings to avoid float errors
export function toMinor(amount: string, currency: string): bigint {
const exp = EXPONENT[currency] ?? 2;
const [int, frac = ''] = amount.split('.');
return BigInt(int + frac.padEnd(exp, '0').slice(0, exp));
}
toMinor('9.99', 'USD'); // 999n
toMinor('12000', 'KRW'); // 12000nEnvironments: beta and real
| Environment | Checkout | Purpose |
|---|---|---|
| beta | https://beta-pay.stagepay.io | Integration development and testing. Uses PG test (sandbox) credentials |
| real | https://pay.stagepay.io | Production. Real payments |
The callback URL is chosen based on the environment.
- Default:
purchaseTestUrlin the test environment,purchaseRealUrlin production (falling back tocallbackUrlif not set). - If you register a test whitelist (IP or userId) for an app, payment callbacks for those users go to
purchaseTestUrleven in production. In that case,environmentin the callback body istest. Use this for QA in production.
Request tracing: requestId
Every request carries a correlation ID, requestId. If you send the X-Request-Id request header, that value is used; otherwise StagePay generates one and returns it in the X-Request-Id response header. The same value is propagated to PG calls and merchant callbacks, so including both the tid and the requestId when you contact support lets us trace the issue quickly. For details, see Debugging with logs and requestId.