Build an app
Overview
An app is your software that serves many merchants, such as cashier software, an online store platform, delivery or accounting. A merchant installs your app with one click and chooses which scopes to grant it. You call the API for every merchant with one credential and name the merchant in the TapPay-Merchant-Id header.
Before you begin
Register the app
First enable TapPay for your Business in gate-hub: open My businesses, choose your Business and enable TapPay under Apps. Enabling is enough. Send a request to join TapPay only if you also want to accept payments. If TapPay is not enabled, sign-in fails with GHB-005.
Sign in to the merchant portal with gate-hub. You do not need to be a TapPay merchant, and a Business owned by a person works too. Open Developers › My apps and click Create app. Only the owner (OWNER) or an admin (ADMIN) of the Business can create apps and issue keys.
Fill in the app name, the category, the scopes you need, the redirect URIs and the webhook URL. The category is cashier software, online store, delivery, accounting or other. Ask only for the scopes you use, for example payments:write or commerce:write. To register cashiers with terminals:write, also ask for terminals:read, because you find the merchant’s terminal IDs with GET /api/v1/terminals. Apps never get payouts:write or split:write, because these move money out of the merchant’s account. Asking for them returns VAL-001. Each redirect URI starts with https://, and you can add up to 5.
Prepare the sandbox
A new app works in the sandbox first. On the app page, click Get test keys in the sandbox, then Issue keys. You get a Client ID that starts with app_test_ and a Client secret. The Client secret is shown only once, so store it on your server. In Test in sandbox, click Install to install the app on your test merchant. The test merchant’s ID is shown there.
Test keys work only with the sandbox API (https://sandbox-api.tappay.mn). In the shell, set APP_CLIENT_ID, APP_CLIENT_SECRET and MERCHANT_ID (the test merchant’s ID). The SDKs cannot sign in with app credentials yet, so the examples below call the API over HTTP.
Steps
Get an access token
Send your Client ID and Client secret to POST /api/v1/oauth/token with grant_type set to client_credentials. The response has an access_token that starts with apt_ and expires_in of 3600 seconds. Get a new token before it expires. The token belongs to the app, not to one merchant. Set it in the shell as ACCESS_TOKEN.
You can also sign every request with HMAC instead of a token. Then send your Client ID in the TapPay-App-Key-Id header and the signature in TapPay-Timestamp, TapPay-Nonce and TapPay-Signature. Sign with the signing secret from the app page, in the same way as API key + HMAC.
curl -sS -X POST "https://api.tappay.mn/api/v1/oauth/token" \
-H "TapPay-Version: 2026-09-27" \
-H "Content-Type: application/json" \
-d '{"grant_type":"client_credentials","client_id":"'"$APP_CLIENT_ID"'","client_secret":"'"$APP_CLIENT_SECRET"'"}'Call the API for a merchant
Send the token in the Authorization: Bearer header and the merchant’s ID in the TapPay-Merchant-Id header on every call. Start with your test merchant. This example reads the merchant’s latest payments and needs payments:write. Your app may use only the scopes that it asked for and that the merchant granted. For a terminal route, name the terminal in the request.
curl -sS "https://api.tappay.mn/api/v1/payments?limit=10" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "TapPay-Version: 2026-09-27" \
-H "TapPay-Merchant-Id: $MERCHANT_ID"Let merchants install the app
Copy the Install link from the app page and put it on your site. It is the /connect?app_id=…&redirect_uri=… address of the merchant portal. When the install starts from your site, add a random state and compare it when the merchant comes back. You may also add a PKCE code_challenge with code_challenge_method=S256.
The merchant signs in, sees your app and its scopes, and approves. The merchant may remove some scopes. TapPay then sends the merchant to redirect_uri?code=…&state=…. If the merchant declines, you get error=access_denied instead of code.
Exchange the code on your server for the merchant’s merchantId and the granted scopes. This call does not need TapPay-Merchant-Id. The code works for 10 minutes and only once. If you sent a code_challenge, also send codeVerifier. Store merchantId and use it on later calls.
curl -sS -X POST "https://api.tappay.mn/api/v1/apps/install/exchange" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "TapPay-Version: 2026-09-27" \
-H "Idempotency-Key: $(openssl rand -hex 16)" \
-H "Content-Type: application/json" \
-d '{"code":"'"$INSTALL_CODE"'"}'Receive webhooks
Your app has one webhook endpoint for all the merchants that installed it. The TapPay-Merchant-Id header and the merchantId in the body tell you which merchant an event is for. The body is small: id, type, objectId and merchantId. You get only the events that the merchant’s granted scopes cover.
Verify the signature as in the Webhooks guide, with your app’s webhook secret. Get the secret on the app page with Issue new secret. It starts with whsec_ and is shown only once. After you issue a new secret, the old one keeps working for 24 hours.
Your app also gets app.installed, app.uninstalled and app.scopes_updated, and their objectId is the merchant’s ID. After app.uninstalled, your access to that merchant is closed, and the cashiers your app registered for that merchant are closed too. A closed cashier never opens again. If the merchant installs your app again, register the cashiers again.
# Run this in your webhook handler with the raw body and the headers you received.
verify_webhook() { # raw_body timestamp nonce signatures secret path
local body_hash canonical expected now sig result=invalid
body_hash=$(printf '%s' "$1" | openssl dgst -sha256 -hex | awk '{print $NF}')
canonical=$(printf 'POST\n%s\n%s\n%s\n%s' "$6" "$2" "$3" "$body_hash")
expected="v1=$(printf '%s' "$canonical" | openssl dgst -sha256 -hmac "$5" -binary | openssl base64 -A)"
now=$(date +%s)
if [ $(( now > $2 ? now - $2 : $2 - now )) -le 300 ]; then
for sig in $(printf '%s' "$4" | tr ',' ' '); do
[ "$sig" = "$expected" ] && result=valid
done
fi
echo "$result"
}
if [ "$(verify_webhook "$RAW_BODY" "$TAPPAY_TIMESTAMP" "$TAPPAY_NONCE" "$TAPPAY_SIGNATURE" "$APP_WEBHOOK_SECRET" "/webhooks/tappay")" = valid ]; then
echo "event for merchant $TAPPAY_MERCHANT_ID"
fiVerify
When you install the app on your test merchant, your webhook endpoint gets app.installed. The install count under Installed merchants on the app page goes up by one. A call with the token and TapPay-Merchant-Id returns the merchant’s data. Pay a test payment with the simulator and check that its event reaches your webhook endpoint.
Common mistakes
- Calling without
TapPay-Merchant-Id, or with a value that is not a merchant ID. TapPay returns400 APP-005. - Calling for a merchant that has not installed the app or has removed it. TapPay returns
403 APP-004and does not say whether the merchant exists. - Calling a route whose scope the merchant did not grant. TapPay returns
403 AUTH-058. - Exchanging a used or expired
code, or a wrongcodeVerifier. TapPay returns400 AUTH-075. - Using a redirect URI that is not registered on the app. The merchant sees the
APP-003error and is not sent back. - Using a wrong Client ID or Client secret, or a test Client ID in production. The token call returns
401 KEY-009. - Calling the code exchange with a merchant’s API key. TapPay returns
403 AUTH-058, because this route accepts only app credentials.
Next steps
Submit for review and publish
When the app works in the sandbox, click Submit for review on the app page. A TapPay reviewer checks this list:
- The logo, name, description and category are filled in.
- The app asks only for the scopes it uses.
- The app was installed in the sandbox and took a payment.
- The app verifies the webhook signature.
- The privacy policy and support links are filled in.
- The app explains how it deletes the merchant’s data when the merchant removes it.
To publish, your Business needs KYB level B1 or higher on gate-hub. A Business owned by a person needs no KYB level: gate-hub activates such a Business only after its owner reaches KYC level L2. You also sign a partner contract with TapPay, and a TapPay staff member contacts you. After approval you get production keys, and merchants see your app in Connections.
If you change the name, scopes or redirect URIs of a published app, the change becomes a new version that is reviewed again. Merchants keep using the current version until it is approved. If you add scopes, each merchant approves them again and keeps the old scopes until then.
Read more
See Get an access token, Exchange an app install code and Uninstall the app from a merchant for every field. Read the Webhooks guide and Events for event types.