> ## 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.

# SDKs Overview

> Code examples and client libraries for integrating with the 123hub API

# SDKs & Code Examples

We provide example client implementations in popular programming languages to help you integrate with the 123hub API. These are reference implementations, not official SDK packages -- you can adapt them to your needs or use them as-is.

> [!NOTE]
>
> Each client authenticates with your **Application ID** and an exact-body SHA-512 hash at
> `POST /public/api/multihub/v1`.

## Available Examples

> [card] [Python](https://prod-docs.123hub.pro/sdks/python.md)
>
> Client class using `requests` and `hashlib`

> [card] [Node.js](https://prod-docs.123hub.pro/sdks/nodejs.md)
>
> Client class using `crypto` and native `fetch`

> [card] [PHP](https://prod-docs.123hub.pro/sdks/php.md)
>
> Client class using cURL and `hash('sha512', ...)`

> [card] [Go](https://prod-docs.123hub.pro/sdks/go.md)
>
> Client struct using `crypto/sha512` and `net/http`

## How It Works

Every API call follows the same pattern regardless of the programming language:

**1. Build the request body**

Construct a JSON body containing `method` (the operation), an optional `service_id`, and a
`params` object.

**2. Sign the request**

Serialize the body once, compute the lowercase hex SHA-512 of those exact bytes followed by your
secret key, and send it as `X-Data-Hash`. Send the same bytes you hashed.

**3. Send the POST request**

POST to `/public/api/multihub/v1` with your exact configured `X-Data-Application-Id`.

**4. Verify and handle the response**

Verify the response `X-Data-Hash` before trusting the body (see
[Response signature](#response-signature)). Successful responses return HTTP 200. Most errors
return HTTP 400; some use 403, 404, 409, 429 or 5xx (see [Error codes](https://prod-docs.123hub.pro/errors/error-codes.md)).
Check the `success` boolean field to determine if the operation succeeded, and handle
`error.code` / `error.message` when it did not.

## Authentication

Every request requires `X-Data-Application-Id` and `X-Data-Hash`:

| Header | Required | Description |
| - | - | - |
| `X-Data-Application-Id` | yes | Your application ID |
| `X-Data-Hash` | yes | Lowercase hex `sha512(exactBody + secretKey)` |
| `X-Data-Timestamp` | optional | Current Unix time in seconds; must be within 5 minutes of server time |
| `X-Data-Nonce` | optional | Unique value per request, up to 128 characters from `A-Z a-z 0-9 . _ : -` |

Send `X-Data-Timestamp` and `X-Data-Nonce` together or not at all — one without the other is
rejected, and so is a reused nonce. They are not part of the `X-Data-Hash` input.

> [!WARNING]
>
> Never expose your secret key in client-side code, logs, or version control. Always store it in
> environment variables or a secrets manager.

### Environment Variables

Store your credentials securely:

```bash Linux/macOS theme={null}
export PAYMENT_API_APP_ID="1"
export PAYMENT_API_SECRET_KEY="your_secret_key"
```

```powershell Windows PowerShell theme={null}
$env:PAYMENT_API_APP_ID = "1"
$env:PAYMENT_API_SECRET_KEY = "your_secret_key"
```

```env .env file theme={null}
PAYMENT_API_APP_ID=1
PAYMENT_API_SECRET_KEY=your_secret_key
```

## API Methods

Method-based routing replaces traditional REST endpoints. You specify the operation in the `method` field of the request body:

| Method | Description |
| - | - |
| `gateway.ping` | Health check / connectivity test |
| `payment.in` | Create a deposit (pay-in) |
| `payment.out` | Create a withdrawal (payout) |
| `payment.status` | Check payment status by identifiers |
| `payment.notification` | Re-send a webhook for an existing payment |
| `balance.get` | Retrieve account balances |

## Request Format

Every request follows this structure:

```json theme={null}
{
  "method": "payment.in",
  "service_id": 14701,
  "params": {
    "payment": {
      "identifiers": { "c_id": "12345" },
      "amount": { "value": 10000, "currency": "INR" },
      "description": "Order #12345",
      "payer": { "email": "customer@example.com" }
    }
  }
}
```

## Response Envelope

Every response uses a consistent envelope:

```json Success (HTTP 200) theme={null}
{
  "success": true,
  "result": { ... },
  "request_id": "abc-123",
  "processing_time": 42
}
```

When an error occurs (HTTP 400 in this example):

```json Error (HTTP 400) theme={null}
{
  "success": false,
  "error": {
    "code": 1005,
    "message": "Invalid request format",
    "details": {
      "description": "missing required properties including: 'service_id'. Path: $"
    },
    "context": null
  },
  "request_id": "abc-456",
  "processing_time": 3
}
```

## Response Signature

Responses are signed with the same secret: the response `X-Data-Hash` header is the lowercase hex
SHA-512 of the exact raw response body followed by your secret key. Every example client checks it
with a constant-time comparison before parsing the body and raises
`response signature verification failed` on a mismatch.

* Successful responses are always signed; treat an unsigned success as untrusted.
* Errors returned before authentication completes (for example `3000`, `3001`, `3003` or `3006`)
  carry no `X-Data-Hash` and are returned as-is.
* A `503` returned before authentication uses a different body (`statusCode`, `message`,
  `timestamp`) without `success`; the example clients raise an error for it.

## Common Pattern Across All SDKs

Regardless of language, every SDK example follows this pseudocode:

Payment status handling should treat `success`, `error`, `canceled`, `declined`, `refunded`, and `partially_refunded` as final statuses for polling loops. Handle `refunded` and `partially_refunded` as refund outcomes, not as new successful order payments.

```
function send(body):
    body_string = json_serialize(body)                  # serialize once
    hash = lowercase_hex(sha512(utf8(body_string + secret_key)))
    response = http_post(BASE_URL + "/public/api/multihub/v1",
        body_string,                                    # send exactly the bytes you hashed
        headers={
            "Content-Type": "application/json",
            "X-Data-Application-Id": app_id,
            "X-Data-Hash": hash,
            "X-Data-Timestamp": unix_seconds_now(),     # optional pair: both or neither,
            "X-Data-Nonce": random_unique_string(),     # not part of the hash
        })
    received = response.headers["X-Data-Hash"]          # may be absent
    if received is present:
        expected = lowercase_hex(sha512(response.raw_body_bytes + utf8(secret_key)))
        if not constant_time_equal(expected, lowercase(received)):
            raise error("response signature verification failed")
    result = parse_json(response.raw_body_bytes)
    if result has no boolean "success":                 # e.g. a 503 before authentication
        raise error(response.status)
    if received is absent and result.success:
        raise error("response signature verification failed")
    return result                                       # unsigned pre-auth errors as-is
```

## Community SDKs

If you have built an SDK or wrapper for the 123hub API, we would love to feature it here. Contact us at [support@123hub.pro](mailto:support@123hub.pro).

## Need Help?

> [card] [API Reference](https://prod-docs.123hub.pro/api-reference/overview.md)
>
> Complete API documentation

> [card] [Support](mailto:support@123hub.pro)
>
> Contact developer support


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