Quick start
From nothing to a succeeded test pay-in, from your own code. Budget: 30 minutes, most of it reading; the code runs in seconds.
| Step | Time |
|---|---|
| 1. Get a test key | 5 min |
| 2. Copy the signing helper | 2 min |
| 3. Run your first pay-in | 5 min |
| 4. Read what happened | 5 min |
| 5. Plan your webhook endpoint | 10 min |
1. Get a test key
In the merchant portal open Developers → API keys, switch to Test, and create a key with the scopes payins:write and payins:read. You get:
- a key id —
np_test_kid_…— sent with every request; - a secret —
np_test_sk_…— shown once. Put it in your secret manager or an environment variable, never in your code or repository.
Test mode is fully simulated: no bank, provider or blockchain is involved and no real money moves, but fees, balances, events and webhooks are the real thing.
2. Copy the signing helper
The API is plain HTTPS and JSON, and there is nothing to install. Every request carries a signature, so the examples on this site use one small file that makes it. Save it next to your code:
| Language | Save as | Needs |
|---|---|---|
| TypeScript / JavaScript | nicepay.ts | Bun, or Node 22.18+ — nothing else |
| PHP | nicepay.php | PHP 8.1+ with ext-curl and ext-json |
The file is about 150 lines that you can read in full on Authentication and signing. Any other language works the same way with HTTPS, SHA-256 and HMAC-SHA256: follow that page and check your code against the test vectors.
3. Run your first pay-in
Set your key in the environment and run the program below.
export NICEPAY_KEY_ID=np_test_kid_...
export NICEPAY_KEY_SECRET=np_test_sk_...samples/ts/quickstart.ts samples/php/quickstart.php// Quick start: your first test pay-in. Needs nicepay.ts (the signing helper) beside it.
// NICEPAY_KEY_ID=np_test_kid_… NICEPAY_KEY_SECRET=np_test_sk_… bun quickstart.ts
import { nicepay } from "./nicepay.ts";
interface Payin {
readonly id: string;
readonly status: string;
readonly checkout_url: string | null;
readonly amount_received: string;
readonly currency: string;
readonly fee: string | null;
readonly net_amount: string | null;
}
// 1. Check the key works. A test key answers livemode: false.
const ping = await nicepay<{ project: string; livemode: boolean }>("GET", "/v1/ping");
console.log(`connected: project ${ping.project}, livemode ${String(ping.livemode)}`);
// 2. Create a pay-in. Your own order id is both merchant_order_id and the idempotency
// key, so sending this again can never create a second pay-in.
const orderId = `DEP-${String(Date.now())}`;
const payin = await nicepay<Payin>("POST", "/v1/payins", {
body: {
merchant_order_id: orderId,
amount: "500.00", // money is always a decimal string
currency: "INR",
method: "upi",
customer: { ref: "player-7591035" },
},
idempotencyKey: orderId,
});
console.log(`created ${payin.id}: ${payin.status}, send the customer to ${String(payin.checkout_url)}`);
// 3. Test mode only: pretend the customer paid.
await nicepay("POST", `/v1/test/payins/${payin.id}/simulate`, { body: { action: "succeed" } });
// 4. Wait for it to succeed. (In production your webhook endpoint hears about it.)
for (let i = 0; i < 30; i += 1) {
const now = await nicepay<Payin>("GET", `/v1/payins/${payin.id}`);
if (now.status === "succeeded") {
console.log(`succeeded: received ${now.amount_received} ${now.currency}, fee ${String(now.fee)}, net ${String(now.net_amount)}`);
process.exit(0);
}
await new Promise((resolve) => setTimeout(resolve, 1000));
}
throw new Error("the pay-in did not succeed within 30 seconds");<?php
// Quick start: your first test pay-in. Needs nicepay.php (the signing helper) beside it.
// NICEPAY_KEY_ID=np_test_kid_… NICEPAY_KEY_SECRET=np_test_sk_… php quickstart.php
declare(strict_types=1);
require __DIR__ . '/nicepay.php';
// 1. Check the key works. A test key answers livemode: false.
$ping = nicepay('GET', '/v1/ping');
echo "connected: project {$ping['project']}, livemode " . var_export($ping['livemode'], true) . "\n";
// 2. Create a pay-in. Your own order id is both merchant_order_id and the idempotency
// key, so sending this again can never create a second pay-in.
$orderId = 'DEP-' . time() . '-' . bin2hex(random_bytes(2));
$payin = nicepay('POST', '/v1/payins', [
'body' => [
'merchant_order_id' => $orderId,
'amount' => '500.00', // money is always a decimal string, never a float
'currency' => 'INR',
'method' => 'upi',
'customer' => ['ref' => 'player-7591035'],
],
'idempotency_key' => $orderId,
]);
echo "created {$payin['id']}: {$payin['status']}, send the customer to {$payin['checkout_url']}\n";
// 3. Test mode only: pretend the customer paid.
nicepay('POST', "/v1/test/payins/{$payin['id']}/simulate", ['body' => ['action' => 'succeed']]);
// 4. Wait for it to succeed. (In production your webhook endpoint hears about it.)
for ($i = 0; $i < 30; $i++) {
$now = nicepay('GET', "/v1/payins/{$payin['id']}");
if ($now['status'] === 'succeeded') {
echo "succeeded: received {$now['amount_received']} {$now['currency']}, fee {$now['fee']}, net {$now['net_amount']}\n";
exit(0);
}
sleep(1);
}
throw new RuntimeException('the pay-in did not succeed within 30 seconds');You should see something like:
connected: project prj_01JD…, livemode false
created pi_01JD…: pending, send the customer to https://pay.mynicepanel.com/c/…
succeeded: received 500.00 INR, fee 10.00, net 490.004. Read what happened
GET/v1/pingproved the signature and the key:livemode falsemeans test mode.POST/v1/payinscreated a pay-in in statuspending. In production you send the customer tocheckout_url, our hosted payment page. That URL is only in this response — store it if you need it again.- Your order id was both
merchant_order_idand the idempotency key, so running the call twice still makes one pay-in (why that matters). POST/v1/test/payins/{id}/simulateis test mode's stand-in for the customer paying.succeededis final.feeandnet_amountappear once it succeeds; your available balance grew bynet_amount. You can see the pay-in in the portal under Pay-ins with the Test switch on.
5. Next: hear about payments with webhooks
Polling was fine for a first run. In production you learn that a pay-in succeeded from a webhook and you credit your customer once, after fetching the pay-in again. Read Webhooks next — it is the page that keeps you from losing money — then Test mode to try failures, late payments and payouts.