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

@g14o/paystack-better-auth

v0.3.0

Published

Paystack billing plugin for Better Auth — subscriptions, checkout, webhooks, and customer management.

Readme

@g14o/paystack-better-auth

Paystack billing plugin for Better Auth. Supports customers, hosted checkout, subscriptions, authorization charges, and webhook synchronization.

Requires @g14o/paystack for the Paystack API client.

Installation

pnpm add @g14o/paystack @g14o/paystack-better-auth better-auth zod

Server setup

Create a Paystack client with your API keys, then pass it to the plugin as paystackClient.

// lib/auth.ts
import { betterAuth } from "better-auth";
import { Paystack } from "@g14o/paystack";
import { paystack } from "@g14o/paystack-better-auth";

const paystackClient = new Paystack({
  secretKey: process.env.PAYSTACK_SECRET_KEY!,
});

export const auth = betterAuth({
  // ...your auth config
  plugins: [
    paystack({
      paystackClient,
      createCustomerOnSignUp: true,
      subscription: {
        enabled: true,
        plans: [
          {
            name: "basic",
            interval: "monthly",
            amount: "500",
            currency: "GHS",
          },
          {
            name: "pro",
            planCode: "PLN_pro_monthly",
            annualDiscountedPlanCode: "PLN_pro_annual",
          },
        ],
        onSubscriptionComplete: async ({ subscription, plan }) => {
          console.log(`Welcome ${subscription.referenceId} to ${plan?.name}`);
        },
      },
      onEvent: async (event) => {
        console.log("Paystack event", event.event);
      },
    }),
  ],
});

Client setup

// lib/auth-client.ts
import { createAuthClient } from "better-auth/client";
import { paystackClient } from "@g14o/paystack-better-auth/client";

export const authClient = createAuthClient({
  plugins: [
    paystackClient({
      subscription: true // enable subscription
    })
  ],
});

Checkout (one-time payments)

const { data, error } = await authClient.paystack.createCheckoutSession({
  amount: 1500,
  currency: "GHS",
  callbackUrl: "https://app.example.com/payment/callback",
  metadata: { orderId: "order_123" },
});

Fulfill one-time orders on the server via checkout.onCheckoutComplete when Paystack sends charge.success (no transactions.verify call needed):

paystack({
  paystackClient,
  checkout: {
    onCheckoutComplete: async ({ reference, amount, metadata, payment }) => {
      // mark order paid, grant access, send receipt, etc.
    },
  },
});

Set disablePaymentPersistence: true to skip the payment table while still using onCheckoutComplete.

Subscriptions

When a plan entry includes planCode, the plugin fetches billing details from Paystack instead of creating a plan. Pass annual: true on upgrade to use annualDiscountedPlanCode.

const { data, error } = await authClient.paystack.subscription.upgrade({
  plan: "pro",
  annual: true,
  subscriptionCode: "SUB_existing",
  callbackUrl: "https://app.example.com/payment/callback",
  cancelActionUrl: "https://app.example.com/pricing",
});

await authClient.paystack.subscription.cancel();
await authClient.paystack.subscription.resume();
await authClient.paystack.subscription.get();
await authClient.paystack.subscription.list();

Server-side subscription API

| Server | Client equivalent | |--------|-------------------| | auth.api.upgradeSubscription | authClient.paystack.subscription.upgrade | | auth.api.cancelSubscription | authClient.paystack.subscription.cancel | | auth.api.resumeSubscription | authClient.paystack.subscription.resume | | auth.api.getSubscription | authClient.paystack.subscription.get | | auth.api.listSubscriptions | authClient.paystack.subscription.list |

Webhooks

Configure your Paystack dashboard webhook URL to:

https://your-domain.com/api/auth/paystack/webhook

The plugin verifies x-paystack-signature via paystackClient.webhook.verifyPaystackWebhookSignature. Events are deduplicated and persisted in paystackWebhookEvent.

Database schema

Run Better Auth CLI to generate migrations:

npx auth@latest generate

Tables added:

  • user field: paystackCustomerCode and paystackCustomerId
  • subscription (includes emailToken for cancel/resume; when subscription.enabled)
  • payment (one-time checkout records; omit when disablePaymentPersistence: true)
  • webhookEvent (included by default; omit when disableWebhookPersistence: true)

License

MIT