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.
- package/README.es-ES.md +51 -920
- package/README.fr-FR.md +51 -920
- package/README.md +67 -913
- package/dist/client.d.mts +17 -16
- package/dist/client.d.mts.map +1 -1
- package/dist/client.mjs +3 -4
- package/dist/client.mjs.map +1 -1
- package/dist/{index-CQ0SNlBx.d.mts → index-Z1gDat7u.d.mts} +9 -28
- package/dist/index-Z1gDat7u.d.mts.map +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +65 -84
- package/dist/index.mjs.map +1 -1
- package/dist/{version-ClvErcin.mjs → version-C8_utAlN.mjs} +4 -6
- package/dist/{version-ClvErcin.mjs.map → version-C8_utAlN.mjs.map} +1 -1
- package/package.json +20 -23
- package/skills/better-auth-paystack-setup/SKILL.md +16 -137
- package/skills/paystack-billing-flows/SKILL.md +19 -144
- package/skills/paystack-catalog-limits/SKILL.md +17 -175
- package/skills/paystack-client-api/SKILL.md +23 -110
- package/skills/paystack-local-subscriptions/SKILL.md +15 -90
- package/skills/paystack-organization-billing/SKILL.md +16 -152
- package/skills/paystack-schema-migrations/SKILL.md +18 -84
- package/skills/paystack-tanstack-start/SKILL.md +22 -162
- package/skills/paystack-testing-fixtures/SKILL.md +15 -90
- package/skills/paystack-webhooks-events/SKILL.md +19 -96
- package/dist/index-CQ0SNlBx.d.mts.map +0 -1
|
@@ -1,172 +1,32 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: paystack-tanstack-start
|
|
3
|
-
description:
|
|
4
|
-
Integrate
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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"
|
|
3
|
+
description: >-
|
|
4
|
+
Integrate Paystack payments with Better Auth in TanStack Start. Use for the auth catch-all route, server-function cookies, the standalone starter, and Cloudflare Workers builds.
|
|
5
|
+
license: MIT
|
|
6
|
+
metadata:
|
|
7
|
+
library: better-auth-paystack
|
|
8
|
+
library_version: "4.0.1" # x-release-please-version
|
|
9
|
+
purpose: >-
|
|
10
|
+
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.
|
|
15
11
|
---
|
|
16
12
|
|
|
17
|
-
|
|
13
|
+
# Paystack payments with Better Auth in TanStack Start
|
|
18
14
|
|
|
19
|
-
|
|
15
|
+
Set up checkout and payment verification in a TanStack Start app with server-side Paystack credentials and a mounted Better Auth handler.
|
|
20
16
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
- Keep the Paystack SDK and secrets in server auth modules. Mount `auth.handler(request)` on both GET and POST in the `/api/auth/$` file route. Add `tanstackStartCookies()` from `better-auth/tanstack-start` last when using Better Auth APIs from Start server functions.
|
|
18
|
+
- Configure the browser with `better-auth/react` and `paystackClient()`. Use the mounted auth path for checkout and verification. Protect any server functions that grant access or manage billing with a session and an ownership check.
|
|
19
|
+
- Use a persistent adapter for production. The repository demo's in-memory adapter is suitable for local development.
|
|
20
|
+
- For repository development, find framework guidance with `pnpm exec intent list` at the root and load the installed Start or Router skill with `pnpm exec intent load <package>#<skill>`.
|
|
25
21
|
|
|
26
|
-
|
|
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
|
-
|
|
46
|
-
import { auth } from "../../../lib/auth";
|
|
47
|
-
|
|
48
|
-
export const Route = createFileRoute("/api/auth/$")({
|
|
49
|
-
server: {
|
|
50
|
-
handlers: {
|
|
51
|
-
GET: ({ request }) => auth.handler(request),
|
|
52
|
-
POST: ({ request }) => auth.handler(request),
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
Create the client plugin:
|
|
59
|
-
|
|
60
|
-
```ts
|
|
61
|
-
import { paystackClient } from "better-auth-paystack/client";
|
|
62
|
-
import { createAuthClient } from "better-auth/client";
|
|
63
|
-
|
|
64
|
-
export const authClient = createAuthClient({
|
|
65
|
-
plugins: [paystackClient()],
|
|
66
|
-
});
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
## Core Patterns
|
|
70
|
-
|
|
71
|
-
### Use Paystack client actions in client components
|
|
72
|
-
|
|
73
|
-
```tsx
|
|
74
|
-
import { authClient } from "../lib/auth-client";
|
|
75
|
-
|
|
76
|
-
export function SubscribeButton() {
|
|
77
|
-
return (
|
|
78
|
-
<button
|
|
79
|
-
type="button"
|
|
80
|
-
onClick={async () => {
|
|
81
|
-
await authClient.subscription.create({
|
|
82
|
-
plan: "starter",
|
|
83
|
-
});
|
|
84
|
-
}}
|
|
85
|
-
>
|
|
86
|
-
Subscribe
|
|
87
|
-
</button>
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
Use client actions for checkout and user-triggered subscription lifecycle calls. Do not import server helpers into React components.
|
|
93
|
-
|
|
94
|
-
### Use server functions for trusted billing operations
|
|
95
|
-
|
|
96
|
-
```ts
|
|
97
|
-
import { createServerFn } from "@tanstack/react-start";
|
|
98
|
-
import { getRequestHeaders } from "@tanstack/react-start/server";
|
|
99
|
-
import { syncPaystackPlans } from "better-auth-paystack";
|
|
100
|
-
|
|
101
|
-
import { auth } from "./auth";
|
|
102
|
-
|
|
103
|
-
export const syncPlans = createServerFn({ method: "POST" }).handler(async () => {
|
|
104
|
-
const session = await auth.api.getSession({
|
|
105
|
-
headers: await getRequestHeaders(),
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
if (!session?.user) {
|
|
109
|
-
throw new Response("Unauthorized", { status: 401 });
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
await syncPaystackPlans(await auth.$context, {
|
|
113
|
-
secretKey: process.env.PAYSTACK_SECRET_KEY!,
|
|
114
|
-
});
|
|
22
|
+
From the repository root:
|
|
115
23
|
|
|
116
|
-
|
|
117
|
-
|
|
24
|
+
```sh
|
|
25
|
+
vp install
|
|
26
|
+
vp pack
|
|
27
|
+
vp -C examples/tanstack test run
|
|
28
|
+
vp -C examples/tanstack build
|
|
29
|
+
vp -C examples/tanstack run wrangler:dry-run
|
|
118
30
|
```
|
|
119
31
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
### Keep SEO and discovery route-owned
|
|
123
|
-
|
|
124
|
-
Use TanStack route `head` functions for titles, descriptions, Open Graph/Twitter tags, canonical
|
|
125
|
-
links, robots meta, and JSON-LD. Keep `<HeadContent />` in the root document head and `<Scripts />`
|
|
126
|
-
in the body.
|
|
127
|
-
|
|
128
|
-
Only leaf public pages should emit canonical links. Authenticated dashboards, billing layouts, and
|
|
129
|
-
Paystack callback routes should be `noindex` and excluded from the sitemap, while still remaining
|
|
130
|
-
available for checkout redirects and payment verification.
|
|
131
|
-
|
|
132
|
-
### Keep Cloudflare Worker dependencies compatible
|
|
133
|
-
|
|
134
|
-
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`.
|
|
135
|
-
|
|
136
|
-
The known safe pin for this package version is:
|
|
137
|
-
|
|
138
|
-
```yaml
|
|
139
|
-
overrides:
|
|
140
|
-
"@better-auth/sso": 1.6.9
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
## Common Mistakes
|
|
144
|
-
|
|
145
|
-
### Putting `tanstackStartCookies()` before Paystack
|
|
146
|
-
|
|
147
|
-
`tanstackStartCookies()` should be last in the Better Auth plugin array so cookie handling wraps the final auth behavior.
|
|
148
|
-
|
|
149
|
-
### Omitting auth headers in server functions
|
|
150
|
-
|
|
151
|
-
Wrong:
|
|
152
|
-
|
|
153
|
-
```ts
|
|
154
|
-
const session = await auth.api.getSession();
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
Correct:
|
|
158
|
-
|
|
159
|
-
```ts
|
|
160
|
-
const session = await auth.api.getSession({
|
|
161
|
-
headers: await getRequestHeaders(),
|
|
162
|
-
});
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
### Debugging only root package builds
|
|
166
|
-
|
|
167
|
-
The root package can pass `vp pack` while the example Worker build fails. Reproduce Worker issues with:
|
|
168
|
-
|
|
169
|
-
```bash
|
|
170
|
-
pnpm --filter ./examples/tanstack build
|
|
171
|
-
pnpm --filter ./examples/tanstack exec wrangler deploy --dry-run
|
|
172
|
-
```
|
|
32
|
+
See the [demo guide](https://github.com/alexasomba/better-auth-paystack/blob/main/examples/tanstack/README.md) and [Paystack setup](../better-auth-paystack-setup/SKILL.md).
|
|
@@ -1,97 +1,22 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: paystack-testing-fixtures
|
|
3
|
-
description:
|
|
4
|
-
Test
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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__"
|
|
3
|
+
description: >-
|
|
4
|
+
Test Paystack checkout, webhooks, and billing with Better Auth. Use for SDK mocks, memory-adapter fixtures, signature tests, and TanStack Start checks.
|
|
5
|
+
license: MIT
|
|
6
|
+
metadata:
|
|
7
|
+
library: better-auth-paystack
|
|
8
|
+
library_version: "4.0.1" # x-release-please-version
|
|
9
|
+
purpose: >-
|
|
10
|
+
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.
|
|
16
11
|
---
|
|
17
12
|
|
|
18
|
-
|
|
13
|
+
# Test Paystack payments and webhooks with Better Auth
|
|
19
14
|
|
|
20
|
-
|
|
15
|
+
Exercise the same checkout, webhook, and billing paths that the app uses with mocked Paystack responses and a signed-in Better Auth session.
|
|
21
16
|
|
|
22
|
-
|
|
17
|
+
- Reuse [the Better Auth memory adapter helper](https://github.com/alexasomba/better-auth-paystack/blob/main/test/helpers/memory-auth.ts) and [Paystack mock result builders](https://github.com/alexasomba/better-auth-paystack/blob/main/test/helpers/paystack-results.ts). Exercise client methods with a signed-in session and realistic SDK inputs and responses.
|
|
18
|
+
- Use the legacy raw-body HMAC fixture for `x-paystack-signature` tests and the timestamped signing-key fixture in `test/payment-integrity.test.ts` for `paystack-signature` tests. Cover duplicate events, retryable failures, and mismatched payment amounts or ownership in reconciliation tests.
|
|
19
|
+
- Run `vp test run test/paystack.test.ts` for route and plugin behavior, `vp test run test/payment-integrity.test.ts` for reconciliation and webhook races, and `vp test run test/typesafety.test.ts` for the client contract. Include the local subscription, seat billing, or schema migration suites when changing those paths.
|
|
20
|
+
- For the package, run `vp check`, `vp test run`, `vp pack`, `vp run lint:package`, and `vp run lint:types`. Use the [TanStack Start checks](../paystack-tanstack-start/SKILL.md) when changing demo behavior.
|
|
23
21
|
|
|
24
|
-
|
|
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.
|
|
22
|
+
See the [CI workflows](https://github.com/alexasomba/better-auth-paystack/tree/main/.github/workflows) for packed-package Better Auth version checks.
|
|
@@ -1,106 +1,29 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: paystack-webhooks-events
|
|
3
|
-
description:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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"
|
|
3
|
+
description: >-
|
|
4
|
+
Configure or troubleshoot Paystack webhooks in Better Auth. Use for timestamped and legacy signatures, event retries, and transaction or subscription reconciliation.
|
|
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 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.
|
|
16
11
|
---
|
|
17
12
|
|
|
18
|
-
|
|
13
|
+
# Verify Paystack webhook signatures and reconcile payments
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
`/api/auth/paystack/webhook` by the plugin. Always send the raw JSON body that Paystack signed.
|
|
15
|
+
Register the Better Auth Paystack webhook, verify the signed request body, and reconcile successful charges against the stored order.
|
|
22
16
|
|
|
23
|
-
|
|
17
|
+
- Register `/api/auth/paystack/webhook` under the mounted auth base path in the Paystack dashboard. Preserve the exact request body through any proxy. Set `webhook.signingKeys` to map key IDs to signing secrets for timestamped `paystack-signature` deliveries. Deliveries with only the legacy `x-paystack-signature` use the Paystack API secret.
|
|
18
|
+
- Let the plugin reconcile transaction and subscription state. Use `onEvent` or subscription lifecycle callbacks for app-specific side effects. Make them idempotent using a transaction reference or durable event/business key. Test duplicate, concurrent, and retried deliveries.
|
|
19
|
+
- Complete a paid order only after verifying its reference, amount, currency, and owner. Keep the product/order binding in server-owned data. A browser return URL or provider event notification alone is insufficient.
|
|
20
|
+
- Use `reconcilePaystackTransaction(ctx, options, { reference })` from trusted server code for recovery. It verifies the reference with the provider and reports reconciliation status. Authorize any application endpoint that invokes the helper.
|
|
21
|
+
- For signature failures, check which Paystack integration sent the event and whether the application read the same bytes Paystack signed. Enable webhook IP validation only when the deployment can reliably identify the sender.
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
`PAYSTACK_WEBHOOK_SECRET`. Deprecated `webhook.secret` and `paystackWebhookSecret` fields are
|
|
27
|
-
ignored.
|
|
23
|
+
## Lifecycle delivery
|
|
28
24
|
|
|
29
|
-
|
|
25
|
+
Subscription callbacks include `onSubscriptionComplete`, `onSubscriptionCreated`, `onSubscriptionUpdate`, and `onSubscriptionCancel`. Use `onCustomerCreate` to react to provider customer creation and `freeTrial.onTrialStart`, `onTrialEnd`, and `onTrialExpired` for trial transitions.
|
|
30
26
|
|
|
31
|
-
|
|
27
|
+
Keep the unique `paystackWebhookEvent.eventId` constraint when customizing the schema. A failed delivery returns HTTP 503 for retry, and a stuck processing claim expires after five minutes. Transaction reconciliation checkpoints lifecycle callbacks across transports. A callback can run again if a worker stopped after an external side effect and before its checkpoint.
|
|
32
28
|
|
|
33
|
-
|
|
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.
|
|
29
|
+
See [webhook routes](https://github.com/alexasomba/better-auth-paystack/blob/main/src/routes.ts), [reconciliation](https://github.com/alexasomba/better-auth-paystack/blob/main/src/reconciliation.ts), and [payment integrity tests](https://github.com/alexasomba/better-auth-paystack/blob/main/test/payment-integrity.test.ts).
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-CQ0SNlBx.d.mts","names":[],"sources":["../src/schema.ts","../src/types.d.ts","../src/billing-store.ts","../src/routes.ts","../src/version.ts","../src/metadata.ts","../src/operations.ts","../src/limits.ts","../src/reconciliation.ts","../src/migrations.ts","../src/index.ts"],"mappings":";;;;;;;KAIK,kBAAkB,0BAA0B,4BAA4B,OAC3E;EAEE,QAAQ,OAAO,WAAW;EAC1B;EACA;;KAIC,qBAAqB;KAgBrB,sBAAsB;KAYtB,sBAAsB;KA0BtB,iBAAiB;KAWjB,2BAA2B;KAS3B,aAAa;KAEb,qBAAqB;KAErB,iBAAiB;KAejB,cAAc;KAeP,uBAAuB,sBACjC,qBACA,iBACA,2BACA,aACA,qBACA,iBACA,cACA;cAwYW,YAAa,SAAS,oBAAkB;;;KCjgBzC;;;;;UAWK;EACb;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,WAAW;EACX,WAAW;;UAEE;EACb;EACA;EACA;EACA;EACA;EACA;EACA,cAAc;EACd,WAAW;EACX,WAAW;;UAEE;EACb;EACA;EACA;;EAEA;EACA;EACA;EACA,WAAW;EACX,WAAW;;;UAGE;EACb;EACA;EACA,WAAW;EACX,WAAW;;UAEE;EACb;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,YAAY;EACZ,YAAY;;UAaC;EACb;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;;EAKA;EACA;EACA;;;;;EAKA;EACA;IACI;;IAEA;IACA,gBAAgB,cAAc,iBAAiB;IAC/C,cAAc,cAAc,iBAAiB;IAC7C,kBAAkB,cAAc,iBAAi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