Take payments in a mobile app
Overview
Your iOS or Android app takes payments through your own server, and only the server calls TapPay. The app opens the TapPay payment page or a wallet app, and the customer pays there. When the app opens again, it asks your server for the result.
Before you begin
Your key needs the checkout:write scope for the payment page, and payments:write for wallet buttons. You use your secret key, shown below as sk_test_YOUR_SECRET_KEY. Use a sandbox key while you build.
The secret key stays on your server. The app talks only to your server, and your server calls TapPay. There is no mobile SDK.
App ──► your server ──► TapPay
App ◄── your server ◄── webhook or GET
Register a return address for your app: an app scheme such as myshop://paid, or a universal link. TapPay sends the customer there after the payment, and the app opens.
Steps
Path 1: create a checkout session
The TapPay payment page shows every channel of the payment in one place. Your server creates a checkout session and sets returnUrl and cancelUrl to your app scheme or universal link. Send the url from the response to the app. The app opens it in the system browser, or in an in-app browser: SFSafariViewController on iOS and Custom Tabs on Android. If you open it in your own WebView, use an app scheme, because an https return address would open in the system browser.
curl -sS -X POST "https://api.tappay.mn/api/v1/checkout/sessions" \
-H "Authorization: Bearer sk_test_YOUR_SECRET_KEY" \
-H "TapPay-Version: 2026-09-27" \
-H "Idempotency-Key: $(openssl rand -hex 16)" \
-H "Content-Type: application/json" \
-d '{"terminalId":"YOUR_TERMINAL_ID","amount":"1000","description":"Order 1","orderId":"order-'"$(uuidgen)"'","returnUrl":"myshop://paid","cancelUrl":"myshop://cancel"}'import { TapPay } from '@tappay-mn/node';
const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const checkoutSession = await tappay.checkoutSessions.create({
body: {
terminalId: 'YOUR_TERMINAL_ID',
amount: '1000',
description: 'Order 1',
orderId: `order-${crypto.randomUUID()}`,
returnUrl: 'myshop://paid',
cancelUrl: 'myshop://cancel',
},
});
console.log(JSON.stringify(checkoutSession));<?php
require 'vendor/autoload.php';
use TapPay\TapPay;
$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$checkoutSession = $tappay->checkoutSessions->create([
'body' => [
'terminalId' => 'YOUR_TERMINAL_ID',
'amount' => '1000',
'description' => 'Order 1',
'orderId' => 'order-' . vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex(random_bytes(16)), 4)) . '',
'returnUrl' => 'myshop://paid',
'cancelUrl' => 'myshop://cancel',
],
]);
echo json_encode($checkoutSession);import json
import uuid
import tappay
client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
checkout_session = client.checkout_sessions.create({
"body": {
"terminalId": "YOUR_TERMINAL_ID",
"amount": "1000",
"description": "Order 1",
"orderId": "order-" + str(uuid.uuid4()) + "",
"returnUrl": "myshop://paid",
"cancelUrl": "myshop://cancel",
},
})
print(json.dumps(checkout_session))Path 2: create an invoice with wallet links
Use this path to show wallet buttons on your own screen. Your server creates an invoice with expand[]=walletLinks and the same returnUrl and cancelUrl. Each item of walletLinks has an appName, a logoUrl that can be null, and a link. The app shows a button for each wallet and opens its link with the system: open on iOS, ACTION_VIEW on Android. After the payment the wallet goes back through the TapPay page, and the page sends the customer on to your returnUrl or cancelUrl.
curl -sS -g -X POST "https://api.tappay.mn/api/v1/invoices?expand[]=walletLinks" \
-H "Authorization: Bearer sk_test_YOUR_SECRET_KEY" \
-H "TapPay-Version: 2026-09-27" \
-H "Idempotency-Key: $(openssl rand -hex 16)" \
-H "Content-Type: application/json" \
-d '{"terminalId":"YOUR_TERMINAL_ID","amount":1000,"description":"Order 1","orderId":"order-'"$(uuidgen)"'","returnUrl":"myshop://paid","cancelUrl":"myshop://cancel"}'import { TapPay } from '@tappay-mn/node';
const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const invoice = await tappay.invoices.create({
query: { expand: ['walletLinks'] },
body: {
terminalId: 'YOUR_TERMINAL_ID',
amount: 1000,
description: 'Order 1',
orderId: `order-${crypto.randomUUID()}`,
returnUrl: 'myshop://paid',
cancelUrl: 'myshop://cancel',
},
});
console.log(JSON.stringify(invoice));<?php
require 'vendor/autoload.php';
use TapPay\TapPay;
$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$invoice = $tappay->invoices->create([
'query' => ['expand' => ['walletLinks']],
'body' => [
'terminalId' => 'YOUR_TERMINAL_ID',
'amount' => 1000,
'description' => 'Order 1',
'orderId' => 'order-' . vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex(random_bytes(16)), 4)) . '',
'returnUrl' => 'myshop://paid',
'cancelUrl' => 'myshop://cancel',
],
]);
echo json_encode($invoice);import json
import uuid
import tappay
client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
invoice = client.invoices.create({
"expand": ["walletLinks"],
"body": {
"terminalId": "YOUR_TERMINAL_ID",
"amount": 1000,
"description": "Order 1",
"orderId": "order-" + str(uuid.uuid4()) + "",
"returnUrl": "myshop://paid",
"cancelUrl": "myshop://cancel",
},
})
print(json.dumps(invoice))Pay in the sandbox
Let the simulator pay the invoice for the customer, as if they paid in a wallet. This works only with a sandbox key.
curl -sS -X POST "https://api.tappay.mn/api/v1/sandbox/intents/INTENT_ID/simulate" \
-H "Authorization: Bearer sk_test_YOUR_SECRET_KEY" \
-H "TapPay-Version: 2026-09-27" \
-H "Idempotency-Key: $(openssl rand -hex 16)" \
-H "Content-Type: application/json" \
-d '{"channel":"QR","outcome":"SUCCEEDED"}'import { TapPay } from '@tappay-mn/node';
const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const result = await tappay.sandbox.simulateIntent({ id: 'INTENT_ID', body: { channel: 'QR', outcome: 'SUCCEEDED' } });
console.log(JSON.stringify(result));<?php
require 'vendor/autoload.php';
use TapPay\TapPay;
$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$result = $tappay->sandbox->simulateIntent(['id' => 'INTENT_ID', 'body' => ['channel' => 'QR', 'outcome' => 'SUCCEEDED']]);
echo json_encode($result);import json
import tappay
client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
result = client.sandbox.simulate_intent({"id": "INTENT_ID", "body": {"channel": "QR", "outcome": "SUCCEEDED"}})
print(json.dumps(result))Confirm on your server
When the app opens again, it asks your server for the result. Your server reads the invoice and checks that its status is PAID. For path 1, read the session and check that its status is COMPLETE, as in the checkout guide. Then the server tells the app whether the order is paid.
curl -sS "https://api.tappay.mn/api/v1/invoices/INVOICE_ID" \
-H "Authorization: Bearer sk_test_YOUR_SECRET_KEY" \
-H "TapPay-Version: 2026-09-27"import { TapPay } from '@tappay-mn/node';
const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const invoice = await tappay.invoices.retrieve({ id: 'INVOICE_ID' });
console.log(JSON.stringify(invoice));<?php
require 'vendor/autoload.php';
use TapPay\TapPay;
$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$invoice = $tappay->invoices->retrieve(['id' => 'INVOICE_ID']);
echo json_encode($invoice);import json
import tappay
client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
invoice = client.invoices.retrieve({"id": "INVOICE_ID"})
print(json.dumps(invoice))Verify
For a faster signal, handle the payment.succeeded event on your webhook endpoint, as described in the webhooks guide. Your server stores the result, and the app reads it from your server. Opening the app at myshop://paid is not proof of payment, because anyone can open that address.
Code in the app
These short examples open TapPay from the app and handle the return. Replace refreshOrderFromServer with a call to your own server.
import SafariServices
import SwiftUI
import UIKit
// Path 1: open the checkout url in an in-app browser.
func openCheckout(_ url: URL, from viewController: UIViewController) {
viewController.present(SFSafariViewController(url: url), animated: true)
}
// Path 2: open a wallet link with the system, never in a WebView.
func openWallet(_ link: URL) {
UIApplication.shared.open(link)
}
// myshop://paid opens the app again. Do not trust it: ask your server.
struct ShopApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.onOpenURL { _ in refreshOrderFromServer() } // also dismiss the SFSafariViewController you presented
}
}
}
import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.browser.customtabs.CustomTabsIntent
// Path 1: open the checkout url in a Custom Tab.
fun openCheckout(context: Context, url: String) {
CustomTabsIntent.Builder().build().launchUrl(context, Uri.parse(url))
}
// Path 2: open a wallet link with the system, never in a WebView.
fun openWallet(context: Context, link: String) {
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link)))
}
// myshop://paid opens your activity again (an intent-filter in AndroidManifest.xml).
// Do not trust it: ask your server.
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
refreshOrderFromServer()
}
Common mistakes
- Putting the secret key in the app. Anyone can take it out of the app package, so keep it on your server.
- Trusting the return address. Mark the order as paid only after your server reads the session or the invoice, or gets the webhook.
- Opening a wallet link in a WebView. Open it with the system, so that the wallet app opens and its return reaches your app.
- Opening the checkout
urlin your own WebView with anhttpsreturn address. The return then opens in the system browser instead of your app, so use an app scheme. - Giving an
http://return address in production. TapPay answers400, so usehttps://or an app scheme.
Next steps
Read the rules for return addresses in the checkout guide, and listen for payments with the webhooks guide. See every field in Create a checkout session, Create an invoice and Retrieve an invoice.