Payouts
A payout sends money from your balance to your customer: a player's withdrawal.
Create one
POST /v1/payoutsReference
- Scope:
payouts:write Idempotency-Keyrequired — use your own id- SDK:
createPayout() - Success: HTTP 201
A key with payouts:write always has an IP allowlist; use an Ed25519 key for it if you can.
Request
| Field | Notes |
|---|---|
merchant_payout_id | your withdrawal id: 1 to 64 characters of A–Z a–z 0–9 _ . : -; unique per project forever |
amount, currency | "5000.00", "INR" (USDT methods take "USDT") |
method | upi, bank_transfer, usdt_trc20, usdt_bep20 |
destination | upi: { vpa, holder_name } · bank_transfer: { account_number, ifsc, holder_name } · USDT: { address } |
customer.ref | optional, your customer's id |
risk_hints | optional facts only you know (customer_age_days, lifetime_deposits, lifetime_withdrawals, kyc_level, flags). They can raise scrutiny; they never lower a limit |
metadata | optional, up to 20 keys with string values |
Destinations are checked strictly — IFSC format, VPA format, address checksum for the stated chain. A Tron address on a BNB Smart Chain payout is refused, never guessed.
Response
201 with the payout, in status queued. The amount plus fee is reserved from your available balance at that moment. destination comes back masked.
Errors
| Code | When |
|---|---|
402 insufficient_balance | the available balance is lower than the amount plus fee |
422 invalid_destination | the destination is malformed or does not match the method |
409 duplicate_merchant_reference | a payout with this merchant_payout_id exists; existing_id is its id |
403 merchant_not_active | your account is frozen or closed |
400 invalid_request | a field is wrong; errors names it |
Nothing is created and nothing is reserved when a request is refused.
Example
runs in CI
samples/ts/payouts.ts samples/php/payouts.php// Payouts: pay a player's withdrawal exactly once, and never guess at an unknown outcome.
// bun payouts.ts WD-99120
import { NicePay, NicePayConnectionError, NicePayError, type Payout } from "@nicepay/sdk-ts";
const nicepay = new NicePay({
keyId: process.env["NICEPAY_KEY_ID"] ?? "",
secret: process.env["NICEPAY_KEY_SECRET"] ?? "",
...(process.env["NICEPAY_API_BASE"] ? { baseUrl: process.env["NICEPAY_API_BASE"] } : {}),
});
const withdrawalId = process.argv[2] ?? `WD-${String(Date.now())}`;
let payout: Payout;
try {
payout = await nicepay.createPayout(
{
merchant_payout_id: withdrawalId, // your withdrawal id: unique forever
amount: "1000.00",
currency: "INR",
method: "upi",
destination: { vpa: "ramesh@okhdfc", holder_name: "Ramesh Kumar" },
customer: { ref: "player-7591035" },
},
{ idempotencyKey: withdrawalId }, // and the idempotency key: a retry never pays twice
);
} catch (error) {
if (error instanceof NicePayConnectionError && error.outcomeUnknown) {
// We do not know whether Nice Pay received it. Keep the withdrawal "processing" on
// your side and send the same call again later with the same key. Never pay the
// player another way and never put the money back on a guess.
console.log(`unknown outcome for ${withdrawalId}: retry later with the same idempotency key`);
process.exit(1);
}
if (error instanceof NicePayError && error.code === "insufficient_balance") {
console.log("not enough available balance: nothing was created");
process.exit(1);
}
throw error;
}
console.log(`payout ${payout.id}: ${payout.status}, fee ${payout.fee}, to ${payout.destination.masked}`);
// Test mode only: the bank pays it.
await nicepay.simulatePayout(payout.id, { action: "succeed" });
for (let i = 0; i < 30; i += 1) {
const now = await nicepay.getPayout(payout.id);
// processing / sent: the money may be on its way — never pay the player again.
if (now.status === "succeeded" || now.status === "failed" || now.status === "cancelled" || now.status === "reversed") {
console.log(`final: ${now.status}, reference ${String(now.reference)}`);
process.exit(0);
}
await new Promise((resolve) => setTimeout(resolve, 1000));
}
throw new Error("the payout did not finish within 30 seconds");<?php
// A player's withdrawal, paid exactly once — and never guessed at when the outcome is unknown.
// php payouts.php WD-99120
declare(strict_types=1);
require 'vendor/autoload.php';
use NicePay\Exception\ApiException;
use NicePay\Exception\ConnectionException;
$config = ['key_id' => getenv('NICEPAY_KEY_ID') ?: '', 'secret' => getenv('NICEPAY_KEY_SECRET') ?: ''];
if (getenv('NICEPAY_API_BASE')) {
$config['base_url'] = getenv('NICEPAY_API_BASE');
}
$nicepay = new NicePay\Client($config);
$withdrawalId = $argv[1] ?? 'WD-' . time();
try {
$payout = $nicepay->createPayout([
'merchant_payout_id' => $withdrawalId, // your withdrawal id: unique forever
'amount' => '1000.00',
'currency' => 'INR',
'method' => 'bank_transfer',
'destination' => ['account_number' => '50100012345678', 'ifsc' => 'HDFC0001234', 'holder_name' => 'Ramesh Kumar'],
'customer' => ['ref' => 'player-7591035'],
], ['idempotency_key' => $withdrawalId]); // and the idempotency key: a retry never pays twice
} catch (ConnectionException $e) {
if ($e->outcomeUnknown) {
// We do not know whether Nice Pay received it. Keep the withdrawal "processing" on
// your side; send the same call later with the same key. Never refund on a guess.
echo "unknown outcome for {$withdrawalId}: retry later with the same idempotency key\n";
exit(1);
}
throw $e;
} catch (ApiException $e) {
if ($e->errorCode === 'insufficient_balance') {
echo "not enough available balance: nothing was created\n";
exit(1);
}
throw $e;
}
echo "payout {$payout['id']}: {$payout['status']}, fee {$payout['fee']}, to {$payout['destination']['masked']}\n";
// Test mode only: the bank pays it.
$nicepay->simulatePayout($payout['id'], ['action' => 'succeed']);
for ($i = 0; $i < 30; $i++) {
$now = $nicepay->getPayout($payout['id']);
// processing / sent: the money may be on its way — never pay the player again.
if (in_array($now['status'], ['succeeded', 'failed', 'cancelled', 'reversed'], true)) {
echo "final: {$now['status']}, reference {$now['reference']}\n";
exit(0);
}
sleep(1);
}
throw new RuntimeException('the payout did not finish within 30 seconds');Statuses
queued ──► processing ──► sent ──► succeeded ──► reversed (paid, later returned by the bank)
│ │ │
│ └───────────┴────► failed (amount and fee released back to you)
└──► cancelledqueued waitingprocessing in progresssent in progresssucceeded finished wellfailed went wrongcancelled overreversed needs a look
queued: reserved, not yet sent. Only now can you cancel (POST/v1/payouts/{id}/cancel); later the answer is409 invalid_state. A queued payout can also go straight tosentor tofailed.sent: handed to the bank or the chain, not yet final. If the transfer proves not to have happened, the payout isprocessingagain.succeeded: paid.reversedcan follow only this status.processing— and"under_review": true— means it may be on its way or its outcome is being confirmed. We never refund or resend an ambiguous payout automatically; our staff resolve it. Treatprocessingas "do not pay this customer again".referencecarries the bank reference (UTR) or transaction hash once known.failed: not paid; the amount and fee are back in your available balance.
Mistakes that lose money
- Paying the customer a second time (another payout, or manually) while the first is
processingorsent. - A new
merchant_payout_idfor a retry of the same withdrawal: that is a second payout. Retry with the same id and idempotency key. - Treating a timeout or
NicePayConnectionErrorwithoutcomeUnknownas failed (idempotency). - Giving the money back to the player's wallet on
payout.processing; onlypayout.failedmeans it was not paid.