Skip to main content
@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.
Prefer a ready-to-run starter? See Stack Builder — it generates a Next.js/Express/Hono project with @drwintech/sandpay already wired up and your keys pre-filled.

Installation

Import and constructor

payments.create(input)

Creates a simulated payment.

payments.get(id)

Returns the same 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(...).
Throws an 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: ...).
Validation is intentionally minimal — it checks the shape just enough to provide safe downstream typing. For exhaustive validation, compose with zod.

Exported types

  • WebhookEventName — literal union of event names ("payment.completed" today).
  • WebhookPayload — interface of the payload returned by parseEvent.

SandPayApiError

Thrown on any non-2xx HTTP status.

Source code

The SDK is open source: github.com/htleclerc/sandpay. PRs welcome.