Payments
Create payment sessions with ZSI Pay and redirect your customers to the hosted checkout experience.
Create a payment
Use zsiPay.pay.init() to create a new payment session. The SDK sends the request securely from your server and returns a checkout URL that you can redirect your customer to.
const payment = await zsiPay.pay.init({
customer_email: "customer@example.com",
currency: "USD",
items: [
{
id: "item_123",
name: "Premium Subscription",
quantity: 1,
price: 5000,
},
],
});Payment request
A payment request contains customer information, currency, and one or more items.
| Field | Type | Required | Description |
|---|---|---|---|
customer_email | string | Required | Email address of the customer making the payment. |
currency | string | Required | Currency used for the payment. |
items | array | Required | List of items included in the payment. |
metadata | object | Optional | Optional application-specific information associated with the payment. |
Payment items
Each payment can contain one or more items. An item identifies what the customer is purchasing.
items: [
{
id: "item_123",
name: "Premium Subscription",
quantity: 1,
price: 5000,
},
{
id: "item_456",
name: "Additional Storage",
quantity: 2,
price: 1500,
},
]| Field | Type | Description | |
|---|---|---|---|
id | string | Required | Unique identifier for the item in your application. |
name | string | Required | Name of the item displayed for the payment. |
quantity | number | Required | Number of units of the item. |
price | number | Required | Price of a single item. |
Amount and currency
The currency field specifies the currency used for the payment, while the item price represents the price of each item.
{
currency: "USD",
items: [
{
id: "item_123",
name: "Premium Subscription",
quantity: 1,
price: 5000,
},
],
}Make sure the amount and currency values follow the payment API requirements for your ZSI Pay project.
Metadata
Use metadata to attach application-specific information to a payment. This is useful for associating a ZSI Pay payment with your internal order or customer records.
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",
},
});Payment response
After creating the payment, the SDK returns the information you need to send the customer to checkout.
{
trackId: "7107319375257",
url: "https://pay.zsi.ai/checkout/...",
status: "pending",
}| Field | Description | ||
|---|---|---|---|
trackId | string | Required | Unique tracking identifier for the payment session. |
url | string | Required | Hosted checkout URL where the customer can complete the payment. |
status | string | Required | Current status of the payment session. |
Redirect the customer
Redirect the customer to the checkout URL returned by ZSI Pay. Redirect handling depends on the Node.js framework you use.
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 using your framework's response API
return Response.redirect(payment.url);For Express, Next.js, and other frameworks, use the framework's recommended redirect API.
Complete example
import { ZSIPay } from "zsi-pay";
const zsiPay = new ZSIPay({
apiKey: process.env.ZSI_PAY_API_KEY!,
apiSecret: process.env.ZSI_PAY_API_SECRET!,
});
const createPayment = async () => {
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",
},
});
return payment;
};
export default createPayment;Payment status
Creating a payment session does not mean the payment has been completed. The initial response can contain a pending status while the customer completes checkout.
For reliable server-side payment confirmation, use webhooks or retrieve the payment session using its track ID.
