better-auth-flutterwave 0.0.0 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +307 -0
  3. package/dist/client.d.mts +96 -0
  4. package/dist/client.d.mts.map +1 -0
  5. package/dist/client.mjs +75 -0
  6. package/dist/client.mjs.map +1 -0
  7. package/dist/index-BxLoiCsI.d.mts +927 -0
  8. package/dist/index-BxLoiCsI.d.mts.map +1 -0
  9. package/dist/index.d.mts +2 -0
  10. package/dist/index.mjs +1753 -0
  11. package/dist/index.mjs.map +1 -0
  12. package/dist/version-csqIJRyo.mjs +73 -0
  13. package/dist/version-csqIJRyo.mjs.map +1 -0
  14. package/package.json +119 -8
  15. package/skills/better-auth-flutterwave-setup/SKILL.md +23 -0
  16. package/skills/better-auth-flutterwave-setup/agents/openai.yaml +6 -0
  17. package/skills/flutterwave-billing-flows/SKILL.md +21 -0
  18. package/skills/flutterwave-billing-flows/agents/openai.yaml +6 -0
  19. package/skills/flutterwave-catalog-limits/SKILL.md +17 -0
  20. package/skills/flutterwave-catalog-limits/agents/openai.yaml +6 -0
  21. package/skills/flutterwave-client-api/SKILL.md +20 -0
  22. package/skills/flutterwave-client-api/agents/openai.yaml +6 -0
  23. package/skills/flutterwave-local-subscriptions/SKILL.md +18 -0
  24. package/skills/flutterwave-local-subscriptions/agents/openai.yaml +6 -0
  25. package/skills/flutterwave-organization-billing/SKILL.md +18 -0
  26. package/skills/flutterwave-organization-billing/agents/openai.yaml +6 -0
  27. package/skills/flutterwave-schema-migrations/SKILL.md +19 -0
  28. package/skills/flutterwave-schema-migrations/agents/openai.yaml +6 -0
  29. package/skills/flutterwave-tanstack-start/SKILL.md +20 -0
  30. package/skills/flutterwave-tanstack-start/agents/openai.yaml +6 -0
  31. package/skills/flutterwave-testing-fixtures/SKILL.md +20 -0
  32. package/skills/flutterwave-testing-fixtures/agents/openai.yaml +6 -0
  33. package/skills/flutterwave-webhooks-events/SKILL.md +17 -0
  34. package/skills/flutterwave-webhooks-events/agents/openai.yaml +6 -0
  35. package/index.js +0 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 alexasomba
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,307 @@
1
+ # Better Auth Flutterwave
2
+
3
+ A TypeScript-first [Better Auth](https://www.better-auth.com) plugin for Flutterwave v3 payments.
4
+ It supports Flutterwave Standard checkout, verified one-time payments, native payment-plan
5
+ subscriptions, locally managed subscriptions, organization billing, marketplace split payments,
6
+ webhooks, refunds, and reconciliation.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install better-auth better-auth-flutterwave flutterwave-node-v3
12
+ ```
13
+
14
+ Node.js 22 or newer is required.
15
+
16
+ ## Configure
17
+
18
+ ```env
19
+ FLUTTERWAVE_PUBLIC_KEY=FLWPUBK_TEST-...
20
+ FLUTTERWAVE_SECRET_KEY=FLWSECK_TEST-...
21
+ FLUTTERWAVE_SECRET_HASH=your-dashboard-webhook-secret-hash
22
+ BETTER_AUTH_SECRET=...
23
+ BETTER_AUTH_URL=http://localhost:3000
24
+ ```
25
+
26
+ ```ts
27
+ import { betterAuth } from "better-auth";
28
+ import { organization } from "better-auth/plugins";
29
+ import { flutterwave } from "better-auth-flutterwave";
30
+
31
+ export const auth = betterAuth({
32
+ plugins: [
33
+ organization(),
34
+ flutterwave({
35
+ publicKey: process.env.FLUTTERWAVE_PUBLIC_KEY!,
36
+ secretKey: process.env.FLUTTERWAVE_SECRET_KEY!,
37
+ secretHash: process.env.FLUTTERWAVE_SECRET_HASH!,
38
+ subscription: {
39
+ enabled: true,
40
+ plans: [
41
+ {
42
+ name: "pro",
43
+ paymentPlanId: 12345,
44
+ amount: 5_000,
45
+ currency: "NGN",
46
+ interval: "monthly",
47
+ },
48
+ {
49
+ name: "starter",
50
+ amount: 2_000,
51
+ currency: "NGN",
52
+ interval: "monthly",
53
+ },
54
+ ],
55
+ },
56
+ organization: { enabled: true },
57
+ marketplace: {
58
+ allowedSubaccountIds: ["RS_1234567890"],
59
+ },
60
+ }),
61
+ ],
62
+ });
63
+ ```
64
+
65
+ `flutterwaveClient` may be injected for testing or advanced integrations, and `fetch` may be
66
+ injected for the narrow direct-HTTP operations used by Flutterwave Standard. By default, the plugin
67
+ constructs `flutterwave-node-v3` from the public and secret keys.
68
+
69
+ Configure the client plugin:
70
+
71
+ ```ts
72
+ import { createAuthClient } from "better-auth/client";
73
+ import { flutterwaveClient } from "better-auth-flutterwave/client";
74
+
75
+ export const authClient = createAuthClient({
76
+ plugins: [flutterwaveClient({ subscription: true })],
77
+ });
78
+ ```
79
+
80
+ Then generate the Better Auth schema and apply it with your database migration workflow:
81
+
82
+ ```bash
83
+ npx @better-auth/cli generate
84
+ ```
85
+
86
+ For supported direct-migration setups, you can instead run:
87
+
88
+ ```bash
89
+ npx @better-auth/cli migrate
90
+ ```
91
+
92
+ ## Checkout and verification
93
+
94
+ Flutterwave Standard checkout requires an amount, currency, redirect URL, and billing email. The
95
+ browser supplies the amount and currency directly or selects a configured plan/product; the server
96
+ resolves billing email from the authenticated user or authorized organization owner. The plugin
97
+ generates a unique `txRef`.
98
+
99
+ ```ts
100
+ const checkout = await authClient.flutterwave.transaction.initialize(
101
+ {
102
+ amount: 5_000,
103
+ currency: "NGN",
104
+ redirectUrl: `${window.location.origin}/billing/flutterwave/callback`,
105
+ },
106
+ { throw: true },
107
+ );
108
+
109
+ window.location.assign(checkout.url);
110
+ ```
111
+
112
+ After redirect, send exactly one transaction locator to the verification action:
113
+
114
+ ```ts
115
+ await authClient.flutterwave.transaction.verify({
116
+ transactionId: Number(searchParams.get("transaction_id")),
117
+ });
118
+ ```
119
+
120
+ Fulfillment only happens after server-side verification confirms the transaction status, `txRef`,
121
+ amount, and currency. A redirect or webhook payload alone is never proof of payment.
122
+
123
+ The typed browser surface is intentionally limited to:
124
+
125
+ - `authClient.flutterwave.transaction.initialize`, `verify`, and `list`
126
+ - `authClient.subscription.create`, `upgrade`, `cancel`, `restore`, and `list`
127
+ - Read-only provider configuration and local catalog actions under `authClient.flutterwave`
128
+
129
+ Reconciliation, renewals, remote plan synchronization, refunds, and subaccount administration are
130
+ trusted-server operations and are not exposed to browser clients.
131
+
132
+ ## Subscription models
133
+
134
+ ### Flutterwave-native plans
135
+
136
+ Set a numeric `paymentPlanId` on a configured plan. Enrollment starts with a card checkout carrying
137
+ that plan ID. After verification, the plugin resolves the Flutterwave subscription using the
138
+ verified transaction, immutable billing email, and payment plan.
139
+
140
+ Flutterwave has no separate “create subscription” endpoint for this flow. Provider-native plans do
141
+ not pretend to support provider-side trials or prorated mutations.
142
+
143
+ ### Locally managed plans
144
+
145
+ Omit `paymentPlanId` for a locally renewed subscription. The plugin stores the subscription,
146
+ group, seat count, and entitlement configuration locally. Automated trial transitions, scheduled
147
+ plan mutations, and proration orchestration are not part of the initial release.
148
+
149
+ Trusted-server renewal prefers that encrypted token. If no token is available, renewal creates a
150
+ hosted checkout and remains pending until the resulting payment is verified.
151
+
152
+ ## Organization and marketplace billing
153
+
154
+ Organization billing controls local ownership and authorization. Flutterwave billing identity is
155
+ an email; the plugin does not create or persist a fictional Flutterwave customer record on users or
156
+ organizations.
157
+
158
+ Marketplace split payments are a separate concern. Configure existing, KYC-approved Flutterwave
159
+ subaccount IDs in `marketplace.allowedSubaccountIds`. Per-checkout overrides must be authorized and
160
+ must reference the allowlist. The plugin does not provision subaccounts or automatically equate an
161
+ organization with a Flutterwave subaccount.
162
+
163
+ ## Webhooks
164
+
165
+ Point Flutterwave at your Better Auth Flutterwave webhook endpoint. The plugin verifies
166
+ `flutterwave-signature` as an HMAC-SHA256 digest of the exact raw request body using the separately
167
+ configured `secretHash`. It compares signatures in constant time, records idempotency state, and
168
+ re-verifies payment transactions before granting value. Keep custom `onEvent` work short so the
169
+ endpoint can acknowledge within Flutterwave's timeout.
170
+
171
+ Do not parse and reserialize the request before signature verification. Do not use the API
172
+ `secretKey` as the webhook secret hash.
173
+
174
+ Polling and reconciliation are provided for pending transactions, subscriptions, and refunds, so
175
+ correctness does not depend on webhook delivery.
176
+
177
+ ## Trusted server operations
178
+
179
+ Privileged operations are exported from the server entry point:
180
+
181
+ ```ts
182
+ import {
183
+ chargeSubscriptionRenewal,
184
+ reconcileFlutterwaveRefunds,
185
+ reconcileFlutterwaveTransaction,
186
+ refundFlutterwaveTransaction,
187
+ syncFlutterwavePlans,
188
+ } from "better-auth-flutterwave";
189
+ ```
190
+
191
+ They require a trusted Better Auth endpoint context plus the same Flutterwave options used by the
192
+ plugin. Call them only from independently authorized server routes, queue consumers, or scheduled
193
+ jobs:
194
+
195
+ - `syncFlutterwavePlans` imports remote Flutterwave payment plans into namespaced local records.
196
+ - `chargeSubscriptionRenewal` uses an encrypted reusable token when available, otherwise returns a
197
+ hosted-checkout URL and leaves renewal pending.
198
+ - `refundFlutterwaveTransaction` starts a full or partial asynchronous refund.
199
+ - `reconcileFlutterwaveTransaction` polls and verifies a pending transaction.
200
+ - `reconcileFlutterwaveRefunds` refreshes pending refund records.
201
+
202
+ ## Packaged agent skills
203
+
204
+ The npm package ships version-matched coding-agent skills in its `skills/` directory. They help an
205
+ agent implement the supported Flutterwave API, data model, security rules, and examples without
206
+ guessing provider behavior.
207
+
208
+ Install the skill linker in your application and run its one-time setup:
209
+
210
+ ```bash
211
+ npm install --save-dev skills-npm
212
+ npx skills-npm setup
213
+ ```
214
+
215
+ `skills-npm setup` adds a `prepare` hook and links skills from installed npm packages into the
216
+ locations detected for Codex, Claude Code, Cursor, and other supported agents. To select only this
217
+ package, create:
218
+
219
+ ```ts
220
+ // skills-npm.config.ts
221
+ import { defineConfig } from "skills-npm";
222
+
223
+ export default defineConfig({
224
+ include: ["better-auth-flutterwave"],
225
+ });
226
+ ```
227
+
228
+ Refresh the links with `npx skills-npm --force`, or preview changes with
229
+ `npx skills-npm --dry-run`.
230
+
231
+ | Skill | Use it for |
232
+ | ----------------------------------- | -------------------------------------------------------- |
233
+ | `$better-auth-flutterwave-setup` | Initial server/client setup, credentials, and migrations |
234
+ | `$flutterwave-billing-flows` | Checkout, verification, and subscription flows |
235
+ | `$flutterwave-client-api` | Typed browser actions and client/server boundaries |
236
+ | `$flutterwave-local-subscriptions` | Encrypted token renewal and hosted-checkout fallback |
237
+ | `$flutterwave-organization-billing` | Organization ownership, roles, and split payments |
238
+ | `$flutterwave-catalog-limits` | Plans, local products, inventory, seats, and limits |
239
+ | `$flutterwave-webhooks-events` | Webhook signatures, idempotency, and re-verification |
240
+ | `$flutterwave-schema-migrations` | Namespaced schema generation and migrations |
241
+ | `$flutterwave-testing-fixtures` | Unit, sandbox, webhook, and reconciliation tests |
242
+ | `$flutterwave-tanstack-start` | TanStack Start integration |
243
+
244
+ Invoke a skill explicitly in your agent prompt:
245
+
246
+ ```text
247
+ Use $better-auth-flutterwave-setup to add Better Auth Flutterwave to this application.
248
+ ```
249
+
250
+ ```text
251
+ Use $flutterwave-webhooks-events to review my webhook route and add signature tests.
252
+ ```
253
+
254
+ ```text
255
+ Use $flutterwave-organization-billing to implement organization checkout with allowlisted splits.
256
+ ```
257
+
258
+ Including the `$skill-name` in the prompt is the most portable explicit invocation form.
259
+
260
+ ## Data model
261
+
262
+ Provider-owned records are namespaced so this plugin can coexist with other billing providers:
263
+
264
+ - `flutterwaveTransaction`
265
+ - `flutterwaveSubscription`
266
+ - `flutterwaveProduct` (local catalog only)
267
+ - `flutterwavePlan`
268
+ - `flutterwaveWebhookEvent`
269
+ - `flutterwaveRefund`
270
+
271
+ Public identifiers use Flutterwave-native names: `txRef`, `transactionId`, `flwRef`,
272
+ `paymentPlanId`, `subscriptionId`, `secretHash`, and `subaccountId`.
273
+
274
+ ## SDK behavior
275
+
276
+ [`flutterwave-node-v3`](https://www.npmjs.com/package/flutterwave-node-v3) is an untyped CommonJS
277
+ SDK. The plugin keeps it behind a Zod-validated adapter, uses only its Promise APIs, and prevents
278
+ SDK `any` values from leaking into the public API.
279
+
280
+ The SDK performs always-on telemetry and may write telemetry data through an operating-system
281
+ temporary file. This behavior comes from the upstream SDK, not Better Auth or this plugin. Review
282
+ the SDK and your deployment environment’s privacy, filesystem, and serverless constraints before
283
+ adopting it. Injecting a compatible client helps with tests but does not change upstream behavior
284
+ when the official SDK is used.
285
+
286
+ ## Development
287
+
288
+ This repository uses [Vite+](https://viteplus.dev):
289
+
290
+ ```bash
291
+ vp install
292
+ vp check
293
+ vp test
294
+ vp pack
295
+ pnpm run lint:types
296
+ pnpm run lint:package
297
+ ```
298
+
299
+ Integration tests require Flutterwave sandbox credentials and are opt-in:
300
+
301
+ ```bash
302
+ RUN_INTEGRATION_TESTS=true vp test
303
+ ```
304
+
305
+ ## License
306
+
307
+ MIT
@@ -0,0 +1,96 @@
1
+ import { K as Subscription, L as FlutterwaveTransaction, M as FlutterwaveProduct, R as FlutterwaveTransactionResponse, b as parseFlutterwaveMetadata, f as FlutterwaveMetadata, j as FlutterwavePlan, k as FlutterwaveInitializeResult, t as flutterwave } from "./index-BxLoiCsI.mjs";
2
+ import { BetterFetch, BetterFetchOption, BetterFetchResponse } from "@better-fetch/fetch";
3
+ import { BetterAuthClientPlugin } from "better-auth/client";
4
+ //#region src/client.d.ts
5
+ type FetchResult<T, O extends BetterFetchOption | undefined> = O extends {
6
+ throw: true;
7
+ } ? T : BetterFetchResponse<T>;
8
+ interface FlutterwaveProviderActions {
9
+ transaction: {
10
+ initialize: <O extends BetterFetchOption | undefined = undefined>(data: {
11
+ amount?: number;
12
+ currency?: string;
13
+ redirectUrl: string;
14
+ txRef?: string;
15
+ referenceId?: string;
16
+ plan?: string;
17
+ product?: string;
18
+ paymentOptions?: string;
19
+ subaccounts?: {
20
+ id: string;
21
+ transactionSplitRatio?: number;
22
+ transactionChargeType?: "flat" | "percentage" | "flat_subaccount";
23
+ transactionCharge?: number;
24
+ }[];
25
+ }, options?: O) => Promise<FetchResult<FlutterwaveInitializeResult, O>>;
26
+ verify: <O extends BetterFetchOption | undefined = undefined>(data: {
27
+ transactionId?: string | number;
28
+ txRef?: string;
29
+ referenceId?: string;
30
+ }, options?: O) => Promise<FetchResult<{
31
+ status: string;
32
+ txRef: string;
33
+ data: FlutterwaveTransactionResponse;
34
+ }, O>>;
35
+ list: <O extends BetterFetchOption | undefined = undefined>(data?: {
36
+ query?: {
37
+ referenceId?: string;
38
+ };
39
+ }, options?: O) => Promise<FetchResult<{
40
+ transactions: FlutterwaveTransaction[];
41
+ }, O>>;
42
+ };
43
+ subscription: {
44
+ create: FlutterwaveProviderActions["transaction"]["initialize"];
45
+ upgrade: FlutterwaveProviderActions["transaction"]["initialize"];
46
+ cancel: <O extends BetterFetchOption | undefined = undefined>(data: {
47
+ subscriptionId: string | number;
48
+ atPeriodEnd?: boolean;
49
+ }, options?: O) => Promise<FetchResult<{
50
+ status: string;
51
+ }, O>>;
52
+ restore: <O extends BetterFetchOption | undefined = undefined>(data: {
53
+ subscriptionId: string | number;
54
+ }, options?: O) => Promise<FetchResult<{
55
+ status: string;
56
+ }, O>>;
57
+ list: <O extends BetterFetchOption | undefined = undefined>(data?: {
58
+ query?: {
59
+ referenceId?: string;
60
+ };
61
+ }, options?: O) => Promise<FetchResult<{
62
+ subscriptions: Subscription[];
63
+ }, O>>;
64
+ };
65
+ config: () => Promise<BetterFetchResponse<{
66
+ plans: FlutterwavePlan[];
67
+ products: FlutterwaveProduct[];
68
+ }>>;
69
+ listPlans: () => Promise<BetterFetchResponse<{
70
+ plans: FlutterwavePlan[];
71
+ }>>;
72
+ listProducts: () => Promise<BetterFetchResponse<{
73
+ products: FlutterwaveProduct[];
74
+ }>>;
75
+ }
76
+ interface FlutterwaveClientActions {
77
+ flutterwave: FlutterwaveProviderActions;
78
+ subscription: FlutterwaveProviderActions["subscription"];
79
+ }
80
+ declare module "better-auth/client" {
81
+ interface BetterAuthClient {
82
+ flutterwave: FlutterwaveProviderActions;
83
+ subscription: FlutterwaveProviderActions["subscription"];
84
+ }
85
+ }
86
+ type FlutterwaveClientPluginInstance = Omit<BetterAuthClientPlugin, "id" | "$InferServerPlugin" | "getActions"> & {
87
+ id: "flutterwave-client";
88
+ $InferServerPlugin: ReturnType<typeof flutterwave>;
89
+ getActions: ($fetch: BetterFetch) => FlutterwaveClientActions;
90
+ };
91
+ declare const flutterwaveClient: (_options?: {
92
+ subscription?: boolean;
93
+ }) => FlutterwaveClientPluginInstance;
94
+ //#endregion
95
+ export { FetchResult, FlutterwaveClientActions, type FlutterwaveMetadata, FlutterwaveProviderActions, flutterwaveClient, parseFlutterwaveMetadata };
96
+ //# sourceMappingURL=client.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.mts","names":[],"sources":["../src/client.ts"],"mappings":";;;;KAgBY,YAAY,GAAG,UAAU,iCAAiC;EAAY;IAC9E,IACA,oBAAoB;UAEP;EACf;IACE,aAAa,UAAU,2CACrB;MACE;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;;;UAG7C;EACf,aAAa;EACb,cAAc;;;YAIJ;IACR,aAAa;IACb,cAAc;;;KAIb,kCAAkC,KACrC;EAGA;EACA,oBAAoB,kBAAkB;EACtC,aAAa,QAAQ,gBAAgB;;cAG1B,oBAAqB;EAChC;MACE"}
@@ -0,0 +1,75 @@
1
+ import { l as parseFlutterwaveMetadata, t as PACKAGE_VERSION } from "./version-csqIJRyo.mjs";
2
+ //#region src/client.ts
3
+ const flutterwaveClient = (_options) => ({
4
+ id: "flutterwave-client",
5
+ version: PACKAGE_VERSION,
6
+ $InferServerPlugin: {},
7
+ pathMethods: {
8
+ "/flutterwave/transaction/initialize": "POST",
9
+ "/flutterwave/transaction/verify": "POST",
10
+ "/flutterwave/subscription/create": "POST",
11
+ "/flutterwave/subscription/upgrade": "POST",
12
+ "/flutterwave/subscription/cancel": "POST",
13
+ "/flutterwave/subscription/restore": "POST"
14
+ },
15
+ getActions: ($fetch) => {
16
+ const transaction = {
17
+ initialize: (data, options) => $fetch("/flutterwave/transaction/initialize", {
18
+ ...options,
19
+ method: "POST",
20
+ body: data
21
+ }),
22
+ verify: (data, options) => $fetch("/flutterwave/transaction/verify", {
23
+ ...options,
24
+ method: "POST",
25
+ body: data
26
+ }),
27
+ list: (data, options) => $fetch("/flutterwave/transaction/list", {
28
+ query: data?.query,
29
+ ...options,
30
+ method: "GET"
31
+ })
32
+ };
33
+ const subscription = {
34
+ create: (data, options) => $fetch("/flutterwave/subscription/create", {
35
+ ...options,
36
+ method: "POST",
37
+ body: data
38
+ }),
39
+ upgrade: (data, options) => $fetch("/flutterwave/subscription/upgrade", {
40
+ ...options,
41
+ method: "POST",
42
+ body: data
43
+ }),
44
+ cancel: (data, options) => $fetch("/flutterwave/subscription/cancel", {
45
+ ...options,
46
+ method: "POST",
47
+ body: data
48
+ }),
49
+ restore: (data, options) => $fetch("/flutterwave/subscription/restore", {
50
+ ...options,
51
+ method: "POST",
52
+ body: data
53
+ }),
54
+ list: (data, options) => $fetch("/flutterwave/subscription/list", {
55
+ query: data?.query,
56
+ ...options,
57
+ method: "GET"
58
+ })
59
+ };
60
+ return {
61
+ flutterwave: {
62
+ transaction,
63
+ subscription,
64
+ config: () => $fetch("/flutterwave/config", { method: "GET" }),
65
+ listPlans: () => $fetch("/flutterwave/plan/list", { method: "GET" }),
66
+ listProducts: () => $fetch("/flutterwave/product/list", { method: "GET" })
67
+ },
68
+ subscription
69
+ };
70
+ }
71
+ });
72
+ //#endregion
73
+ export { flutterwaveClient, parseFlutterwaveMetadata };
74
+
75
+ //# sourceMappingURL=client.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import type { BetterFetch, 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\";\nimport type { flutterwave as flutterwaveServer } from \"./index\";\nimport { PACKAGE_VERSION } from \"./version\";\n\nexport { parseFlutterwaveMetadata } from \"./metadata\";\nexport type { FlutterwaveMetadata } from \"./metadata\";\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 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\" | \"$InferServerPlugin\" | \"getActions\"\n> & {\n id: \"flutterwave-client\";\n $InferServerPlugin: ReturnType<typeof flutterwaveServer>;\n getActions: ($fetch: BetterFetch) => 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":";;AAgGA,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"}