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

@bagou/payment-stripe

v0.2.0

Published

Stripe payment abstractions (StripeClient, CheckoutSession, WebhookEvent) for bagou-packages

Readme

@bagou/payment-stripe

Part of the bagou-packages monorepo.

Stripe payment abstractions built on top of the official Stripe SDK. Covers checkout sessions, webhooks, customers, subscriptions, products, discounts, and analytics — all with typed, injectable services.

Install

bun add @bagou/payment-stripe

Set STRIPE_SECRET_KEY in your environment (e.g. via .env):

STRIPE_SECRET_KEY=sk_live_xxx
STRIPE_WEBHOOK_SECRET=whsec_xxx

Services

| Class | Responsibility | |-------|---------------| | StripeClient | Holds the authenticated Stripe SDK instance | | StripeProvider | High-level facade — checkout + webhooks | | StripeCheckoutSession | Create and retrieve Checkout Sessions | | StripeWebhookEvent | Verify and parse incoming webhook events | | StripeCustomer | Customer CRUD + listing | | StripeCustomerPortal | Create Billing Portal sessions | | StripeDiscount | Coupon / promo-code management | | StripeProducts | Product and price CRUD | | StripeAnalytics | Revenue and subscription summary |

Usage

Checkout session

import { StripeProvider } from "@bagou/payment-stripe";

const provider = new StripeProvider();

const session = await provider.createCheckoutSession({
  lineItems: [{ price: "price_xxx", quantity: 1 }],
  mode: "subscription",
  successUrl: "https://example.com/success",
  cancelUrl: "https://example.com/cancel",
});

const retrieved = await provider.retrieveSession(session.id);

Webhook verification

const event = await provider.constructWebhookEvent(
  rawBody,
  stripeSignatureHeader,
  process.env.STRIPE_WEBHOOK_SECRET!,
);

if (event.type === "checkout.session.completed") {
  const data = event.data; // CheckoutSessionCompletedDataType
}

Customers

import { StripeClient, StripeCustomer } from "@bagou/payment-stripe";

const customer = new StripeCustomer(new StripeClient());

const created = await customer.create({ email: "[email protected]", name: "Alice" });
const updated = await customer.update(created.id, { name: "Alice B." });
const found   = await customer.get(created.id);
const list    = await customer.list({ limit: 20 });
await customer.remove(created.id);

Billing Portal

import { StripeClient, StripeCustomerPortal } from "@bagou/payment-stripe";

const portal = new StripeCustomerPortal(new StripeClient());

const session = await portal.create({
  customerId: "cus_xxx",
  returnUrl: "https://example.com/account",
});

// Redirect the user to session.url

Discounts (coupons)

import { StripeClient, StripeDiscount } from "@bagou/payment-stripe";

const discount = new StripeDiscount(new StripeClient());

const coupon = await discount.create({
  name: "SUMMER20",
  type: "percentage",
  amount: 20,
  duration: "once",
  code: "SUMMER20",
});

Products & prices

import { StripeClient, StripeProducts } from "@bagou/payment-stripe";

const products = new StripeProducts(new StripeClient());

const product = await products.create({ name: "Pro Plan" });

const price = await products.createPrice({
  productId: product.id,
  currency: "eur",
  unitAmount: 1999,
  type: "recurring",
  interval: "month",
});

Analytics

import { StripeClient, StripeAnalytics } from "@bagou/payment-stripe";

const analytics = new StripeAnalytics(new StripeClient());

const summary = await analytics.get({
  startDate: new Date("2025-01-01"),
  endDate: new Date("2025-12-31"),
  currency: "eur",
});

console.log(summary.totalRevenue, summary.activeSubscriptions);

Supported Webhook Events

| Event | Type constant | |-------|--------------| | checkout.session.completed | EStripeEvent.CheckoutSessionCompleted | | invoice.paid | EStripeEvent.InvoicePaid | | customer.subscription.deleted | EStripeEvent.CustomerSubscriptionDeleted | | customer.subscription.updated | EStripeEvent.CustomerSubscriptionUpdated | | payment_intent.payment_failed | EStripeEvent.PaymentIntentPaymentFailed |

License

MIT © Bagou