Skip to content

Exchange a connection code

View as Markdown

Your plugin server exchanges the one-time code from the TapPay Connect redirect, with its PKCE verifier, for a secret key, a signing secret and a webhook secret. TapPay returns the secrets only once, so store them right away.

Changes in 2026-09-27

POST /api/v1/connect/tokenSince 2026-09-27

Authentication

Secret key (Bearer)

Request body

NameTypeRequiredValuesDescription
codestringyes
codeVerifierstringyes
redirectUristringyes

Response 200

NameTypeRequiredValuesDescription
successbooleanyestrue
dataobjectyes
data.secretKeystringyes
data.signingSecretstringyes
data.webhookSecretstringyes
data.webhookEndpointIdstring (uuid)yes
data.connectionIdstring (uuid)yes
data.clientSystemIdstring (uuid)yes
data.merchantIdstring (uuid)yes
data.merchantobjectyes
data.merchant.idstring (uuid)yes
data.merchant.namestringyes
data.gateHubBusinessIdstring | nullyes
data.terminalIdstring | nullyes
data.environmentstringyesSANDBOX, PRODUCTION
data.stickerSecretstring | nullyes

Errors

CodeStatusMessage
VAL-001400The request failed validation.
AUTH-075400The connection code is invalid, expired or already used.
AUTH-077409The maximum number of active connections has been reached.
BIZ-005403The merchant account is not in a state that allows this request.
BIZ-013404The terminal was not found.
EVT-002422The webhook endpoint limit has been reached.
EVT-004422The webhook endpoint URL must use HTTPS.
curl -sS -X POST "https://api.tappay.mn/api/v1/connect/token" \
  -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 '{"code":"CONNECT_CODE","codeVerifier":"PKCE_CODE_VERIFIER","redirectUri":"https://shop.example.com/tappay/callback"}'
import { TapPay } from '@tappay-mn/node';

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const result = await tappay.connect.exchangeCode({
  body: {
    code: 'CONNECT_CODE',
    codeVerifier: 'PKCE_CODE_VERIFIER',
    redirectUri: 'https://shop.example.com/tappay/callback',
  },
});
console.log(JSON.stringify(result));
<?php
require 'vendor/autoload.php';

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$result = $tappay->connect->exchangeCode([
    'body' => [
        'code' => 'CONNECT_CODE',
        'codeVerifier' => 'PKCE_CODE_VERIFIER',
        'redirectUri' => 'https://shop.example.com/tappay/callback',
    ],
]);
echo json_encode($result);
import json
import tappay

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
result = client.connect.exchange_code({
    "body": {
        "code": "CONNECT_CODE",
        "codeVerifier": "PKCE_CODE_VERIFIER",
        "redirectUri": "https://shop.example.com/tappay/callback",
    },
})
print(json.dumps(result))
{
  "success": true,
  "data": {
    "secretKey": "sk_test_YOUR_SECRET_KEY",
    "signingSecret": "YOUR_SIGNING_SECRET",
    "webhookSecret": "YOUR_WEBHOOK_SECRET",
    "webhookEndpointId": "0192f8a4-1b2c-7d3e-8f40-5a6b7c8d9f0c",
    "connectionId": "0192f8a4-1b2c-7d3e-8f40-5a6b7c8d9f0d",
    "clientSystemId": "0192f8a4-1b2c-7d3e-8f40-5a6b7c8d9f0d",
    "merchantId": "YOUR_MERCHANT_ID",
    "merchant": {
      "id": "YOUR_MERCHANT_ID",
      "name": "Sandbox Cafe"
    },
    "gateHubBusinessId": null,
    "terminalId": null,
    "environment": "SANDBOX",
    "stickerSecret": null
  }
}