Quickstart
Create your first ZSI Pay payment in a few simple steps using the official Node.js SDK.
What you'll build
In this guide, you'll create a payment session, receive a secure checkout URL, and redirect your customer to complete the payment.
Install the SDK
If you haven't installed the ZSI Pay SDK yet, install it using your preferred package manager.
npm install zsi-payAlready installed the SDK? Continue to the next step.
Get your API credentials
Create a project in the ZSI Pay Dashboard and generate your API credentials.
- 1.Sign in to your ZSI Pay Dashboard.
- 2.Create or select a project.
- 3.Generate your API Key and API Secret.
- 4.Keep your credentials on the server and never expose them in client-side code.
Configure environment variables
Store your ZSI Pay credentials in environment variables.
ZSI_PAY_API_KEY=your_api_key
ZSI_PAY_API_SECRET=your_api_secretAPI credentials are sensitive. Keep them on your backend and never expose your API Secret in browser or client-side code.
Initialize the SDK
Create a ZSIPay instance using your API credentials.
import { ZSIPay } from "zsi-pay";
const zsiPay = new ZSIPay({
apiKey: process.env.ZSI_PAY_API_KEY!,
apiSecret: process.env.ZSI_PAY_API_SECRET!,
});Create a payment
Use pay.init() to create a new payment session.
const payment = await zsiPay.pay.init({
customer_email: "customer@example.com",
currency: "USD",
items: [
{
id: "item_123",
name: "Premium Subscription",
quantity: 1,
price: 5000,
},
],
metadata: {
orderId: "ord_98765",
customerId: "cust_123",
},
});
console.log(payment);Example response
{
trackId: "7107319375257",
url: "https://pay.zsi.ai/checkout/...",
status: "pending"
}The url returned by ZSI Pay is the checkout URL for the customer.
Redirect your customer
Send the customer to the checkout URL returned by ZSI Pay.
const payment = await zsiPay.pay.init({
customer_email: "customer@example.com",
currency: "USD",
items: [
{
id: "item_123",
name: "Premium Subscription",
quantity: 1,
price: 5000,
},
],
});
// Redirect the customer to ZSI Pay checkout
return Response.redirect(payment.url);Important
Always create payment sessions from your backend. Do not expose your API credentials or create authenticated payment requests directly from browser code.
Verify the payment
After the customer completes checkout, use the payment session or webhook event to determine the final payment status.
The payment session contains a unique trackId. You can use it to retrieve the latest server-side payment information.
const session =
await zsiPay.sessions.findByTrackId(
"7107319375257"
);
console.log(session.status);Use webhooks for payment events
For reliable asynchronous payment updates, configure a webhook endpoint and verify the webhook signature before processing the event.
Complete example
Here is a minimal server-side example that creates a ZSI Pay payment.
import { ZSIPay } from "zsi-pay";
const zsiPay = new ZSIPay({
apiKey: process.env.ZSI_PAY_API_KEY!,
apiSecret: process.env.ZSI_PAY_API_SECRET!,
});
async function createPayment() {
const payment = await zsiPay.pay.init({
customer_email: "customer@example.com",
currency: "USD",
items: [
{
id: "item_123",
name: "Premium Subscription",
quantity: 1,
price: 5000,
},
],
metadata: {
orderId: "ord_98765",
},
});
console.log("Track ID:", payment.trackId);
console.log("Checkout URL:", payment.url);
return payment;
}
createPayment();Important notes
- β’Create payment sessions from your trusted backend environment.
- β’Never expose your API Secret or Webhook Secret to customers.
- β’Do not treat a customer returning to a success page as definitive proof of payment.
- β’Use webhooks or retrieve the payment session to confirm the server-side payment status.
