Webhooks allow SaligPay to notify your server about payment events in real-time. Instead of polling for status updates, your application receives instant notifications when payments complete, subscriptions activate, or refunds process.
How Webhooks Work
Code
Customer Pays → SaligPay Processes → Webhook Sent → Your Server Receives ↓ Verify Signature ↓ Process Event ↓ Return 200 OK
Quick Start
Step 1: Set Up Webhook Endpoint
Code
import express from "express";import { SaligPay } from "saligpay-node";const app = express();const saligpay = new SaligPay({ webhookSecret: process.env.SALIGPAY_WEBHOOK_SECRET!,});// Use raw body for signature verificationapp.use("/webhooks/saligpay", express.raw({ type: "application/json" }));app.post("/webhooks/saligpay", async (req, res) => { try { const payload = saligpay.webhooks.constructEvent(req.body); switch (payload.status) { case "completed": console.log("Payment completed:", payload.externalId); // Update order, send email, etc. break; case "failed": console.log("Payment failed:", payload.externalId); break; } res.status(200).json({ received: true }); } catch (error) { console.error("Webhook error:", error); res.status(400).json({ error: "Invalid webhook" }); }});
Step 2: Configure Webhook URL
Set your webhook URL when creating checkout sessions or payment intents: