Test mode
Every project has a test mode and a live mode. Test keys (np_test_…) see only test objects. In test mode nothing real moves: no bank, provider or blockchain is involved. Everything after that — fees, balances, the ledger, events, webhooks, the stream, reports — is the real code, so what works in test works in live.
Moving things along
Pay-ins and payouts in test mode stay where they are until you move them:
| Call | Actions |
|---|---|
POST/v1/test/payins/{id}/simulate | succeed (optionally with amount — a different amount received), fail, expire, partial (processing) |
POST/v1/test/payouts/{id}/simulate | succeed, fail, reverse |
POST/v1/test/crypto/transfers | address (one of your customers' test addresses) and amount in USDT: a confirmed transfer with a made-up transaction hash |
They answer 202: the change happens a moment later, with its events and webhooks, like the real thing. Live keys get 403 test_mode_only.
samples/ts/test-mode.ts// Test mode: drive pay-ins and payouts through every outcome, including the ones that
// lose money when handled wrongly.
import { nicepay } from "./nicepay.ts";
interface Payin {
readonly id: string;
readonly status: string;
readonly amount: string;
readonly amount_received: string;
readonly late: boolean;
}
if (!(process.env["NICEPAY_KEY_ID"] ?? "").startsWith("np_test_")) throw new Error("use a test key (np_test_kid_…)");
const run = String(Date.now());
function newPayin(tag: string): Promise<Payin> {
const orderId = `TEST-${tag}-${run}`;
return nicepay<Payin>("POST", "/v1/payins", { body: { merchant_order_id: orderId, amount: "1000.00", currency: "INR", method: "upi", customer: { ref: "tester" } }, idempotencyKey: orderId });
}
/** The test-mode stand-in for what the customer, the bank or the clock does. */
function simulate(id: string, body: { action: "succeed" | "fail" | "expire"; amount?: string }): Promise<unknown> {
return nicepay("POST", `/v1/test/payins/${id}/simulate`, { body });
}
async function settled(id: string, from: string): Promise<Payin> {
for (let i = 0; i < 30; i += 1) {
const p = await nicepay<Payin>("GET", `/v1/payins/${id}`);
if (p.status !== from) return p;
await new Promise((resolve) => setTimeout(resolve, 500));
}
throw new Error(`${id} stayed ${from}`);
}
// The customer pays less than asked: you are credited what arrived.
const partial = await newPayin("partial");
await simulate(partial.id, { action: "succeed", amount: "600.00" });
const p1 = await settled(partial.id, "pending");
console.log(`partial: ${p1.status}, asked ${p1.amount}, received ${p1.amount_received}`);
// Failed, then the money arrives anyway: late money always wins.
const late = await newPayin("late");
await simulate(late.id, { action: "fail" });
const failed = await settled(late.id, "pending");
await simulate(late.id, { action: "succeed" });
const won = await settled(late.id, "failed");
console.log(`late: ${failed.status} → ${won.status}, late=${String(won.late)}`);
// Expired: your order times out, but it is not "failed" until you stop waiting for money.
const expired = await newPayin("expire");
await simulate(expired.id, { action: "expire" });
console.log(`expire: ${(await settled(expired.id, "pending")).status}`);What to test before going live
Run every one of these through your own code, webhooks included:
- a pay-in that succeeds — credited once, even when the webhook is delivered twice (redeliver it);
- a pay-in that fails, then succeeds late — credited once, after the failure;
- a pay-in paid with less than asked — credited
amount_received; - a payout that succeeds, one that fails (the player's money handled), one reversed after success;
- a payout your balance cannot cover — accepted with
funding: unfunded, then funded once you top up the test balance, or failed after 24 hours withfailure_reason: negative_balance(the player's money handled once); - a payout you cancel —
cancelled, and409 payout_in_progressonce it is being paid; - your endpoint down for a while — then catch up with
GET/v1/events; - a request with a wrong signature — you see
401 invalid_signatureand alert; - a USDT transfer to a customer's permanent address — one credit per transfer, in USDT, whatever rate your platform shows the player.
USDT in test mode
USDT in test mode carries your live USDT fees: a test USDT pay-in or payout is priced by the same rules as a live one (by the amount received for a pay-in, 1 % plus the chain's flat amount for a payout), so test balances, fee, net_amount and webhooks show what live will. Your per-payment limits and the on/off of a currency apply to live keys only.
Test addresses are real-format addresses that nothing on any blockchain watches — never send real coins to one. POST/v1/test/crypto/transfers stands in for a customer's transfer: a moment later the address's open invoice (or a new open deposit for that customer) is credited exactly as a confirmed on-chain transfer would be, with crypto.transfer.confirmed and payin.succeeded. Send two transfers to the same address to see two deposits; send less than an invoice asks to see it stay processing.