Example: Payments Integration
Overview
This example illustrates ingesting payment state via /v1/record and handling payment provider webhooks.
REST Flow
ts
import { CloudSDK } from "@syllecta/sdk-js"; const sdk = new CloudSDK({ baseUrl: "https://cloud.syllecta.example", auth: { type: "bearer", token: process.env.SYLLECTA_API_KEY! } }); const lock = await sdk.idempotency.checkOrLock({ scope: "payments", key: "pay_123" }); if (lock.cached) { return lock.record; } if (!lock.locked) { throw new Error(`Retry after ${lock.retryAfterMs}ms`); } await sdk.idempotency.save({ scope: "payments", key: "pay_123", body: { status: "authorized", amount: 4200, currency: "usd" } });
- This flow stores a payment status once and avoids duplicate processing.
- If another caller already created the record, you receive
cached: trueand reuse it. - If the record is locked by another request, wait
retryAfterMsand retry. - Syllecta enforces plan limits automatically (returns
429when exceeded).
Webhook Forwarding
- Configure provider secret/callback via Backoffice UI.
- Payments provider (Stripe/PayPal) sends events to
/v1/webhooks/:provider. - Syllecta logs payload, dedupes, and forwards to your configured callback URL.
Example callback handler
ts
app.post("/webhooks/syllecta", express.json(), async (req, res) => { const event = req.body; if (event.type === "payment.succeeded") { await orders.markPaid(event.data.orderId); } res.json({ ok: true }); });
Normalized events contain provider-agnostic fields, so the handler simply checks event.type and updates local records.