better-auth-flutterwave 0.4.3 → 1.0.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/README.es-ES.md +73 -346
- package/README.fr-FR.md +76 -346
- package/README.md +75 -349
- package/dist/client.d.mts +5 -6
- package/dist/client.d.mts.map +1 -1
- package/dist/client.mjs +2 -3
- package/dist/client.mjs.map +1 -1
- package/dist/{index-BqoHQ7eU.d.mts → index-DpejOhTY.d.mts} +17 -151
- package/dist/index-DpejOhTY.d.mts.map +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +33 -46
- package/dist/index.mjs.map +1 -1
- package/dist/{version-eSGk9I11.mjs → version-DfR5E0nB.mjs} +4 -6
- package/dist/{version-eSGk9I11.mjs.map → version-DfR5E0nB.mjs.map} +1 -1
- package/package.json +15 -17
- package/skills/better-auth-flutterwave-setup/SKILL.md +13 -14
- package/skills/flutterwave-billing-flows/SKILL.md +16 -11
- package/skills/flutterwave-catalog-limits/SKILL.md +12 -8
- package/skills/flutterwave-client-api/SKILL.md +13 -11
- package/skills/flutterwave-local-subscriptions/SKILL.md +14 -17
- package/skills/flutterwave-organization-billing/SKILL.md +11 -8
- package/skills/flutterwave-schema-migrations/SKILL.md +13 -15
- package/skills/flutterwave-tanstack-start/SKILL.md +13 -17
- package/skills/flutterwave-testing-fixtures/SKILL.md +14 -10
- package/skills/flutterwave-webhooks-events/SKILL.md +13 -12
- package/dist/index-BqoHQ7eU.d.mts.map +0 -1
package/README.md
CHANGED
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[English](README.md) · [Español](README.es-ES.md) · [Français](README.fr-FR.md)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
It supports Flutterwave Standard checkout, verified one-time payments, native payment-plan
|
|
7
|
-
subscriptions, locally managed subscriptions, organization billing, marketplace split payments,
|
|
8
|
-
webhooks, refunds, and reconciliation.
|
|
5
|
+
Add Flutterwave Standard Checkout, subscriptions, organization billing, and verified webhooks to Better Auth.
|
|
9
6
|
|
|
10
7
|
## Install
|
|
11
8
|
|
|
@@ -13,134 +10,49 @@ webhooks, refunds, and reconciliation.
|
|
|
13
10
|
npm install better-auth better-auth-flutterwave
|
|
14
11
|
```
|
|
15
12
|
|
|
16
|
-
Node.js 22
|
|
13
|
+
Requires Node.js 22 or newer and Better Auth `>=1.4.22 <2`. Tested with Better Auth 1.4.22, 1.5.6,
|
|
14
|
+
1.6.35, 1.7.7, and 1.7.28.
|
|
15
|
+
|
|
16
|
+
See the [API and compatibility policy](COMPATIBILITY.md).
|
|
17
17
|
|
|
18
18
|
## Configure
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
FLUTTERWAVE_SECRET_KEY=FLWSECK_TEST-...
|
|
23
|
-
FLUTTERWAVE_SECRET_HASH=your-dashboard-webhook-secret-hash
|
|
24
|
-
BETTER_AUTH_SECRET=...
|
|
25
|
-
BETTER_AUTH_URL=http://localhost:3000
|
|
26
|
-
```
|
|
20
|
+
Add the server plugin to your Better Auth instance and keep these credentials in your server
|
|
21
|
+
environment. Set `FLUTTERWAVE_SECRET_HASH` to the separately configured webhook secret hash.
|
|
27
22
|
|
|
28
23
|
```ts
|
|
29
|
-
import { betterAuth } from "better-auth";
|
|
30
|
-
import { organization } from "better-auth/plugins";
|
|
31
24
|
import { flutterwave } from "better-auth-flutterwave";
|
|
32
25
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
publicKey: process.env.FLUTTERWAVE_PUBLIC_KEY!,
|
|
38
|
-
secretKey: process.env.FLUTTERWAVE_SECRET_KEY!,
|
|
39
|
-
secretHash: process.env.FLUTTERWAVE_SECRET_HASH!,
|
|
40
|
-
subscription: {
|
|
41
|
-
enabled: true,
|
|
42
|
-
plans: [
|
|
43
|
-
{
|
|
44
|
-
name: "pro",
|
|
45
|
-
paymentPlanId: 12345,
|
|
46
|
-
amount: 5_000,
|
|
47
|
-
currency: "NGN",
|
|
48
|
-
interval: "monthly",
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
name: "starter",
|
|
52
|
-
amount: 2_000,
|
|
53
|
-
currency: "NGN",
|
|
54
|
-
interval: "monthly",
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
},
|
|
58
|
-
organization: { enabled: true },
|
|
59
|
-
marketplace: {
|
|
60
|
-
allowedSubaccountIds: ["RS_1234567890"],
|
|
61
|
-
},
|
|
62
|
-
}),
|
|
63
|
-
],
|
|
64
|
-
});
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
The plugin calls Flutterwave's v3 API with Node's built-in `fetch`; you do not need a separate
|
|
68
|
-
Flutterwave SDK dependency. Inject `flutterwaveClient` for a custom provider boundary or `fetch` for
|
|
69
|
-
tests and controlled transports.
|
|
70
|
-
|
|
71
|
-
### Flutterwave v4 server API
|
|
72
|
-
|
|
73
|
-
For new direct-charge integrations, the server entry point also exports
|
|
74
|
-
`createFlutterwaveV4Adapter`. It uses OAuth client credentials, refreshes its cached token at least
|
|
75
|
-
60 seconds before expiry, and exposes customer, encrypted card payment-method, charge, charge
|
|
76
|
-
authorization, charge retrieval, and refund operations. Configure the sandbox base URL explicitly
|
|
77
|
-
as `https://developersandbox-api.flutterwave.com`; the default base URL is production.
|
|
78
|
-
These operations follow Flutterwave's [v4 authentication](https://developer.flutterwave.com/v4.0.0/docs/authentication),
|
|
79
|
-
[card](https://developer.flutterwave.com/v4.0.0/docs/card),
|
|
80
|
-
[charge](https://developer.flutterwave.com/v4/reference/charges_post), and
|
|
81
|
-
[refund](https://developer.flutterwave.com/v4/reference/refunds_post) APIs.
|
|
82
|
-
|
|
83
|
-
```ts
|
|
84
|
-
import { createFlutterwaveV4Adapter } from "better-auth-flutterwave";
|
|
85
|
-
|
|
86
|
-
const flutterwaveV4 = createFlutterwaveV4Adapter({
|
|
87
|
-
clientId: process.env.FLW_V4_CLIENT_ID!,
|
|
88
|
-
clientSecret: process.env.FLW_V4_CLIENT_SECRET!,
|
|
89
|
-
apiBaseUrl:
|
|
90
|
-
process.env.NODE_ENV === "production"
|
|
91
|
-
? "https://f4bexperience.flutterwave.com"
|
|
92
|
-
: "https://developersandbox-api.flutterwave.com",
|
|
26
|
+
const payments = flutterwave({
|
|
27
|
+
publicKey: process.env.FLUTTERWAVE_PUBLIC_KEY!,
|
|
28
|
+
secretKey: process.env.FLUTTERWAVE_SECRET_KEY!,
|
|
29
|
+
secretHash: process.env.FLUTTERWAVE_SECRET_HASH!,
|
|
93
30
|
});
|
|
94
31
|
```
|
|
95
32
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
Better Auth billing rows or fulfill a v4 charge automatically; verify the charge and match its
|
|
100
|
-
reference, amount, currency, and customer to your own pending order before granting value. Existing
|
|
101
|
-
Better Auth checkout and subscription routes continue to use v3 Standard Checkout and payment plans.
|
|
102
|
-
|
|
103
|
-
Configure the client plugin:
|
|
33
|
+
Include `payments` in your server's `plugins` array. Generate the schema with the CLI for your
|
|
34
|
+
installed Better Auth version and apply it through your database's migration workflow.
|
|
35
|
+
[Better Auth CLI guide](https://better-auth.com/docs/concepts/cli)
|
|
104
36
|
|
|
105
37
|
```ts
|
|
106
38
|
import { createAuthClient } from "better-auth/client";
|
|
107
39
|
import { flutterwaveClient } from "better-auth-flutterwave/client";
|
|
108
40
|
|
|
109
|
-
export const authClient = createAuthClient({
|
|
110
|
-
plugins: [flutterwaveClient({ subscription: true })],
|
|
111
|
-
});
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
Then generate the Better Auth schema and apply it with your database migration workflow:
|
|
115
|
-
|
|
116
|
-
```bash
|
|
117
|
-
npx @better-auth/cli generate
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
For supported direct-migration setups, you can instead run:
|
|
121
|
-
|
|
122
|
-
```bash
|
|
123
|
-
npx @better-auth/cli migrate
|
|
41
|
+
export const authClient = createAuthClient({ plugins: [flutterwaveClient()] });
|
|
124
42
|
```
|
|
125
43
|
|
|
126
|
-
## Checkout
|
|
127
|
-
|
|
128
|
-
Flutterwave Standard checkout requires an amount, currency, redirect URL, and billing email. The
|
|
129
|
-
browser supplies the amount and currency directly or selects a configured plan/product; the server
|
|
130
|
-
resolves billing email from the authenticated user or authorized organization owner. The plugin
|
|
131
|
-
generates a unique `txRef`.
|
|
44
|
+
## Checkout
|
|
132
45
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
apply only to a payment without a configured plan or product.
|
|
46
|
+
A signed-in user can start checkout with an amount and currency or a configured plan or product.
|
|
47
|
+
Configure server-priced plans and products for fixed-price purchases. The server resolves the
|
|
48
|
+
billing email and uses the configured price and currency for catalog purchases.
|
|
137
49
|
|
|
138
50
|
```ts
|
|
139
51
|
const checkout = await authClient.flutterwave.transaction.initialize(
|
|
140
52
|
{
|
|
141
53
|
amount: 5_000,
|
|
142
54
|
currency: "NGN",
|
|
143
|
-
redirectUrl:
|
|
55
|
+
redirectUrl: new URL("/billing/flutterwave/callback", window.location.origin).href,
|
|
144
56
|
},
|
|
145
57
|
{ throw: true },
|
|
146
58
|
);
|
|
@@ -148,269 +60,83 @@ const checkout = await authClient.flutterwave.transaction.initialize(
|
|
|
148
60
|
window.location.assign(checkout.url);
|
|
149
61
|
```
|
|
150
62
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
Set a numeric `paymentPlanId` on a configured plan. Enrollment starts with a card checkout carrying
|
|
176
|
-
that plan ID. After verification, the plugin resolves the Flutterwave subscription using the
|
|
177
|
-
verified transaction, immutable billing email, and payment plan.
|
|
178
|
-
|
|
179
|
-
Flutterwave has no separate “create subscription” endpoint for this flow. Provider-native plans do
|
|
180
|
-
not pretend to support provider-side trials or prorated mutations.
|
|
181
|
-
|
|
182
|
-
### Locally managed plans
|
|
183
|
-
|
|
184
|
-
Omit `paymentPlanId` for a locally renewed subscription. The plugin stores the subscription,
|
|
185
|
-
group, seat count, and entitlement configuration locally. Automated trial transitions, scheduled
|
|
186
|
-
plan mutations, and proration orchestration are not part of the initial release.
|
|
187
|
-
|
|
188
|
-
Trusted-server renewal prefers that encrypted token. If no token is available, renewal creates a
|
|
189
|
-
hosted checkout and remains pending until the resulting payment is verified.
|
|
190
|
-
|
|
191
|
-
## Organization and marketplace billing
|
|
192
|
-
|
|
193
|
-
Organization billing controls local ownership and authorization. Flutterwave billing identity is
|
|
194
|
-
an email; the plugin does not create or persist a fictional Flutterwave customer record on users or
|
|
195
|
-
organizations.
|
|
196
|
-
|
|
197
|
-
Marketplace split payments are a separate concern. Configure existing, KYC-approved Flutterwave
|
|
198
|
-
subaccount IDs in `marketplace.allowedSubaccountIds`. Per-checkout overrides must be authorized and
|
|
199
|
-
must reference the allowlist. The plugin does not provision subaccounts or automatically equate an
|
|
200
|
-
organization with a Flutterwave subaccount.
|
|
63
|
+
On return, pass exactly one locator to
|
|
64
|
+
`authClient.flutterwave.transaction.verify({ transactionId })` or
|
|
65
|
+
`authClient.flutterwave.transaction.verify({ txRef })`. Fulfill after server verification matches
|
|
66
|
+
the successful payment to the pending reference, amount, and currency.
|
|
67
|
+
|
|
68
|
+
## Billing options
|
|
69
|
+
|
|
70
|
+
- **Subscriptions.** Set a numeric `paymentPlanId` for Flutterwave-managed card renewals. Omit it for a
|
|
71
|
+
locally managed plan. The first seat is included in the base amount and additional seats use
|
|
72
|
+
`seatAmount`.
|
|
73
|
+
- **Organizations and splits.** Enable organization billing with the Better Auth organization plugin
|
|
74
|
+
and pass an authorized organization ID as `referenceId`. Allowlist existing Flutterwave subaccounts
|
|
75
|
+
separately for split payments.
|
|
76
|
+
- **Server operations.** The server export includes `chargeSubscriptionRenewal`,
|
|
77
|
+
`processScheduledFlutterwaveCancellations`, `refundFlutterwaveTransaction`,
|
|
78
|
+
`reconcileFlutterwaveTransaction`, `reconcileFlutterwaveRefunds`, and `syncFlutterwavePlans`.
|
|
79
|
+
Call them from independently authorized server routes or jobs. Reuse the same `renewalId` for
|
|
80
|
+
retries of a renewal. A period-end cancellation requires a known paid-period end and a scheduler.
|
|
81
|
+
- **Flutterwave v4.** `createFlutterwaveV4Adapter` supports separate server-side direct-charge
|
|
82
|
+
integrations. Use Flutterwave-encrypted card fields for card inputs. Set the sandbox API URL
|
|
83
|
+
during testing, reuse idempotency keys on retries, and verify charges against pending orders
|
|
84
|
+
before fulfillment.
|
|
85
|
+
[Flutterwave v4 API](https://developer.flutterwave.com/v4.0.0/docs/authentication)
|
|
201
86
|
|
|
202
87
|
## Webhooks
|
|
203
88
|
|
|
204
|
-
|
|
205
|
-
`flutterwave-signature`
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
use the separately configured `secretHash`. It records idempotency state and re-verifies v3 payment
|
|
210
|
-
transactions before granting value. V4 event payloads are delivered to `onEvent` after signature
|
|
211
|
-
verification and deduplication; retrieve the v4 charge and match it to a pending order before
|
|
212
|
-
granting value. Keep custom `onEvent` work short so the endpoint can acknowledge within Flutterwave's
|
|
213
|
-
timeout.
|
|
214
|
-
|
|
215
|
-
Callback and reconciliation failures return a retryable HTTP 503. Webhook processing uses a
|
|
216
|
-
database claim to prevent simultaneous callbacks for the same event, and an abandoned claim can
|
|
217
|
-
be retried after five minutes. Payment, subscription lifecycle, and `onEvent` callbacks must be
|
|
218
|
-
idempotent: a crash after external work but before recording completion can cause a later retry to
|
|
219
|
-
execute a callback again. A provider cancellation notification preserves access through a future
|
|
220
|
-
scheduled paid-period end; immediate cancellations end access when processed.
|
|
221
|
-
|
|
222
|
-
Verified-payment lifecycle hooks share a durable fulfillment record across browser verification,
|
|
223
|
-
webhooks, and reconciliation. The record retains initial subscription intent before activation and
|
|
224
|
-
checkpoints each successful hook. A failed initial hook is retried even after the subscription becomes
|
|
225
|
-
active; successful earlier hooks are skipped. Fulfillment records use the existing event table and
|
|
226
|
-
five-minute leases, so concurrent requests retry instead of dispatching the same hooks simultaneously.
|
|
227
|
-
Handlers must still be idempotent if external work succeeds before its checkpoint is stored.
|
|
228
|
-
|
|
229
|
-
Do not parse and reserialize the request before signature verification. Do not use the API
|
|
230
|
-
`secretKey` as the webhook secret hash.
|
|
231
|
-
|
|
232
|
-
Polling and reconciliation are provided for pending v3 transactions and refunds. Native v3
|
|
233
|
-
subscription state is updated from verified payment events and uniquely matched provider
|
|
234
|
-
cancellation events; local subscription reconciliation is not currently exposed.
|
|
235
|
-
|
|
236
|
-
## Trusted server operations
|
|
237
|
-
|
|
238
|
-
Privileged operations are exported from the server entry point:
|
|
89
|
+
Configure `/api/auth/flutterwave/webhook` under your Better Auth base path. The plugin verifies
|
|
90
|
+
`flutterwave-signature` against the exact raw body using base64 HMAC-SHA256 and the webhook secret
|
|
91
|
+
hash. Legacy v3 deliveries use `verif-hash`. Keep callbacks idempotent and preserve the unique
|
|
92
|
+
webhook event constraint when migrating. A verified v4 event still requires retrieving the charge
|
|
93
|
+
and matching the pending order before fulfillment.
|
|
239
94
|
|
|
240
|
-
|
|
241
|
-
import {
|
|
242
|
-
chargeSubscriptionRenewal,
|
|
243
|
-
processScheduledFlutterwaveCancellations,
|
|
244
|
-
reconcileFlutterwaveRefunds,
|
|
245
|
-
reconcileFlutterwaveTransaction,
|
|
246
|
-
refundFlutterwaveTransaction,
|
|
247
|
-
syncFlutterwavePlans,
|
|
248
|
-
} from "better-auth-flutterwave";
|
|
249
|
-
```
|
|
95
|
+
## Examples
|
|
250
96
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
jobs:
|
|
254
|
-
|
|
255
|
-
- `syncFlutterwavePlans` imports remote Flutterwave payment plans into namespaced local records.
|
|
256
|
-
- `chargeSubscriptionRenewal` uses an encrypted reusable token when available, otherwise returns a
|
|
257
|
-
hosted-checkout URL and leaves renewal pending.
|
|
258
|
-
- `refundFlutterwaveTransaction` starts a full or partial asynchronous refund.
|
|
259
|
-
- `reconcileFlutterwaveTransaction` polls and verifies a pending transaction.
|
|
260
|
-
- `reconcileFlutterwaveRefunds` refreshes pending refund records.
|
|
261
|
-
- `processScheduledFlutterwaveCancellations` executes due cancellation requests, canceling native
|
|
262
|
-
subscriptions through Flutterwave if needed and ending local subscriptions. New native
|
|
263
|
-
cancellation requests stop provider billing immediately while preserving access until the paid
|
|
264
|
-
period ends; withdrawing that request reactivates provider billing. Run the processor from your
|
|
265
|
-
scheduler at period end, inspect returned `failed` IDs, and retry failures. Each
|
|
266
|
-
invocation processes up to 100 requests by default (maximum 1,000); `hasMore` indicates that
|
|
267
|
-
another batch may be needed. Scheduling requires a known paid `periodEnd`; legacy records must
|
|
268
|
-
be reconciled first or canceled immediately.
|
|
269
|
-
|
|
270
|
-
Renewal jobs should supply a stable `renewalId` and reuse it for every retry of the same billing
|
|
271
|
-
intent. Without one, the plugin reserves the current paid-period end (or the initial period).
|
|
272
|
-
New renewal intents are rejected before a future paid period ends. A pending transaction and dispatch intent are saved
|
|
273
|
-
before charging. Once dispatch starts, retries verify that same reference and never initiate another
|
|
274
|
-
charge, even if the provider response or subsequent verification was lost. A provider rejection or
|
|
275
|
-
an unverifiable reference requires reconciliation or operator investigation; it does not authorize a
|
|
276
|
-
new charge. Hosted-checkout retries return the saved URL. No provider-side idempotency guarantee is
|
|
277
|
-
assumed. Completed `renewalId` retries return the original verified payment.
|
|
278
|
-
|
|
279
|
-
For v3 refunds, `completed` means initiated and awaiting disbursement. Reconciliation also polls
|
|
280
|
-
`processing`, `pending-momo`, and `pending`, and accepts only successful fetch responses with the
|
|
281
|
-
expected refund ID. Method-specific terminal statuses such as `completed-mpgs` and
|
|
282
|
-
`completed-bank-transfer` indicate successful disbursement. See the
|
|
283
|
-
[Flutterwave v3 refund lifecycle](https://developer.flutterwave.com/docs/refunds).
|
|
284
|
-
|
|
285
|
-
Cancellation and restoration accept either the local subscription `id` or a numeric Flutterwave
|
|
286
|
-
`subscriptionId`. A scheduled local cancellation can be withdrawn while its paid period is still
|
|
287
|
-
active. A local subscription that has already ended requires a new checkout. Renewal calculates
|
|
288
|
-
the same seat price as checkout and rejects canceled or provider-managed subscriptions.
|
|
289
|
-
|
|
290
|
-
## Release and downstream updates
|
|
291
|
-
|
|
292
|
-
Release Please opens the version/change-log PR after reviewed changes reach `main`. Merging that
|
|
293
|
-
release PR creates the version tag and triggers the tag-pinned npm trusted-publishing workflow.
|
|
294
|
-
The npm trusted publisher must reference this repository and `.github/workflows/release-please.yml`.
|
|
295
|
-
The workflow requires Node 22.23.3, the locked pnpm version, library tests, a package build, package/type
|
|
296
|
-
lint, and the downstream example/schema checks. A branch push or ordinary application build does
|
|
297
|
-
not publish this package.
|
|
298
|
-
|
|
299
|
-
Consumers must use a release containing the new scheduled-cancellation export before importing
|
|
300
|
-
it; the previously published 0.2.1 release does not include these changes. The example uses
|
|
301
|
-
`workspace:*` and therefore follows the library in this checkout. External consumers must update
|
|
302
|
-
their dependency and lockfile after publication, review billing schema constraints, and wire the
|
|
303
|
-
processor into their authorized scheduler. See [the persistent example setup](examples/tanstack/README.md)
|
|
304
|
-
for the D1 migration and Cron Trigger configuration. This repository does not automatically
|
|
305
|
-
upgrade or deploy external applications.
|
|
306
|
-
|
|
307
|
-
## Packaged agent skills
|
|
308
|
-
|
|
309
|
-
The npm package ships version-matched coding-agent skills in its `skills/` directory. They help an
|
|
310
|
-
agent implement the supported Flutterwave API, data model, security rules, and examples without
|
|
311
|
-
guessing provider behavior.
|
|
312
|
-
|
|
313
|
-
Install the skill linker in your application and run its one-time setup:
|
|
97
|
+
Use the [TanStack Start](examples/tanstack/README.md), [Next.js](examples/nextjs/README.md), or
|
|
98
|
+
[Hono](examples/hono/README.md) example to try authentication and Flutterwave billing.
|
|
314
99
|
|
|
315
|
-
```
|
|
316
|
-
npm
|
|
317
|
-
npx skills-npm setup
|
|
100
|
+
```sh
|
|
101
|
+
npm create better-auth-flutterwave@latest my-app -- --template nextjs
|
|
318
102
|
```
|
|
319
103
|
|
|
320
|
-
`
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
```ts
|
|
325
|
-
// skills-npm.config.ts
|
|
326
|
-
import { defineConfig } from "skills-npm";
|
|
327
|
-
|
|
328
|
-
export default defineConfig({
|
|
329
|
-
include: ["better-auth-flutterwave"],
|
|
330
|
-
});
|
|
331
|
-
```
|
|
104
|
+
Choose `tanstack`, `nextjs`, or `hono`. TanStack Start is the default. The creator package becomes
|
|
105
|
+
available on npm after its first publication. The [GitHub Release](https://github.com/alexasomba/better-auth-flutterwave/releases)
|
|
106
|
+
also provides starter archives.
|
|
332
107
|
|
|
333
|
-
|
|
334
|
-
`npx skills-npm --dry-run`.
|
|
335
|
-
|
|
336
|
-
| Skill | Use it for |
|
|
337
|
-
| ----------------------------------- | -------------------------------------------------------- |
|
|
338
|
-
| `$better-auth-flutterwave-setup` | Initial server/client setup, credentials, and migrations |
|
|
339
|
-
| `$flutterwave-billing-flows` | Checkout, verification, and subscription flows |
|
|
340
|
-
| `$flutterwave-client-api` | Typed browser actions and client/server boundaries |
|
|
341
|
-
| `$flutterwave-local-subscriptions` | Encrypted token renewal and hosted-checkout fallback |
|
|
342
|
-
| `$flutterwave-organization-billing` | Organization ownership, roles, and split payments |
|
|
343
|
-
| `$flutterwave-catalog-limits` | Plans, local products, inventory, seats, and limits |
|
|
344
|
-
| `$flutterwave-webhooks-events` | Webhook signatures, idempotency, and re-verification |
|
|
345
|
-
| `$flutterwave-schema-migrations` | Namespaced schema generation and migrations |
|
|
346
|
-
| `$flutterwave-testing-fixtures` | Unit, sandbox, webhook, and reconciliation tests |
|
|
347
|
-
| `$flutterwave-tanstack-start` | TanStack Start integration |
|
|
348
|
-
|
|
349
|
-
Invoke a skill explicitly in your agent prompt:
|
|
350
|
-
|
|
351
|
-
```text
|
|
352
|
-
Use $better-auth-flutterwave-setup to add Better Auth Flutterwave to this application.
|
|
353
|
-
```
|
|
108
|
+
To export directly from the repository after installing its dependencies:
|
|
354
109
|
|
|
355
|
-
```
|
|
356
|
-
|
|
110
|
+
```sh
|
|
111
|
+
pnpm starter:export tanstack ./flutterwave-starter
|
|
357
112
|
```
|
|
358
113
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
114
|
+
The export uses this repository’s plugin version from npm. For an unpublished build, run
|
|
115
|
+
`vp pack` and `pnpm pack --pack-destination ./starter-pack`, then pass
|
|
116
|
+
`--tarball ./starter-pack/<package>.tgz` to the export command.
|
|
362
117
|
|
|
363
|
-
|
|
118
|
+
## Agent skills
|
|
364
119
|
|
|
365
|
-
|
|
120
|
+
The package ships [ten agent skills](skills/) alongside its code.
|
|
366
121
|
|
|
367
|
-
|
|
122
|
+
- With [pnpm 12.11 or newer](https://pnpm.io/agent-skills), install the package directly in your
|
|
123
|
+
project and run `pnpm approve` to review its skills. pnpm links approved skills into your
|
|
124
|
+
configured agent directories.
|
|
125
|
+
- With [TanStack Intent](https://tanstack.com/intent/latest/docs/getting-started/quick-start-consumers)
|
|
126
|
+
installed in your project, use `pnpm exec intent list` and load a skill by its package and name.
|
|
368
127
|
|
|
369
|
-
|
|
370
|
-
-
|
|
371
|
-
|
|
372
|
-
- `flutterwavePlan`
|
|
373
|
-
- `flutterwaveWebhookEvent`
|
|
374
|
-
- `flutterwaveRefund`
|
|
375
|
-
|
|
376
|
-
The Paystack plugin is being aligned incrementally with this provider-namespaced approach. Its
|
|
377
|
-
transaction, catalog, and webhook records are provider-namespaced today; its legacy generic
|
|
378
|
-
subscription table remains compatibility-sensitive until the planned migration is released. The
|
|
379
|
-
two existing plugins can still be installed together because Flutterwave's subscription and other
|
|
380
|
-
provider records are namespaced separately. Shared application behavior should rely on each
|
|
381
|
-
provider's normalized lifecycle fields and reference authorization rather than assuming that either
|
|
382
|
-
provider exposes the other's customer or subscription identifiers.
|
|
383
|
-
|
|
384
|
-
Public identifiers use Flutterwave-native names: `txRef`, `transactionId`, `flwRef`,
|
|
385
|
-
`paymentPlanId`, `subscriptionId`, `secretHash`, and `subaccountId`.
|
|
386
|
-
|
|
387
|
-
## Provider transport
|
|
388
|
-
|
|
389
|
-
Provider requests use Flutterwave's v3 HTTP API with bearer authentication and validate response
|
|
390
|
-
envelopes before returning data to the plugin. The adapter accepts injected `fetch` and
|
|
391
|
-
`flutterwaveClient` implementations for tests and custom transports.
|
|
128
|
+
```sh
|
|
129
|
+
pnpm exec intent load better-auth-flutterwave#better-auth-flutterwave-setup
|
|
130
|
+
```
|
|
392
131
|
|
|
393
132
|
## Development
|
|
394
133
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
Commands:
|
|
398
|
-
|
|
399
|
-
```bash
|
|
134
|
+
```sh
|
|
400
135
|
vp install
|
|
136
|
+
vp pack
|
|
401
137
|
vp check
|
|
402
138
|
vp test
|
|
403
|
-
|
|
404
|
-
pnpm run lint:types
|
|
405
|
-
pnpm run lint:package
|
|
139
|
+
pnpm exec intent validate skills --check
|
|
406
140
|
```
|
|
407
141
|
|
|
408
|
-
Integration tests require Flutterwave sandbox credentials and are opt-in:
|
|
409
|
-
|
|
410
|
-
```bash
|
|
411
|
-
RUN_INTEGRATION_TESTS=true vp test
|
|
412
|
-
```
|
|
413
|
-
|
|
414
|
-
## License
|
|
415
|
-
|
|
416
142
|
MIT
|
package/dist/client.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { C as FlutterwaveMetadata, N as PACKAGE_VERSION, U as FlutterwavePlan, V as FlutterwaveInitializeResult, W as FlutterwaveProduct, X as FlutterwaveTransactionResponse, Y as FlutterwaveTransaction, at as Subscription, j as parseFlutterwaveMetadata, t as flutterwave } from "./index-DpejOhTY.mjs";
|
|
2
|
+
import { BetterFetchOption, BetterFetchResponse } from "@better-fetch/fetch";
|
|
3
3
|
import { BetterAuthClientPlugin } from "better-auth/client";
|
|
4
|
-
//#region src/client.d.ts
|
|
5
4
|
export type FetchResult<T, O extends BetterFetchOption | undefined> = O extends {
|
|
6
5
|
throw: true;
|
|
7
6
|
} ? T : BetterFetchResponse<T>;
|
|
@@ -84,14 +83,14 @@ declare module "better-auth/client" {
|
|
|
84
83
|
subscription: FlutterwaveProviderActions["subscription"];
|
|
85
84
|
}
|
|
86
85
|
}
|
|
87
|
-
type FlutterwaveClientPluginInstance = Omit<BetterAuthClientPlugin, "id" | "$InferServerPlugin" | "getActions"> & {
|
|
86
|
+
type FlutterwaveClientPluginInstance = Omit<BetterAuthClientPlugin, "id" | "version" | "$InferServerPlugin" | "getActions"> & {
|
|
88
87
|
id: "flutterwave-client";
|
|
88
|
+
version: typeof PACKAGE_VERSION;
|
|
89
89
|
$InferServerPlugin: ReturnType<typeof flutterwave>;
|
|
90
|
-
getActions: ($fetch:
|
|
90
|
+
getActions: ($fetch: Parameters<NonNullable<BetterAuthClientPlugin["getActions"]>>[0]) => FlutterwaveClientActions;
|
|
91
91
|
};
|
|
92
92
|
export declare const flutterwaveClient: (_options?: {
|
|
93
93
|
subscription?: boolean;
|
|
94
94
|
}) => FlutterwaveClientPluginInstance;
|
|
95
|
-
//#endregion
|
|
96
95
|
export { type FlutterwaveMetadata, parseFlutterwaveMetadata };
|
|
97
96
|
//# sourceMappingURL=client.d.mts.map
|
package/dist/client.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.mts","names":["flutterwaveServer"],"sources":["../src/client.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.mts","names":["flutterwaveServer"],"sources":["../src/client.ts"],"mappings":";;;YAgBY,YAAY,GAAG,UAAU,iCAAiC;EAAY;IAC9E,IACA,oBAAoB;iBAEP;EACf;IACE,aAAa,UAAU,2CACrB;MACE;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;QACE;QACA;QACA;QACA;;OAGJ,UAAU,MACP,QAAQ,YAAY,6BAA6B;IACtD,SAAS,UAAU,2CACjB;MAAQ;MAAiC;MAAgB;OACzD,UAAU,MACP,QACH;MAAc;MAAgB;MAAe,MAAM;OAAkC;IAEvF,OAAO,UAAU,2CACf;MAAS;QAAU;;OACnB,UAAU,MACP,QAAQ;MAAc,cAAc;OAA4B;;EAEvE;IACE,QAAQ;IACR,SAAS;IACT,SAAS,UAAU,2CACjB;MAAQ;MAAiC;OACzC,UAAU,MACP,QAAQ;MAAc;OAAkB;IAC7C,UAAU,UAAU,2CAClB;MAAQ;OACR,UAAU,MACP,QAAQ;MAAc;OAAkB;IAC7C,OAAO,UAAU,2CACf;MAAS;QAAU;;OACnB,UAAU,MACP,QAAQ;MAAc,eAAe;OAAkB;;EAE9D,cAAc,QACZ;IAAsB,OAAO;IAAmB,UAAU;;EAE5D,iBAAiB,QAAQ;IAAsB,OAAO;;EACtD,oBAAoB,QAAQ;IAAsB,UAAU;;;iBAG7C;EACf,aAAa;EACb,cAAc;;;YAIJ;IACR,aAAa;IACb,cAAc;;;KAIb,kCAAkC,KACrC;EAGA;EACA,gBAAgB;EAChB,oBAAoB,kBAAkBA;EACtC,aACE,QAAQ,WAAW,YAAY,8CAC5B;;qBAGM,oBAAiB;EAC5B;MACE"}
|
package/dist/client.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { l as parseFlutterwaveMetadata, t as PACKAGE_VERSION } from "./version-
|
|
2
|
-
|
|
1
|
+
import { l as parseFlutterwaveMetadata, t as PACKAGE_VERSION } from "./version-DfR5E0nB.mjs";
|
|
2
|
+
// src/client.ts
|
|
3
3
|
const flutterwaveClient = (_options) => ({
|
|
4
4
|
id: "flutterwave-client",
|
|
5
5
|
version: PACKAGE_VERSION,
|
|
@@ -69,7 +69,6 @@ const flutterwaveClient = (_options) => ({
|
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
|
-
//#endregion
|
|
73
72
|
export { flutterwaveClient, parseFlutterwaveMetadata };
|
|
74
73
|
|
|
75
74
|
//# sourceMappingURL=client.mjs.map
|
package/dist/client.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"client.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import type { BetterFetchOption, BetterFetchResponse } from \"@better-fetch/fetch\";\nimport type { BetterAuthClientPlugin } from \"better-auth/client\";\nimport type {\n FlutterwaveInitializeResult,\n FlutterwavePlan,\n FlutterwaveProduct,\n FlutterwaveTransaction,\n FlutterwaveTransactionResponse,\n Subscription,\n} from \"./types.ts\";\nimport type { flutterwave as flutterwaveServer } from \"./index.ts\";\nimport { PACKAGE_VERSION } from \"./version.ts\";\n\nexport { parseFlutterwaveMetadata } from \"./metadata.ts\";\nexport type { FlutterwaveMetadata } from \"./metadata.ts\";\n\nexport type FetchResult<T, O extends BetterFetchOption | undefined> = O extends { throw: true }\n ? T\n : BetterFetchResponse<T>;\n\nexport interface FlutterwaveProviderActions {\n transaction: {\n initialize: <O extends BetterFetchOption | undefined = undefined>(\n data: {\n amount?: number;\n currency?: string;\n redirectUrl: string;\n txRef?: string;\n referenceId?: string;\n plan?: string;\n product?: string;\n quantity?: number;\n paymentOptions?: string;\n subaccounts?: {\n id: string;\n transactionSplitRatio?: number;\n transactionChargeType?: \"flat\" | \"percentage\" | \"flat_subaccount\";\n transactionCharge?: number;\n }[];\n },\n options?: O,\n ) => Promise<FetchResult<FlutterwaveInitializeResult, O>>;\n verify: <O extends BetterFetchOption | undefined = undefined>(\n data: { transactionId?: string | number; txRef?: string; referenceId?: string },\n options?: O,\n ) => Promise<\n FetchResult<{ status: string; txRef: string; data: FlutterwaveTransactionResponse }, O>\n >;\n list: <O extends BetterFetchOption | undefined = undefined>(\n data?: { query?: { referenceId?: string } },\n options?: O,\n ) => Promise<FetchResult<{ transactions: FlutterwaveTransaction[] }, O>>;\n };\n subscription: {\n create: FlutterwaveProviderActions[\"transaction\"][\"initialize\"];\n upgrade: FlutterwaveProviderActions[\"transaction\"][\"initialize\"];\n cancel: <O extends BetterFetchOption | undefined = undefined>(\n data: { subscriptionId: string | number; atPeriodEnd?: boolean },\n options?: O,\n ) => Promise<FetchResult<{ status: string }, O>>;\n restore: <O extends BetterFetchOption | undefined = undefined>(\n data: { subscriptionId: string | number },\n options?: O,\n ) => Promise<FetchResult<{ status: string }, O>>;\n list: <O extends BetterFetchOption | undefined = undefined>(\n data?: { query?: { referenceId?: string } },\n options?: O,\n ) => Promise<FetchResult<{ subscriptions: Subscription[] }, O>>;\n };\n config: () => Promise<\n BetterFetchResponse<{ plans: FlutterwavePlan[]; products: FlutterwaveProduct[] }>\n >;\n listPlans: () => Promise<BetterFetchResponse<{ plans: FlutterwavePlan[] }>>;\n listProducts: () => Promise<BetterFetchResponse<{ products: FlutterwaveProduct[] }>>;\n}\n\nexport interface FlutterwaveClientActions {\n flutterwave: FlutterwaveProviderActions;\n subscription: FlutterwaveProviderActions[\"subscription\"];\n}\n\ndeclare module \"better-auth/client\" {\n interface BetterAuthClient {\n flutterwave: FlutterwaveProviderActions;\n subscription: FlutterwaveProviderActions[\"subscription\"];\n }\n}\n\ntype FlutterwaveClientPluginInstance = Omit<\n BetterAuthClientPlugin,\n \"id\" | \"version\" | \"$InferServerPlugin\" | \"getActions\"\n> & {\n id: \"flutterwave-client\";\n version: typeof PACKAGE_VERSION;\n $InferServerPlugin: ReturnType<typeof flutterwaveServer>;\n getActions: (\n $fetch: Parameters<NonNullable<BetterAuthClientPlugin[\"getActions\"]>>[0],\n ) => FlutterwaveClientActions;\n};\n\nexport const flutterwaveClient = (_options?: {\n subscription?: boolean;\n}): FlutterwaveClientPluginInstance => ({\n id: \"flutterwave-client\",\n version: PACKAGE_VERSION,\n $InferServerPlugin: {} as ReturnType<typeof flutterwaveServer>,\n pathMethods: {\n \"/flutterwave/transaction/initialize\": \"POST\",\n \"/flutterwave/transaction/verify\": \"POST\",\n \"/flutterwave/subscription/create\": \"POST\",\n \"/flutterwave/subscription/upgrade\": \"POST\",\n \"/flutterwave/subscription/cancel\": \"POST\",\n \"/flutterwave/subscription/restore\": \"POST\",\n },\n getActions: ($fetch) => {\n const transaction: FlutterwaveProviderActions[\"transaction\"] = {\n initialize: (data, options) =>\n $fetch(\"/flutterwave/transaction/initialize\", { ...options, method: \"POST\", body: data }),\n verify: (data, options) =>\n $fetch(\"/flutterwave/transaction/verify\", { ...options, method: \"POST\", body: data }),\n list: (data, options) =>\n $fetch(\"/flutterwave/transaction/list\", {\n query: data?.query,\n ...options,\n method: \"GET\",\n }),\n };\n const subscription: FlutterwaveProviderActions[\"subscription\"] = {\n create: (data, options) =>\n $fetch(\"/flutterwave/subscription/create\", { ...options, method: \"POST\", body: data }),\n upgrade: (data, options) =>\n $fetch(\"/flutterwave/subscription/upgrade\", { ...options, method: \"POST\", body: data }),\n cancel: (data, options) =>\n $fetch(\"/flutterwave/subscription/cancel\", { ...options, method: \"POST\", body: data }),\n restore: (data, options) =>\n $fetch(\"/flutterwave/subscription/restore\", { ...options, method: \"POST\", body: data }),\n list: (data, options) =>\n $fetch(\"/flutterwave/subscription/list\", {\n query: data?.query,\n ...options,\n method: \"GET\",\n }),\n };\n const provider: FlutterwaveProviderActions = {\n transaction,\n subscription,\n config: () => $fetch(\"/flutterwave/config\", { method: \"GET\" }),\n listPlans: () => $fetch(\"/flutterwave/plan/list\", { method: \"GET\" }),\n listProducts: () => $fetch(\"/flutterwave/product/list\", { method: \"GET\" }),\n };\n return { flutterwave: provider, subscription };\n },\n});\n"],"mappings":";;AAoGA,MAAa,qBAAqB,cAEM;CACtC,IAAI;CACJ,SAAS;CACT,oBAAoB,CAAC;CACrB,aAAa;EACX,uCAAuC;EACvC,mCAAmC;EACnC,oCAAoC;EACpC,qCAAqC;EACrC,oCAAoC;EACpC,qCAAqC;CACvC;CACA,aAAa,WAAW;EACtB,MAAM,cAAyD;GAC7D,aAAa,MAAM,YACjB,OAAO,uCAAuC;IAAE,GAAG;IAAS,QAAQ;IAAQ,MAAM;GAAK,CAAC;GAC1F,SAAS,MAAM,YACb,OAAO,mCAAmC;IAAE,GAAG;IAAS,QAAQ;IAAQ,MAAM;GAAK,CAAC;GACtF,OAAO,MAAM,YACX,OAAO,iCAAiC;IACtC,OAAO,MAAM;IACb,GAAG;IACH,QAAQ;GACV,CAAC;EACL;EACA,MAAM,eAA2D;GAC/D,SAAS,MAAM,YACb,OAAO,oCAAoC;IAAE,GAAG;IAAS,QAAQ;IAAQ,MAAM;GAAK,CAAC;GACvF,UAAU,MAAM,YACd,OAAO,qCAAqC;IAAE,GAAG;IAAS,QAAQ;IAAQ,MAAM;GAAK,CAAC;GACxF,SAAS,MAAM,YACb,OAAO,oCAAoC;IAAE,GAAG;IAAS,QAAQ;IAAQ,MAAM;GAAK,CAAC;GACvF,UAAU,MAAM,YACd,OAAO,qCAAqC;IAAE,GAAG;IAAS,QAAQ;IAAQ,MAAM;GAAK,CAAC;GACxF,OAAO,MAAM,YACX,OAAO,kCAAkC;IACvC,OAAO,MAAM;IACb,GAAG;IACH,QAAQ;GACV,CAAC;EACL;EAQA,OAAO;GAAE,aAAa;IANpB;IACA;IACA,cAAc,OAAO,uBAAuB,EAAE,QAAQ,MAAM,CAAC;IAC7D,iBAAiB,OAAO,0BAA0B,EAAE,QAAQ,MAAM,CAAC;IACnE,oBAAoB,OAAO,6BAA6B,EAAE,QAAQ,MAAM,CAAC;GAE9C;GAAG;EAAa;CAC/C;AACF"}
|