g14o
Packages@g14o/paystack-better-auth

Checkout

One-time payments with hosted Paystack checkout.

Create a checkout session

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

const session = await auth.api.createCheckoutSession({
  body: {
    email: "user@example.com",
    amount: 1500,
    currency: "GHS",
    reference: "order_123",
    callbackUrl: "https://app.example.com/payment/callback",
    channels: ["card", "mobile_money"],
    metadata: {
      orderId: "order_123",
      customerName: "Ada Lovelace",
    },
    disableRedirect: true,
  },
  headers: await headers(),
});

// session.authorizationUrl — redirect the user or open in a popup

Set disableRedirect: true on the server to receive { authorizationUrl, reference } as JSON instead of an HTTP redirect.

Fulfill on the server

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.

On this page