better-auth-paystack 0.0.0 → 3.1.2

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 +842 -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-BfHLsAWb.d.mts +781 -0
  8. package/dist/index-BfHLsAWb.d.mts.map +1 -0
  9. package/dist/index.d.mts +2 -0
  10. package/dist/index.mjs +2760 -0
  11. package/dist/index.mjs.map +1 -0
  12. package/dist/version-Db-470Pe.mjs +73 -0
  13. package/dist/version-Db-470Pe.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,183 @@
1
+ ---
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.1.2" # 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/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"
16
+ ---
17
+
18
+ ## Setup
19
+
20
+ Configure catalog data on the server plugin. Products are one-time purchasable catalog items. Plans are subscription catalog items.
21
+
22
+ ```ts
23
+ import { paystack } from "better-auth-paystack";
24
+
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.
@@ -0,0 +1,6 @@
1
+ interface:
2
+ display_name: "Better Auth Paystack Catalog"
3
+ short_description: "Products, plans, trials, seats, and limits"
4
+ default_prompt: "Use $paystack-catalog-limits to configure Paystack products, subscription plans, free trials, seat billing, and resource limits."
5
+ policy:
6
+ allow_implicit_invocation: true
@@ -0,0 +1,120 @@
1
+ ---
2
+ name: paystack-client-api
3
+ description: >
4
+ Modify or use the better-auth-paystack browser client API. Use for paystackClient(), authClient.paystack, authClient.transaction, authClient.subscription, initializeTransaction, verifyTransaction, listTransactions, listSubscriptions, listProducts, listPlans, subscription billingPortal/manageLink, cancel/restore methods, BetterFetch throw option return types, and legacy disable/enable aliases.
5
+ type: core
6
+ library: "better-auth-paystack"
7
+ library_version: "3.1.2" # 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:src/client.ts"
12
+ - "alexasomba/better-auth-paystack:src/routes.ts"
13
+ - "alexasomba/better-auth-paystack:test/typesafety.test.ts"
14
+ - "alexasomba/better-auth-paystack:examples/tanstack/src/lib/paystack-client.ts"
15
+ ---
16
+
17
+ ## Client Contract
18
+
19
+ Install the browser plugin from the client entrypoint:
20
+
21
+ ```ts
22
+ import { createAuthClient } from "better-auth/client";
23
+ import { paystackClient } from "better-auth-paystack/client";
24
+
25
+ export const authClient = createAuthClient({
26
+ plugins: [paystackClient({ subscription: true })],
27
+ });
28
+ ```
29
+
30
+ The plugin exposes three public surfaces:
31
+
32
+ - `authClient.paystack`: top-level Paystack actions
33
+ - `authClient.transaction`: transaction namespace
34
+ - `authClient.subscription`: subscription namespace
35
+
36
+ `authClient.paystack.paystack` points back to the same actions object for compatibility.
37
+
38
+ ## Core Patterns
39
+
40
+ ### Prefer stable names in examples
41
+
42
+ Use these methods in new examples and application code:
43
+
44
+ ```ts
45
+ await authClient.paystack.config();
46
+ await authClient.paystack.listProducts();
47
+ await authClient.paystack.listPlans();
48
+ await authClient.paystack.initializeTransaction({ amount: 500_000 });
49
+ await authClient.paystack.verifyTransaction({ reference: "REF" });
50
+ await authClient.paystack.listTransactions();
51
+
52
+ await authClient.transaction.initialize({ amount: 500_000 });
53
+ await authClient.transaction.verify({ reference: "REF" });
54
+ await authClient.transaction.list();
55
+
56
+ await authClient.subscription.create({ plan: "starter" });
57
+ await authClient.subscription.upgrade({ plan: "team" });
58
+ await authClient.subscription.list();
59
+ await authClient.subscription.billingPortal({ subscriptionCode: "SUB_code" });
60
+ await authClient.subscription.cancel({
61
+ subscriptionCode: "SUB_code",
62
+ atPeriodEnd: true,
63
+ });
64
+ await authClient.subscription.restore({ subscriptionCode: "SUB_code" });
65
+ ```
66
+
67
+ `subscription.manageLink` is an alias for `subscription.billingPortal`.
68
+
69
+ ### Preserve legacy aliases
70
+
71
+ `subscription.disable` maps to `subscription.cancel`.
72
+ `subscription.enable` maps to `subscription.restore`.
73
+
74
+ Keep these aliases for migration compatibility, but do not introduce them in new examples.
75
+
76
+ ### Respect BetterFetch return typing
77
+
78
+ Methods use `FetchResult<T, O>`:
79
+
80
+ - with `{ throw: true }`, the promise resolves to `T`
81
+ - without `{ throw: true }`, the promise resolves to `BetterFetchResponse<T>`
82
+
83
+ When changing method signatures, update both the interface and implementation, then run type tests.
84
+
85
+ ## Common Mistakes
86
+
87
+ ### Using old `getConfig`
88
+
89
+ The stable method is `authClient.paystack.config()`. Do not add new examples that call
90
+ `authClient.paystack.getConfig()`.
91
+
92
+ ### Passing query data in the body for list endpoints
93
+
94
+ List endpoints use GET with query data:
95
+
96
+ ```ts
97
+ await authClient.subscription.list({ query: { referenceId: "org_123" } });
98
+ await authClient.transaction.list({ query: { referenceId: "org_123" } });
99
+ ```
100
+
101
+ ### Importing the server package in browser code
102
+
103
+ Browser code should import only `better-auth-paystack/client`. Server helpers such as
104
+ `syncPaystackPlans` and `chargeSubscriptionRenewal` belong in server functions, cron jobs, or trusted
105
+ routes.
106
+
107
+ ## Verification
108
+
109
+ Run these after client API changes:
110
+
111
+ ```bash
112
+ vp test test/typesafety.test.ts
113
+ vp test test/paystack.test.ts
114
+ ```
115
+
116
+ Run TanStack example tests when examples or client usage are changed:
117
+
118
+ ```bash
119
+ pnpm --filter ./examples/tanstack test
120
+ ```
@@ -0,0 +1,6 @@
1
+ interface:
2
+ display_name: "Better Auth Paystack Client API"
3
+ short_description: "Browser client methods and return contracts"
4
+ default_prompt: "Use $paystack-client-api to wire or review authClient Paystack, transaction, and subscription browser APIs."
5
+ policy:
6
+ allow_implicit_invocation: true
@@ -0,0 +1,97 @@
1
+ ---
2
+ name: paystack-local-subscriptions
3
+ description: >
4
+ Implement, debug, or test local-managed subscription behavior in better-auth-paystack. Use for local plans without planCode, saved authorization renewal, chargeSubscriptionRenewal, seat billing, prorateAndCharge, pendingPlan, LOC_ subscription codes, trial transitions, schedule-at-period-end upgrades, and Paystack-managed vs local-managed behavior.
5
+ type: core
6
+ library: "better-auth-paystack"
7
+ library_version: "3.1.2" # 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:src/subscription-lifecycle.ts"
12
+ - "alexasomba/better-auth-paystack:src/operations.ts"
13
+ - "alexasomba/better-auth-paystack:src/routes.ts"
14
+ - "alexasomba/better-auth-paystack:src/utils.ts"
15
+ - "alexasomba/better-auth-paystack:test/local_subscription.test.ts"
16
+ - "alexasomba/better-auth-paystack:test/seat_billing.test.ts"
17
+ ---
18
+
19
+ ## Local Subscription Model
20
+
21
+ A plan without `planCode` is locally managed. The plugin stores subscription state in the Better Auth
22
+ database and charges future renewals with a saved Paystack authorization code.
23
+
24
+ Local-managed subscriptions are required for:
25
+
26
+ - seat-based local billing
27
+ - prorated mid-cycle seat or plan upgrades
28
+ - trusted backend renewal jobs through `chargeSubscriptionRenewal`
29
+ - local trial and pending plan transitions
30
+
31
+ Use Paystack-native `planCode` plans for simple fixed recurring billing.
32
+
33
+ ## Core Patterns
34
+
35
+ ### Capture reusable authorization during verification
36
+
37
+ Local subscriptions become renewable after transaction verification or webhook reconciliation stores
38
+ `authorization.authorization_code` on the subscription. If the authorization is absent, renewal must
39
+ fail with a clear error instead of inventing a charge path.
40
+
41
+ ### Use server-only renewal helpers
42
+
43
+ `chargeSubscriptionRenewal(ctx, options, { subscriptionId })` is for cron jobs, admin server
44
+ functions, or trusted server routes. Never expose it directly as a browser action.
45
+
46
+ Before charging, verify the caller can manage the subscription reference. For organization billing,
47
+ only owners/admins should trigger renewals.
48
+
49
+ ### Prorate only local active subscriptions
50
+
51
+ `prorateAndCharge` is handled by `handleProratedUpgrade`.
52
+
53
+ The existing active subscription must have:
54
+
55
+ - status `active`
56
+ - a Paystack or local subscription code
57
+ - `periodStart` and `periodEnd`
58
+ - local-management compatibility for plan or seat changes
59
+
60
+ If a saved authorization exists, the prorated amount is charged immediately. If not, the code creates
61
+ a checkout transaction and applies the upgrade after the reference is verified.
62
+
63
+ Paystack minimum charge behavior matters. If the prorated amount is below the supported minimum,
64
+ surface a BAD_REQUEST and advise scheduling the change for period end.
65
+
66
+ ### Preserve pending plan semantics
67
+
68
+ Scheduled changes should use `pendingPlan` rather than silently changing the active plan. Immediate
69
+ local changes should update `plan`, `seats`, and transaction reference consistently.
70
+
71
+ ## Common Mistakes
72
+
73
+ ### Adding `planCode` to a local billing plan
74
+
75
+ Do not add `planCode` to a plan that needs local seat billing, prorated upgrades, or local renewals.
76
+ That turns the plan into a Paystack-managed subscription path.
77
+
78
+ ### Updating seats for Paystack-managed subscriptions
79
+
80
+ Seat and proration helpers intentionally reject Paystack-managed subscriptions. Use local-managed
81
+ plans for seat-aware billing.
82
+
83
+ ### Charging renewals from client components
84
+
85
+ The client may trigger checkout. Renewal jobs require trusted server code and a validated session or
86
+ job context.
87
+
88
+ ## Verification
89
+
90
+ Run focused tests after lifecycle changes:
91
+
92
+ ```bash
93
+ vp test test/local_subscription.test.ts
94
+ vp test test/seat_billing.test.ts
95
+ ```
96
+
97
+ Run `vp test test/paystack.test.ts` when route behavior, trials, or organization billing are touched.
@@ -0,0 +1,6 @@
1
+ interface:
2
+ display_name: "Better Auth Paystack Local Subs"
3
+ short_description: "Local subscriptions, renewals, and proration"
4
+ default_prompt: "Use $paystack-local-subscriptions to implement or debug local-managed Paystack subscription lifecycle behavior."
5
+ policy:
6
+ allow_implicit_invocation: true
@@ -0,0 +1,159 @@
1
+ ---
2
+ name: paystack-organization-billing
3
+ description: >
4
+ Configure organization billing in better-auth-paystack. Use for organization.enabled, Better Auth organization plugin setup, owner/admin default billing authorization, organization.billingRoles, subscription.authorizeReference, organization Paystack customers, seats, invitations, members, and team limits.
5
+ type: core
6
+ library: "better-auth-paystack"
7
+ library_version: "3.1.2" # 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/utils.ts"
14
+ - "alexasomba/better-auth-paystack:src/limits.ts"
15
+ ---
16
+
17
+ ## Setup
18
+
19
+ Install the Better Auth organization plugin and enable Paystack organization billing:
20
+
21
+ ```ts
22
+ import { betterAuth } from "better-auth";
23
+ import { organization } from "better-auth/plugins/organization";
24
+ import { paystack } from "better-auth-paystack";
25
+
26
+ export const auth = betterAuth({
27
+ plugins: [
28
+ organization(),
29
+ paystack({
30
+ secretKey: process.env.PAYSTACK_SECRET_KEY!,
31
+ subscription: {
32
+ enabled: true,
33
+ plans: [
34
+ {
35
+ name: "team",
36
+ amount: 1_000_000,
37
+ currency: "NGN",
38
+ interval: "monthly",
39
+ planCode: "PLN_team",
40
+ paystackId: "1002",
41
+ limits: {
42
+ seats: 10,
43
+ teams: 3,
44
+ },
45
+ },
46
+ ],
47
+ },
48
+ organization: {
49
+ enabled: true,
50
+ billingRoles: ["owner", "admin", "billing"],
51
+ },
52
+ }),
53
+ ],
54
+ });
55
+ ```
56
+
57
+ ## Core Patterns
58
+
59
+ ### Rely on the safe default for billing authorization
60
+
61
+ When `subscription.authorizeReference` is not supplied, organization billing actions require membership role `owner` or `admin`.
62
+
63
+ Ordinary members are rejected by default. Do not write UI or tests that assume any member can create, upgrade, cancel, or restore organization subscriptions.
64
+
65
+ ### Add trusted billing roles without replacing the default
66
+
67
+ Use `organization.billingRoles` when a product needs a role such as `billing`, `finance`, or `accounting` to manage organization billing while preserving the built-in user self-access, organization membership lookup, and action scoping.
68
+
69
+ ```ts
70
+ paystack({
71
+ secretKey: process.env.PAYSTACK_SECRET_KEY!,
72
+ subscription: {
73
+ enabled: true,
74
+ plans: [],
75
+ },
76
+ organization: {
77
+ enabled: true,
78
+ billingRoles: ["owner", "admin", "billing"],
79
+ },
80
+ });
81
+ ```
82
+
83
+ Role matching supports Better Auth string roles, comma-separated role strings like `"member,billing"`, and array roles like `["member", "billing"]`.
84
+
85
+ ### Override authorization explicitly for custom workflows
86
+
87
+ Use `subscription.authorizeReference` when a product needs lower-level policy checks that cannot be represented as organization roles:
88
+
89
+ ```ts
90
+ paystack({
91
+ secretKey: process.env.PAYSTACK_SECRET_KEY!,
92
+ subscription: {
93
+ enabled: true,
94
+ plans: [],
95
+ authorizeReference: async ({ user, referenceId }, ctx) => {
96
+ if (referenceId === user.id) return true;
97
+
98
+ const memberships = await ctx.context.adapter.findMany({
99
+ model: "member",
100
+ where: [
101
+ { field: "userId", value: user.id },
102
+ { field: "organizationId", value: referenceId },
103
+ ],
104
+ });
105
+
106
+ return memberships.some((membership) => {
107
+ const role = (membership as { role?: string }).role;
108
+ return role === "owner" || role === "admin" || role === "billing";
109
+ });
110
+ },
111
+ },
112
+ organization: {
113
+ enabled: true,
114
+ },
115
+ });
116
+ ```
117
+
118
+ When supplied, `authorizeReference` is authoritative. Include all user and organization cases you want to allow.
119
+
120
+ ### Create organization Paystack customers
121
+
122
+ When organization billing is enabled and the organization plugin is present, the plugin wires organization creation hooks. It tries to create a Paystack customer for the organization and stores `paystackCustomerCode`.
123
+
124
+ Customize creation params when needed:
125
+
126
+ ```ts
127
+ organization: {
128
+ enabled: true,
129
+ getCustomerCreateParams: async (org) => ({
130
+ metadata: JSON.stringify({
131
+ organizationId: org.id,
132
+ billingSource: "better-auth-paystack",
133
+ }),
134
+ }),
135
+ onCustomerCreate: async ({ paystackCustomer, organization }, ctx) => {
136
+ await ctx.context.adapter.update({
137
+ model: "organization",
138
+ where: [{ field: "id", value: organization.id }],
139
+ update: {
140
+ paystackCustomerCode: paystackCustomer.customer_code,
141
+ },
142
+ });
143
+ },
144
+ }
145
+ ```
146
+
147
+ ## Common Mistakes
148
+
149
+ ### Enabling organization billing without the organization plugin
150
+
151
+ If `organization.enabled` is true but Better Auth's organization plugin is missing, Paystack logs a clear error and skips organization hook wiring. Add `organization()` before relying on organization customer creation, members, invitations, seats, or team hooks.
152
+
153
+ ### Assuming member limits apply without subscription plans
154
+
155
+ Seat and team limits come from subscription plan limits. If a plan has no relevant `limits` value, the plugin cannot enforce that limit.
156
+
157
+ ### Forgetting seat sync after membership changes
158
+
159
+ The plugin hooks member/invitation lifecycle events when the organization plugin is present. If you implement custom membership mutation routes outside Better Auth's adapter hooks, explicitly re-check or sync seat state in that custom path.
@@ -0,0 +1,6 @@
1
+ interface:
2
+ display_name: "Better Auth Paystack Org Billing"
3
+ short_description: "Organization billing, seats, and access"
4
+ default_prompt: "Use $paystack-organization-billing to configure Paystack billing for Better Auth organizations, seats, and admin access."
5
+ policy:
6
+ allow_implicit_invocation: true
@@ -0,0 +1,94 @@
1
+ ---
2
+ name: paystack-schema-migrations
3
+ description: >
4
+ Modify or review better-auth-paystack database schema behavior. Use for paystackProduct, paystackPlan, paystackTransaction, subscription, user.paystackCustomerCode, organization.paystackCustomerCode/email, Better Auth schema overrides, mergeSchema behavior, migrations, indexes, unique fields, and backward-compatible table or field changes.
5
+ type: core
6
+ library: "better-auth-paystack"
7
+ library_version: "3.1.2" # 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:src/schema.ts"
12
+ - "alexasomba/better-auth-paystack:src/types.ts"
13
+ - "alexasomba/better-auth-paystack:test/paystack.test.ts"
14
+ - "alexasomba/better-auth-paystack:test/typesafety.test.ts"
15
+ ---
16
+
17
+ ## Schema Contract
18
+
19
+ The plugin contributes Better Auth schema through `getSchema(options)`.
20
+
21
+ Always included:
22
+
23
+ - `user.paystackCustomerCode`
24
+ - `paystackTransaction`
25
+ - `paystackProduct`
26
+ - `paystackPlan`
27
+
28
+ Included when `subscription.enabled` is true:
29
+
30
+ - `subscription`
31
+
32
+ Included when `organization.enabled` is true:
33
+
34
+ - `organization.paystackCustomerCode`
35
+ - `organization.email`
36
+
37
+ Product and plan tables are intentionally always present. Do not make them optional in a
38
+ compatibility-preserving release.
39
+
40
+ ## Core Patterns
41
+
42
+ ### Use schema overrides only for Better Auth-supported customization
43
+
44
+ Consumers can pass `options.schema` and the plugin merges it with the default schema via
45
+ `mergeSchema`. Use this for model/field naming and migration metadata, not for removing core billing
46
+ state.
47
+
48
+ When subscriptions are disabled, `getSchema` strips a user-provided `subscription` override before
49
+ merging so the subscription model is not reintroduced accidentally.
50
+
51
+ ### Preserve field compatibility
52
+
53
+ Schema changes affect persisted billing state. Treat these as migration-sensitive:
54
+
55
+ - changing required fields
56
+ - changing uniqueness or indexes
57
+ - renaming `paystack*` identity fields
58
+ - changing transaction `reference` uniqueness
59
+ - changing subscription `paystackSubscriptionCode` uniqueness
60
+ - changing product/plan `paystackId` or `planCode` uniqueness
61
+
62
+ Prefer additive optional fields in minor releases. Required field changes need clear migrations and
63
+ major-version scrutiny.
64
+
65
+ ### Keep TypeScript schema exports aligned
66
+
67
+ `PaystackPluginSchema`, individual schema exports, and `PaystackOptions["schema"]` should stay in
68
+ sync. If a field is added to a schema table, update the corresponding TypeScript table type in
69
+ `src/schema.ts`.
70
+
71
+ ## Common Mistakes
72
+
73
+ ### Removing catalog tables when products are unused
74
+
75
+ The package supports catalog sync and discovery. `paystackProduct` and `paystackPlan` remain part of
76
+ the plugin schema even if a specific app only uses subscriptions or only uses transactions.
77
+
78
+ ### Reintroducing subscription schema when subscriptions are disabled
79
+
80
+ Keep the guard in `getSchema` that removes `options.schema.subscription` unless
81
+ `subscription.enabled` is true.
82
+
83
+ ### Forgetting organization schema conditions
84
+
85
+ Organization billing fields should only be added when `organization.enabled` is true.
86
+
87
+ ## Verification
88
+
89
+ Run schema and type tests after schema changes:
90
+
91
+ ```bash
92
+ vp test test/paystack.test.ts test/typesafety.test.ts
93
+ vp check
94
+ ```
@@ -0,0 +1,6 @@
1
+ interface:
2
+ display_name: "Better Auth Paystack Schema"
3
+ short_description: "Database schema and migration guidance"
4
+ default_prompt: "Use $paystack-schema-migrations to review or change Better Auth Paystack schema and migration behavior."
5
+ policy:
6
+ allow_implicit_invocation: true