npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

paysafe-sdk

v1.0.0

Published

Production-grade, zero-dependency TypeScript SDK for the Paysafe API: Payment Handles, Payments, Settlements, Refunds, Payouts, Verifications, Customer Vault, Payment Scheduler (Plans & Subscriptions), merchant onboarding Applications, Value Added Service

Readme

paysafe-sdk

Production-grade TypeScript SDK for the Paysafe API.

npm version License: MIT

Coverage

| Bounded context | Resources | |---|---| | Payments | Payment Handles, Payments, Settlements, Refunds, Payouts (standalone & original credits), Verifications | | Customer Vault | Customer profiles, saved payment handles, single-use customer tokens | | Payment Scheduler | Plans, Subscriptions (create, update, cancel, suspend, reactivate) | | Applications | Merchant onboarding: create, update, submit, terms & conditions, document upload | | Value Added Services | FX Rates, Customer Identity (KYC), Bank Account Validation, Interac Verification (VerifiedMe) | | Webhooks | HMAC-SHA256 signature verification (constant-time) and event parsing |

Install

npm install paysafe-sdk

Requires Node.js >= 18. Also runs on any runtime with fetch and either node:crypto or Web Crypto (SubtleCrypto) — browsers, Deno, Cloudflare Workers, and other edge runtimes.

Quick start

import { PaysafeClient } from "paysafe-sdk";

const client = new PaysafeClient({
  username: process.env.PAYSAFE_USERNAME!,
  password: process.env.PAYSAFE_PASSWORD!,
  environment: "test", // or "production"
  accountId: process.env.PAYSAFE_ACCOUNT_ID!,
});

// 1. Tokenize a card into a Payment Handle.
const handle = await client.paymentHandles.create({
  merchantRefNum: "order-1",
  amount: 5000, // minor currency units — $50.00
  currencyCode: "USD",
  paymentType: "CARD",
  transactionType: "PAYMENT",
  card: {
    cardNum: "4111111111111111",
    cardExpiry: { month: 12, year: 2030 },
    cvv: "123",
    holderName: "Jane Doe",
  },
});

// 2. Charge it.
const payment = await client.payments.create({
  merchantRefNum: "order-1",
  amount: 5000,
  currencyCode: "USD",
  paymentHandleToken: handle.paymentHandleToken,
  settleWithAuth: true,
});

console.log(payment.status); // "COMPLETED"

Or build a client from PAYSAFE_USERNAME / PAYSAFE_PASSWORD / PAYSAFE_ENVIRONMENT / PAYSAFE_ACCOUNT_ID environment variables:

const client = PaysafeClient.fromEnv();

See examples/ for a full payment flow, a subscription signup flow, and a webhook receiver.

Error handling

Every rejected promise from this SDK rejects with a PaysafeError — never a bare string or plain object:

import { PaysafeError } from "paysafe-sdk";

try {
  await client.payments.create(req);
} catch (err) {
  if (err instanceof PaysafeError) {
    console.error(err.kind);       // "api_error" | "http_error" | "rate_limited" | "timeout" | ...
    console.error(err.code);       // Paysafe error code, e.g. "5068"
    console.error(err.httpStatus); // e.g. 400
    console.error(err.fieldErrors); // [{ field: "card.cardNum", error: "Invalid card number" }]
    console.error(err.retryable);  // whether the SDK's own retry policy would retry this
  }
}

Webhooks

import { WebhooksResource, webhookTopic, PaysafeError } from "paysafe-sdk";

const webhooks = new WebhooksResource();

// In your HTTP handler, using the *raw* request body:
try {
  const event = await webhooks.verifyAndParse(rawBody, req.headers["signature"], hmacKey);
  switch (webhookTopic(event)) {
    case "payment_handle":
      // ...
      break;
    // ...
  }
  res.status(200).send("OK");
} catch (err) {
  if (err instanceof PaysafeError && err.kind === "webhook_signature_mismatch") {
    res.status(401).send("Invalid signature");
  }
}

Signature verification uses a constant-time comparison and works identically on Node.js (node:crypto) and Web Crypto runtimes (browsers, Deno, Cloudflare Workers).

Configuration reference

new PaysafeClient({
  username: string,               // required
  password: string,                // required
  environment?: "test" | "production", // default: "test"
  accountId?: string,               // default account ID for resources that need one
  baseUrlOverride?: string,         // override the base URL entirely (e.g. for a mock server in tests)
  timeoutMs?: number,               // per-request timeout, default 30_000
  maxRetries?: number,              // default 3
  retryBaseDelayMs?: number,        // exponential backoff base delay, default 500
  rateLimit?: { limit: number; windowMs: number }, // local token bucket, default 100 req / 1000ms
  fetch?: (url, init) => Promise<Response>, // custom fetch implementation
  telemetryPrefix?: string,         // metric/event name prefix, default "paysafe"
});

Pass a TelemetryHook as the second constructor argument to observe every request:

const client = new PaysafeClient(options, {
  onStart: (meta) => metrics.increment(`${meta.prefix}.${meta.api}.start`),
  onStop: (meta) => metrics.timing(`${meta.prefix}.${meta.api}.duration`, meta.durationMs),
});

Design principles

  • Zero runtime dependencies. Built entirely on platform fetch and crypto APIs.
  • Dual ESM/CJS build with full TypeScript declarations, via tsup.
  • Retry with exponential backoff + jitter on transient failures (5xx, 429, timeouts, and a documented set of Paysafe API error codes).
  • Token-bucket rate limiting per credential, enforced client-side before any network call.
  • Structured errors. Every failure mode maps to a typed PaysafeError.kind.
  • Strict TypeScript: strict, noUncheckedIndexedAccess, and friends are all on.
  • Every resource method accepts an optional AbortSignal for cancellation, composed with the client's own timeout.

Development

npm install
npm run build       # tsup -> dist/ (ESM + CJS + .d.ts)
npm run test         # vitest
npm run lint         # eslint
npm run typecheck    # tsc --noEmit
npm run format       # prettier --write

License

MIT