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

# Authentication

> Learn how to authenticate and secure API requests using Paytring.

## V2 API authentication

Requests to `/api/v2/` use HTTP Basic Auth. Use your API key as the username and your API secret as the password.

```http theme={null}
Authorization: Basic <Base64(API_KEY:API_SECRET)>
Content-Type: application/json
```

Encode the complete `API_KEY:API_SECRET` string as Base64. Use the `Basic` prefix, not `Bearer`. With cURL, `--user` creates this header for you:

```bash theme={null}
curl --request POST 'https://api.paytring.com/api/v2/order/fetch/receipt' \
  --user "${PAYTRING_API_KEY}:${PAYTRING_API_SECRET}" \
  --header 'Content-Type: application/json' \
  --data '{"id":"DEMO202611030001"}'
```

V2 does not require `key` or `hash` in the request body. Omit both fields. You do not need to calculate a request hash or send `"hash": "none"`.

> [!WARNING]
>
> Make authenticated requests from your backend over HTTPS. Base64 is encoding, not encryption. Do not expose your API secret or Authorization header in browser code, mobile apps, URLs, or logs.

## Migrating collection requests from V1

| V1 endpoint | V2 endpoint |
| - | - |
| `POST /api/v1/order/create` | [`POST /api/v2/order/create`](https://docs.paytring.com/api-reference/endpoint/order) |
| `POST /api/v1/order/fetch/receipt` | [`POST /api/v2/order/fetch/receipt`](https://docs.paytring.com/api-reference/endpoint/fetch-order-by-receipt-id) |

For these methods, change the endpoint version, add Basic Auth, and remove the body `key` and `hash`. The business parameters and success response formats stay the same.

* Create an order with `receipt_id`. Fetch that order by sending the same receipt ID as `id`.
* Amounts remain integer minor units, such as paise for INR. The create response's `url` remains Base64-encoded. Decode it before redirecting the customer.
* Existing V1 orders can be fetched through V2 for the same business account and environment. Use the matching test or live credentials.
* Existing active API credentials and valid `pg_pool_id` values can be reused. Migrating to V2 does not require regenerating them or changing gateway configuration.

### Collection webhooks

Changing the order API version does not itself change your configured collection webhooks. Keep webhook verification separate from API request authentication. Basic Auth does not replace webhook signature verification, and the V1 request-hashing example below is not a webhook-verification recipe.

Collection senders can use different payload and hash inputs, including variants with `order_id`. Confirm the payload and signing contract for your configured collection sender with [support](mailto:support@paytring.com) before changing your webhook handler. A payout webhook contract does not establish the collection webhook format.

Use an authenticated order fetch to confirm `order_status`, the receipt ID, amount, and currency against your records before marking a payment successful. Receiving a webhook alone does not establish payment success.

## V1 request hashing

V1 requests still send `key` and `hash` in the JSON body. The following algorithm applies to V1 API requests, not V2 requests or webhook payloads.

1. Exclude `hash` and sort the request parameters by key.
2. Exclude nested objects and arrays from the hash input.
3. Convert scalar values to strings. Represent `true` as `1`, and `false` or `null` as an empty string.
4. Join those values with `|`, then append `|` and the API secret.
5. Compute the SHA-512 digest as lowercase hexadecimal and send it as `hash`.

This Node.js example hashes a V1 collection request on your backend:

```javascript theme={null}
import { createHash } from 'node:crypto';

const params = {
  amount: 10000,
  callback_url: 'https://merchant.example.com/payment/callback',
  cname: 'Test Customer',
  currency: 'INR',
  email: 'customer@example.com',
  key: process.env.PAYTRING_API_KEY,
  phone: '9999999999',
  receipt_id: 'DEMO202611030001',
  notes: { udf1: 'Example order' },
};

const values = Object.keys(params)
  .filter((key) => key !== 'hash' && (params[key] === null || typeof params[key] !== 'object'))
  .sort()
  .map((key) => {
    const value = params[key];
    if (value === true) return '1';
    if (value === false || value === null) return '';
    return String(value);
  });

params.hash = createHash('sha512')
  .update(`${values.join('|')}|${process.env.PAYTRING_API_SECRET}`)
  .digest('hex');
```


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