g14o
Packages@g14o/paystack-better-auth

Subscriptions

Upgrade, cancel, resume, and list 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.

Upgrade

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",
});
import { headers } from "next/headers";
import { auth } from "@/lib/auth";

const result = await auth.api.upgradeSubscription({
  body: {
    plan: "pro",
    annual: true,
    subscriptionCode: "SUB_existing",
    callbackUrl: "https://app.example.com/payment/callback",
    cancelActionUrl: "https://app.example.com/pricing",
    channels: ["card", "mobile_money"],
    disableRedirect: true,
  },
  headers: await headers(),
});

Cancel

await authClient.paystack.subscription.cancel({
  subscriptionCode: "SUB_existing",
});
import { headers } from "next/headers";
import { auth } from "@/lib/auth";

await auth.api.cancelSubscription({
  body: { subscriptionCode: "SUB_existing" },
  headers: await headers(),
});

Resume

await authClient.paystack.subscription.resume({
  subscriptionCode: "SUB_existing",
});
import { headers } from "next/headers";
import { auth } from "@/lib/auth";

await auth.api.resumeSubscription({
  body: { subscriptionCode: "SUB_existing" },
  headers: await headers(),
});

Get

await authClient.paystack.subscription.get({
  subscriptionCode: "SUB_existing",
});
import { headers } from "next/headers";
import { auth } from "@/lib/auth";

const subscription = await auth.api.getSubscription({
  query: { subscriptionCode: "SUB_existing" },
  headers: await headers(),
});

List

await authClient.paystack.subscription.list();
import { headers } from "next/headers";
import { auth } from "@/lib/auth";

const subscriptions = await auth.api.listActiveSubscriptions({
  query: { customer: session.user.paystackCustomerId },
  headers: await headers(),
});

On this page