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.
- package/LICENSE +21 -0
- package/README.md +919 -0
- package/dist/client.d.mts +151 -0
- package/dist/client.d.mts.map +1 -0
- package/dist/client.mjs +129 -0
- package/dist/client.mjs.map +1 -0
- package/dist/index-CXuHlFoy.d.mts +858 -0
- package/dist/index-CXuHlFoy.d.mts.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +3288 -0
- package/dist/index.mjs.map +1 -0
- package/dist/version-BYbIySEf.mjs +73 -0
- package/dist/version-BYbIySEf.mjs.map +1 -0
- package/package.json +118 -8
- package/skills/better-auth-paystack-setup/SKILL.md +144 -0
- package/skills/better-auth-paystack-setup/agents/openai.yaml +6 -0
- package/skills/paystack-billing-flows/SKILL.md +154 -0
- package/skills/paystack-billing-flows/agents/openai.yaml +6 -0
- package/skills/paystack-catalog-limits/SKILL.md +183 -0
- package/skills/paystack-catalog-limits/agents/openai.yaml +6 -0
- package/skills/paystack-client-api/SKILL.md +120 -0
- package/skills/paystack-client-api/agents/openai.yaml +6 -0
- package/skills/paystack-local-subscriptions/SKILL.md +97 -0
- package/skills/paystack-local-subscriptions/agents/openai.yaml +6 -0
- package/skills/paystack-organization-billing/SKILL.md +159 -0
- package/skills/paystack-organization-billing/agents/openai.yaml +6 -0
- package/skills/paystack-schema-migrations/SKILL.md +94 -0
- package/skills/paystack-schema-migrations/agents/openai.yaml +6 -0
- package/skills/paystack-tanstack-start/SKILL.md +170 -0
- package/skills/paystack-tanstack-start/agents/openai.yaml +6 -0
- package/skills/paystack-testing-fixtures/SKILL.md +97 -0
- package/skills/paystack-testing-fixtures/agents/openai.yaml +6 -0
- package/skills/paystack-webhooks-events/SKILL.md +106 -0
- package/skills/paystack-webhooks-events/agents/openai.yaml +6 -0
- package/index.js +0 -1
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: paystack-tanstack-start
|
|
3
|
+
description: >
|
|
4
|
+
Integrate better-auth-paystack in TanStack Start. Use for Better Auth API routes, tanstackStartCookies(), server functions, getRequestHeaders(), authClient Paystack actions, admin billing server functions, and Cloudflare Workers deployment.
|
|
5
|
+
type: composition
|
|
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:examples/tanstack/README.md"
|
|
12
|
+
- "alexasomba/better-auth-paystack:examples/tanstack/src/lib/auth.ts"
|
|
13
|
+
- "alexasomba/better-auth-paystack:examples/tanstack/src/lib/auth-client.ts"
|
|
14
|
+
- "alexasomba/better-auth-paystack:examples/tanstack/src/routes/api/auth/$.ts"
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Setup
|
|
18
|
+
|
|
19
|
+
Create the Better Auth server config with Paystack and `tanstackStartCookies()` last:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { betterAuth } from "better-auth";
|
|
23
|
+
import { tanstackStartCookies } from "better-auth/tanstack-start";
|
|
24
|
+
import { paystack } from "better-auth-paystack";
|
|
25
|
+
|
|
26
|
+
export const auth = betterAuth({
|
|
27
|
+
baseURL: process.env.BETTER_AUTH_URL,
|
|
28
|
+
plugins: [
|
|
29
|
+
paystack({
|
|
30
|
+
secretKey: process.env.PAYSTACK_SECRET_KEY!,
|
|
31
|
+
subscription: {
|
|
32
|
+
enabled: true,
|
|
33
|
+
plans: [],
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
tanstackStartCookies(),
|
|
37
|
+
],
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Wire the catch-all auth route:
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { createFileRoute } from "@tanstack/react-router";
|
|
45
|
+
import { auth } from "../../../lib/auth";
|
|
46
|
+
|
|
47
|
+
export const Route = createFileRoute("/api/auth/$")({
|
|
48
|
+
server: {
|
|
49
|
+
handlers: {
|
|
50
|
+
GET: ({ request }) => auth.handler(request),
|
|
51
|
+
POST: ({ request }) => auth.handler(request),
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Create the client plugin:
|
|
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 Paystack client actions in client components
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
import { authClient } from "../lib/auth-client";
|
|
74
|
+
|
|
75
|
+
export function SubscribeButton() {
|
|
76
|
+
return (
|
|
77
|
+
<button
|
|
78
|
+
type="button"
|
|
79
|
+
onClick={async () => {
|
|
80
|
+
await authClient.subscription.create({
|
|
81
|
+
plan: "starter",
|
|
82
|
+
});
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
Subscribe
|
|
86
|
+
</button>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Use client actions for checkout and user-triggered subscription lifecycle calls. Do not import server helpers into React components.
|
|
92
|
+
|
|
93
|
+
### Use server functions for trusted billing operations
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
import { createServerFn } from "@tanstack/react-start";
|
|
97
|
+
import { getRequestHeaders } from "@tanstack/react-start/server";
|
|
98
|
+
import { auth } from "./auth";
|
|
99
|
+
import { syncPaystackPlans } from "better-auth-paystack";
|
|
100
|
+
|
|
101
|
+
export const syncPlans = createServerFn({ method: "POST" }).handler(async () => {
|
|
102
|
+
const session = await auth.api.getSession({
|
|
103
|
+
headers: await getRequestHeaders(),
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
if (!session?.user) {
|
|
107
|
+
throw new Response("Unauthorized", { status: 401 });
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
await syncPaystackPlans(await auth.$context, {
|
|
111
|
+
secretKey: process.env.PAYSTACK_SECRET_KEY!,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return { ok: true };
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Pass request headers when Better Auth needs session context.
|
|
119
|
+
|
|
120
|
+
### Keep SEO and discovery route-owned
|
|
121
|
+
|
|
122
|
+
Use TanStack route `head` functions for titles, descriptions, Open Graph/Twitter tags, canonical
|
|
123
|
+
links, robots meta, and JSON-LD. Keep `<HeadContent />` in the root document head and `<Scripts />`
|
|
124
|
+
in the body.
|
|
125
|
+
|
|
126
|
+
Only leaf public pages should emit canonical links. Authenticated dashboards, billing layouts, and
|
|
127
|
+
Paystack callback routes should be `noindex` and excluded from the sitemap, while still remaining
|
|
128
|
+
available for checkout redirects and payment verification.
|
|
129
|
+
|
|
130
|
+
### Keep Cloudflare Worker dependencies compatible
|
|
131
|
+
|
|
132
|
+
The TanStack example deploys to Cloudflare Workers. Keep Better Auth companion packages on compatible versions. If `@better-auth/infra` pulls in `@better-auth/sso`, avoid mixing a beta SSO package with stable `better-auth`.
|
|
133
|
+
|
|
134
|
+
The known safe pin for this package version is:
|
|
135
|
+
|
|
136
|
+
```yaml
|
|
137
|
+
overrides:
|
|
138
|
+
"@better-auth/sso": 1.6.9
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Common Mistakes
|
|
142
|
+
|
|
143
|
+
### Putting `tanstackStartCookies()` before Paystack
|
|
144
|
+
|
|
145
|
+
`tanstackStartCookies()` should be last in the Better Auth plugin array so cookie handling wraps the final auth behavior.
|
|
146
|
+
|
|
147
|
+
### Omitting auth headers in server functions
|
|
148
|
+
|
|
149
|
+
Wrong:
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
const session = await auth.api.getSession();
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Correct:
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
const session = await auth.api.getSession({
|
|
159
|
+
headers: await getRequestHeaders(),
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Debugging only root package builds
|
|
164
|
+
|
|
165
|
+
The root package can pass `vp pack` while the example Worker build fails. Reproduce Worker issues with:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
pnpm --filter ./examples/tanstack build
|
|
169
|
+
pnpm --filter ./examples/tanstack exec wrangler deploy --dry-run
|
|
170
|
+
```
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
interface:
|
|
2
|
+
display_name: "Better Auth Paystack TanStack Start"
|
|
3
|
+
short_description: "TanStack Start integration patterns"
|
|
4
|
+
default_prompt: "Use $paystack-tanstack-start to integrate Better Auth Paystack in a TanStack Start application."
|
|
5
|
+
policy:
|
|
6
|
+
allow_implicit_invocation: true
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: paystack-testing-fixtures
|
|
3
|
+
description: >
|
|
4
|
+
Test better-auth-paystack changes. Use for choosing focused vp test commands, Better Auth test clients, in-memory adapters, mocked Paystack SDK responses, webhook signatures, TanStack example tests, integration tests, type-safety tests, and verification before landing changes.
|
|
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:test/paystack.test.ts"
|
|
12
|
+
- "alexasomba/better-auth-paystack:test/local_subscription.test.ts"
|
|
13
|
+
- "alexasomba/better-auth-paystack:test/seat_billing.test.ts"
|
|
14
|
+
- "alexasomba/better-auth-paystack:test/typesafety.test.ts"
|
|
15
|
+
- "alexasomba/better-auth-paystack:examples/tanstack/src/__tests__"
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Test Selection
|
|
19
|
+
|
|
20
|
+
Use `vp test` instead of invoking Vitest directly.
|
|
21
|
+
|
|
22
|
+
Focused suites:
|
|
23
|
+
|
|
24
|
+
- core plugin routes, schema, webhooks, products, org billing: `vp test test/paystack.test.ts`
|
|
25
|
+
- local-managed subscriptions and authorization capture: `vp test test/local_subscription.test.ts`
|
|
26
|
+
- seat billing, proration, local renewal UI paths: `vp test test/seat_billing.test.ts`
|
|
27
|
+
- planCode and organization integration regressions: `vp test test/plancode-and-org.integration.test.ts`
|
|
28
|
+
- package type contracts: `vp test test/typesafety.test.ts`
|
|
29
|
+
- TanStack example components/routes: `pnpm --filter ./examples/tanstack test`
|
|
30
|
+
|
|
31
|
+
Broad gates before landing:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
vp check
|
|
35
|
+
vp test
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Run integration tests only when needed and credentials/environment are available:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
RUN_INTEGRATION_TESTS=1 vp test
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Fixture Patterns
|
|
45
|
+
|
|
46
|
+
### Mock Paystack SDK at the adapter boundary
|
|
47
|
+
|
|
48
|
+
Mocks should resemble `@alexasomba/paystack-node` grouped operations:
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
const paystackClient = {
|
|
52
|
+
transaction: {
|
|
53
|
+
initialize: vi.fn().mockResolvedValue({
|
|
54
|
+
data: { reference: "REF", authorization_url: "..." },
|
|
55
|
+
}),
|
|
56
|
+
verify: vi.fn().mockResolvedValue({ data: { status: "success", reference: "REF" } }),
|
|
57
|
+
chargeAuthorization: vi.fn(),
|
|
58
|
+
},
|
|
59
|
+
subscription: {
|
|
60
|
+
create: vi.fn(),
|
|
61
|
+
fetch: vi.fn(),
|
|
62
|
+
disable: vi.fn(),
|
|
63
|
+
enable: vi.fn(),
|
|
64
|
+
manageLink: vi.fn(),
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The package supports SDK `PaystackResponse` objects and legacy/custom nested `{ data }` test shapes.
|
|
70
|
+
Do not overfit tests to only one response wrapper unless the change is specifically about
|
|
71
|
+
`unwrapSdkResult`.
|
|
72
|
+
|
|
73
|
+
### Sign webhooks like Paystack
|
|
74
|
+
|
|
75
|
+
Webhook tests should create the exact JSON payload string, sign it with HMAC SHA-512, and send the
|
|
76
|
+
signature in `x-paystack-signature`.
|
|
77
|
+
|
|
78
|
+
### Use Better Auth client behavior realistically
|
|
79
|
+
|
|
80
|
+
For browser-style flows, sign up/sign in and pass cookies into the auth client. Use `{ throw: true }`
|
|
81
|
+
when the test should fail immediately on Better Auth errors.
|
|
82
|
+
|
|
83
|
+
## Common Mistakes
|
|
84
|
+
|
|
85
|
+
### Only testing the root package after example changes
|
|
86
|
+
|
|
87
|
+
The TanStack example has its own component and route tests. Run its test/build command when touching
|
|
88
|
+
`examples/tanstack`.
|
|
89
|
+
|
|
90
|
+
### Skipping type tests for client API changes
|
|
91
|
+
|
|
92
|
+
Any change to `src/client.ts`, route return shapes, or public exports should run
|
|
93
|
+
`test/typesafety.test.ts`.
|
|
94
|
+
|
|
95
|
+
### Assuming live Paystack is available
|
|
96
|
+
|
|
97
|
+
Most tests should use mocked SDK operations. Keep live/integration tests opt-in.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
interface:
|
|
2
|
+
display_name: "Better Auth Paystack Tests"
|
|
3
|
+
short_description: "Focused tests, mocks, and verification"
|
|
4
|
+
default_prompt: "Use $paystack-testing-fixtures to choose tests, fixtures, and verification commands for Better Auth Paystack changes."
|
|
5
|
+
policy:
|
|
6
|
+
allow_implicit_invocation: true
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: paystack-webhooks-events
|
|
3
|
+
description: >
|
|
4
|
+
Implement, debug, or test better-auth-paystack webhook handling. Use for Paystack webhook signatures, secretKey verification, trusted IP checks, charge.success, reconcilePaystackTransaction, subscription.create, subscription.disable, subscription.enable, product quantity updates, subscription status changes, metadata parsing, and event hooks.
|
|
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:src/routes.ts"
|
|
12
|
+
- "alexasomba/better-auth-paystack:src/types.ts"
|
|
13
|
+
- "alexasomba/better-auth-paystack:src/utils.ts"
|
|
14
|
+
- "alexasomba/better-auth-paystack:test/paystack.test.ts"
|
|
15
|
+
- "alexasomba/better-auth-paystack:test/seat_billing.test.ts"
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Webhook Contract
|
|
19
|
+
|
|
20
|
+
The Better Auth endpoint is registered as `auth.api.paystackWebhook` and mounted under
|
|
21
|
+
`/api/auth/paystack/webhook` by the plugin. Always send the raw JSON body that Paystack signed.
|
|
22
|
+
|
|
23
|
+
Signature verification uses HMAC SHA-512 over the raw request body with `secretKey`.
|
|
24
|
+
|
|
25
|
+
Paystack does not issue a separate webhook signing secret. Never introduce
|
|
26
|
+
`PAYSTACK_WEBHOOK_SECRET`. Deprecated `webhook.secret` and `paystackWebhookSecret` fields are
|
|
27
|
+
ignored.
|
|
28
|
+
|
|
29
|
+
## Core Patterns
|
|
30
|
+
|
|
31
|
+
### Verify before processing
|
|
32
|
+
|
|
33
|
+
Webhook code must reject invalid signatures before parsing business effects:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
const signature = createHmac("sha512", webhookSecret).update(payload).digest("hex");
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
If `webhook.verifyIP` is true, the request must come from `webhook.trustedIPs` or the built-in
|
|
40
|
+
Paystack IP allowlist. Preserve support for common forwarded IP headers when changing this path.
|
|
41
|
+
|
|
42
|
+
### Treat `charge.success` as reconciliation
|
|
43
|
+
|
|
44
|
+
`charge.success` can update multiple local records:
|
|
45
|
+
|
|
46
|
+
- mark a pending transaction as `success`
|
|
47
|
+
- finalize local subscription checkout when metadata identifies a plan
|
|
48
|
+
- apply checkout-based proration metadata with `type: "proration"`
|
|
49
|
+
- capture `authorization.authorization_code` for local renewals
|
|
50
|
+
- decrement one-time product quantity when product metadata is present
|
|
51
|
+
|
|
52
|
+
Do not grant paid access from a redirect alone. The callback should verify the transaction and
|
|
53
|
+
webhooks should reconcile persisted state.
|
|
54
|
+
|
|
55
|
+
For trusted server paths that need to re-verify and apply the plugin's local side effects outside a browser session, call `reconcilePaystackTransaction`:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { reconcilePaystackTransaction } from "better-auth-paystack";
|
|
59
|
+
|
|
60
|
+
await reconcilePaystackTransaction(ctx, paystackOptions, {
|
|
61
|
+
reference,
|
|
62
|
+
source: "webhook",
|
|
63
|
+
referenceId,
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The helper is suitable for webhook handlers, queue retries, cron jobs, and admin repair actions.
|
|
68
|
+
|
|
69
|
+
### Handle subscription events idempotently
|
|
70
|
+
|
|
71
|
+
Paystack subscription events should update matching subscriptions without assuming one delivery:
|
|
72
|
+
|
|
73
|
+
- `subscription.create`: activate or update the subscription and call creation hooks
|
|
74
|
+
- `subscription.disable`: mark cancellation/non-renewal and call cancel hooks
|
|
75
|
+
- `subscription.enable`: restore active state when Paystack re-enables a subscription
|
|
76
|
+
|
|
77
|
+
Match by known Paystack identifiers first, then metadata such as `referenceId` and plan when needed.
|
|
78
|
+
Avoid creating duplicate subscriptions on repeated webhook delivery.
|
|
79
|
+
|
|
80
|
+
## Common Mistakes
|
|
81
|
+
|
|
82
|
+
### Parsing body before signature verification
|
|
83
|
+
|
|
84
|
+
Do not route Paystack webhooks through a generic JSON handler that loses the exact signed payload.
|
|
85
|
+
The signature must be checked against the same raw string Paystack sent.
|
|
86
|
+
|
|
87
|
+
### Assuming all metadata is an object
|
|
88
|
+
|
|
89
|
+
Paystack metadata may arrive as an object or a JSON string. Existing route code handles both forms.
|
|
90
|
+
Keep that tolerance when changing metadata handling.
|
|
91
|
+
|
|
92
|
+
### Forgetting product side effects
|
|
93
|
+
|
|
94
|
+
Webhook work is not subscription-only. Successful product purchases must update transaction state and
|
|
95
|
+
respect product quantity/unlimited settings.
|
|
96
|
+
|
|
97
|
+
## Verification
|
|
98
|
+
|
|
99
|
+
Run focused tests after webhook changes:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
vp test test/paystack.test.ts
|
|
103
|
+
vp test test/seat_billing.test.ts
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Also run `vp check` before landing broad route or type changes.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
interface:
|
|
2
|
+
display_name: "Better Auth Paystack Webhooks"
|
|
3
|
+
short_description: "Webhook signatures, events, and reconciliation"
|
|
4
|
+
default_prompt: "Use $paystack-webhooks-events to implement, debug, or test Paystack webhook event processing."
|
|
5
|
+
policy:
|
|
6
|
+
allow_implicit_invocation: true
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// Placeholder
|