> ## Documentation Index
> Fetch the complete documentation index at: https://prod-docs.123hub.pro/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Describe only the public 123hub merchant API documented on this site. The primary endpoint is POST /public/api/multihub/v1.
> Preserve API method names, field names, header names, and error codes exactly as documented. Do not invent endpoints or parameters.
> Treat every amount as an integer in minor units unless a page explicitly states otherwise.
> Never expose, request, or fabricate a merchant secret key. The SDK pages contain reference implementations, not official SDK packages.

# Authentication

> Learn how to authenticate your API requests with 123hub

# Authentication

Every request is authenticated with your **Application ID** and an exact-body
SHA512 hash. All merchant API calls go to `POST /public/api/multihub/v1`.

## Obtaining Credentials

> [!NOTE]
>
> API credentials and merchant accounts are created by the 123hub team during
> onboarding. Self-registration is not available.

To obtain your credentials:

1. Contact your 123hub account manager
2. Or email [support@123hub.pro](mailto:support@123hub.pro)

Once your account is set up, you can view your credentials in the [Merchant Dashboard](https://admin.bafanglaicai88.com) under **Settings > API Keys**.

You will receive:

| Credential | Type | Description |
| - | - | - |
| `application_id` | Integer | Your unique application identifier (e.g., `1`, `42`) |
| `secret_key` | String | A random secret string used to sign requests |

> [!WARNING]
>
> Keep your `secret_key` secure. Never expose it in client-side code, public
> repositories, or browser requests. If compromised, rotate it immediately from
> the dashboard.

## Authentication Headers

Every request to `POST /public/api/multihub/v1` must include the first two
headers below. For that endpoint the replay headers are optional, but when used
they must be sent together:

| Header | Value | Description |
| - | - | - |
| `X-Data-Application-Id` | Integer | Your application ID |
| `X-Data-Hash` | Hex string | SHA512 hash of `requestBody + secretKey` |
| `X-Data-Timestamp` | Unix seconds | Optional current request timestamp |
| `X-Data-Nonce` | String | Optional unique nonce for this request |

## How Signing Works

**1. Prepare the request body**

Serialize your request body as a JSON string. This is the exact string that
will be sent as the HTTP body.

**2. Compute the hash**

Concatenate the JSON string with your `secret_key` (no separator), then
compute the SHA512 hash of the result. Output as a **lowercase** hex string
(128 characters); an uppercase hash is rejected with `3000`.

```
hash = SHA512(jsonBody + secretKey)
```

**3. Send the request**

Send the two required headers. You may also include timestamp and nonce as a
pair, as shown below. On `/public/api/multihub/v1` the timestamp and nonce
are **not** part of the hash. Webhook resend also accepts the two-header
legacy mode; when you send both replay headers, the route-bound signing
rules in [Webhooks](https://prod-docs.123hub.pro/api-reference/webhooks.md) apply.

> [!WARNING]
>
> The JSON string you hash **must be byte-for-byte identical** to the JSON
> string sent as the HTTP body. If you use compact serialization (e.g.,
> `json.dumps(body, separators=(',',':'))` in Python), you must send that exact
> compact string as the request body. Differences in whitespace, key ordering,
> or formatting between the hashed string and the sent body will cause error
> `3000` (Authentication error).

## Replay Protection

`X-Data-Timestamp` and `X-Data-Nonce` are optional on `POST /public/api/multihub/v1`. When you
send them:

* Send both or neither. Only one of the two is rejected with `3000`.
* `X-Data-Timestamp` is the current Unix time in seconds (digits only) and must be within 5
  minutes of the server clock.
* `X-Data-Nonce` is up to 128 characters of `A–Z`, `a–z`, `0–9`, `.`, `_`, `:` and `-` (a UUID
  works). Each nonce can be used once per application; a repeat within 10 minutes is rejected with
  `3000`.
* They are checked separately from `X-Data-Hash` and are not included in it.

Every rejection above returns `3000 Authentication error` with HTTP `400`.

## Code Examples

```bash cURL theme={null}
# Step 1: Define your body
BODY='{"method":"gateway.ping","params":{}}'

# Step 2: Compute the SHA512 hash and replay proof
# Concatenate body + secret key, then hash
HASH=$(printf '%s%s' "${BODY}" "your_secret_key" | sha512sum | awk '{print $1}')
TIMESTAMP=$(date +%s)
NONCE=$(uuidgen | tr '[:upper:]' '[:lower:]')

# Step 3: Send the request
curl -X POST https://api.bafanglaicai88.com/public/api/multihub/v1 \
  -H "Content-Type: application/json" \
  -H "X-Data-Application-Id: 1" \
  -H "X-Data-Hash: ${HASH}" \
  -H "X-Data-Timestamp: ${TIMESTAMP}" \
  -H "X-Data-Nonce: ${NONCE}" \
  --data-binary "${BODY}"
```

```python Python theme={null}
import hashlib
import json
import time
import uuid
import requests

APP_ID = "1"
SECRET_KEY = "your_secret_key"
BASE_URL = "https://api.bafanglaicai88.com/public/api/multihub/v1"

# Step 1: Prepare the request body
body = {"method": "gateway.ping", "params": {}}
body_str = json.dumps(body, separators=(',', ':'))

# Step 2: Compute the SHA512 hash
hash_value = hashlib.sha512((body_str + SECRET_KEY).encode()).hexdigest()

# Step 3: Send the request
response = requests.post(BASE_URL, data=body_str, headers={
    "Content-Type": "application/json",
    "X-Data-Application-Id": APP_ID,
    "X-Data-Hash": hash_value,
    "X-Data-Timestamp": str(int(time.time())),
    "X-Data-Nonce": str(uuid.uuid4()),
}, timeout=(3.05, 30))

print(response.json())
```

```javascript Node.js theme={null}
const crypto = require("crypto");

const APP_ID = "1";
const SECRET_KEY = "your_secret_key";
const BASE_URL = "https://api.bafanglaicai88.com/public/api/multihub/v1";

// Step 1: Prepare the request body
const body = { method: "gateway.ping", params: {} };
const bodyStr = JSON.stringify(body);

// Step 2: Compute the SHA512 hash
const hash = crypto
  .createHash("sha512")
  .update(bodyStr + SECRET_KEY)
  .digest("hex");
const timestamp = Math.floor(Date.now() / 1000).toString();
const nonce = crypto.randomUUID();

// Step 3: Send the request
const response = await fetch(BASE_URL, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-Data-Application-Id": APP_ID,
    "X-Data-Hash": hash,
    "X-Data-Timestamp": timestamp,
    "X-Data-Nonce": nonce,
  },
  body: bodyStr,
  signal: AbortSignal.timeout(30000),
});

const data = await response.json();
console.log(data);
```

```php PHP theme={null}
<?php
$appId = '1';
$secretKey = 'your_secret_key';
$baseUrl = 'https://api.bafanglaicai88.com/public/api/multihub/v1';

// Step 1: Prepare the request body
$body = json_encode([
    'method' => 'gateway.ping',
    'params' => new stdClass(),
]);

// Step 2: Compute the SHA512 hash
$hash = hash('sha512', $body . $secretKey);
$timestamp = (string) time();
$nonce = bin2hex(random_bytes(16));

// Step 3: Send the request
$ch = curl_init($baseUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    "X-Data-Application-Id: $appId",
    "X-Data-Hash: $hash",
    "X-Data-Timestamp: $timestamp",
    "X-Data-Nonce: $nonce",
]);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);

$response = curl_exec($ch);
curl_close($ch);

echo $response;
```

```go Go theme={null}
package main

import (
	"bytes"
	"crypto/sha512"
	"encoding/hex"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
	"time"
)

func main() {
	appID := "1"
	secretKey := "your_secret_key"
	baseURL := "https://api.bafanglaicai88.com/public/api/multihub/v1"

	// Step 1: Prepare the request body
	body := map[string]interface{}{
		"method": "gateway.ping",
		"params": map[string]interface{}{},
	}
	bodyBytes, _ := json.Marshal(body)

	// Step 2: Compute the SHA512 hash
	hasher := sha512.New()
	hasher.Write(bodyBytes)
	hasher.Write([]byte(secretKey))
	hashHex := hex.EncodeToString(hasher.Sum(nil))
	timestamp := fmt.Sprintf("%d", time.Now().Unix())
	nonce := fmt.Sprintf("%d", time.Now().UnixNano())

	// Step 3: Send the request
	req, _ := http.NewRequest("POST", baseURL, bytes.NewBuffer(bodyBytes))
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("X-Data-Application-Id", appID)
	req.Header.Set("X-Data-Hash", hashHex)
	req.Header.Set("X-Data-Timestamp", timestamp)
	req.Header.Set("X-Data-Nonce", nonce)

	client := &http.Client{Timeout: 30 * time.Second}
	resp, _ := client.Do(req)
	defer resp.Body.Close()

	respBody, _ := io.ReadAll(resp.Body)
	fmt.Println(string(respBody))
}
```

## Verifying API Response Signatures

Successful API responses — and error responses returned after your application was authenticated —
include `X-Data-Hash`. Errors raised before authentication succeeds (for example `3000`, `3001`,
`3003`) are not signed. Verify the header with the same merchant API secret:

```
SHA512(rawResponseBody + apiSecret)
```

Use the raw response body bytes exactly as received. This check protects your integration from tampered responses and should be performed before trusting payment identifiers, balances, or status values.

## Verifying Webhook Signatures

When 123hub sends webhook notifications to your server, the request includes an `X-Data-Hash` header. New deliveries also include replay-protection metadata in `X-Webhook-Id`, `X-Webhook-Timestamp`, `X-Webhook-Nonce`, `X-Webhook-Signature-V2`, and `X-Webhook-Signature-V3`. Prefer `X-Webhook-Signature-V3` when present, and fall back to V2 or `X-Data-Hash` only for legacy deliveries.

`X-Webhook-Signature-V3` is `HMAC-SHA512(timestamp.nonce.webhookId.rawBody, webhook secret)`. `X-Data-Hash` remains `SHA512(webhookBody + webhook secret)`.

Webhook create/rotation reveals a dedicated webhook-only secret once. Store it
separately from the API credential; rotating one does not rotate the other.
Historical API-compatible webhook rows are blocked until explicit webhook secret
rotation. For a callback auto-created through `params.payment.webhook_url`, derive
the lowercase webhook secret with
`HMAC-SHA256(apiSecret, "quadpay:merchant-webhook-signing:v1")`, using the exact
API secret that authenticated that payment create. Test and production keys do
not cross; the resulting callback destination is scoped to that payment.
Per-payment `webhook_url` is temporarily unavailable — see
[Webhooks](https://prod-docs.123hub.pro/guides/webhooks.md).

```python Python — Verify Webhook theme={null}
import hashlib
import hmac

def verify_webhook(raw_body: bytes, signature: str, webhook_secret: str) -> bool:
    expected = hashlib.sha512(raw_body + webhook_secret.encode()).hexdigest()
    return hmac.compare_digest(expected, signature)  # constant-time comparison
```

```javascript Node.js — Verify Webhook theme={null}
const crypto = require("crypto");

function verifyWebhook(rawBody, signature, webhookSecret) {
  const expected = crypto
    .createHash("sha512")
    .update(Buffer.concat([Buffer.from(rawBody), Buffer.from(webhookSecret)]))
    .digest("hex");
  if (!/^[a-f0-9]{128}$/i.test(signature || "")) {
    return false;
  }
  return crypto.timingSafeEqual(
    Buffer.from(expected, "hex"),
    Buffer.from(signature, "hex"),
  );
}

function verifyWebhookV2(rawBody, signature, timestamp, webhookSecret) {
  const timestampMs = Date.parse(timestamp || "");
  if (
    !Number.isFinite(timestampMs) ||
    Math.abs(Date.now() - timestampMs) > 5 * 60 * 1000
  ) {
    return false;
  }
  const expected = crypto
    .createHash("sha512")
    .update(
      String(timestamp) + Buffer.from(rawBody).toString("utf8") + webhookSecret,
    )
    .digest("hex");
  if (!/^[a-f0-9]{128}$/i.test(signature || "")) {
    return false;
  }
  return crypto.timingSafeEqual(
    Buffer.from(expected, "hex"),
    Buffer.from(signature, "hex"),
  );
}

function verifyWebhookV3(
  rawBody,
  signature,
  timestamp,
  nonce,
  webhookId,
  webhookSecret,
) {
  const timestampMs = Date.parse(timestamp || "");
  if (!timestamp || !nonce || !webhookId || !Number.isFinite(timestampMs)) {
    return false;
  }
  if (Math.abs(Date.now() - timestampMs) > 5 * 60 * 1000) {
    return false;
  }
  const expected = crypto
    .createHmac("sha512", webhookSecret)
    .update(
      [timestamp, nonce, webhookId, Buffer.from(rawBody).toString("utf8")].join(
        ".",
      ),
    )
    .digest("hex");
  if (!/^[a-f0-9]{128}$/i.test(signature || "")) {
    return false;
  }
  return crypto.timingSafeEqual(
    Buffer.from(expected, "hex"),
    Buffer.from(signature, "hex"),
  );
}
```

```php PHP — Verify Webhook theme={null}
<?php
function verifyWebhook(string $rawBody, string $signature, string $webhookSecret): bool {
    $expected = hash('sha512', $rawBody . $webhookSecret);
    return hash_equals($expected, $signature);
}
```

```go Go — Verify Webhook theme={null}
import (
	"crypto/sha512"
	"crypto/subtle"
	"encoding/hex"
)

func verifyWebhook(rawBody []byte, signature string, webhookSecret string) bool {
	hasher := sha512.New()
	hasher.Write(rawBody)
	hasher.Write([]byte(webhookSecret))
	expected := hex.EncodeToString(hasher.Sum(nil))
	return subtle.ConstantTimeCompare([]byte(expected), []byte(signature)) == 1
}
```

> [!WARNING]
>
> Always verify webhook signatures before processing the payload. Use a
> constant-time comparison function (like `hash_equals` in PHP or
> `crypto.timingSafeEqual` in Node.js) to prevent timing attacks.

## Test Mode vs Production

> [!NOTE]
>
> Test and production requests use the **same API endpoint** and the same
> authentication mechanism. The environment is determined by which credentials
> you use.

* **Test credentials** identify an account-specific test environment and routes confirmed during onboarding
* **Production credentials** create real transactions with actual money movement
* Credentials whose environment does not match the merchant are rejected. Test
  payments select sandbox provider credentials only and never fall back to a
  production provider credential or endpoint.
* Webhooks are delivered in both environments for testing integrations
* All API responses follow the same format in both environments

## Key Scopes and IP Allowlist

Each API key carries scopes and, optionally, an IP allowlist and access policy:

| Method | Required scope (any of) |
| - | - |
| `payment.in`, `payment.out` | `payments.create` |
| `payment.status` | `payments.read`, `payments.view` |
| `payment.notification` | `webhooks.create`, `webhooks.update` |
| `balance.get` | `balance.read`, `balance.view` |
| `gateway.ping` | none |

* A key without the scope a payment method needs is rejected with `3000 Authentication error`
  (HTTP `400`), the same code as a bad signature.
* If the key has an IP allowlist (single addresses or CIDR ranges), requests from any other address
  are rejected with `3006`. A key without an allowlist accepts any address.
* If the key is limited to certain currencies or `service_id` routes, `payment.in` and
  `payment.out` outside them are rejected with `3008` (HTTP `403`).

## Rate Limits

API requests are rate-limited to protect the platform. Before authentication a high per-IP ceiling
applies; after authentication each application has protective per-method buckets for
`payment.in`, `payment.out`, `payment.status`, `payment.notification` and `balance.get`.

| Method | Default limit per application |
| - | - |
| `payment.in` | 60,000 requests / minute |
| `payment.out` | 60,000 requests / minute |
| `payment.status` | 30,000 requests / minute |
| `balance.get` | 6,000 requests / minute |
| `payment.notification` | 10 requests / minute |

Limits can be set per application; confirm your production profile during onboarding. Buckets are
counted per merchant, application and method — not per client IP.

> [!NOTE]
>
> If you exceed a limit, the response returns HTTP `429` with the standard API
> error envelope (`error.code` `1000`, message `Too many requests`) and a
> `Retry-After-*` header. Retry with backoff or contact support if you need a
> higher production throughput profile. A separate optional daily request limit
> per key returns `3009` (HTTP `429`) and resets at 00:00 UTC.

## Error Responses

Authentication errors are returned in the standard response envelope with HTTP 400:

| Code | Cause |
| - | - |
| `3001` | `X-Data-Application-Id` missing or not a positive integer |
| `3002` | `X-Data-Hash` missing or not a 128-character hex string |
| `3003` | Unknown application ID, or a key whose environment (test/production) does not match the merchant |
| `3005` | The merchant account is not active |
| `3006` | Request IP is not in the key's IP allowlist |
| `3000` | Hash mismatch, invalid or reused replay headers, or a key without the required scope |

Credential policy or merchant-ownership denials return HTTP `403` with code `3008`. An enforced credential daily-request limit returns HTTP `429` with code `3009`; its counter resets at UTC day rollover. DTO validation failures, including unknown fields rejected by strict validation, return code `9000` when request validation reaches the DTO layer. During deployments, readiness gating can return a non-envelope HTTP `503` before API handling starts.

```json Invalid Application ID theme={null}
{
  "success": false,
  "error": {
    "code": 3003,
    "message": "The app does not exist",
    "details": null,
    "context": null
  },
  "request_id": "req_a1b2c3d4",
  "processing_time": 2
}
```

```json Invalid Hash Signature theme={null}
{
  "success": false,
  "error": {
    "code": 3000,
    "message": "Authentication error",
    "details": null,
    "context": null
  },
  "request_id": "req_e5f6g7h8",
  "processing_time": 1
}
```

## Best Practices

> [card] Use Environment Variables
>
> Store your `application_id` and `secret_key` in environment variables, never
> in source code

> [card] Rotate Keys Regularly
>
> Regenerate your secret key periodically from the dashboard for enhanced
> security

> [card] Verify Webhooks
>
> Always verify the `X-Data-Hash` header on incoming webhooks before
> processing

> [card] Monitor Usage
>
> Track API usage in the dashboard to detect anomalies and stay within rate
> limits


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.