TypeScript Usage
The SDK is written in TypeScript and exports all types:
Codeimport { SaligPay, SaligPayConfig, SaligPayAuthTokens, CreateCheckoutOptions, CreateCheckoutApiResponse, SaligPayWebhookPayload, ContactInfo, } from "saligpay-node"; // Strongly typed configuration const config: SaligPayConfig = { clientId: "your-id", clientSecret: "your-secret", env: "sandbox", }; // Typed response const checkout: CreateCheckoutApiResponse = await saligpay.checkout.create({ externalId: "order-123", amount: 10000, description: "Test", webhookUrl: "https://example.com/webhook", returnUrl: "https://example.com/success", contact: { name: "John Doe", email: "john@example.com", }, }); // Typed webhook payload const handleWebhook = (payload: SaligPayWebhookPayload) => { if (payload.status === "COMPLETED") { // TypeScript knows payload has all required properties console.log(`Payment ${payload.externalId} completed`); } };
CommonJS Usage
The SDK supports both ESM and CommonJS:
Code// Using require() const { SaligPay } = require("saligpay-node"); const saligpay = new SaligPay({ clientId: "your-client-id", clientSecret: "your-client-secret", env: "sandbox", }); async function createCheckout() { try { const checkout = await saligpay.checkout.create({ externalId: "order-123", amount: 10000, description: "Test payment", webhookUrl: "https://example.com/webhook", returnUrl: "https://example.com/success", contact: { name: "John Doe", email: "john@example.com", }, }); console.log(checkout.checkoutUrl); } catch (error) { console.error(error); } } createCheckout();
Last modified on
