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. Install the SDK | 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. Install the SDK
TypeScript / JavaScript (Node 20.3+, Bun or Deno):
npm install @nicepay/sdk-tsPHP 8.1+ with ext-curl, ext-json and ext-sodium:
composer require nicepay/sdk-phpNo SDK for your language? Every request is plain HTTPS and JSON; see signing by hand.
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.
// NICEPAY_KEY_ID=np_test_kid_… NICEPAY_KEY_SECRET=np_test_sk_… bun quickstart.ts
import { NicePay } from "@nicepay/sdk-ts";
const nicepay = new NicePay({
keyId: process.env["NICEPAY_KEY_ID"] ?? "",
secret: process.env["NICEPAY_KEY_SECRET"] ?? "",
// Leave unset: the SDK talks to https://api.mynicepanel.com (test and live alike).
...(process.env["NICEPAY_API_BASE"] ? { baseUrl: process.env["NICEPAY_API_BASE"] } : {}),
});
// 1. Check the key works. A test key answers livemode: false.
const ping = await nicepay.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.createPayin(
{
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.simulatePayin(payin.id, { 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.getPayin(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.
// composer require nicepay/sdk-php
// NICEPAY_KEY_ID=np_test_kid_… NICEPAY_KEY_SECRET=np_test_sk_… php quickstart.php
declare(strict_types=1);
require 'vendor/autoload.php';
$config = [
'key_id' => getenv('NICEPAY_KEY_ID') ?: '',
'secret' => getenv('NICEPAY_KEY_SECRET') ?: '',
];
// Leave unset: the SDK talks to https://api.mynicepanel.com (test and live alike).
if (getenv('NICEPAY_API_BASE')) {
$config['base_url'] = getenv('NICEPAY_API_BASE');
}
$nicepay = new NicePay\Client($config);
// 1. Check the key works. A test key answers livemode: false.
$ping = $nicepay->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->createPayin([
'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->simulatePayin($payin['id'], ['action' => 'succeed']);
// 4. Wait for it to succeed. (In production your webhook endpoint hears about it.)
for ($i = 0; $i < 30; $i++) {
$now = $nicepay->getPayin($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
pingproved the signature and the key:livemode falsemeans test mode.createPayincreated 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). simulatePayinis 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.