Skip to Content
StagePayDocs v2

Return to merchant (returnUrl)

Send customers back to your page or app after payment — register addresses in the console, pass returnUrl, and handle the return page.

When checkout runs in the same window (mobile web, an external browser), the customer ends on the StagePay result screen (/return). Pass returnUrl in the payment request and that screen shows a Back to merchant button that goes to your address with the result appended.

Your page ── requestPayment({ returnUrl }) ──▶ StagePay checkout ──▶ PG payment
    ▲                                                           │
    └── /orders/A-1001?stagepay_tid=…&stagepay_status=success ◀── result screen [Back to merchant]

Returned values are for display only

stagepay_tid and stagepay_status are query values anyone can change. Decide fulfilment only from the signed callback or a server-side transaction lookup.

When the button appears

How checkout was openedResult screenHow you get the result
Mobile web (redirect)Back to merchantNavigates to returnUrl
App → external browserBack to merchant (app deep link)Back to the app via mygame://…
PC popup · layer (iframe)ClosepostMessage → SDK Promise
App WebView native bridgeCloseBridge message (In-app / WebView)

Inside a popup, layer or WebView the result arrives as a message, so a Close button is shown instead — your page is never opened inside that window.

Setup

Register addresses in the console

In the console, go to Apps → Edit app → Return addresses after payment, enter one per line and save (up to 10).

https://shop.example.com
https://m.shop.example.com
mygame://
  • For the web, enter the origin only, no path. Register other ports separately (https://shop.example.com:8443).
  • http works only for development hosts localhost, 127.0.0.1 and [::1].
  • For an app deep link enter the scheme only (mygame://). Schemes such as javascript:, data: and intent: cannot be registered.
  • Case, the default port (:443) and a trailing / are normalized on save.

Pass returnUrl in the payment request

Any path, query or # under a registered origin is fine.

StagePay.requestPayment({
  pg: 'KCP', method: 'card',
  productId: 'gem_100', currency: 'KRW', userId: 'user_42',
  uniqueId: 'A-1001',
  returnUrl: 'https://shop.example.com/orders/A-1001',
});

Handle the return page

The button goes to returnUrl with stagepay_tid (the StagePay transaction ID) and stagepay_status (success, pending, failed) appended. Your own query and # are kept.

Browser (https://shop.example.com/orders/A-1001)
const back = StagePay.getReturnResult({ clean: true }); // removes stagepay_* from the address bar
if (back) {
  // { transactionId: 'KCP-…', status: 'success', verified: false }
  showSpinner('Checking payment…');
  const order = await fetch('/api/orders/A-1001').then((r) => r.json()); // your server decides
  render(order);
}
Your server — confirm the transaction
const res = await fetch(`https://api.stagepay.io/api/v1/transactions/${tid}`, {
  headers: { Authorization: `Bearer ${process.env.STAGEPAY_KEY_ID}:${process.env.STAGEPAY_KEY_SECRET}` },
});
const { data } = await res.json(); // fulfil only when data.status is success (usually the callback already did)

pending (a virtual account was issued, for example) is not final. Show "checking" until the callback arrives.

Matching rules

With https://shop.example.com and mygame:// registered:

returnUrlResult
https://shop.example.com/orders/7?x=1#topAllowed
https://SHOP.example.com:443/Allowed (case and default port ignored)
mygame://pay/doneAllowed
https://m.shop.example.com/Rejected — register subdomains separately
https://shop.example.com:8443/Rejected — different port
http://shop.example.com/Rejected — http
https://shop.example.com@evil.com/Rejected — user info (@)
/orders/7, //shop.example.com/Rejected — not an absolute URL
javascript:…, data:…Rejected
  • Values over 2048 characters, or with whitespace, control characters or backslashes, are rejected.
  • The result screen re-checks against the current app settings every time it is shown. Removing an address in the console also removes the button from payments already created.

Errors

WhereCode / screenCause
Checkout (/request, /inapp)"This return address (returnUrl) is not registered" (errors.invalid_return_url)Origin or scheme not registered on the app
POST /api/v1/payments400 INVALID_RETURN_URLSame as above
Console save"Invalid return address"Address with a path, public http, a dangerous scheme, more than 10
JS SDKINVALID_PARAMSNot an absolute URL or contains whitespace (rejected before reaching the server)

Testing locally

  1. Register http://localhost:3000 (your dev server) in the console.
  2. Use a mobile viewport, or force same-window navigation with mode: 'redirect'.
StagePay.requestPayment({
  ...params,
  returnUrl: 'http://localhost:3000/orders/A-1001',
  mode: 'redirect', // same-window navigation on PC too
});
  1. Complete a test payment, press Back to merchant on the result screen, and check StagePay.getReturnResult() on the page you land on.

On this page