| Collection method | Pick this when | Reliability check |
|---|---|---|
| Bounded API polling | An order investigation needs a finite receipt snapshot | Report incomplete collection separately from delivery failure |
| Callback ingestion | Your application needs to react as receipts arrive | Persist each accepted event before advancing application state |
| Callbacks plus reconciliation | You need prompt updates and a separate check for missing evidence | Compare receipts against the orders awaiting notification |
TL;DR: For a fintech marketplace notifying sellers about new orders, fetch SMS delivery status events into a validated receipt snapshot, then alert separately on missing receipts and collection errors. The Node.js TypeScript example below runs against an inline fixture first. Connect its adapter to a documented API only after mapping that API's actual fields and delivery semantics.
The useful result is an answer to an operational question: which seller notifications still lack delivery evidence? A successful HTTP request alone doesn't answer it. Neither does an empty event array. This guide uses a small, explicit contract so the logging and alert decisions remain inspectable. It makes no claim that any commercial API returns this schema.
How should code fetch SMS delivery status events for seller orders?
Pick bounded polling when an operator needs to inspect a specific order cohort. It gives the investigation a beginning and an end. Set a deadline, record how many requests succeeded, and preserve the distinction between a completed snapshot and a failed fetch. The example implements one request for one snapshot; it deliberately has no pagination loop.
Pick callback ingestion when receipt arrival should trigger application work. That design needs an ingress handler, persistence, duplicate handling, and an explicit policy for acknowledging events. Those responsibilities belong in the implementation review even if a callback appears easier to wire up than a scheduled collector.
Pick callbacks plus reconciliation when the operational requirement includes finding orders whose notification evidence never appeared. Reconciliation starts from the expected order cohort. Otherwise, a dashboard built entirely from received events has no row for the missing receipt it needs to expose. The trade-off is another job to operate and another state boundary to test.
Count the absences.
Diagram in words: new order → expected notification record → receipt collector → validated snapshot → order comparison → structured summary and alert decision. Keep the order and receipt identifiers in restricted investigation records; use aggregate counts for routine monitoring. The example emits no phone numbers, message bodies, or access tokens.
Step 1: Define the receipt boundary before fetching
Use this local contract as a teaching fixture. Its three status values are application choices, not a standardized SMS vocabulary. Here, delivered means the adapter has mapped a documented delivery receipt into that value. It must never mean merely accepted for sending. Define that mapping during integration, including what to do with statuses the application doesn't understand.
The code below is one complete TypeScript module. Run it with a TypeScript-capable Node.js setup. It uses an inline data URL, so the first run needs no account, credentials, or external service. The strict validator is intentionally small: it rejects unexpected statuses, duplicate message IDs, and malformed rows instead of manufacturing a healthy-looking summary.
import assert from "node:assert/strict"; type Receipt = { messageId: string; status: "pending" | "delivered" | "failed"; }; type Snapshot = { complete: true; events: Receipt[] }; type Expected = { orderId: string; messageId: string }; function parseSnapshot(value: unknown): Snapshot { if (typeof value !== "object" || value === null) { throw new Error("invalid_snapshot"); } const root = value as Record<string, unknown>; if (root.complete !== true || !Array.isArray(root.events)) { throw new Error("incomplete_or_invalid_snapshot"); } const seen = new Set<string>(); const events: Receipt[] = []; for (const item of root.events) { if (typeof item !== "object" || item === null) { throw new Error("invalid_event"); } const row = item as Record<string, unknown>; if (typeof row.messageId !== "string" || row.messageId.length === 0) { throw new Error("invalid_message_id"); } if (row.status !== "pending" && row.status !== "delivered" && row.status !== "failed") { throw new Error("unknown_status"); } if (seen.has(row.messageId)) throw new Error("duplicate_message_id"); seen.add(row.messageId); events.push({ messageId: row.messageId, status: row.status }); } return { complete: true, events }; } async function fetchSnapshot(url: string, token?: string): Promise<Snapshot> { const headers: Record<string, string> = { Accept: "application/json" }; if (token) headers.Authorization = `Bearer ${token}`; const response = await fetch(url, { headers, signal: AbortSignal.timeout(5_000), redirect: "error", }); if (!response.ok) throw new Error(`receipt_http_${response.status}`); return parseSnapshot(await response.json()); } function summarize(expected: Expected[], snapshot: Snapshot) { const byMessage = new Map(snapshot.events.map(row => [row.messageId, row])); const counts = { expected: expected.length, delivered: 0, pending: 0, failed: 0, missing: 0 }; for (const notification of expected) { const receipt = byMessage.get(notification.messageId); if (!receipt) counts.missing += 1; else counts[receipt.status] += 1; } return counts; } async function main() { const expected: Expected[] = [ { orderId: "order-701", messageId: "sms-701" }, { orderId: "order-702", messageId: "sms-702" }, { orderId: "order-703", messageId: "sms-703" }, { orderId: "order-704", messageId: "sms-704" }, ]; const fixture = { complete: true, events: [ { messageId: "sms-701", status: "delivered" }, { messageId: "sms-702", status: "pending" }, { messageId: "sms-703", status: "failed" }, ] }; const url = `data:application/json,${encodeURIComponent(JSON.stringify(fixture))}`; const started = performance.now(); try { const snapshot = await fetchSnapshot(url); const counts = summarize(expected, snapshot); assert.deepEqual(counts, { expected: 4, delivered: 1, pending: 1, failed: 1, missing: 1 }); assert.throws(() => parseSnapshot({ complete: false, events: [] })); assert.throws(() => parseSnapshot({ complete: true, events: [ { messageId: "sms-701", status: "unmapped" }, ] })); console.log(JSON.stringify({ event: "seller_sms_receipt_snapshot", collection: "complete", durationMs: Math.round(performance.now() - started), ...counts, reviewNeeded: counts.failed > 0 || counts.missing > 0, })); } catch { console.error(JSON.stringify({ event: "seller_sms_receipt_collection_error", collection: "failed", durationMs: Math.round(performance.now() - started), })); process.exitCode = 1; } } void main(); The deadline is 5,000 milliseconds in this example.
That's a chosen collection budget, not a delivery guarantee or a measured service response time. A timeout produces a collection error. It does not assign a failed delivery status to all four orders.
Step 2: Turn the snapshot into an operational signal
The module prints four expected notifications, one delivered receipt, one pending receipt, one failed receipt, and one missing receipt. Those are fixture results. The assertion makes the expected before-and-after visible: three received rows become an accounting of four expected notifications.
The missing fourth message is the important teaching case. An event-only count would omit it. Here it triggers reviewNeeded, while the pending receipt remains separately visible. For a live deployment, add an explicit age policy before promoting that review signal into a page: a fresh order awaiting a receipt and an old order without one need different treatment. Choose that policy from the seller notification requirement, then test its boundary. For example, consider the fixture's order-704 during an investigation: it belongs to the expected cohort, but sms-704 has no receipt row. Before acting, verify that the collector queried the right cohort and finished collecting its evidence. If that collection was partial, a missing row could reflect an unfinished fetch rather than a notification problem. The complete flag is therefore an adapter assertion that needs supporting checks, not a value to hard-code onto whatever response arrived. No universal delivery deadline is assumed here.
Missing needs context.
Keep the signals separate: collection failures tell the team it cannot trust the current snapshot; failed receipts describe an explicit mapped outcome; missing receipts describe absent evidence for an expected message. Alert routing can then distinguish a broken collector from a seller notification that needs investigation. Do not automatically send another SMS on either signal. Put repeat-send decisions behind a separate policy that accounts for duplicate seller notifications.
Step 3: Replace the fixture and test the adapter
Retain summarize and replace the fetch boundary with an adapter for the chosen API's documented authentication, response fields, and pagination. The optional bearer header demonstrates one authentication shape; use it only if that API specifies it. Fetching a real endpoint without mapping its response into this contract should fail validation.
That's useful feedback.
A snapshot must represent one current receipt per message ID for the selected cohort. If the source returns a history, define its ordering and reduction rules from that source's documentation before returning complete: true. Do not take the last array element on faith. Likewise, finish every required page before claiming completeness. A partial page set must not become a list of supposedly missing seller notifications.
The inline assertions cover the fixture accounting, an incomplete snapshot, and an unknown status. Extend this same test boundary with duplicate IDs, an empty complete snapshot, non-success HTTP responses, and a timed-out request. The empty complete snapshot should report four missing receipts; a fetch failure should emit the collection error instead. During deployment, run the collector in observation mode for a reviewed order cohort and inspect those two paths before enabling paging. This keeps the first operational decision concrete: is the receipt evidence complete enough to act on?
Limits of receipt evidence
This example fetches one snapshot. It does not implement durable checkpoints, callback verification, pagination, or a repeat-send queue. Its in-memory expected cohort also needs a persisted equivalent before it can support an operational workflow.
Treat delivery evidence as a notification signal, not proof that a seller read the order or accepted it. Keep order acknowledgement as a separate application event. If the workflow also sends email, evaluate its authentication separately: SPF specifies authorization of hosts to use a domain in email identities; it is not an SMS receipt mechanism.
References
- Node.js globals, including fetch and AbortSignal: https://nodejs.org/api/globals.html
- Node.js assertions: https://nodejs.org/api/assert.html
- RFC 7208, Sender Policy Framework: https://datatracker.ietf.org/doc/html/rfc7208

