أنشئ جلسة الدفع، وأرفق مرجع المشتري، وتحقق من الـ Webhooks الموقّعة من خادم Node أو Bun أو Deno. وهي الحزمة نفسها التي تستخدمها في المتصفح، لكن من مدخل `esaalat/server`.
npm install esaalatimport { createEsaalatServer } from "esaalat/server";
// Reads ESAALAT_CLIENT_ID, ESAALAT_CLIENT_SECRET and ESAALAT_WEBHOOK_SECRET.
const esaalat = createEsaalatServer();
// Your server fixes the amount; the browser only ever receives the token.
const session = await esaalat.sessions.create({
orderId: "order-12345",
amount: 5000, // whole riyals, as a number or a string
});
// session.session_token → open the checkout from your page
// session.portal_url → or redirect the buyer straight to it// Keep the raw body: a parsed-and-restringified object will not match.
app.post(
"/esaalat/webhooks",
express.raw({ type: "application/json" }),
async (req, res) => {
try {
const { payload } = await esaalat.webhooks.verify(
req.body,
req.header("X-Esaalat-Signature") ?? ""
);
if (payload.event === "payment.verified") {
releaseOrder(payload.order_id); // idempotent on intent_id
}
res.sendStatus(200);
} catch {
res.sendStatus(400); // anything but 2xx schedules a retry
}
}
);exp داخل الـ JWT، فلا تبدأ طلباتك بالفشل عند انتهاء الساعة.429 أو انتهاء المهلة أن ينشئ الطلب مرتين.429 و5xx وفشل الشبكة، مع احترام Retry-After.| المعامل | متغير البيئة | القيمة الافتراضية |
|---|---|---|
clientId | ESAALAT_CLIENT_ID | مطلوب |
clientSecret | ESAALAT_CLIENT_SECRET | مطلوب |
webhookSecret | ESAALAT_WEBHOOK_SECRET | يحتاجه webhooks.verify |
baseUrl | ESAALAT_BASE_URL | https://api.esaalat.com/api/v1 |
timeoutMs | — | 20000 |
maxRetries | — | 2 |
window، فلا يمكن لأداة تجميع أن تُرسلها إلى صفحة.esaalat للمتصفح وesaalat/server لهذا الخادم.