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

@ras-sh/convex-stripe

v0.0.4

Published

Convex component for Stripe integration with subscription management, webhooks, and billing portal

Readme

@ras-sh/convex-stripe

⚡💳 Stripe integration for Convex. Syncs customers, subscriptions, and payments through secure webhooks and helpful utilities.

Features

  • Full Stripe integration (customers, subscriptions, products, prices, invoices)
  • Automatic webhook sync with signature verification
  • Product slugs for developer-friendly references
  • Multi-currency support
  • Checkout sessions and billing portal
  • Type-safe with full TypeScript support

Installation

npm install @ras-sh/convex-stripe stripe convex-helpers

Quick Start

1. Configure the component

In convex/convex.config.ts:

import { defineApp } from "convex/server";
import stripe from "@ras-sh/convex-stripe/convex.config";

const app = defineApp();
app.use(stripe);

export default app;

2. Initialize Stripe

In convex/stripe.ts:

import { components } from "./_generated/api";
import { StripeComponent } from "@ras-sh/convex-stripe";
import Stripe from "stripe";

const stripeClient = new Stripe(process.env.STRIPE_SECRET_KEY!, {
  apiVersion: "2025-09-30.clover",
});

export const stripe = new StripeComponent(components.stripe, {
  getUserInfo: async (ctx) => {
    const user = await getCurrentUser(ctx);
    return { userId: user._id, email: user.email };
  },
  products: {
    premiumMonthly: { productId: "prod_xxx", priceId: "price_xxx" },
  },
  stripe: stripeClient,
  stripeSecretKey: process.env.STRIPE_SECRET_KEY!,
  webhookSecret: process.env.STRIPE_WEBHOOK_SECRET!,
});

export const {
  getCurrentSubscription,
  listUserSubscriptions,
  listActiveProducts,
  getConfiguredProducts,
  listUserInvoices,
  generateCheckoutLink,
  generateBillingPortalLink,
  cancelSubscription,
} = stripe.api();

3. Set up webhooks

In convex/http.ts:

import { httpRouter } from "convex/server";
import { stripe } from "./stripe";

const http = httpRouter();

stripe.registerRoutes(http, {
  path: "/stripe/webhook",
});

export default http;

Add custom webhook handlers (optional):

stripe.registerRoutes(http, {
  path: "/stripe/webhook",
  onCheckoutComplete: async (ctx, event) => {},
  onSubscriptionCreated: async (ctx, event) => {},
  onSubscriptionUpdated: async (ctx, event) => {},
  onSubscriptionDeleted: async (ctx, event) => {},
  onInvoicePaid: async (ctx, event) => {},
  onInvoiceFailed: async (ctx, event) => {},
});

4. Use in React

import { ConvexProvider } from "convex/react";
import { StripeProvider } from "@ras-sh/convex-stripe/react";
import { api } from "../convex/_generated/api";

function App() {
  return (
    <ConvexProvider client={convex}>
      <StripeProvider api={api.stripe}>
        <YourApp />
      </StripeProvider>
    </ConvexProvider>
  );
}
import { useSubscription, useGenerateCheckoutLink } from "@ras-sh/convex-stripe/react";

function SubscriptionPage() {
  const subscription = useSubscription();
  const generateCheckout = useGenerateCheckoutLink();

  const handleUpgrade = async () => {
    const { url } = await generateCheckout({
      priceIds: ["price_xxx"],
      successUrl: `${window.location.origin}/success`,
      cancelUrl: `${window.location.origin}/cancel`,
    });
    window.location.href = url;
  };

  return subscription?.isActive ? (
    <p>Active until {subscription.periodEndDate}</p>
  ) : (
    <button onClick={handleUpgrade}>Upgrade</button>
  );
}

Configuration

Environment Variables

STRIPE_SECRET_KEY=sk_test_xxx
STRIPE_WEBHOOK_SECRET=whsec_xxx

Webhook Setup

Configure webhook endpoint in your Stripe dashboard:

  • URL: https://your-deployment.convex.site/stripe/webhook
  • Events: Select all checkout, customer, subscription, invoice, product, and price events

API

Queries

  • getCurrentSubscription()
  • listUserSubscriptions()
  • listActiveProducts()
  • getConfiguredProducts()
  • listUserInvoices({ limit? })

Actions

  • generateCheckoutLink({ priceIds, successUrl, cancelUrl, mode? })
  • generateBillingPortalLink({ returnUrl })
  • cancelSubscription({ immediate? })

Internal Actions

Available via ctx.runAction(internal.stripe.*):

  • syncAll()
  • syncProducts()
  • syncCustomers()
  • syncSubscriptions()
  • syncInvoices()

React Hooks

  • useSubscription()
  • useCurrentSubscription()
  • useUserSubscriptions()
  • useActiveProducts()
  • useConfiguredProducts()
  • useUserInvoices({ limit? })
  • useGenerateCheckoutLink()
  • useGenerateBillingPortalLink()
  • useCancelSubscription()

Utilities

  • formatCurrency(amountInCents, currency)
  • formatDate(timestamp, options?)
  • isSubscriptionActive(status)

License

MIT

Links