Node.js SDK
Official Node.js SDK for PayzCore. TypeScript support, create and manage payments, verify webhook signatures, and monitor USDT/USDC across 5 networks.
Node.js SDK
The official Node.js SDK for PayzCore. Written in TypeScript with full type definitions.
- Package:
@payzcore/node - Source: github.com/payzcore/node-sdk
- Requirements: Node.js 18+
Installation
npm install @payzcore/nodeInitialization
import { PayzCore } from '@payzcore/node';
// Project API (payment monitoring)
const client = new PayzCore('pk_live_YOUR_KEY');
// With options
const client = new PayzCore('pk_live_YOUR_KEY', {
baseUrl: 'https://api.payzcore.com', // optional, default
timeout: 30000, // optional, ms
maxRetries: 2, // optional, retries on 5xx
});
// Admin API (project management)
const admin = new PayzCore('mk_YOUR_MASTER_KEY', { masterKey: true });Create a Payment
const { payment } = await client.payments.create({
amount: 50,
network: 'TRC20',
token: 'USDT', // optional, defaults to 'USDT'
externalRef: 'customer-123',
externalOrderId: 'ORD-456', // optional, enables idempotency
expiresIn: 3600, // optional, seconds (300-86400)
metadata: { type: 'topup' }, // optional, max 4KB
});
console.log(payment.id); // UUID
console.log(payment.address); // blockchain address
console.log(payment.amount); // "50.00" (string)
console.log(payment.status); // "pending"
console.log(payment.qrCode); // base64 PNGGet Payment Status
const { payment } = await client.payments.get('payment-uuid');
console.log(payment.status); // 'pending' | 'confirming' | 'paid' | 'overpaid' | 'partial' | 'expired' | 'cancelled'
console.log(payment.paidAmount); // total received
console.log(payment.transactions); // array of blockchain txsThe get method returns the latest cached status from the database. Blockchain polling is handled by background workers.
List Payments
const result = await client.payments.list({
status: 'paid', // optional filter
limit: 25, // optional, default 50
offset: 0, // optional, for pagination
});
for (const payment of result.payments) {
console.log(payment.id, payment.status, payment.paidAmount);
}Cancel a Payment
const result = await client.payments.cancel('payment-uuid');
// Only works on 'pending' paymentsConfirm Transaction Hash (Pool + TxID Mode)
const result = await client.payments.confirm('payment-uuid', 'abc123def...');
console.log(result.status); // 'confirming' | 'pending' | 'paid'
console.log(result.verified); // true if found on blockchainSee Pool + TxID mode for details.
Webhook Verification
The SDK exports standalone functions for webhook verification. Import them directly from the package:
import { verifyWebhookSignature, constructEvent } from '@payzcore/node';Verify Signature Only
import { verifyWebhookSignature } from '@payzcore/node';
const isValid = verifyWebhookSignature(
rawBody, // raw request body string
req.headers.get('x-payzcore-signature')!, // signature header
'whsec_YOUR_SECRET', // webhook secret
{ timestamp: req.headers.get('x-payzcore-timestamp')! },
);Verify and Parse (Recommended)
import { constructEvent } from '@payzcore/node';
// Verifies signature and returns a typed WebhookPayload
// Throws WebhookSignatureError if signature is invalid
const event = constructEvent(
rawBody,
req.headers.get('x-payzcore-signature')!,
'whsec_YOUR_SECRET',
{ timestamp: req.headers.get('x-payzcore-timestamp')! },
);
console.log(event.event); // 'payment.completed'
console.log(event.paymentId); // UUID
console.log(event.paidAmount); // '50.00'The timestamp option is required. The signature covers timestamp + "." + body to prevent replay attacks. You can optionally customize the tolerance window:
const event = constructEvent(body, signature, secret, {
timestamp: req.headers.get('x-payzcore-timestamp')!,
toleranceMs: 300_000, // 5 minutes (default)
});Full Webhook Handler Example
import { constructEvent, WebhookSignatureError } from '@payzcore/node';
export async function POST(req: Request) {
const body = await req.text();
const signature = req.headers.get('x-payzcore-signature')!;
let event;
try {
const timestamp = req.headers.get('x-payzcore-timestamp')!;
event = constructEvent(body, signature, 'whsec_YOUR_SECRET', { timestamp });
} catch (err) {
if (err instanceof WebhookSignatureError) {
return new Response('Invalid signature', { status: 401 });
}
throw err;
}
switch (event.event) {
case 'payment.completed':
await creditUser(event.externalRef, parseFloat(event.paidAmount));
break;
case 'payment.overpaid':
await creditUser(event.externalRef, parseFloat(event.paidAmount));
await logOverpayment(event.paymentId, event.expectedAmount, event.paidAmount);
break;
case 'payment.partial':
await notifyPartial(event.externalRef, event.expectedAmount, event.paidAmount);
break;
case 'payment.expired':
await handleExpired(event.externalRef, event.paymentId);
break;
}
return new Response('OK', { status: 200 });
}Error Handling
The SDK throws typed error classes for different HTTP status codes:
import {
PayzCoreError,
AuthenticationError,
ValidationError,
RateLimitError,
NotFoundError,
} from '@payzcore/node';
try {
const { payment } = await client.payments.create({ ... });
} catch (error) {
if (error instanceof ValidationError) {
console.log('Invalid request:', error.message, error.details);
} else if (error instanceof AuthenticationError) {
console.log('Invalid API key');
} else if (error instanceof RateLimitError) {
console.log('Rate limit exceeded, daily:', error.isDaily);
} else if (error instanceof NotFoundError) {
console.log('Payment not found');
} else if (error instanceof PayzCoreError) {
console.log(`API error ${error.status}: ${error.message}`);
}
}| Error Class | Status | Meaning |
|---|---|---|
ValidationError | 400 | Invalid request parameters |
AuthenticationError | 401 | Invalid or missing API key |
ForbiddenError | 403 | Project inactive or limit exceeded |
NotFoundError | 404 | Payment not found |
RateLimitError | 429 | Daily API call limit reached |
PayzCoreError | 5xx | Server error (auto-retried) |
TypeScript Types
The SDK exports full TypeScript types for all request/response objects:
import type {
Payment,
PaymentDetail,
CreatePaymentParams,
ListPaymentsResponse,
WebhookPayload,
Network,
Token,
PaymentStatus,
} from '@payzcore/node';See Also
- Authentication & API Keys - API key setup and credential management
- Webhooks Guide - Events, headers, and signature verification
- Error Reference - HTTP status codes and troubleshooting
- Supported Networks - Available networks and tokens
FAQ & Troubleshooting
Frequently asked questions and troubleshooting guide. Payment issues, webhook debugging, network selection, address modes, security, billing, and common integration problems.
Python SDK
Official Python SDK for PayzCore. Create payments, check status, verify webhooks with HMAC-SHA256. Flask and Django examples included. Python 3.9+.