Quickstart (5-Minute Integration)
Follow five steps for a minimal integration — issue an API key and webhook secret, open the checkout, verify the callback signature, and test in the beta environment.
By the end of this guide, you will have completed one payment in the beta environment and received a signature-verified callback on your merchant server.
Check your app and issue keys
Sign in to the merchant console and open the app you want to integrate from the Apps menu.
- Copy the App ID (
appId). - Create a secret on the Webhook secret tab. The full
whsec_value is shown only once, right after it is created, so store it in your server's secret store. - Enter your merchant server address in Callback URL. You can start by filling in only
purchaseTestUrl(test). Example:https://game.example.com/stagepay/callback - In the Products menu, check the
productIdand per-currency prices of the products you will sell. - (Optional) To use the server-to-server API, issue a REST API key from the API keys menu.
Open the checkout
The simplest approach is to open the checkout URL. When the user taps the buy button, build the URL on your merchant server and send it to the client.
https://beta-pay.stagepay.io/request?appId=6650f0c2a1b2c3d4e5f60718&pg=KCP&method=card&productId=gem_100¤cy=KRW&userId=user_42&serverId=s1&playerId=hero42&language=koconst PAY_BASE = process.env.STAGEPAY_PAY_URL ?? 'https://beta-pay.stagepay.io';
export function checkoutUrl(params: {
productId: string;
userId: string;
pg?: string;
method?: string;
currency: string;
serverId?: string;
playerId?: string;
}) {
const url = new URL('/request', PAY_BASE);
url.searchParams.set('appId', process.env.STAGEPAY_APP_ID!);
for (const [k, v] of Object.entries(params)) if (v) url.searchParams.set(k, v);
return url.toString();
}If you omit pg and method and open /inapp, StagePay shows a payment method selection screen. For the full list of parameters, see Opening the checkout.
Receive the callback and verify the signature
When a payment is confirmed, StagePay sends a POST request to your callback URL. Verify the signature against the raw body, then grant the item and respond with 200.
import crypto from 'node:crypto';
import express from 'express';
const app = express();
const SECRET = process.env.STAGEPAY_WEBHOOK_SECRET; // whsec_...
app.post('/stagepay/callback', express.raw({ type: 'application/json' }), async (req, res) => {
const raw = req.body.toString('utf8');
const ts = req.get('X-StagePay-Timestamp') ?? '';
const sig = req.get('X-StagePay-Signature') ?? '';
const expected = 'v1=' + crypto.createHmac('sha256', SECRET).update(`${ts}.${raw}`).digest('hex');
const fresh = Math.abs(Date.now() / 1000 - Number(ts)) <= 300;
const valid =
fresh && sig.length === expected.length && crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(expected));
if (!valid) return res.status(401).send('invalid signature');
const event = JSON.parse(raw);
const deliveryId = req.get('X-StagePay-Delivery');
// TODO: check for duplicates by deliveryId or tid, then grant (idempotent handling)
console.log(event.event, event.tid, event.amountMinor, event.currency, deliveryId);
res.status(200).send('ok');
});
app.listen(3000);Examples in other languages (PHP, Python, Go, Java) and test vectors are in Signature verification.
Test in the beta environment
- Open the beta checkout URL from step 2 in a browser.
- Pay with a PG test payment method (e.g. the Stripe test card
4242 4242 4242 4242). For PG-specific testing instructions, see Testing. - Confirm that the
payment.succeededcallback appears in your merchant server logs. - In the console Transactions menu, confirm that the transaction status is
successand the callback status isdelivered.
Receiving callbacks on a local server
Callbacks can only be sent to an HTTPS address reachable from the internet. During local development, use a tunneling tool (e.g. Cloudflare Tunnel, ngrok) to create a temporary public address and register it as purchaseTestUrl.
Go live
When testing is complete, follow the Go-live checklist to register purchaseRealUrl, connect production PG credentials, and change the checkout address to https://pay.stagepay.io.
What to read next
- Webhook events and payloads — All callback fields
- Retries and idempotency — Preventing duplicate grants
- In-app/WebView integration — Showing the checkout in a mobile game
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.
Opening the Checkout
URL parameters for the /request / /inapp checkout, price override signatures, and error responses.