Skip to Content
StagePayDocs v2

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:

ItemDescription
appIdApp identifier (a 24-character hexadecimal string, e.g. 6650f0c2a1b2c3d4e5f60718). Used when opening the checkout
ProductsPrice per productId (per currency). The payment amount is always determined by the product price registered on the server
PG connectionsThe PGs and payment methods the app uses, plus PG credentials
Callback URLsThe merchant server addresses that receive payment completion notices — purchaseRealUrl (production), purchaseTestUrl (test), callbackUrl (shared fallback)
webhookSecretHMAC key for callback signatures (whsec_ + 64 hexadecimal characters). Created and reissued in the console
apiKeyApp API key for v1 compatibility. Used in the callback's Authorization: Bearer header and in the refund API's X-Api-Key
REST API keysKeys for REST API v1 (sk_... key ID + secret). Supports scopes, IP allowlist, and expiry
allowCustomPriceWhether 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 pending state 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. KCP tno, Stripe PaymentIntent ID). You may need it when calling the refund API.
  • The v1 callback field orderId has the same value as tid.

Transaction state machine

            ┌──────────► failed
            │
 pending ───┼──────────► cancelled
            │
            ├──────────► expired
            │
            └──────────► success ──┬──► partial_refunded ──► refunded
                                   └──────────────────────► refunded
StateMeaningCallback
pendingPayment request created, waiting for the customer to pay—
successPG server verification complete, payment confirmedpayment.succeeded
failedPayment failed (declined, error)—
cancelledCancelled by the customer—
expiredPayment validity period elapsed (USDT, etc.)—
partial_refundedPartially refundedpayment.refunded
refundedFully refundedpayment.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.

CurrencyDecimal places (exponent)Display amount → amountMinor
KRW, JPY, IDR, VND, TWD, CLP0₩12,000 → 12000
USD, EUR, SGD, MYR, THB, PHP, BRL, MXN, etc.2$9.99 → 999
USDT610.5 USDT → 10500000
  • amount is the major-unit value for display (e.g. 9.99) and is sent alongside for v1 compatibility. Use amountMinor and currency for 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.
Example major ↔ minor conversion (TypeScript)
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'); // 12000n

Environments: beta and real

EnvironmentCheckoutPurpose
betahttps://beta-pay.stagepay.ioIntegration development and testing. Uses PG test (sandbox) credentials
realhttps://pay.stagepay.ioProduction. Real payments

The callback URL is chosen based on the environment.

  • Default: purchaseTestUrl in the test environment, purchaseRealUrl in production (falling back to callbackUrl if not set).
  • If you register a test whitelist (IP or userId) for an app, payment callbacks for those users go to purchaseTestUrl even in production. In that case, environment in the callback body is test. 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.

On this page