better-auth-paystack 0.0.0 → 3.2.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.
Files changed (35) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +919 -0
  3. package/dist/client.d.mts +151 -0
  4. package/dist/client.d.mts.map +1 -0
  5. package/dist/client.mjs +129 -0
  6. package/dist/client.mjs.map +1 -0
  7. package/dist/index-CXuHlFoy.d.mts +858 -0
  8. package/dist/index-CXuHlFoy.d.mts.map +1 -0
  9. package/dist/index.d.mts +2 -0
  10. package/dist/index.mjs +3288 -0
  11. package/dist/index.mjs.map +1 -0
  12. package/dist/version-BYbIySEf.mjs +73 -0
  13. package/dist/version-BYbIySEf.mjs.map +1 -0
  14. package/package.json +118 -8
  15. package/skills/better-auth-paystack-setup/SKILL.md +144 -0
  16. package/skills/better-auth-paystack-setup/agents/openai.yaml +6 -0
  17. package/skills/paystack-billing-flows/SKILL.md +154 -0
  18. package/skills/paystack-billing-flows/agents/openai.yaml +6 -0
  19. package/skills/paystack-catalog-limits/SKILL.md +183 -0
  20. package/skills/paystack-catalog-limits/agents/openai.yaml +6 -0
  21. package/skills/paystack-client-api/SKILL.md +120 -0
  22. package/skills/paystack-client-api/agents/openai.yaml +6 -0
  23. package/skills/paystack-local-subscriptions/SKILL.md +97 -0
  24. package/skills/paystack-local-subscriptions/agents/openai.yaml +6 -0
  25. package/skills/paystack-organization-billing/SKILL.md +159 -0
  26. package/skills/paystack-organization-billing/agents/openai.yaml +6 -0
  27. package/skills/paystack-schema-migrations/SKILL.md +94 -0
  28. package/skills/paystack-schema-migrations/agents/openai.yaml +6 -0
  29. package/skills/paystack-tanstack-start/SKILL.md +170 -0
  30. package/skills/paystack-tanstack-start/agents/openai.yaml +6 -0
  31. package/skills/paystack-testing-fixtures/SKILL.md +97 -0
  32. package/skills/paystack-testing-fixtures/agents/openai.yaml +6 -0
  33. package/skills/paystack-webhooks-events/SKILL.md +106 -0
  34. package/skills/paystack-webhooks-events/agents/openai.yaml +6 -0
  35. package/index.js +0 -1
@@ -0,0 +1,73 @@
1
+ //#region src/metadata.ts
2
+ function isMetadataRecord(value) {
3
+ return value !== null && typeof value === "object" && !Array.isArray(value);
4
+ }
5
+ function parsePaystackMetadata(value) {
6
+ if (value === void 0 || value === null || value === "") return {};
7
+ if (typeof value === "string") try {
8
+ const parsed = JSON.parse(value);
9
+ return isMetadataRecord(parsed) ? parsed : {};
10
+ } catch {
11
+ return {};
12
+ }
13
+ return isMetadataRecord(value) ? value : {};
14
+ }
15
+ function stringifyPaystackMetadata(value) {
16
+ if (value === void 0 || value === null || value === "") return void 0;
17
+ return JSON.stringify(parsePaystackMetadata(value));
18
+ }
19
+ function hasPaystackMetadata(value) {
20
+ return Object.keys(parsePaystackMetadata(value)).length > 0;
21
+ }
22
+ function getMetadataString(metadata, key) {
23
+ const value = metadata[key];
24
+ return typeof value === "string" && value !== "" ? value : void 0;
25
+ }
26
+ function getMetadataNumber(metadata, key) {
27
+ const value = metadata[key];
28
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
29
+ }
30
+ function getMetadataBoolean(metadata, key) {
31
+ const value = metadata[key];
32
+ return value === true || value === "true";
33
+ }
34
+ function createCheckoutMetadata(input) {
35
+ return {
36
+ referenceId: input.referenceId,
37
+ userId: input.userId,
38
+ plan: input.plan,
39
+ groupId: input.groupId,
40
+ product: input.product,
41
+ ...input.extra,
42
+ isTrial: input.trial.isTrial,
43
+ trialRequested: input.trial.requested,
44
+ trialGranted: input.trial.granted,
45
+ trialDeniedReason: input.trial.deniedReason,
46
+ trialEnd: input.trial.endsAt?.toISOString()
47
+ };
48
+ }
49
+ function createProrationMetadata(input) {
50
+ return {
51
+ type: "proration",
52
+ subscriptionId: input.subscriptionId,
53
+ referenceId: input.referenceId,
54
+ newPlan: input.newPlan,
55
+ oldPlan: input.oldPlan,
56
+ newSeatCount: input.newSeatCount,
57
+ remainingDays: input.remainingDays
58
+ };
59
+ }
60
+ function createRenewalMetadata(input) {
61
+ return {
62
+ type: "renewal",
63
+ subscriptionId: input.subscriptionId,
64
+ referenceId: input.referenceId
65
+ };
66
+ }
67
+ //#endregion
68
+ //#region src/version.ts
69
+ const PACKAGE_VERSION = "3.2.0";
70
+ //#endregion
71
+ 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
+
73
+ //# sourceMappingURL=version-BYbIySEf.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version-BYbIySEf.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.2.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,iBAAiB,KAAK,IAAI,QAAQ,CAAC;AAC5C;AAEA,SAAgB,0BAA0B,OAAoC;CAC5E,IAAI,UAAU,KAAA,KAAa,UAAU,QAAQ,UAAU,IAAI,OAAO,KAAA;CAClE,OAAO,KAAK,UAAU,sBAAsB,KAAK,CAAC;AACpD;AAEA,SAAgB,oBAAoB,OAAyB;CAC3D,OAAO,OAAO,KAAK,sBAAsB,KAAK,CAAC,CAAC,CAAC,SAAS;AAC5D;AAEA,SAAgB,kBAAkB,UAA4B,KAAiC;CAC7F,MAAM,QAAQ,SAAS;CACvB,OAAO,OAAO,UAAU,YAAY,UAAU,KAAK,QAAQ,KAAA;AAC7D;AAEA,SAAgB,kBAAkB,UAA4B,KAAiC;CAC7F,MAAM,QAAQ,SAAS;CACvB,OAAO,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,IAAI,QAAQ,KAAA;AACvE;AAEA,SAAgB,mBAAmB,UAA4B,KAAsB;CACnF,MAAM,QAAQ,SAAS;CACvB,OAAO,UAAU,QAAQ,UAAU;AACrC;AAEA,SAAgB,uBAAuB,OAAgD;CACrF,OAAO;EACL,aAAa,MAAM;EACnB,QAAQ,MAAM;EACd,MAAM,MAAM;EACZ,SAAS,MAAM;EACf,SAAS,MAAM;EACf,GAAG,MAAM;EACT,SAAS,MAAM,MAAM;EACrB,gBAAgB,MAAM,MAAM;EAC5B,cAAc,MAAM,MAAM;EAC1B,mBAAmB,MAAM,MAAM;EAC/B,UAAU,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"}
package/package.json CHANGED
@@ -1,11 +1,121 @@
1
1
  {
2
2
  "name": "better-auth-paystack",
3
- "version": "0.0.0",
4
- "description": "Placeholder for better-auth-paystack",
5
- "main": "index.js",
6
- "scripts": {},
7
- "keywords": [],
8
- "author": "alexasomba (https://www.npmjs.com/~alexasomba)",
9
- "license": "UNLICENSED",
10
- "private": false
3
+ "version": "3.2.0",
4
+ "description": "Production-ready Paystack billing plugin for Better Auth. Supports subscriptions, one-time payments, organization billing, secure webhooks and more",
5
+ "keywords": [
6
+ "africa",
7
+ "auth",
8
+ "better-auth",
9
+ "billing-system",
10
+ "checkout",
11
+ "cote-divoire",
12
+ "egp",
13
+ "egypt",
14
+ "fintech",
15
+ "ghana",
16
+ "ghs",
17
+ "ivory-coast",
18
+ "kenya",
19
+ "kes",
20
+ "ngn",
21
+ "nigeria",
22
+ "paystack",
23
+ "rwanda",
24
+ "saas",
25
+ "south-africa",
26
+ "subscriptions",
27
+ "tanstack-intent",
28
+ "usd",
29
+ "zar"
30
+ ],
31
+ "homepage": "https://github.com/alexasomba/better-auth-paystack#readme",
32
+ "bugs": {
33
+ "url": "https://github.com/alexasomba/better-auth-paystack/issues"
34
+ },
35
+ "license": "MIT",
36
+ "author": "alexasomba",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/alexasomba/better-auth-paystack.git"
40
+ },
41
+ "funding": [
42
+ {
43
+ "type": "individual",
44
+ "url": "https://solscan.io/account/Gepby394bBBn4AEKkSwAPVnjgBULvYTiXBpbZe9CQqSp"
45
+ }
46
+ ],
47
+ "files": [
48
+ "dist",
49
+ "skills"
50
+ ],
51
+ "type": "module",
52
+ "sideEffects": false,
53
+ "types": "./dist/index.d.mts",
54
+ "exports": {
55
+ ".": {
56
+ "types": "./dist/index.d.mts",
57
+ "import": "./dist/index.mjs",
58
+ "default": "./dist/index.mjs"
59
+ },
60
+ "./client": {
61
+ "types": "./dist/client.d.mts",
62
+ "import": "./dist/client.mjs",
63
+ "default": "./dist/client.mjs"
64
+ }
65
+ },
66
+ "publishConfig": {
67
+ "access": "public"
68
+ },
69
+ "dependencies": {
70
+ "@alexasomba/paystack-node": "^1.10.8",
71
+ "better-call": "~1.3.7",
72
+ "defu": "^6.1.7",
73
+ "zod": "^4.4.3"
74
+ },
75
+ "devDependencies": {
76
+ "@arethetypeswrong/cli": "^0.18.4",
77
+ "@better-fetch/fetch": "^1.3.1",
78
+ "@commitlint/cli": "^21.1.0",
79
+ "@commitlint/config-conventional": "^21.1.0",
80
+ "@eslint/compat": "^2.1.0",
81
+ "@eslint/js": "^10.0.1",
82
+ "@tanstack/intent": "^0.0.41",
83
+ "@types/node": "^24.13.2",
84
+ "@typescript-eslint/eslint-plugin": "^8.62.0",
85
+ "@typescript-eslint/parser": "^8.62.0",
86
+ "@vitest/coverage-v8": "^4.1.9",
87
+ "better-auth": "^1.6.25",
88
+ "eslint-plugin-import-x": "^4.17.0",
89
+ "eslint-plugin-promise": "^7.3.0",
90
+ "eslint-plugin-react-hooks": "^7.1.1",
91
+ "eslint-plugin-unicorn": "^64.0.0",
92
+ "publint": "^0.3.21",
93
+ "skills-npm": "^1.2.0",
94
+ "typescript": "^6.0.3",
95
+ "typescript-eslint": "^8.62.0",
96
+ "vite-plus": "^0.2.6",
97
+ "vitest": "^4.1.10"
98
+ },
99
+ "peerDependencies": {
100
+ "better-auth": "^1.6.25"
101
+ },
102
+ "optionalDependencies": {
103
+ "@rollup/rollup-linux-x64-gnu": "^4.62.2"
104
+ },
105
+ "engines": {
106
+ "node": ">=22.0.0"
107
+ },
108
+ "scripts": {
109
+ "build": "vp pack",
110
+ "dev": "vp pack --watch",
111
+ "test": "vp test run",
112
+ "test:integration": "RUN_INTEGRATION_TESTS=1 vp test run",
113
+ "coverage": "vp test run --coverage",
114
+ "lint": "vp lint src",
115
+ "lint:package": "publint run --strict",
116
+ "lint:types": "node scripts/lint-types-packed.mjs",
117
+ "typecheck": "tsc -p tsconfig.json --noEmit",
118
+ "skills:install": "skills-npm --cwd examples/tanstack --yes --force",
119
+ "skills:dry-run": "skills-npm --cwd examples/tanstack --dry-run --yes --agents universal --force"
120
+ }
11
121
  }
@@ -0,0 +1,144 @@
1
+ ---
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.2.0" # x-release-please-version
8
+ license: "MIT"
9
+ compatibility: "Node.js >=22.0.0; better-auth ^1.6.9; @alexasomba/paystack-node 1.10.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"
15
+ ---
16
+
17
+ ## Setup
18
+
19
+ Install the package alongside Better Auth and a Paystack client:
20
+
21
+ ```ts
22
+ import { betterAuth } from "better-auth";
23
+ import { createPaystack } from "@alexasomba/paystack-node";
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 { createAuthClient } from "better-auth/client";
61
+ import { paystackClient } from "better-auth-paystack/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.
@@ -0,0 +1,6 @@
1
+ interface:
2
+ display_name: "Better Auth Paystack Setup"
3
+ short_description: "Server and client plugin setup guidance"
4
+ default_prompt: "Use $better-auth-paystack-setup to configure the Better Auth Paystack server and client plugins."
5
+ policy:
6
+ allow_implicit_invocation: true
@@ -0,0 +1,154 @@
1
+ ---
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.2.0" # x-release-please-version
8
+ license: "MIT"
9
+ compatibility: "Node.js >=22.0.0; better-auth ^1.6.9; @alexasomba/paystack-node 1.10.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"
15
+ ---
16
+
17
+ ## Setup
18
+
19
+ Enable subscriptions with concrete Paystack plan metadata:
20
+
21
+ ```ts
22
+ import { paystack } from "better-auth-paystack";
23
+
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
+ ```
53
+
54
+ ## Core Patterns
55
+
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.
@@ -0,0 +1,6 @@
1
+ interface:
2
+ display_name: "Better Auth Paystack Billing Flows"
3
+ short_description: "Transactions, subscriptions, and billing flows"
4
+ default_prompt: "Use $paystack-billing-flows to build Paystack transaction, subscription, product, and billing portal flows."
5
+ policy:
6
+ allow_implicit_invocation: true