@sandpay/node 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
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | — | Required. Your sp_sk_test_... key. |
baseUrl | string | https://api.sandpay.dev | API root URL. Override to point at a custom environment. |
payments.create(input)
Creates a simulated payment.
| Field | Type | Required | Notes |
|---|---|---|---|
amount | number | yes | Positive integer, smallest unit (FCFA = whole unit). |
currency | string | yes | FCFA, XOF, XAF, RWF… |
operator | mtn/orange/moov/airtel | yes | See operator guides. |
country | string (2 chars) | yes | ISO-3166. CI, BJ, TG, RW. |
msisdn | string | yes | E.164 format (+225…). |
reference | string | yes | Your internal reference (idempotency key). |
description | string | no | Free-form description (max 200 characters). |
scenario | PaymentScenario | no | See Scenarios. |
payments.get(id)
Payment object as create. Throws SandPayApiError with status: 404 if the ID is unknown.
payments.list(params?)
| Param | Type | Default | Notes |
|---|---|---|---|
limit | number (1–100) | 50 | |
country | string | — | 2-letter filter. |
operator | PaymentOperator | — | |
status | PaymentStatus | — | See scenarios for all 11 values. |
cursor | string | — | Opaque cursor returned by the previous page. |
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.
SandPayApiError
Thrown on any non-2xx HTTP status.
| Property | Type | Description |
|---|---|---|
status | number | HTTP status (400, 401, 402, 404, 429, 5xx). |
code | string | Machine-readable code (see Errors). |
message | string | Human-readable message. |
detail | unknown | Optional structured payload. |
requestId | string? | X-Request-Id response header (useful for support). |