Skip to Content
StagePayDocs v2

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.

  1. Copy the App ID (appId).
  2. 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.
  3. Enter your merchant server address in Callback URL. You can start by filling in only purchaseTestUrl (test). Example: https://game.example.com/stagepay/callback
  4. In the Products menu, check the productId and per-currency prices of the products you will sell.
  5. (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&currency=KRW&userId=user_42&serverId=s1&playerId=hero42&language=ko
server.ts — Building the checkout URL (Node.js)
const 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.

callback.mjs (Node.js + Express)
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

  1. Open the beta checkout URL from step 2 in a browser.
  2. Pay with a PG test payment method (e.g. the Stripe test card 4242 4242 4242 4242). For PG-specific testing instructions, see Testing.
  3. Confirm that the payment.succeeded callback appears in your merchant server logs.
  4. In the console Transactions menu, confirm that the transaction status is success and the callback status is delivered.

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.

On this page