Payment Sessions
Retrieve an existing payment session using its track ID and inspect the current payment status from your server.
Retrieve a payment session
After creating a payment, ZSI Pay returns a unique trackId. You can use this ID to retrieve the associated payment session.
const session =
await zsiPay.sessions.findByTrackId("7107319375257");
console.log(session);Using the track ID
The track ID is returned when you create a payment session. Store it with your own order or transaction record so you can retrieve the corresponding ZSI Pay session later.
const payment = await zsiPay.pay.init({
customer_email: "customer@example.com",
currency: "USD",
items: [
{
id: "item_123",
name: "Premium Subscription",
quantity: 1,
price: 5000,
},
],
});
console.log(payment.trackId);Example:
7107319375257Session response
A session response contains information about the payment associated with the supplied track ID.
const session =
await zsiPay.sessions.findByTrackId("7107319375257");
console.log(session);The exact response structure depends on the payment session returned by the ZSI Pay API. Use the returned session data and status as the server-side source of truth for your application.
Check payment status
You can inspect the session status after retrieving the session.
const session =
await zsiPay.sessions.findByTrackId("7107319375257");
if (session.status === "success") {
console.log("Payment completed");
}Use the exact status values returned by your ZSI Pay API. Do not assume a payment is successful simply because the customer was redirected back to your application.
Server-side payment verification
Payment confirmation should happen on your server. A successful browser redirect only indicates that the customer returned to your application; it should not be treated as proof that the payment was completed.
const session =
await zsiPay.sessions.findByTrackId(trackId);
if (session.status === "success") {
// Mark your internal order as paid
// Fulfill the order
} else {
// Keep the order pending or handle the returned status
}Sessions and webhooks
Session retrieval is useful when you need to query the current state of a payment. For asynchronous payment updates, webhooks provide a way for ZSI Pay to notify your server when payment events occur.
Session retrieval
Query a payment session using its track ID when your application needs the current payment state.
Webhooks
Receive server-to-server notifications when payment events occur.
See the Webhooks guide for webhook verification and event handling.
Store the track ID with your order
A common integration pattern is to store the ZSI Pay track ID with your own order or transaction record.
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",
},
});
// Save the relationship in your database
await orders.update({
orderId: "ord_98765",
paymentTrackId: payment.trackId,
});Keeping this relationship allows your application to connect ZSI Pay payment sessions with your internal orders.
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 getPaymentSession = async (trackId: string) => {
const session =
await zsiPay.sessions.findByTrackId(trackId);
return session;
};
const session = await getPaymentSession(
"7107319375257"
);
console.log(session.status);Important
- • Retrieve sessions from your server, not directly from the browser.
- • Do not mark an order as paid based only on a frontend redirect.
- • Store the payment track ID with your internal order or transaction.
- • Use webhooks for asynchronous payment status updates.
