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

@saasifier/billing

v0.1.1

Published

Provider-independent billing primitives for SaaSify — the `BillingProvider` interface and types that `@saasifier/core` builds subscription billing on top of, plus an in-memory mock provider for tests and local development.

Readme

@saasifier/billing

Provider-independent billing primitives for SaaSify — the BillingProvider interface and types that @saasifier/core builds subscription billing on top of, plus an in-memory mock provider for tests and local development.

Installation

npm install @saasifier/billing
# or
pnpm add @saasifier/billing

Overview

SaaSify's core never talks to a payment provider's SDK directly. Instead, every provider (Stripe, and eventually Paddle, Lemon Squeezy, or a custom one) implements the same BillingProvider interface defined here, and @saasifier/core depends only on that interface. This package owns the provider-independent shape of a subscription, the webhook event types SaaSify understands, and a fully in-memory createMockBillingProvider implementation that lets you exercise checkout, subscription lifecycle, and webhook-signature-failure paths without any real billing credentials.

Usage

import { createMockBillingProvider } from "@saasifier/billing";

const billing = createMockBillingProvider({ webhookSecret: "test-secret" });

const { customerId } = await billing.createCustomer({
  organizationId: "org_123",
  email: "[email protected]"
});

const { url } = await billing.createCheckout({
  organizationId: "org_123",
  customerId,
  planKey: "pro",
  successUrl: "https://app.example.com/billing/success",
  cancelUrl: "https://app.example.com/billing/cancel"
});

const subscription = await billing.createSubscription({
  organizationId: "org_123",
  customerId,
  planKey: "pro"
});

// Verifying an inbound webhook payload (throws WebhookVerificationError on mismatch)
const event = billing.verifyWebhook({
  payload: JSON.stringify({ id: "evt_1", type: "subscription.created", subscription }),
  signature: "test-secret"
});

In a real app, @saasifier/core is what actually calls a BillingProvider — this package is typically consumed indirectly, with @saasifier/billing's types used to type your own provider config or a custom adapter.

API Reference

BillingProvider

The interface every billing provider adapter (e.g. @saasifier/billing-stripe) implements. core depends only on this interface, never a provider SDK.

  • name: string — provider identifier (e.g. "stripe", "mock").
  • createCustomer({ organizationId, email?, name? }) — creates a billing customer for an organization, returns { customerId }.
  • createCheckout({ organizationId, customerId, planKey, successUrl, cancelUrl }) — creates a hosted checkout session, returns { url }.
  • createSubscription({ organizationId, customerId, planKey }) — creates a subscription directly (no checkout), returns a ProviderSubscription.
  • cancelSubscription({ subscriptionId }) — cancels a subscription, returns the updated ProviderSubscription.
  • changeSubscription({ subscriptionId, planKey }) — changes the plan on an existing subscription.
  • getSubscription({ subscriptionId }) — fetches a subscription, or null if it doesn't exist.
  • createPortalSession({ customerId, returnUrl }) — creates a hosted billing-management portal session, returns { url }.
  • verifyWebhook({ payload, signature }) — verifies a webhook's signature and parses it into a BillingWebhookEvent. Throws WebhookVerificationError (from @saasifier/types) on a signature mismatch. Returns null for an authentically-signed event whose type SaaSify doesn't model — callers should acknowledge it (HTTP 200) without further processing.

createMockBillingProvider(options?)

Returns a BillingProvider backed entirely by in-memory Maps — no network calls. Useful for unit tests, the playground app, and any environment without real billing credentials.

  • options.webhookSecret?: string — the signature verifyWebhook requires exact-match against (defaults to "mock-webhook-secret"). Lets you exercise signature-mismatch handling without a real provider.

Types

  • ProviderSubscription — normalized subscription state: providerSubscriptionId, providerCustomerId, organizationId, planKey, status (SubscriptionStatus), currentPeriodEnd?, cancelAtPeriodEnd.
  • BillingEventType — the webhook event types SaaSify models: "subscription.created", "subscription.updated", "subscription.cancelled", "payment.succeeded", "payment.failed", "invoice.created", "invoice.paid".
  • BillingWebhookEvent — { id, type, subscription? }, the normalized result of verifyWebhook.

Design notes

  • organizationId is recovered by the adapter, not stored by this package — each provider is responsible for attaching and reading back the organization id (e.g. via Stripe customer/subscription metadata) so multi-tenant billing events can be routed to the right tenant.
  • Signature failures must throw, never degrade into a best-effort guess. verifyWebhook either returns a trustworthy BillingWebhookEvent, returns null for an event type SaaSify doesn't handle, or throws WebhookVerificationError.
  • This package intentionally has no dependency on any provider SDK — only @saasifier/types.