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

@suluk/billing

v0.2.4

Published

Stripe PLUMBING over an injected config (secret key + a mockable fetch): the HTTP transport (with the refund idempotency-key), customer/SetupIntent/PaymentIntent creation, the saved-card surface, the money-moving paths (hosted Checkout + portal + on-defau

Readme


CANDIDATE tooling — not official OpenAPI. Suluk is a single-contributor candidate for OpenAPI Specification v4.0 ("Moonwalk"), unaffiliated with the OpenAPI Initiative and unable to ratify anything on the SIG's behalf.

Install

bun add @suluk/billing

What it does

Stripe wrappers, extracted verbatim from a real app (C046), over an injected StripeConfig (a secret key plus a mockable fetch) so every call site is testable without hitting Stripe. It is deliberately just the plumbing:

  • TransportstripePost / stripeGet / toForm, including the refund idempotency-key.
  • Customer + intentscreateCustomer, createSetupIntent, createPaymentIntent, and the saved-card surface (listPaymentMethods, defaultCard, setDefaultPaymentMethod, ownsPaymentMethod, …).
  • Money-moving paths — hosted Checkout (createCheckout / createSubscriptionCheckout), the billing portal, on-default-card top-up (createPaymentIntentOnDefaultCard), and the off-session charge (chargeOffSession).
  • Stripe TaxcalculateTax / recordTaxTransaction, graceful by design (any failure → taxCents 0, the top-up still proceeds).
  • Subscriptions — the recurring-billing mechanics made generic over a SubPlan catalog the app supplies (find-or-create pricing, create-on-default-card, live status, in-place plan change).
  • The billing-account store — the package-owned user ↔ Stripe link (billingAccount), applied by the app's migrations over an injected Drizzle handle.

What stays in the app (policy, not library): the Stripe webhook dispatch (which composes @suluk/payments' webhookRouter + these primitives + @suluk/credits.grantOnce), the branded email templates, payment-alert kinds, and refund/subscription pooling.

Usage

import {
  createCustomer, createCheckout, createPaymentIntentOnDefaultCard,
  createSubscriptionOnDefaultCard, type StripeConfig, type SubPlan,
} from "@suluk/billing";

// The injected config — a Worker passes global fetch; a test passes a mock.
const cfg: StripeConfig = { secretKey: env.STRIPE_SECRET_KEY };

// A hosted Checkout for a one-time top-up (app supplies product name + URLs).
const { url } = await createCheckout(cfg, {
  customerId: await ensureCustomer(cfg, userId),
  amountCents: 2000,
  productName: "1,000 credits",
  successUrl: "https://app.example/thanks",
  cancelUrl: "https://app.example/billing",
});

// One-click top-up on the saved default card.
await createPaymentIntentOnDefaultCard(cfg, { customerId, amountCents: 2000, meta: { userId, credits: "1000" } });

Subscriptions are generic over your plan catalog — the pricing matrix stays in the app:

import { planById, createSubscriptionOnDefaultCard, changeSubscriptionPlan } from "@suluk/billing";

const plans: SubPlan[] = [
  { id: "pro", name: "Pro", credits: 5000, priceCents: 2900, label: "Pro — $29/mo" },
];

const sub = await createSubscriptionOnDefaultCard(cfg, { customerId, plan: planById(plans, "pro")! });

The billing-account store owns the user ↔ Stripe link (inject a Drizzle handle):

import { billingAccount, linkBillingCustomer, billingCustomerId } from "@suluk/billing";
// include `billingAccount` in your migration; `userId` is the PK as a plain column.
await linkBillingCustomer(db, userId, "cus_123");
const existing = await billingCustomerId(db, userId); // "cus_123" | null

What's inside

| Module | Exports | | --- | --- | | transport | stripePost, stripeGet, toForm, StripeConfig. | | billing (v1) | createCustomer, createSetupIntent, createPaymentIntent, the saved-card surface (listPaymentMethods, defaultCard, defaultPaymentMethodId, ownsPaymentMethod, setDefaultPaymentMethod, detachPaymentMethod, …), payOpenInvoice. | | payments (v2) | createCheckout, createSubscriptionCheckout, createPortalSessionForCustomer, createPaymentIntentOnDefaultCard, chargeOffSession. | | tax (v2) | calculateTax, recordTaxTransaction (graceful → 0 on failure). | | subscriptions (v2) | SubPlan, planById, planByPrice, ceilingFor, ensurePlanPrice, createSubscriptionOnDefaultCard, getSubscriptionStatus, changeSubscriptionPlan. | | account (v2) | billingAccount (schema), billingCustomerId, billingSubscriptionId, linkBillingCustomer, upsertBillingAccount, clearSubscription. |

Boundary

The whole surface is pure Stripe wrappers over an injected config — inject the config (secret + fetch) and the Drizzle handle, and everything is deterministically testable. Charging policy (webhook routing, crediting, branded email, refund/pooling) is the app's, not the library's.

Depends on @suluk/payments, @suluk/drizzle, and drizzle-orm. It composes with @suluk/credits in the app's webhook handler (grant credits on a paid invoice).

License

Apache-2.0