Pay-ins
A pay-in is one payment from your customer to you. You create it, the customer pays, we tell you.
Create one
POST /v1/payinsReference
- Scope:
payins:write Idempotency-Keyrequired — use your own id- Success: HTTP 201
Request
| Field | Notes |
|---|---|
merchant_order_id | your order id: 1 to 64 characters of A–Z a–z 0–9 _ . : -; unique per project forever |
amount, currency | "10000.00", "INR" (USDT methods take "USDT") |
method | upi, bank_transfer, usdt_trc20, usdt_bep20, or auto (we pick: in live mode an INR auto pay-in is UPI, and the pay-in says upi) |
customer.ref | your customer's id, in the same form as an order id; name, phone, email and ip are optional — but see your customer's mobile and e-mail |
return_url | optional https URL where the payment page sends the customer back. Its host must be on your project's allowlist in the portal |
expires_in | optional, seconds (60–86,400): how long the customer has to pay; the payment page's clock counts it down |
channel | optional, INR only: one channel by its id — upi, qr, instant, qr_lite, qr_2 or bank: that channel's QR or payment page is used for the deposit, and the pay-in never moves to another channel; or desk (a payment desk's QR or account, shown on the payment page) or gateway (any channel's payment page). Leave it out and your routing chooses among all. A channel that is not on your routes: 422 method_not_available; when nothing of that kind can take the payment now: 503 rail_unavailable, as when nothing can |
metadata | optional, up to 20 keys with string values (at most 500 characters each); returned on the object and in events |
description | optional: why, in your words — e.g. "player deposit" (at most 200 characters); shown on the payment, in exports and in its payment record |
Response
201 with the pay-in, in status pending:
checkout_url— send the customer here. Only the create response carries it (a retrieved pay-in showsnull), so store it if you may need it again. Use it exactly as given; never build it yourself.instructions.type—redirect(usecheckout_url), or, when you show the payment details yourself,upi_qr,bank_detailsorcrypto_address. In test mode it issimulated: nobody pays, you move the pay-in with the simulation call.rail— which kind of rail serves it (desk_upi,desk_bank,gatewayfor every channel,usdt_trc20,usdt_bep20). It is our routing decision, for your information only.
Errors
| Code | When |
|---|---|
422 amount_too_small | the amount is below your smallest pay-in in that currency (live mode; min_amount and max_amount give your range), or the fees would leave you nothing of it (no range given) |
409 duplicate_merchant_reference | a pay-in with this merchant_order_id exists; existing_id is its id |
409 invoice_already_open | this customer already has an open USDT invoice on that chain, still waiting for money |
403 limit_exceeded | the amount is above your largest pay-in (limit amount_max, with min_amount and max_amount); or this customer has too many open pay-ins, reached the number allowed for the period, or asked again too soon — limit says which (customer_open, customer_unreferenced, customer_daily, customer_hourly, customer_gap), limit_max how many a count allows, and for the gap retry_after_seconds how long until the customer may ask again |
422 method_not_available | the method is not set up for your project, the channel you named is not on your routes, or Nice Pay has switched that currency off for you (live mode): switched_off is fiat (INR) or crypto (USDT) |
503 rail_unavailable | nothing can take this payment right now; retry later or offer another method |
400 invalid_request | a field is wrong; errors names it |
Nothing is created when a request is refused. The idempotency errors are on the idempotency page, and every code is on the errors page.
Your customer's mobile and e-mail
Some channels pass the payer's mobile number and e-mail to the bank and refuse a payment without a mobile (today the QR channel and the Bank channel). The portal's Developers and Channels pages list the channels on your routes that need them.
customer.phone: digits with an optional leading+; for these channels a 10-digit Indian mobile (9876543210,919876543210and+919876543210are the same number). Send it whenever you have it. A pay-in without one is never routed to a channel that requires it: another of your routes takes it, and when only such channels could take it the answer is503 rail_unavailable.customer.email: an e-mail address of at most 120 characters. Without one, these channels are given an address formed fromcustomer.ref.- Both are used only for those channels: they are never returned on the API, in events or in exports.
Your limits
In live mode every pay-in is checked against your terms with Nice Pay: whether INR ("fiat") and USDT ("crypto") are on for you, and the smallest and largest single pay-in in each currency. Unless agreed otherwise they are ₹300 to ₹20,000 and 5 to 50,000 USDT, both on; your terms are on the portal's Settings page, and GET/v1/methods applies them. Test mode does not apply them.
Example
samples/ts/payins.ts// Pay-ins: create one per order exactly once, read it back, list, cancel.
// bun payins.ts DEP-48213
import { nicepay, NicePayError } from "./nicepay.ts";
interface Payin {
readonly id: string;
readonly status: string;
readonly amount: string;
readonly currency: string;
readonly rail: string;
}
/**
* The pay-in for one of your orders: created the first time, the same one every time
* after — whether you retry a second later (idempotency key) or a week later
* (merchant_order_id is unique per project forever).
*/
async function payinForOrder(orderId: string, amount: string): Promise<Payin> {
try {
return await nicepay<Payin>("POST", "/v1/payins", {
body: { merchant_order_id: orderId, amount, currency: "INR", method: "upi", customer: { ref: "player-7591035" }, metadata: { cart: "c-1" } },
idempotencyKey: orderId,
});
} catch (error) {
if (error instanceof NicePayError && error.code === "duplicate_merchant_reference") {
return nicepay<Payin>("GET", `/v1/payins/${String(error.problem["existing_id"])}`);
}
throw error;
}
}
const orderId = process.argv[2] ?? `DEP-${String(Date.now())}`;
const first = await payinForOrder(orderId, "750.00");
const again = await payinForOrder(orderId, "750.00");
console.log(`order ${orderId} → ${first.id} (again: ${again.id}, same: ${String(first.id === again.id)})`);
// Read it back. checkout_url is only in the create response; store it if you need it.
const fetched = await nicepay<Payin>("GET", `/v1/payins/${first.id}`);
console.log(`status ${fetched.status}, amount ${fetched.amount} ${fetched.currency}, rail ${fetched.rail}`);
// Find it by your own id.
const found = await nicepay<{ data: Payin[] }>("GET", "/v1/payins", { query: { merchant_order_id: orderId } });
console.log(`found by merchant_order_id: ${String(found.data.length)}`);
// The customer gave up: cancel. (If money still arrives, the pay-in succeeds anyway — "late money wins".)
if (fetched.status === "pending") {
const cancelled = await nicepay<Payin>("POST", `/v1/payins/${first.id}/cancel`);
console.log(`cancelled: ${cancelled.status}`);
}Which methods you can offer now
GET /v1/methodsReference
- Scope: any valid key
- Success: HTTP 200
Ask before you show your payment choices. Each method comes with available, your fee and, in live mode, min_amount and max_amount:
- Live mode tells you the truth of this moment. UPI or a bank transfer is
availablewhen something we route to can take it right now (a payment desk or a gateway that is on, healthy and priced for you). USDT isavailablewhen your project's wallet can give your customer an address. A payout method isavailablewhen it is priced for you and payouts are not stopped — and, forupi, when UPI payouts are on for you. Hide a tile whose method is not available, and ask again every few minutes: rails come and go. min_amountandmax_amountare the widest limits of what can take it now, never wider than your limits; a particular amount can still be refused (503 rail_unavailable), for example when a desk has reached its daily limit.switched_off(live mode):fiatorcryptowhen Nice Pay has switched that currency off for you; the method is then notavailable.fee.bands: when your fee depends on the amount — USDT pay-ins — one entry per band, lowest first:from_amount(inclusive),to_amount(exclusive;nullfor the last), and your wholebpsandfixedin that band. The fee of a payment is the band its amount received falls in;fee.bpsandfee.fixedare then the highest a band takes.channels(live mode, INR pay-in methods): the same answer for eachchannelyou can name when you create one —desk,gatewayand each channel id — so a page that offers a desk's QR and a channel's payment page as separate tiles shows each only while it can be used. A channel that is not on your routes is listed as notavailable.- Test mode says
availablefor every method priced on the simulated rail, without limits.
Find pay-ins
GET/v1/payins and GET/v1/payouts list yours, newest first, 100 at most per page (limit, starting_after). Filters, all optional and combined:
| Filter | Matches |
|---|---|
customer_ref | your customer's reference |
reference | exactly one reference: a UTR or bank reference (spaces and case ignored) or a transaction hash |
method, status, currency | as on the object |
created_from, created_to | an ISO 8601 instant with its offset, both inclusive |
amount_min, amount_max | an amount in currency (required with them) |
legacy_id, imported | payments imported from your previous system, by their old id; imported=true, false or both (the default) |
A pay-in carries reference once it is known: the UTR (or bank reference) for INR, the transaction hash of its first transfer for USDT.
Statuses
pending ──► processing ──► succeeded (final)
│ ├──► failed ──┐
│ └──► expired ──┤
├──► succeeded ├──► succeeded (money arrived late)
├──► failed ────────────────┤
├──► expired ────────────────┤
└──► cancelled ──────────────┘pending waitingprocessing in progresssucceeded finished wellfailed went wrongexpired overcancelled over
processing: a reference was submitted, the rail reported progress, or an on-chain transfer is seen but not confirmed. Not money yet.succeededis final and is the only status in which money has been credited (one exception for USDT invoices, below).feeandnet_amountare set then.- Late money always wins. If real money arrives for a pay-in that is
failed,expiredorcancelled, it becomessucceededwith"late": true, you are credited, and you getpayin.succeeded. Never close an order on your side so hard that a latepayin.succeededcannot credit it. - Reversal. If a credited pay-in turns out not to be real money, it stays
succeededbut gainsreversed_atandreversed_amount; your balance is reduced and you getpayin.reversed. amount_receivedis what actually arrived. Credit your customer that, notamount.
Cancel
POST/v1/payins/{id}/cancel while it is pending; in any other status the answer is 409 invalid_state. Cancelling is not a refusal of money: if the customer pays anyway, late money wins.
Your own payment page
If you show the UPI QR or bank details yourself (instructions.type upi_qr or bank_details), send the customer's payment reference (UTR) with POST/v1/payins/{id}/reference. A reference already used for another pay-in is refused with reference_already_used.
USDT
Each customer gets one permanent deposit address per chain (tron or bsc). Asking again returns the same address; it is never given to anyone else.
samples/ts/crypto-address.ts// USDT: each customer gets one permanent deposit address per chain. Ask as often as you
// like — it is a get-or-create and always returns the same address.
// bun crypto-address.ts player-7591035 bsc
import { nicepay, NicePayError } from "./nicepay.ts";
const customerRef = process.argv[2] ?? "player-7591035";
const chain = process.argv[3] ?? "tron"; // "tron" or "bsc"
async function depositAddress(): Promise<string> {
for (let attempt = 0; ; attempt += 1) {
try {
return (await nicepay<{ address: string }>("POST", "/v1/crypto/addresses", { body: { customer_ref: customerRef, chain } })).address;
} catch (error) {
// A new address comes from a pool filled in advance; if it is momentarily empty, wait and ask again.
if (error instanceof NicePayError && error.code === "address_pool_empty" && attempt < 5) {
await new Promise((resolve) => setTimeout(resolve, 2000));
continue;
}
throw error;
}
}
}
const first = await depositAddress();
const second = await depositAddress();
console.log(`${customerRef} on ${chain}: ${first} (stable: ${String(first === second)})`);
// Every confirmed transfer to it becomes its own pay-in (payin.succeeded with the amount received).- Open deposits: every confirmed transfer to the address becomes its own pay-in (no
merchant_order_id) for the amount received, withpayin.succeeded. Three transfers are three pay-ins and three credits. - Invoices:
POST/v1/payinswithmethod: "usdt_trc20"or"usdt_bep20"and anamountopens an invoice on the customer's address. Transfers while it is open add up in that one pay-in:amount_receivedgrows, each transfer is listed intransfers[], and it succeeds when enough arrived (more is credited in full; at expiry a partly paid invoice succeeds for what arrived,amount_receivedbelowamount, and USDT sent after that is a deposit of its own). Each confirmed transfer is credited to you as it confirms and raisescrypto.transfer.confirmed, whosetransfergivestx_hash,log_index, this transfer's ownamountand thetotal_receivedso far, in USDT. Nice Pay keeps no USDT price: the amounts are USDT, and you apply your own price. Credit your customer either per confirmed transfer or once onpayin.succeededwithamount_received— pick one and key your credit on it. - One invoice per address may be open at a time: a new one while the open one still waits for money is refused
409 invoice_already_open. An invoice whose pay-in ended (expired,cancelled) with nothing received makes way for the customer's new invoice; USDT that arrives after that is credited to the newer invoice, or is a deposit of its own — once either way. - The fee of USDT is taken from each transfer as it is credited, by its amount: under 10 USDT 2 %, 10 to under 100 USDT 1 %, 100 to 1,000 USDT 0.5 %, over 1,000 USDT 0.1 %, unless agreed otherwise (
GET/v1/methodsgives your bands). Two transfers of 8 USDT each pay 2 % each. - Money that arrives with no invoice is always credited, even while USDT is switched off for you or outside your limits.
- Never credit on
crypto.transfer.detected: it is seen, not confirmed.
In test mode, addresses are real-format addresses that nothing watches; simulated USDT transfers are not available yet.
Mistakes that lose money
- Crediting your customer from the event body or from the redirect back to
return_url. Always fetch the pay-in by id and checkstatus === "succeeded", as the webhook examples do. - Crediting
amountinstead ofamount_received(a partial or late payment). - Crediting twice: a unique key on the pay-in id in your database, inserted in the same transaction as the credit (webhooks).
- Refusing a late
payin.succeededbecause the order "expired": the money is yours and the customer paid.
Imported pay-ins
If your platform moved to Nice Pay from its own payment system, its past pay-ins may have been imported so you can find them here. They come back from the same endpoints with imported: true and legacy_id (your old system's id); every pay-in made at Nice Pay has imported: false and legacy_id: null. An imported pay-in moved no money at Nice Pay: no balance, no event. A reversed imported deposit shows succeeded with reversed_at; instructions.type is none; fee is null. Any write request on one (cancel, reference, check) answers 409 imported_record.