import { GenericEndpointContext, InferOptionSchema, Session, User } from "better-auth"; import { PaystackCustomerClient, PaystackPlanClient, PaystackProductClient, PaystackSubscriptionClient, PaystackTransactionClient, PaystackWebhookEvent, TransactionChargeAuthorizationResponseData, TransactionVerifyResponseData } from "@alexasomba/paystack-node"; import { BetterAuthPluginDBSchema, DBFieldAttribute } from "better-auth/db"; //#region src/schema.d.ts type PluginSchemaTable = Record; disableMigration?: boolean; modelName?: string; }>; type TransactionsSchema = PluginSchemaTable<"paystackTransaction", "reference" | "paystackId" | "referenceId" | "userId" | "amount" | "currency" | "status" | "plan" | "product" | "metadata" | "createdAt" | "updatedAt">; type SubscriptionsSchema = PluginSchemaTable<"subscription", "plan" | "referenceId" | "paystackCustomerCode" | "paystackSubscriptionCode" | "paystackTransactionReference" | "paystackAuthorizationCode" | "paystackEmailToken" | "status" | "periodStart" | "periodEnd" | "trialStart" | "trialEnd" | "cancelAtPeriodEnd" | "groupId" | "seats" | "pendingPlan">; type UserSchema = PluginSchemaTable<"user", "paystackCustomerCode">; type OrganizationSchema = PluginSchemaTable<"organization", "paystackCustomerCode" | "email">; type ProductsSchema = PluginSchemaTable<"paystackProduct", "name" | "description" | "price" | "currency" | "quantity" | "unlimited" | "paystackId" | "slug" | "metadata" | "createdAt" | "updatedAt">; type PlansSchema = PluginSchemaTable<"paystackPlan", "name" | "description" | "amount" | "currency" | "interval" | "planCode" | "paystackId" | "metadata" | "createdAt" | "updatedAt">; type PaystackPluginSchema = SubscriptionsSchema & TransactionsSchema & UserSchema & OrganizationSchema & ProductsSchema & PlansSchema; declare const getSchema: (options: PaystackOptions) => BetterAuthPluginDBSchema; //#endregion //#region src/types.d.ts type PaystackCheckoutChannel = "card" | "bank" | "ussd" | "qr" | "mobile_money" | "bank_transfer" | "eft" | "apple_pay"; /** * Custom models for Paystack Plugin * These align with the database schema in src/schema.ts */ interface PaystackTransaction { id: string; reference: string; paystackId?: string; referenceId: string; userId: string; amount: number; currency: string; status: string; plan?: string | null; product?: string | null; metadata?: string | null; createdAt: Date; updatedAt: Date; } interface PaystackProduct { id?: string; name: string; description?: string; price: number; currency: string; quantity?: number; unlimited?: boolean; paystackId?: string; slug?: string; metadata?: string | null; createdAt?: Date; updatedAt?: Date; } interface PaystackPlan { id?: string; name: string; description?: string; amount?: number; currency?: string; interval?: string; planCode?: string; paystackId?: string; seatAmount?: number; /** * Deprecated legacy alias for `seatAmount`. * If used, it must still be a numeric amount in the smallest currency unit. */ seatPriceId?: number | string; seatPlanCode?: string; invoiceLimit?: number; freeTrial?: { days?: number; onTrialStart?: (subscription: Subscription) => Promise; }; limits?: Record; features?: string[]; metadata?: string | null; createdAt?: Date; updatedAt?: Date; } /** * Paystack Webhook Payload structure */ type PaystackWebhookPayload = PaystackWebhookEvent; /** * Paystack SDK Result types */ type PaystackTransactionResponse = TransactionVerifyResponseData; type PaystackChargeAuthorizationResponse = TransactionChargeAuthorizationResponseData; type PaystackInitializeResult = { kind: "checkout"; url: string; reference: string; accessCode: string; redirect: true; } | { kind: "scheduled"; status: "success"; message: string; scheduled: true; } | { kind: "prorated"; status: "success"; message: string; prorated: true; }; interface SubscriptionOptions { /** * Enable subscriptions */ enabled?: boolean; /** * Plans configuration */ plans: PaystackPlan[] | (() => Promise); /** * Automatically sync quantity from local DB to Paystack (if seats are used) */ autoSyncQuantity?: boolean; /** * Handling of subscription cancellation * @default "at_period_end" */ cancelBehavior?: "at_period_end" | "immediately"; /** * Handlers for subscription events */ onSubscriptionComplete?: (data: { event: PaystackWebhookPayload; subscription: Subscription; plan: PaystackPlan; }, ctx: GenericEndpointContext) => Promise; onSubscriptionCreated?: (data: { event: PaystackWebhookPayload; subscription: Subscription; plan: PaystackPlan; }, ctx: GenericEndpointContext) => Promise; onSubscriptionCancel?: (data: { event: PaystackWebhookPayload; subscription: Subscription; }, ctx: GenericEndpointContext) => Promise; /** * Authorization handler for reference checks */ authorizeReference?: (data: { user: User; session: Session; referenceId: string; action: string; }, ctx: GenericEndpointContext) => Promise; /** * Require email verification before subscription */ requireEmailVerification?: boolean; /** * Restrict checkout to specific Paystack channels for subscription flows. * Use `["card"]` to enforce card-only subscriptions. */ allowedPaymentChannels?: PaystackCheckoutChannel[]; } interface PaystackOptions { /** * Paystack Secret Key */ secretKey: string; /** * Deprecated alias for `webhook.secret`. * Use `webhook.secret` for new code. */ paystackWebhookSecret?: string; /** * Paystack Client Instance * If provided, will be used instead of creating a new one with secretKey */ paystackClient?: TPaystackClient; /** * Webhook configuration */ webhook?: { /** * Webhook secret for signature verification */ secret?: string; /** * Whether to verify the request origin IP address * @default false */ verifyIP?: boolean; /** * List of trusted IP addresses for webhooks. * Defaults to official Paystack IPs if verifyIP is true and this is empty. */ trustedIPs?: string[]; }; /** * Subscription configuration */ subscription?: SubscriptionOptions; /** * Billing pattern * @default "native" */ billingPattern?: "native" | "local"; /** * Global event handler */ onEvent?: (event: PaystackWebhookEvent) => Promise; /** * Organization billing configuration */ organization?: { enabled?: boolean; /** * Organization member roles allowed to manage billing when `subscription.authorizeReference` * is not provided. * * @default ["owner", "admin"] */ billingRoles?: string[]; getCustomerCreateParams?: (org: { id: string; name: string; email?: string | null; }, ctx: GenericEndpointContext) => Promise>; onCustomerCreate?: (data: { paystackCustomer: Record; organization: unknown; }, ctx: GenericEndpointContext) => Promise; }; /** * Products configuration */ products?: { products?: PaystackProduct[] | (() => Promise); }; createCustomerOnSignUp?: boolean; onCustomerCreate?: (data: { paystackCustomer: Record; user: unknown; }, ctx: GenericEndpointContext) => Promise; /** * Custom database schema / model names */ schema?: InferOptionSchema; } interface Subscription { id: string; userId: string; organizationId?: string; plan: string; pendingPlan?: string | null; paystackSubscriptionCode?: string; paystackCustomerCode?: string; paystackPlanCode?: string; paystackAuthorizationCode?: string; paystackTransactionReference?: string; paystackEmailToken?: string; status: string; seats: number; referenceId: string; periodStart?: Date | null; periodEnd?: Date | null; cancelAtPeriodEnd: boolean; trialStart?: Date | null; trialEnd?: Date | null; groupId?: string | null; createdAt: Date; updatedAt: Date; } interface ChargeRecurringSubscriptionInput { subscriptionId: string; amount?: number; } interface ChargeRecurringSubscriptionResult { status: "success" | "failed"; data: PaystackChargeAuthorizationResponse; } interface PaystackSyncResult { status: "success"; count: number; } type AnyPaystackOptions = PaystackOptions; /** * Exact grouped SDK slices used by this plugin. * This deliberately matches the official SDK surface instead of a handwritten approximation. */ interface PaystackClientLike { transaction: Pick; customer: Pick; subscription: Pick; product: Pick; plan: Pick; } //#endregion //#region src/metadata.d.ts type PaystackMetadata = Record; interface CheckoutMetadataInput { referenceId: string; userId: string; plan?: string; product?: string; extra?: PaystackMetadata; trial: { isTrial: boolean; requested: boolean; granted: boolean; deniedReason?: "already_used"; endsAt?: Date; }; } interface ProrationMetadataInput { subscriptionId: string; referenceId: string; newPlan: string; oldPlan: string; newSeatCount: number; remainingDays: number; } interface RenewalMetadataInput { subscriptionId: string; referenceId: string; } declare function parsePaystackMetadata(value: unknown): PaystackMetadata; declare function stringifyPaystackMetadata(value: unknown): string | undefined; declare function hasPaystackMetadata(value: unknown): boolean; declare function getMetadataString(metadata: PaystackMetadata, key: string): string | undefined; declare function getMetadataNumber(metadata: PaystackMetadata, key: string): number | undefined; declare function getMetadataBoolean(metadata: PaystackMetadata, key: string): boolean; declare function createCheckoutMetadata(input: CheckoutMetadataInput): PaystackMetadata; declare function createProrationMetadata(input: ProrationMetadataInput): PaystackMetadata; declare function createRenewalMetadata(input: RenewalMetadataInput): PaystackMetadata; //#endregion export { Subscription as C, getSchema as E, Session as S, User as T, PaystackPlan as _, getMetadataBoolean as a, PaystackTransaction as b, hasPaystackMetadata as c, AnyPaystackOptions as d, ChargeRecurringSubscriptionInput as f, PaystackOptions as g, PaystackInitializeResult as h, createRenewalMetadata as i, parsePaystackMetadata as l, PaystackClientLike as m, createCheckoutMetadata as n, getMetadataNumber as o, ChargeRecurringSubscriptionResult as p, createProrationMetadata as r, getMetadataString as s, PaystackMetadata as t, stringifyPaystackMetadata as u, PaystackProduct as v, SubscriptionOptions as w, PaystackTransactionResponse as x, PaystackSyncResult as y }; //# sourceMappingURL=metadata-BQrgMYcE.d.mts.map