TypeScript and PHP SDKs
Both SDKs are thin: their types and methods are generated from our OpenAPI document; signing, idempotency, retries and webhook verification are written by hand and tested against the same test vectors as our server. Neither has third-party dependencies.
TypeScript @nicepay/sdk-ts | PHP nicepay/sdk-php | |
|---|---|---|
| Runs on | Node 20.3+, Bun, Deno | PHP 8.1+ with ext-curl, ext-json, ext-sodium |
| Signing | HMAC-SHA256 and Ed25519 | HMAC-SHA256 and Ed25519 (libsodium) |
| Idempotency | a key per money call unless you pass one; reused on retries | same |
| Retries | at most 3, back-off with jitter, only where safe (table) | same |
| Webhooks | constructEvent(rawBody, header), keys cached, rotation handled | same, with an optional cache_file |
| Safe credit | handlePayinEvent(event, creditOnce) | handlePayinEvent($event, $creditOnce) |
| Money | decimal strings; Money helper on bigint | decimal strings; Money helper on int (no bcmath needed) |
| Stream | WebSocket client with token refresh and resume | not included |
| Errors | NicePayError (code, requestId, retryable), NicePayConnectionError (outcomeUnknown) | ApiException (errorCode, requestId, retryable), ConnectionException (outcomeUnknown) |
Every API operation is a method named after its operation id in the reference: createPayin, getPayin, listPayins, createPayout, listEvents, …
TypeScript
import { NicePay } from "@nicepay/sdk-ts";
const nicepay = new NicePay({
keyId: process.env["NICEPAY_KEY_ID"] ?? "",
secret: process.env["NICEPAY_KEY_SECRET"] ?? "", // or privateKey for an Ed25519 key
});
const payin = await nicepay.createPayin({ merchant_order_id: "DEP-1", amount: "100.00", currency: "INR", method: "upi", customer: { ref: "p1" } }, { idempotencyKey: "DEP-1" });Options: baseUrl (default the production API — test and live use the same host), maxRetries (3), timeoutMs (30,000 per attempt), apiVersion, fetch. Per call: idempotencyKey, maxRetries, timeoutMs, signal.
PHP
$nicepay = new NicePay\Client([
'key_id' => getenv('NICEPAY_KEY_ID'),
'secret' => getenv('NICEPAY_KEY_SECRET'), // or 'private_key' for an Ed25519 key
]);
$payin = $nicepay->createPayin(['merchant_order_id' => 'DEP-1', 'amount' => '100.00', 'currency' => 'INR', 'method' => 'upi', 'customer' => ['ref' => 'p1']], ['idempotency_key' => 'DEP-1']);Objects come back as associative arrays, exactly as the JSON; money stays a string. Options: base_url, max_retries, timeout_ms, api_version, transport (your own HTTP stack). A float anywhere in the parameters is refused before anything is sent.
Money helper
import { Money } from "@nicepay/sdk-ts";
const total = Money.of("0.10", "INR").add(Money.of("0.20", "INR")); // "0.30", exactly
const usdt = Money.of("25.500000", "USDT"); // six decimal places; usdt.minor === 25500000n$minor = NicePay\Money::toMinor('10000.50'); // 1000050 (INR unless you name the currency)
$total = NicePay\Money::of('0.10', 'INR')->add(NicePay\Money::of('0.20', 'INR')); // "0.30"
$usdt = NicePay\Money::toMinor('25.500000', 'USDT'); // 25500000: USDT has six decimal placesThe helper knows each currency's decimal places (INR two, USDT six). Always pass the object's own currency: an amount with more places than its currency has is refused, never rounded.
No SDK
Any language with HTTPS, SHA-256 and HMAC-SHA256 (or Ed25519) can call the API: see signing by hand and check your code against the test vectors.
Versions
The SDKs follow semantic versioning. A release names the API version it was generated from; it never contains a default host other than our production API, and never logs request bodies.