@drwintech/sandpay is the official TypeScript SDK for Node.js 20+. It wraps the HTTP API, normalizes errors, and exposes a helper for verifying webhook signatures.
Installation
Import and constructor
payments.create(input)
Creates a simulated payment.
payments.get(id)
Payment object as create. Throws SandPayApiError with status: 404 if the ID is unknown.
payments.list(params?)
webhooks.verify(header, payload, secret)
Verifies the HMAC-SHA256 signature of a webhook. payload must be the raw body, exactly as received.
Getting the rawBody
webhooks.parseEvent(rawBody)
Parses an already-verified webhook body into a typed WebhookPayload. Call this after verify(...).
Error if:
- the body is not valid JSON (
Invalid JSON in webhook body), - the body is not a JSON object (
Webhook body must be a JSON object), - the event name is unknown (
Unknown webhook event: ...), - a required field is missing or has the wrong type (
Missing or invalid field: ...).
Exported types
WebhookEventName— literal union of event names ("payment.completed"today).WebhookPayload— interface of the payload returned byparseEvent.