better-auth-paystack 3.5.6 → 4.0.1

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,120 +1,33 @@
1
1
  ---
2
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.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: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"
3
+ description: >-
4
+ Use the Better Auth Paystack browser client for transaction and subscription methods, catalog queries, typed responses, and fetch errors.
5
+ license: MIT
6
+ metadata:
7
+ library: better-auth-paystack
8
+ library_version: "4.0.1" # x-release-please-version
9
+ purpose: >-
10
+ 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.
15
11
  ---
16
12
 
17
- ## Client Contract
13
+ # Paystack browser client API for Better Auth
18
14
 
19
- Install the browser plugin from the client entrypoint:
15
+ The `paystackClient()` plugin exposes typed checkout, verification, subscriptions, and catalog methods on the Better Auth client.
20
16
 
21
- ```ts
22
- import { paystackClient } from "better-auth-paystack/client";
23
- import { createAuthClient } from "better-auth/client";
17
+ Register `paystackClient()` from `better-auth-paystack/client`.
24
18
 
25
- export const authClient = createAuthClient({
26
- plugins: [paystackClient({ subscription: true })],
27
- });
28
- ```
19
+ | Method | Input or purpose |
20
+ | -------------------------------------------------------------------- | ------------------------------------------------------------------------- |
21
+ | `transaction.initialize` | `{ product, callbackURL }` for a fixed purchase |
22
+ | `transaction.verify` | `{ reference }` from the checkout callback |
23
+ | `transaction.list` and `subscription.list` | Optional `{ query: { referenceId } }` for organization scope |
24
+ | `subscription.create` and `subscription.upgrade` | `{ plan, callbackURL }`, optionally with `referenceId` or seat `quantity` |
25
+ | `subscription.cancel` | `{ subscriptionCode, atPeriodEnd? }` |
26
+ | `subscription.restore` and `subscription.billingPortal` | `{ subscriptionCode }` |
27
+ | `paystack.config`, `paystack.listProducts`, and `paystack.listPlans` | Public-facing catalog and plugin configuration |
29
28
 
30
- The plugin exposes three public surfaces:
29
+ Read the Better Auth `{ data, error }` result, or use the supported fetch option `{ throw: true }` for rejection. For initialization, check `data.kind` before reading `url`, `reference`, or `accessCode`. The `scheduled` and `prorated` variants provide no checkout URL.
31
30
 
32
- - `authClient.paystack`: top-level Paystack actions
33
- - `authClient.transaction`: transaction namespace
34
- - `authClient.subscription`: subscription namespace
31
+ Use provider checkout redirects, or pass a checkout's `accessCode` to the optional `@alexasomba/paystack-inline` SDK. A checkout callback still needs transaction verification. Paystack server credentials and trusted operations belong in server modules.
35
32
 
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
- ```
33
+ See [client method definitions](https://github.com/alexasomba/better-auth-paystack/blob/main/src/client.ts) and [billing flows](../paystack-billing-flows/SKILL.md).
@@ -1,97 +1,22 @@
1
1
  ---
2
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.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: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"
3
+ description: >-
4
+ Run app-managed Paystack recurring payments in Better Auth. Use for saved authorizations, renewal jobs, seat changes, mid-cycle proration, and scheduled plan changes.
5
+ license: MIT
6
+ metadata:
7
+ library: better-auth-paystack
8
+ library_version: "4.0.1" # x-release-please-version
9
+ purpose: >-
10
+ 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.
17
11
  ---
18
12
 
19
- ## Local Subscription Model
13
+ # Paystack recurring payments and local subscription renewals
20
14
 
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.
15
+ Use a plan without `planCode` for recurring billing controlled by your app. Configure amount, currency, and interval server-side. Verification or webhook reconciliation stores any reusable authorization in the encrypted payment-credential record.
23
16
 
24
- Local-managed subscriptions are required for:
17
+ - Schedule renewals in trusted server code with `chargeSubscriptionRenewal(ctx, options, { subscriptionId })`. Pass the local database subscription ID and the server's configured Paystack options. Coordinate workers so the same subscription period is not charged concurrently. A saved reusable authorization is required.
18
+ - To change an active local subscription mid-cycle, request `prorateAndCharge: true` on upgrade. The plugin can charge a saved authorization or return a checkout. Amounts below the Paystack minimum can be handled by scheduling the change for period end.
19
+ - Preserve `pendingPlan` and the current period when showing scheduled changes. Apply entitlements once the verified subscription state reflects the new plan.
20
+ - Inspect the stored transaction and subscription state before retrying failed renewals. Track job retries against a stable subscription-and-period key.
25
21
 
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.
22
+ See [renewal operations](https://github.com/alexasomba/better-auth-paystack/blob/main/src/operations.ts), [lifecycle helpers](https://github.com/alexasomba/better-auth-paystack/blob/main/src/subscription-lifecycle.ts), and [seat billing tests](https://github.com/alexasomba/better-auth-paystack/blob/main/test/seat_billing.test.ts).
@@ -1,159 +1,23 @@
1
1
  ---
2
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.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/utils.ts"
14
- - "alexasomba/better-auth-paystack:src/limits.ts"
3
+ description: >-
4
+ Configure Paystack organization billing in Better Auth. Use for team subscriptions, billing roles, reference authorization, seat limits, and organization entitlements.
5
+ license: MIT
6
+ metadata:
7
+ library: better-auth-paystack
8
+ library_version: "4.0.1" # x-release-please-version
9
+ purpose: >-
10
+ 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.
15
11
  ---
16
12
 
17
- ## Setup
13
+ # Paystack organization billing and team subscriptions in Better Auth
18
14
 
19
- Install the Better Auth organization plugin and enable Paystack organization billing:
15
+ Bill a team through its Better Auth organization ID and enforce billing permissions and subscription limits on the server.
20
16
 
21
- ```ts
22
- import { betterAuth } from "better-auth";
23
- import { paystack } from "better-auth-paystack";
24
- import { organization } from "better-auth/plugins/organization";
17
+ 1. Install the Better Auth organization plugin alongside `paystack({ organization: { enabled: true }, ... })`.
18
+ 2. Pass the selected organization ID as `referenceId` on checkout and use the same scope on list requests. The default billing roles are `owner` and `admin`. Configure `organization.billingRoles` for an additional role.
19
+ 3. When using `subscription.authorizeReference`, verify the authenticated user, membership, and permitted action for the supplied reference. This callback controls reference access when provided. Check app-specific permissions again on protected application mutations.
20
+ 4. Read active and trialing plan access using `getOrganizationEntitlements`. Enforce resource limits server-side. For local seat billing, derive the seat count from authorized membership and choose a plan configured for local seats.
21
+ 5. Confirm access with tests for an authorized billing manager, a regular member, and a user in another organization. Exercise the same checks when verifying or managing an existing subscription.
25
22
 
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.
23
+ See [organization integration tests](https://github.com/alexasomba/better-auth-paystack/blob/main/test/plancode-and-org.integration.test.ts), [catalog and limits](../paystack-catalog-limits/SKILL.md), and [local billing](../paystack-local-subscriptions/SKILL.md).
@@ -1,94 +1,28 @@
1
1
  ---
2
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.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: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"
3
+ description: >-
4
+ Generate the Better Auth schema for Paystack or migrate existing billing records. Use for the old scoped package, legacy customer and subscription data, and encrypted credentials.
5
+ license: MIT
6
+ metadata:
7
+ library: better-auth-paystack
8
+ library_version: "4.0.1" # x-release-please-version
9
+ purpose: >-
10
+ 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.
15
11
  ---
16
12
 
17
- ## Schema Contract
13
+ # Paystack database schema and migrations for Better Auth
18
14
 
19
- The plugin contributes Better Auth schema through `getSchema(options)`.
15
+ Generate and apply the Better Auth schema using the app's configured database adapter and plugin options. See the [Better Auth CLI guide](https://www.better-auth.com/docs/concepts/cli).
20
16
 
21
- Always included:
17
+ The default provider models are `paystackCustomer`, `paystackPaymentCredential`, `paystackTransaction`, `paystackProduct`, `paystackPlan`, and `paystackWebhookEvent`. Enabling subscriptions adds `paystackSubscription`. Enabling organization billing also adds an optional `organization.email` field. Customer associations live in `paystackCustomer` and credential ciphertext lives in `paystackPaymentCredential`. Review the [schema](https://github.com/alexasomba/better-auth-paystack/blob/main/src/schema.ts) for model or field mappings.
22
18
 
23
- - `user.paystackCustomerCode`
24
- - `paystackTransaction`
25
- - `paystackProduct`
26
- - `paystackPlan`
19
+ For an existing installation with legacy billing data:
27
20
 
28
- Included when `subscription.enabled` is true:
21
+ 1. Back up the data. Replace `@alexasomba/better-auth-paystack` and its `/client` imports with the unscoped package if needed.
22
+ 2. Apply an additive schema migration. Keep the old subscription records and customer code columns available for the copy.
23
+ 3. Run `migratePaystackSubscriptionSchema(ctx, options)` from a trusted server job with the configured Paystack options and a Better Auth endpoint context.
24
+ 4. Review the migrated, skipped, and failed counts. Retry partial failures and verify checkout, verification, and renewals against the new records before retiring the legacy schema.
29
25
 
30
- - `subscription`
26
+ Configure a stable server-only `credentialEncryptionKey`, typically loaded from `PAYSTACK_CREDENTIAL_ENCRYPTION_KEY`. The API secret is a compatibility fallback. Preserve access to the original encryption key until credential rotation or re-encryption is complete.
31
27
 
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
- ```
28
+ See the [migration implementation](https://github.com/alexasomba/better-auth-paystack/blob/main/src/migrations.ts) and [migration tests](https://github.com/alexasomba/better-auth-paystack/blob/main/test/schema-migration.test.ts).