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 |
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.
runs in CI
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, type Payin } 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"] } : {}),
});
if (!nicepay.testMode) throw new Error("use a test key (np_test_kid_…)");
const run = String(Date.now());
async function newPayin(tag: string): Promise<Payin> {
const orderId = `TEST-${tag}-${run}`;
return nicepay.createPayin({ merchant_order_id: orderId, amount: "1000.00", currency: "INR", method: "upi", customer: { ref: "tester" } }, { idempotencyKey: orderId });
}
async function settled(id: string, from: string): Promise<Payin> {
for (let i = 0; i < 30; i += 1) {
const p = await nicepay.getPayin(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 nicepay.simulatePayin(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 nicepay.simulatePayin(late.id, { action: "fail" });
const failed = await settled(late.id, "pending");
await nicepay.simulatePayin(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 nicepay.simulatePayin(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 refused for
insufficient_balance; - 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.
USDT addresses work in test mode (real-format addresses that nothing watches); simulated USDT transfers are not available yet.