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

# Payouts Best Practices

> Check the best practices when integrating RazorpayX payouts in Malaysia.

Available in
🇲🇾 Malaysia

> [!NOTE]
>
> RazorpayX payouts in Malaysia are available on request. RazorpayX is not enabled on Razorpay Curlec accounts by default. To enquire about RazorpayX for your business, [contact our Support team](https://curlec.com/docs/payments/dashboard/support.md).

The following table lists the best practices for integrating RazorpayX payouts:

| Guideline | Description |
| - | - |
| [API guidelines](#api-guidelines) | Guidelines to follow when making API calls. |
| [API key guidelines](#api-key-guidelines) | Save and manage your API keys. |
| [Types of Payout API](#types-of-payout-apis) | Select how you want to create payouts using APIs. |
| [Payout states](#payout-states) | Best way to check the payout state. |
| [Payout Status Details](#payout-status-details) | Provides additional details about each payout's status. |
| [Fund account validation](#fund-account-validation) | Check the beneficiary before you pay. |
| [Approvals](#approvals) | Reduce human error when creating payouts. |
| [Queued payouts](#queued-payouts) | Keep payouts waiting for balance instead of losing them. |
| [Handling 5XX Errors & Idempotency](#handling-5xx-errors-and-idempotency) | Safely retry the same request without performing the same action more than once. |
| [IP Allowlisting](#ip-allowlisting) | API calls are accepted only from allowlisted IPs. |

## API Guidelines

Guidelines to follow while making API calls:

* Make all API calls from your server. Live calls work only from your allowlisted server IPs.
* Pass your RazorpayX account number in the `account_number` parameter of the Payout API and the Composite Payout API. This is the 16-digit number that starts with 818181, shown on the RazorpayX Dashboard.
  * **DO NOT** pass your beneficiary's account number here.
* Send `currency` as `MYR` and amounts in sen. `100000` is RM 1,000.00.
* Send `mode` in upper case: `IBFT` for a bank account or `DUITNOW` for a DuitNow proxy.
* We recommend using your internal transaction ID as the `reference_id` value in a Payout API request. It can be up to 40 characters.
* A webhook can be sent more than once and events can arrive out of order. Deduplicate webhooks using the payout ID and the payout status.

### API Key Guidelines

* The owner of your RazorpayX account generates the API keys on the Dashboard under **Account & Settings** → **Developer Controls** → **API Keys**. Know more about [API keys](https://curlec.com/docs/x/dashboard/api-keys.md).
* Ensure that your API key, that is the `<KEY_ID>` and `<KEY_SECRET>`, is not publicly available. Only a limited number of people should have access to it. We recommend you store the key as environment variables.
* Download and save your API key when you generate it. The key secret is shown only once. If you lose it, you must regenerate the key.
* When you regenerate your API key, the Dashboard asks for an OTP. You can deactivate the old key immediately or within 24 hours, so that you can switch over without a gap. Update your production configuration before the old key stops working.

### Types of Payout APIs

There are two ways to create payouts by API.

#### Composite Payout API

Use the Composite Payout API to create a Contact, a Fund account and a payout in a single API call. Send the beneficiary inline as `fund_account` with `contact`. Refer to the composite payout to a [bank account](https://curlec.com/docs/api/x/payout-composite/create/bank-account.md) or to a [DuitNow proxy](https://curlec.com/docs/api/x/payout-composite/create/duitnow.md).

#### Payout API with a Fund Account ID

A composite payout or a composite validation returns a `fund_account.id`. Reuse it in later payouts to the same beneficiary by sending it as `fund_account_id` in the [Payout API](https://curlec.com/docs/api/x/payouts/create/bank-account.md).

## Payout States

* A payout above the approval amount set for your account starts in the `pending` state and waits for a checker to approve it on the Dashboard. A payout below this amount goes to the bank directly. Build your integration to handle `pending` and `rejected`.
* `processed`, `failed`, `reversed`, `rejected` and `cancelled` are final states.
* A payout can move to `reversed` when the beneficiary was credited and the bank then returns the payout. The amount is credited back to your balance.

Know more about [payout states and life cycle](https://curlec.com/docs/x/payouts/states-life-cycle.md).

### Payout Status Details

[Status details](https://curlec.com/docs/x/payouts/status-details.md) are sent as part of the fetch payout API response and webhook payloads. They give the reason for the current payout status. Failure and reversal reasons come in `status_details`.

#### Check Payout Status

* Subscribe to our [webhooks](https://curlec.com/docs/x/apis/subscribe.md) to get notified whenever the status of a payout changes. Update your database using the webhook payload.
* Subscribe to `payout.failed`. If you do not, a failed payout is reported to you as `payout.reversed` instead.
* Verify every webhook. Compute the HMAC SHA-256 of the raw request body with your webhook secret and compare it with the `X-Razorpay-Signature` header. Discard the webhook if they differ.
* Respond with HTTP 200 within 5 seconds. A webhook that does not receive a 2xx response is sent again.
* Use the [Fetch a Payout API](https://curlec.com/docs/api/x/payouts/fetch-with-id.md) to confirm the status of a single payout, for example when a webhook is delayed.

## Other Guidelines

### Fund Account Validation

Validate a beneficiary's bank account or DuitNow proxy before you pay. The validation returns the name registered with the bank, which you can compare with the name the beneficiary gave you. No amount is credited to the beneficiary. Know more about [Fund account validation](https://curlec.com/docs/x/fund-account-validation.md).

> [!WARNING]
>
> **Watch Out!**
>
> If a beneficiary gives you a wrong account number and that account exists, the payout can still be processed. Validate Fund accounts before making a payout.

### Approvals

Keep the people who create payouts (makers) separate from the people who approve them (checkers). Payouts above the approval amount set for your account wait until a checker on your team approves or rejects them on the Dashboard. Payouts below this amount go to the bank directly. Know more about the [approval workflow](https://curlec.com/docs/x/manage-teams/approval-workflow.md).

### Queued Payouts

Pass `queue_if_low_balance: true` in the Payout API request. If you do not have sufficient balance to process the payout, the payout is queued. Queued payouts are processed after you add funds to your RazorpayX account. Know more about [Queued Payouts](https://curlec.com/docs/x/payouts/queued.md).

### Handling 5XX Errors and Idempotency

The `X-Payout-Idempotency` header is mandatory on every payout create request. Idempotency allows you to safely retry or send the same request multiple times without performing the same action more than once.

**Example**

You made a request but were unable to read or save the response. You then make another payout request. If the first request was successful, your account is debited twice. Making your payout requests idempotent helps you avoid this.

To make a request idempotent:

1. Add the header `X-Payout-Idempotency` to the request and pass a unique idempotency key against it. You can make the same call multiple times, but the amount is deducted only once.
2. If a duplicate request is found with the same idempotency key, we return the payout's latest state.

Know more about [Idempotency](https://curlec.com/docs/api/x/payout-idempotency/make-request.md).

### IP Allowlisting

Live API calls work only from your allowlisted server IPs. A call from any other IP returns HTTP 401. Tell your account manager before you add or change your server IPs. Know more about the [IP allowlist](https://curlec.com/docs/x/dashboard/allowlist-ip.md).

### Related Information

* [About Payouts](https://curlec.com/docs/x/payouts.md)
* [Payout Life Cycle and States](https://curlec.com/docs/x/payouts/states-life-cycle.md)
* [Payout Status Details](https://curlec.com/docs/x/payouts/status-details.md)
