better-auth-paystack 3.5.6 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- //#region src/metadata.ts
1
+ // src/metadata.ts
2
2
  function isMetadataRecord(value) {
3
3
  return value !== null && typeof value === "object" && !Array.isArray(value);
4
4
  }
@@ -64,10 +64,8 @@ function createRenewalMetadata(input) {
64
64
  referenceId: input.referenceId
65
65
  };
66
66
  }
67
- //#endregion
68
- //#region src/version.ts
69
- const PACKAGE_VERSION = "3.5.6";
70
- //#endregion
67
+ // src/version.ts
68
+ const PACKAGE_VERSION = "4.0.0";
71
69
  export { getMetadataBoolean as a, hasPaystackMetadata as c, createRenewalMetadata as i, parsePaystackMetadata as l, createCheckoutMetadata as n, getMetadataNumber as o, createProrationMetadata as r, getMetadataString as s, PACKAGE_VERSION as t, stringifyPaystackMetadata as u };
72
70
 
73
- //# sourceMappingURL=version-ClvErcin.mjs.map
71
+ //# sourceMappingURL=version-BW3EZXTR.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"version-ClvErcin.mjs","names":[],"sources":["../src/metadata.ts","../src/version.ts"],"sourcesContent":["export type PaystackMetadata = Record<string, unknown>;\n\nexport interface CheckoutMetadataInput {\n referenceId: string;\n userId: string;\n plan?: string;\n groupId?: string | null;\n product?: string;\n extra?: PaystackMetadata;\n trial: {\n isTrial: boolean;\n requested: boolean;\n granted: boolean;\n deniedReason?: \"already_used\";\n endsAt?: Date;\n };\n}\n\nexport interface ProrationMetadataInput {\n subscriptionId: string;\n referenceId: string;\n newPlan: string;\n oldPlan: string;\n newSeatCount: number;\n remainingDays: number;\n}\n\nexport interface RenewalMetadataInput {\n subscriptionId: string;\n referenceId: string;\n}\n\nfunction isMetadataRecord(value: unknown): value is PaystackMetadata {\n return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\nexport function parsePaystackMetadata(value: unknown): PaystackMetadata {\n if (value === undefined || value === null || value === \"\") return {};\n\n if (typeof value === \"string\") {\n try {\n const parsed: unknown = JSON.parse(value);\n return isMetadataRecord(parsed) ? parsed : {};\n } catch {\n return {};\n }\n }\n\n return isMetadataRecord(value) ? value : {};\n}\n\nexport function stringifyPaystackMetadata(value: unknown): string | undefined {\n if (value === undefined || value === null || value === \"\") return undefined;\n return JSON.stringify(parsePaystackMetadata(value));\n}\n\nexport function hasPaystackMetadata(value: unknown): boolean {\n return Object.keys(parsePaystackMetadata(value)).length > 0;\n}\n\nexport function getMetadataString(metadata: PaystackMetadata, key: string): string | undefined {\n const value = metadata[key];\n return typeof value === \"string\" && value !== \"\" ? value : undefined;\n}\n\nexport function getMetadataNumber(metadata: PaystackMetadata, key: string): number | undefined {\n const value = metadata[key];\n return typeof value === \"number\" && Number.isFinite(value) ? value : undefined;\n}\n\nexport function getMetadataBoolean(metadata: PaystackMetadata, key: string): boolean {\n const value = metadata[key];\n return value === true || value === \"true\";\n}\n\nexport function createCheckoutMetadata(input: CheckoutMetadataInput): PaystackMetadata {\n return {\n referenceId: input.referenceId,\n userId: input.userId,\n plan: input.plan,\n groupId: input.groupId,\n product: input.product,\n ...input.extra,\n isTrial: input.trial.isTrial,\n trialRequested: input.trial.requested,\n trialGranted: input.trial.granted,\n trialDeniedReason: input.trial.deniedReason,\n trialEnd: input.trial.endsAt?.toISOString(),\n };\n}\n\nexport function createProrationMetadata(input: ProrationMetadataInput): PaystackMetadata {\n return {\n type: \"proration\",\n subscriptionId: input.subscriptionId,\n referenceId: input.referenceId,\n newPlan: input.newPlan,\n oldPlan: input.oldPlan,\n newSeatCount: input.newSeatCount,\n remainingDays: input.remainingDays,\n };\n}\n\nexport function createRenewalMetadata(input: RenewalMetadataInput): PaystackMetadata {\n return {\n type: \"renewal\",\n subscriptionId: input.subscriptionId,\n referenceId: input.referenceId,\n };\n}\n","export const PACKAGE_VERSION = \"3.5.6\"; // x-release-please-version\n"],"mappings":";AAgCA,SAAS,iBAAiB,OAA2C;CACnE,OAAO,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AU,MAAM,MAAM,QAAQ,YAAY;CAC5C;AACF;AAEA,SAAgB,wBAAwB,OAAiD;CACvF,OAAO;EACL,MAAM;EACN,gBAAgB,MAAM;EACtB,aAAa,MAAM;EACnB,SAAS,MAAM;EACf,SAAS,MAAM;EACf,cAAc,MAAM;EACpB,eAAe,MAAM;CACvB;AACF;AAEA,SAAgB,sBAAsB,OAA+C;CACnF,OAAO;EACL,MAAM;EACN,gBAAgB,MAAM;EACtB,aAAa,MAAM;CACrB;AACF;;;AC7GA,MAAa,kBAAkB"}
1
+ {"version":3,"file":"version-BW3EZXTR.mjs","names":[],"sources":["../src/metadata.ts","../src/version.ts"],"sourcesContent":["export type PaystackMetadata = Record<string, unknown>;\n\nexport interface CheckoutMetadataInput {\n referenceId: string;\n userId: string;\n plan?: string;\n groupId?: string | null;\n product?: string;\n extra?: PaystackMetadata;\n trial: {\n isTrial: boolean;\n requested: boolean;\n granted: boolean;\n deniedReason?: \"already_used\";\n endsAt?: Date;\n };\n}\n\nexport interface ProrationMetadataInput {\n subscriptionId: string;\n referenceId: string;\n newPlan: string;\n oldPlan: string;\n newSeatCount: number;\n remainingDays: number;\n}\n\nexport interface RenewalMetadataInput {\n subscriptionId: string;\n referenceId: string;\n}\n\nfunction isMetadataRecord(value: unknown): value is PaystackMetadata {\n return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\nexport function parsePaystackMetadata(value: unknown): PaystackMetadata {\n if (value === undefined || value === null || value === \"\") return {};\n\n if (typeof value === \"string\") {\n try {\n const parsed: unknown = JSON.parse(value);\n return isMetadataRecord(parsed) ? parsed : {};\n } catch {\n return {};\n }\n }\n\n return isMetadataRecord(value) ? value : {};\n}\n\nexport function stringifyPaystackMetadata(value: unknown): string | undefined {\n if (value === undefined || value === null || value === \"\") return undefined;\n return JSON.stringify(parsePaystackMetadata(value));\n}\n\nexport function hasPaystackMetadata(value: unknown): boolean {\n return Object.keys(parsePaystackMetadata(value)).length > 0;\n}\n\nexport function getMetadataString(metadata: PaystackMetadata, key: string): string | undefined {\n const value = metadata[key];\n return typeof value === \"string\" && value !== \"\" ? value : undefined;\n}\n\nexport function getMetadataNumber(metadata: PaystackMetadata, key: string): number | undefined {\n const value = metadata[key];\n return typeof value === \"number\" && Number.isFinite(value) ? value : undefined;\n}\n\nexport function getMetadataBoolean(metadata: PaystackMetadata, key: string): boolean {\n const value = metadata[key];\n return value === true || value === \"true\";\n}\n\nexport function createCheckoutMetadata(input: CheckoutMetadataInput): PaystackMetadata {\n return {\n referenceId: input.referenceId,\n userId: input.userId,\n plan: input.plan,\n groupId: input.groupId,\n product: input.product,\n ...input.extra,\n isTrial: input.trial.isTrial,\n trialRequested: input.trial.requested,\n trialGranted: input.trial.granted,\n trialDeniedReason: input.trial.deniedReason,\n trialEnd: input.trial.endsAt?.toISOString(),\n };\n}\n\nexport function createProrationMetadata(input: ProrationMetadataInput): PaystackMetadata {\n return {\n type: \"proration\",\n subscriptionId: input.subscriptionId,\n referenceId: input.referenceId,\n newPlan: input.newPlan,\n oldPlan: input.oldPlan,\n newSeatCount: input.newSeatCount,\n remainingDays: input.remainingDays,\n };\n}\n\nexport function createRenewalMetadata(input: RenewalMetadataInput): PaystackMetadata {\n return {\n type: \"renewal\",\n subscriptionId: input.subscriptionId,\n referenceId: input.referenceId,\n };\n}\n","export const PACKAGE_VERSION = \"4.0.0\"; // x-release-please-version\n"],"mappings":";AAgCA,SAAS,iBAAiB,OAA2C;CACnE,OAAO,UAAU,QAAQ,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAgB,sBAAsB,OAAkC;CACtE,IAAI,UAAU,KAAA,KAAa,UAAU,QAAQ,UAAU,IAAI,OAAO,CAAC;CAEnE,IAAI,OAAO,UAAU,UACnB,IAAI;EACF,MAAM,SAAkB,KAAK,MAAM,KAAK;EACxC,OAAO,iBAAiB,MAAM,IAAI,SAAS,CAAC;CAC9C,QAAQ;EACN,OAAO,CAAC;CACV;CAGF,OAAO,iBAA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B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-auth-paystack",
3
- "version": "3.5.6",
3
+ "version": "4.0.0",
4
4
  "description": "Production-ready Paystack billing plugin for Better Auth. Supports subscriptions, one-time payments, organization billing, secure webhooks and more",
5
5
  "keywords": [
6
6
  "africa",
@@ -67,31 +67,27 @@
67
67
  "access": "public"
68
68
  },
69
69
  "dependencies": {
70
- "@alexasomba/paystack-node": "^1.12.0",
70
+ "@alexasomba/paystack-node": "^1.12.1",
71
+ "@better-fetch/fetch": "^1.3.3",
71
72
  "defu": "^6.1.7",
72
- "zod": "^4.6.5"
73
+ "zod": "^4.6.7"
73
74
  },
74
75
  "devDependencies": {
75
76
  "@arethetypeswrong/cli": "^0.18.5",
76
- "@better-fetch/fetch": "^1.3.2",
77
- "@commitlint/cli": "^21.2.3",
78
- "@commitlint/config-conventional": "^21.2.3",
79
- "@tanstack/intent": "^0.5.5",
80
- "@types/node": "^26.6.5",
81
- "@vitest/coverage-v8": "5.0.3",
82
- "better-auth": "1.7.7",
77
+ "@commitlint/cli": "^21.2.4",
78
+ "@commitlint/config-conventional": "^21.2.4",
79
+ "@tanstack/intent": "^0.5.6",
80
+ "@types/node": "^22.20.7",
81
+ "@vitest/coverage-v8": "5.1.1",
82
+ "better-auth": "1.7.28",
83
83
  "publint": "^0.3.25",
84
- "skills-npm": "^4.0.0",
85
- "typescript": "npm:@typescript/typescript6@6.0.2",
86
- "vite": "npm:@voidzero-dev/vite-plus-core@1.1.0",
87
- "vite-plus": "1.1.0",
88
- "vitest": "5.0.3"
84
+ "typescript": "7.0.2",
85
+ "vite": "npm:@voidzero-dev/vite-plus-core@8.3.8001",
86
+ "vite-plus": "1.8.0",
87
+ "vitest": "5.1.1"
89
88
  },
90
89
  "peerDependencies": {
91
- "better-auth": "1.7.7"
92
- },
93
- "optionalDependencies": {
94
- "@rollup/rollup-linux-x64-gnu": "^4.64.3"
90
+ "better-auth": ">=1.4.22 <2"
95
91
  },
96
92
  "engines": {
97
93
  "node": ">=22.0.0"
@@ -105,9 +101,10 @@
105
101
  "lint": "vp lint src",
106
102
  "lint:package": "publint run --strict",
107
103
  "lint:types": "node scripts/lint-types-packed.mjs",
108
- "typecheck:nextjs": "tsc6 -p examples/nextjs/tsconfig.json --noEmit",
109
- "typecheck": "tsc6 -p tsconfig.json --noEmit",
110
- "skills:install": "skills-npm --cwd examples/tanstack --yes --force",
111
- "skills:dry-run": "skills-npm --cwd examples/tanstack --dry-run --yes --agents universal --force"
104
+ "typecheck:nextjs": "vp -C examples/nextjs run typecheck",
105
+ "typecheck": "tsc -p tsconfig.json --noEmit",
106
+ "starter:export": "node scripts/export-starter.mjs",
107
+ "starter:check": "node scripts/check-starters.mjs",
108
+ "creator:pack": "node scripts/pack-creator.mjs"
112
109
  }
113
110
  }
@@ -1,144 +1,21 @@
1
1
  ---
2
2
  name: better-auth-paystack-setup
3
- description: >
4
- Configure better-auth-paystack with Better Auth. Use when adding the paystack() server plugin, paystackClient() client plugin, schema overrides, products/plans, webhook verification, or canonical authClient.paystack/subscription/transaction actions.
5
- type: core
6
- library: "better-auth-paystack"
7
- library_version: "3.5.6" # x-release-please-version
8
- license: "MIT"
9
- compatibility: "Node.js >=22.0.0; better-auth ^1.6.9; @alexasomba/paystack-node 1.12.x; better-auth-paystack >=3.0.0 <4.0.0"
10
- sources:
11
- - "alexasomba/better-auth-paystack:README.md"
12
- - "alexasomba/better-auth-paystack:src/index.ts"
13
- - "alexasomba/better-auth-paystack:src/client.ts"
14
- - "alexasomba/better-auth-paystack:src/schema.ts"
3
+ description: >-
4
+ Set up better-auth-paystack. Use when installing the Paystack SDK, adding the Better Auth server or client plugin, configuring secrets, or making the first payment in a new app.
5
+ license: MIT
6
+ metadata:
7
+ library: better-auth-paystack
8
+ library_version: "4.0.0" # x-release-please-version
9
+ purpose: >-
10
+ Configure better-auth-paystack with Better Auth. Use when adding the paystack() server plugin, paystackClient() client plugin, schema overrides, products/plans, webhook verification, or canonical authClient.paystack/subscription/transaction actions.
15
11
  ---
16
12
 
17
- ## Setup
13
+ # Set up Better Auth Paystack
18
14
 
19
- Install the package alongside Better Auth and a Paystack client:
15
+ 1. Install `better-auth-paystack`, `better-auth` and `@alexasomba/paystack-node`. Use Node.js 22+, Better Auth `>=1.4.22 <2`, and the Paystack SDK `^1.12.1`.
16
+ 2. On the server, create the SDK with `createPaystack({ secretKey })` and pass it as `paystackClient` to `paystack({ secretKey, paystackClient, ... })`. Load the key from `PAYSTACK_SECRET_KEY`. Use a persistent Better Auth adapter and mount the normal auth handler.
17
+ 3. Generate and apply the schema for the configured adapter. If an older installation used the scoped package or legacy billing tables, use the [schema migration skill](../paystack-schema-migrations/SKILL.md).
18
+ 4. Add `paystackClient()` from `better-auth-paystack/client` to your Better Auth browser client. Enable recurring billing on the server with `subscription.enabled` and `subscription.plans`.
19
+ 5. Try a test-mode payment with an authenticated session and a server-priced product. Set the Paystack dashboard webhook to `/api/auth/paystack/webhook` under the default Better Auth base path.
20
20
 
21
- ```ts
22
- import { createPaystack } from "@alexasomba/paystack-node";
23
- import { betterAuth } from "better-auth";
24
- import { paystack } from "better-auth-paystack";
25
-
26
- const paystackSdk = createPaystack({
27
- secretKey: process.env.PAYSTACK_SECRET_KEY!,
28
- });
29
-
30
- export const auth = betterAuth({
31
- database: {
32
- provider: "sqlite",
33
- url: process.env.DATABASE_URL!,
34
- },
35
- plugins: [
36
- paystack({
37
- paystackClient: paystackSdk,
38
- secretKey: process.env.PAYSTACK_SECRET_KEY!,
39
- subscription: {
40
- enabled: true,
41
- plans: [
42
- {
43
- name: "pro",
44
- amount: 500_000,
45
- currency: "NGN",
46
- interval: "monthly",
47
- planCode: "PLN_pro_monthly",
48
- paystackId: "123456",
49
- },
50
- ],
51
- },
52
- }),
53
- ],
54
- });
55
- ```
56
-
57
- Add the client plugin in browser-safe code:
58
-
59
- ```ts
60
- import { paystackClient } from "better-auth-paystack/client";
61
- import { createAuthClient } from "better-auth/client";
62
-
63
- export const authClient = createAuthClient({
64
- plugins: [paystackClient()],
65
- });
66
- ```
67
-
68
- ## Core Patterns
69
-
70
- ### Use canonical client namespaces
71
-
72
- The client plugin exposes these namespaces:
73
-
74
- ```ts
75
- await authClient.paystack.config();
76
- await authClient.transaction.initialize({
77
- amount: 500_000,
78
- email: "user@example.com",
79
- });
80
- await authClient.transaction.verify({ reference: "trx_ref" });
81
- await authClient.transaction.list();
82
- await authClient.subscription.create({ plan: "pro" });
83
- await authClient.subscription.upgrade({ plan: "team" });
84
- await authClient.subscription.cancel({ subscriptionId: "sub_id" });
85
- await authClient.subscription.restore({ subscriptionId: "sub_id" });
86
- await authClient.subscription.list();
87
- await authClient.subscription.billingPortal();
88
- ```
89
-
90
- `subscription.disable` and `subscription.enable` are legacy compatibility aliases. Prefer `cancel` and `restore` in new code.
91
-
92
- ### Keep schema behavior stable
93
-
94
- The plugin always contributes Paystack product and plan tables:
95
-
96
- - `paystackProduct`
97
- - `paystackPlan`
98
-
99
- Subscription tables are included when `subscription.enabled` is true. User and transaction tables are always included. Organization fields are included when `organization.enabled` is true.
100
-
101
- Use Better Auth-style schema overrides only to rename models or fields. Do not remove the Paystack product/plan tables unless you are making a breaking major release.
102
-
103
- ### Use public Better Auth imports in package code
104
-
105
- Runtime code should import from public Better Auth entrypoints:
106
-
107
- ```ts
108
- import { betterAuth } from "better-auth";
109
- import { createAuthClient } from "better-auth/client";
110
- import type { BetterAuthPluginDBSchema } from "better-auth/db";
111
- ```
112
-
113
- Do not add runtime imports from `@better-auth/core/*` in this package. Tests can use internals only if no public API covers the case.
114
-
115
- ## Common Mistakes
116
-
117
- ### Calling server-only helpers from the browser
118
-
119
- Wrong:
120
-
121
- ```ts
122
- import { syncPaystackPlans } from "better-auth-paystack";
123
-
124
- await syncPaystackPlans(auth.$context, options);
125
- ```
126
-
127
- Correct: call admin helpers from server jobs, cron handlers, CLI scripts, or trusted server routes only.
128
-
129
- ### Inventing a separate webhook secret
130
-
131
- Paystack signs `x-paystack-signature` with the same secret key used for API authentication:
132
-
133
- ```ts
134
- paystack({
135
- secretKey: process.env.PAYSTACK_SECRET_KEY!,
136
- });
137
- ```
138
-
139
- Do not introduce `PAYSTACK_WEBHOOK_SECRET`, `webhook.secret`, or `paystackWebhookSecret`. The two
140
- options remain deprecated source-compatibility fields and are ignored.
141
-
142
- ### Treating plans as just display data
143
-
144
- Plans are used to validate billing operations and map Paystack plan codes. Include stable `name`, `amount`, `currency`, `interval`, `planCode`, and `paystackId` values when subscriptions are enabled.
21
+ See the [quick start](https://github.com/alexasomba/better-auth-paystack/blob/main/README.md) and [TanStack Start skill](../paystack-tanstack-start/SKILL.md).
@@ -1,154 +1,27 @@
1
1
  ---
2
2
  name: paystack-billing-flows
3
- description: >
4
- Build Paystack transaction and subscription flows with better-auth-paystack. Use for initialize/verify transaction, create/upgrade/cancel/restore/list subscriptions, products/plans, billing portal links, webhooks, reconcilePaystackTransaction, chargeSubscriptionRenewal, syncPaystackProducts, and syncPaystackPlans.
5
- type: core
6
- library: "better-auth-paystack"
7
- library_version: "3.5.6" # x-release-please-version
8
- license: "MIT"
9
- compatibility: "Node.js >=22.0.0; better-auth ^1.6.9; @alexasomba/paystack-node 1.12.x; better-auth-paystack >=3.0.0 <4.0.0"
10
- sources:
11
- - "alexasomba/better-auth-paystack:README.md"
12
- - "alexasomba/better-auth-paystack:src/routes.ts"
13
- - "alexasomba/better-auth-paystack:src/operations.ts"
14
- - "alexasomba/better-auth-paystack:src/client.ts"
3
+ description: >-
4
+ Implement one-time payments, subscription checkout, plan changes, cancellation, and customer billing portals with better-auth-paystack. Use when choosing a billing flow or handling a checkout, scheduled change, or prorated response.
5
+ license: MIT
6
+ metadata:
7
+ library: better-auth-paystack
8
+ library_version: "4.0.0" # x-release-please-version
9
+ purpose: >-
10
+ Build Paystack transaction and subscription flows with better-auth-paystack. Use for initialize/verify transaction, create/upgrade/cancel/restore/list subscriptions, products/plans, billing portal links, webhooks, reconcilePaystackTransaction, chargeSubscriptionRenewal, syncPaystackProducts, and syncPaystackPlans.
15
11
  ---
16
12
 
17
- ## Setup
13
+ # Paystack billing flows
18
14
 
19
- Enable subscriptions with concrete Paystack plan metadata:
15
+ - Use `transaction.initialize({ product, callbackURL })` for a fixed one-time purchase. Keep the price on the server. For variable prices, validate the server-side order and reconcile the paid amount and currency before fulfillment.
16
+ - Use `subscription.create` or `subscription.upgrade` with the configured `plan` name and, for organization billing, `referenceId`. A plan with a Paystack `planCode` uses provider-managed billing. Plans without it use local renewals, and `billingPattern: "local"` can force local billing.
17
+ - Check the Better Auth client error, then branch on `data.kind`. Open `checkout.url` for `checkout`. A `scheduled` result leaves the current plan in effect until the change takes effect. A `prorated` result reflects an applied change.
18
+ - After redirect, verify the reference and check the transaction against the stored order before granting anything. Link custom fulfillment to the verified reference and make it idempotent.
19
+ - Use `subscription.cancel({ subscriptionCode, atPeriodEnd })`, `subscription.restore({ subscriptionCode })`, and `subscription.billingPortal({ subscriptionCode })` for an existing subscription.
20
20
 
21
- ```ts
22
- import { paystack } from "better-auth-paystack";
21
+ ## Reserve plan operations on the server
23
22
 
24
- paystack({
25
- secretKey: process.env.PAYSTACK_SECRET_KEY!,
26
- subscription: {
27
- enabled: true,
28
- plans: [
29
- {
30
- name: "starter",
31
- amount: 250_000,
32
- currency: "NGN",
33
- interval: "monthly",
34
- planCode: "PLN_starter",
35
- paystackId: "1001",
36
- },
37
- {
38
- name: "team",
39
- amount: 1_000_000,
40
- currency: "NGN",
41
- interval: "monthly",
42
- planCode: "PLN_team",
43
- paystackId: "1002",
44
- limits: {
45
- seats: 10,
46
- teams: 3,
47
- },
48
- },
49
- ],
50
- },
51
- });
52
- ```
23
+ Set `subscription.operationHooks` when the application maintains a durable reservation for plan changes. After the plugin validates the actor, reference, and intent, `before` can return `{ kind: "proceed", providerReference, context? }`, replay an authorized stored `{ kind: "replay", result }`, or return `{ kind: "block", message? }`. Reserve the reference before dispatch and keep replay results scoped to the authorized billing owner.
53
24
 
54
- ## Core Patterns
25
+ The `after` hook runs after the plugin persists the result. `onError` reports the `provider`, `persistence`, or `completion` phase. Keep uncertain reservations open and reconcile the provider reference before retrying a charge. The application owns reservation storage and concurrency. One-time checkout and scheduled renewals use their own paths.
55
26
 
56
- ### Initialize and verify a transaction
57
-
58
- Use the client plugin for browser-triggered checkout:
59
-
60
- ```ts
61
- const initialized = await authClient.transaction.initialize({
62
- amount: 250_000,
63
- email: "customer@example.com",
64
- currency: "NGN",
65
- metadata: {
66
- product: "starter-pack",
67
- },
68
- });
69
-
70
- const verified = await authClient.transaction.verify({
71
- reference: initialized.data.reference,
72
- });
73
- ```
74
-
75
- Do not trust a redirect callback alone. Always verify the Paystack reference before granting access or updating billing state.
76
-
77
- ### Manage subscription lifecycle
78
-
79
- Use canonical methods in new code:
80
-
81
- ```ts
82
- await authClient.subscription.create({
83
- plan: "starter",
84
- });
85
-
86
- await authClient.subscription.upgrade({
87
- plan: "team",
88
- });
89
-
90
- await authClient.subscription.cancel({
91
- subscriptionId: "subscription_id",
92
- });
93
-
94
- await authClient.subscription.restore({
95
- subscriptionId: "subscription_id",
96
- });
97
-
98
- const subscriptions = await authClient.subscription.list();
99
- ```
100
-
101
- Legacy aliases:
102
-
103
- - `subscription.disable` maps to `subscription.cancel`
104
- - `subscription.enable` maps to `subscription.restore`
105
-
106
- Keep aliases only for compatibility tests or migration examples.
107
-
108
- ### Keep renewal and catalog sync server-side
109
-
110
- These helpers are exported by the server package and are intentionally not client actions:
111
-
112
- ```ts
113
- import {
114
- chargeSubscriptionRenewal,
115
- reconcilePaystackTransaction,
116
- syncPaystackPlans,
117
- syncPaystackProducts,
118
- } from "better-auth-paystack";
119
-
120
- export async function runBillingJob(ctx: unknown, options: unknown) {
121
- await reconcilePaystackTransaction(ctx, options, {
122
- reference: "paystack_reference",
123
- source: "queue",
124
- referenceId: "user_or_org_id",
125
- });
126
- await syncPaystackProducts(ctx, options);
127
- await syncPaystackPlans(ctx, options);
128
- await chargeSubscriptionRenewal(ctx, options, {
129
- subscriptionId: "subscription_id",
130
- });
131
- }
132
- ```
133
-
134
- Use cron, background jobs, or trusted server functions. Do not call these from a browser component.
135
-
136
- `reconcilePaystackTransaction` verifies the Paystack reference and applies the same local transaction, customer, product, subscription, trial, and proration side effects used by the browser verify endpoint. Use it for webhook handlers, queue retries, cron jobs, and admin repair actions.
137
-
138
- ## Common Mistakes
139
-
140
- ### Mutating Paystack-managed subscriptions like local subscriptions
141
-
142
- Seat-based or prorated subscription changes require locally managed subscription state. Paystack-managed subscriptions do not support every local mutation path.
143
-
144
- Before implementing seat changes, check whether the target plan is local/seat-aware and whether the operation is supported by the helper being used.
145
-
146
- ### Skipping webhook verification
147
-
148
- Configure `secretKey` and let the plugin verify incoming webhook payloads with that same Paystack
149
- API key. Do not invent a separate webhook secret or process Paystack webhook bodies through an
150
- unrelated JSON route that bypasses the plugin endpoint.
151
-
152
- ### Mixing plan name and Paystack plan code
153
-
154
- Use `plan.name` for app-facing plan selection and `plan.planCode`/`paystackId` for Paystack identity. Do not send a Paystack plan code where the plugin expects the configured plan name.
27
+ See [client calls](../paystack-client-api/SKILL.md), [local subscriptions](../paystack-local-subscriptions/SKILL.md), and the [initialization route](https://github.com/alexasomba/better-auth-paystack/blob/main/src/routes.ts).
@@ -1,183 +1,23 @@
1
1
  ---
2
2
  name: paystack-catalog-limits
3
- description: >
4
- Configure products, Paystack-native plans, local-managed plans, free trials, seat billing, resource limits, and catalog sync in better-auth-paystack. Use when tasks mention planCode, freeTrial, trial eligibility, seatAmount, seatPlanCode, limits, products, syncPaystackProducts, or syncPaystackPlans.
5
- type: core
6
- library: "better-auth-paystack"
7
- library_version: "3.5.6" # x-release-please-version
8
- license: "MIT"
9
- compatibility: "Node.js >=22.0.0; better-auth ^1.6.9; @alexasomba/paystack-node 1.12.x; better-auth-paystack >=3.0.0 <4.0.0"
10
- sources:
11
- - "alexasomba/better-auth-paystack:README.md"
12
- - "alexasomba/better-auth-paystack:src/types.ts"
13
- - "alexasomba/better-auth-paystack:src/routes.ts"
14
- - "alexasomba/better-auth-paystack:src/operations.ts"
15
- - "alexasomba/better-auth-paystack:src/utils.ts"
3
+ description: >-
4
+ Configure products, plans, free trials, seat pricing, subscription groups, and resource limits in better-auth-paystack. Use for catalog sync, planCode, freeTrial, seatAmount, limits, or getOrganizationEntitlements.
5
+ license: MIT
6
+ metadata:
7
+ library: better-auth-paystack
8
+ library_version: "4.0.0" # x-release-please-version
9
+ purpose: >-
10
+ Configure products, Paystack-native plans, local-managed plans, free trials, seat billing, resource limits, and catalog sync in better-auth-paystack. Use when tasks mention planCode, freeTrial, trial eligibility, seatAmount, seatPlanCode, limits, products, syncPaystackProducts, or syncPaystackPlans.
16
11
  ---
17
12
 
18
- ## Setup
13
+ # Paystack catalog and limits
19
14
 
20
- Configure catalog data on the server plugin. Products are one-time purchasable catalog items. Plans are subscription catalog items.
15
+ - Define one-time items under `products.products` and recurring plans under `subscription.plans`. Use unique names and integer amounts in the currency's minor units. Set `price` for products and `amount` for local plans. Set a Paystack `planCode` for provider-managed plans. Set amount, currency, and interval for local plans.
16
+ - Use `seatAmount` for local per-seat pricing. Set explicit `limits` and `features` on plans. A reference can have one active or trialing subscription per normalized group. Plans without a group share the default group.
17
+ - A trial can involve a one-time tokenization charge. Show its amount and currency before checkout and send `confirmTrialTokenizationCharge: true` only after the customer agrees. Set `freeTrial.tokenizationCharge` if the configured currency lacks a default. Require verified email where your billing policy calls for it.
18
+ - Call `getOrganizationEntitlements(ctx, organizationId, options)` on the server. Active and trialing plans are combined by the maximum numeric limit per key and the union of features. Authorize access independently and enforce limits in the protected server mutation.
19
+ - Run `syncPaystackProducts(ctx, options)` or `syncPaystackPlans(ctx, options)` from trusted server code to import provider catalog records.
21
20
 
22
- ```ts
23
- import { paystack } from "better-auth-paystack";
21
+ A trial stays incomplete until Paystack confirms the tokenization charge. Historical trial use affects future eligibility. If your offer includes a refund for the tokenization charge, arrange it through your own refund workflow.
24
22
 
25
- export const paystackPlugin = paystack({
26
- secretKey: process.env.PAYSTACK_SECRET_KEY!,
27
- products: {
28
- products: [
29
- {
30
- name: "credits_50",
31
- amount: 200_000,
32
- currency: "NGN",
33
- },
34
- ],
35
- },
36
- subscription: {
37
- enabled: true,
38
- plans: [
39
- {
40
- name: "pro",
41
- amount: 500_000,
42
- currency: "NGN",
43
- interval: "monthly",
44
- planCode: "PLN_pro_monthly",
45
- paystackId: "1001",
46
- freeTrial: {
47
- days: 14,
48
- },
49
- limits: {
50
- seats: 10,
51
- teams: 5,
52
- },
53
- },
54
- ],
55
- },
56
- });
57
- ```
58
-
59
- ## Core Patterns
60
-
61
- ### Choose Paystack-native plans for simple recurring billing
62
-
63
- Use `planCode` from the Paystack Dashboard when Paystack should manage the recurring subscription.
64
-
65
- ```ts
66
- {
67
- name: "pro",
68
- amount: 500_000,
69
- currency: "NGN",
70
- interval: "monthly",
71
- planCode: "PLN_pro_monthly",
72
- paystackId: "1001",
73
- }
74
- ```
75
-
76
- Paystack-native plans are the right default for fixed-price recurring billing. Do not use native plans for flows that require local seat proration or locally managed renewals.
77
-
78
- ### Omit planCode for local-managed subscriptions
79
-
80
- Local-managed plans are tracked in your database and renewed from stored Paystack authorizations by trusted backend code.
81
-
82
- ```ts
83
- {
84
- name: "local-team",
85
- amount: 1_000_000,
86
- currency: "NGN",
87
- interval: "monthly",
88
- seatAmount: 100_000,
89
- limits: {
90
- seats: 10,
91
- teams: 3,
92
- },
93
- }
94
- ```
95
-
96
- For local-managed subscriptions, no `planCode` means the plugin captures and stores the authorization code after transaction verification. Trigger renewals from server code with `chargeSubscriptionRenewal`.
97
-
98
- ### Configure trials on plans
99
-
100
- Trials are declared per plan:
101
-
102
- ```ts
103
- {
104
- name: "starter",
105
- amount: 250_000,
106
- currency: "NGN",
107
- interval: "monthly",
108
- planCode: "PLN_starter",
109
- paystackId: "1002",
110
- freeTrial: {
111
- days: 7,
112
- onTrialStart: async (subscription) => {
113
- await notifyTrialStarted(subscription.referenceId);
114
- },
115
- },
116
- }
117
- ```
118
-
119
- The plugin checks previous subscription history for the `referenceId`. If a trial was ever used, expired, or marked `trialing`, another trial is denied for that reference. Do not build UI that promises repeat trials for the same user or organization.
120
-
121
- ### Configure seats and resource limits
122
-
123
- Use `limits` for app resource enforcement and `seatAmount` for local seat billing amounts:
124
-
125
- ```ts
126
- {
127
- name: "team",
128
- amount: 1_000_000,
129
- currency: "NGN",
130
- interval: "monthly",
131
- seatAmount: 100_000,
132
- seatPlanCode: "PLN_extra_seat",
133
- limits: {
134
- seats: 10,
135
- teams: 3,
136
- },
137
- }
138
- ```
139
-
140
- `seatPriceId` is a deprecated alias. Use `seatAmount` in new code. `seatPlanCode` is only useful when a Paystack plan code exists for extra seats.
141
-
142
- ### Sync products and plans from trusted server jobs
143
-
144
- Use server-only helpers to mirror Paystack catalog data into local tables:
145
-
146
- ```ts
147
- import { syncPaystackPlans, syncPaystackProducts } from "better-auth-paystack";
148
-
149
- export async function syncCatalog(ctx: unknown, options: unknown) {
150
- await syncPaystackProducts(ctx, options);
151
- await syncPaystackPlans(ctx, options);
152
- }
153
- ```
154
-
155
- These operations are not browser client actions. Run them from cron, admin-only server functions, CI jobs, or deployment tasks.
156
-
157
- ## Common Mistakes
158
-
159
- ### Using native planCode for local seat/proration behavior
160
-
161
- Wrong:
162
-
163
- ```ts
164
- {
165
- name: "team",
166
- planCode: "PLN_team",
167
- seatAmount: 100_000,
168
- }
169
- ```
170
-
171
- Correct: omit `planCode` when the plan needs local seat billing, local renewals, or prorated seat changes.
172
-
173
- ### Treating products like subscription plans
174
-
175
- Products are one-time purchases. Plans are subscriptions. Use transaction initialization for product purchases and subscription actions for plans.
176
-
177
- ### Expecting product and plan tables to be optional
178
-
179
- `paystackProduct` and `paystackPlan` schema tables are always included by the plugin. Do not remove them in compatibility-preserving releases.
180
-
181
- ### Trusting trial state without verification
182
-
183
- Trial metadata is created during subscription checkout and finalized through transaction/webhook handling. Always verify the Paystack reference and rely on persisted subscription state before granting paid access.
23
+ See the [configuration types](https://github.com/alexasomba/better-auth-paystack/blob/main/src/types.ts) and [limits implementation](https://github.com/alexasomba/better-auth-paystack/blob/main/src/limits.ts).