better-auth-flutterwave 0.0.0 → 0.1.5

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-Dcwl_2fw.d.mts +927 -0
  8. package/dist/index-Dcwl_2fw.d.mts.map +1 -0
  9. package/dist/index.d.mts +2 -0
  10. package/dist/index.mjs +1752 -0
  11. package/dist/index.mjs.map +1 -0
  12. package/dist/version-CzIALUmS.mjs +73 -0
  13. package/dist/version-CzIALUmS.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
@@ -0,0 +1,927 @@
1
+ import { AuthContext, BetterAuthPlugin, GenericEndpointContext, InferOptionSchema, Session, User } from "better-auth";
2
+ import * as z from "zod";
3
+ import { BetterAuthPluginDBSchema, DBFieldAttribute } from "better-auth/db";
4
+ import { Member, Organization } from "better-auth/plugins/organization";
5
+ //#region src/schema.d.ts
6
+ type PluginSchemaTable<TableName extends string, FieldName extends string> = Record<TableName, {
7
+ fields: Record<FieldName, DBFieldAttribute>;
8
+ disableMigration?: boolean;
9
+ modelName?: string;
10
+ }>;
11
+ type TransactionsSchema = PluginSchemaTable<"flutterwaveTransaction", "txRef" | "transactionId" | "flwRef" | "referenceId" | "userId" | "amount" | "chargedAmount" | "currency" | "status" | "paymentPlanId" | "plan" | "product" | "paymentType" | "subaccountId" | "metadata" | "verifiedAt" | "reconciledAt" | "createdAt" | "updatedAt">;
12
+ type SubscriptionsSchema = PluginSchemaTable<"flutterwaveSubscription", "plan" | "referenceId" | "userId" | "billingEmail" | "subscriptionId" | "paymentPlanId" | "txRef" | "encryptedPaymentToken" | "status" | "periodStart" | "periodEnd" | "trialStart" | "trialEnd" | "cancelAtPeriodEnd" | "cancelAt" | "canceledAt" | "endedAt" | "billingInterval" | "groupId" | "seats" | "pendingPlan" | "reconciledAt" | "createdAt" | "updatedAt">;
13
+ type ProductsSchema = PluginSchemaTable<"flutterwaveProduct", "name" | "description" | "price" | "currency" | "quantity" | "unlimited" | "slug" | "metadata" | "createdAt" | "updatedAt">;
14
+ type PlansSchema = PluginSchemaTable<"flutterwavePlan", "name" | "description" | "amount" | "currency" | "interval" | "group" | "paymentPlanId" | "metadata" | "reconciledAt" | "createdAt" | "updatedAt">;
15
+ type WebhookEventsSchema = PluginSchemaTable<"flutterwaveWebhookEvent", "eventId" | "eventType" | "transactionId" | "txRef" | "payload" | "status" | "processedAt" | "createdAt" | "updatedAt">;
16
+ type RefundsSchema = PluginSchemaTable<"flutterwaveRefund", "refundId" | "transactionId" | "txRef" | "referenceId" | "amount" | "currency" | "status" | "reason" | "metadata" | "reconciledAt" | "createdAt" | "updatedAt">;
17
+ type FlutterwavePluginSchema = TransactionsSchema & SubscriptionsSchema & ProductsSchema & PlansSchema & WebhookEventsSchema & RefundsSchema;
18
+ declare const getSchema: (options: FlutterwaveOptions) => BetterAuthPluginDBSchema;
19
+ //#endregion
20
+ //#region src/flutterwave-contracts.d.ts
21
+ declare const standardCheckoutInputSchema: z.ZodObject<{
22
+ tx_ref: z.ZodString;
23
+ amount: z.ZodCoercedNumber<unknown>;
24
+ currency: z.ZodString;
25
+ redirect_url: z.ZodURL;
26
+ customer: z.ZodObject<{
27
+ email: z.ZodEmail;
28
+ name: z.ZodOptional<z.ZodString>;
29
+ phonenumber: z.ZodOptional<z.ZodString>;
30
+ }, z.core.$loose>;
31
+ payment_options: z.ZodOptional<z.ZodString>;
32
+ payment_plan: z.ZodOptional<z.ZodNumber>;
33
+ subaccounts: z.ZodOptional<z.ZodArray<z.ZodObject<{
34
+ id: z.ZodString;
35
+ transaction_charge_type: z.ZodOptional<z.ZodEnum<{
36
+ flat: "flat";
37
+ percentage: "percentage";
38
+ }>>;
39
+ transaction_charge: z.ZodOptional<z.ZodNumber>;
40
+ }, z.core.$loose>>>;
41
+ customizations: z.ZodOptional<z.ZodObject<{
42
+ title: z.ZodOptional<z.ZodString>;
43
+ description: z.ZodOptional<z.ZodString>;
44
+ logo: z.ZodOptional<z.ZodURL>;
45
+ }, z.core.$strip>>;
46
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
47
+ }, z.core.$loose>;
48
+ declare const checkoutDataSchema: z.ZodObject<{
49
+ link: z.ZodURL;
50
+ }, z.core.$loose>;
51
+ declare const transactionSchema: z.ZodObject<{
52
+ id: z.ZodCoercedNumber<unknown>;
53
+ tx_ref: z.ZodString;
54
+ flw_ref: z.ZodOptional<z.ZodNullable<z.ZodString>>;
55
+ amount: z.ZodCoercedNumber<unknown>;
56
+ charged_amount: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
57
+ currency: z.ZodString;
58
+ status: z.ZodString;
59
+ payment_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
60
+ created_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
61
+ customer: z.ZodOptional<z.ZodObject<{
62
+ id: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
63
+ email: z.ZodEmail;
64
+ name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
65
+ }, z.core.$loose>>;
66
+ card: z.ZodOptional<z.ZodNullable<z.ZodObject<{
67
+ token: z.ZodOptional<z.ZodString>;
68
+ }, z.core.$loose>>>;
69
+ }, z.core.$loose>;
70
+ declare const paymentPlanSchema: z.ZodObject<{
71
+ id: z.ZodCoercedNumber<unknown>;
72
+ name: z.ZodString;
73
+ amount: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodCoercedNumber<unknown>>>, z.ZodTransform<number | undefined, number | null | undefined>>;
74
+ interval: z.ZodString;
75
+ currency: z.ZodString;
76
+ status: z.ZodOptional<z.ZodString>;
77
+ duration: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
78
+ created_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
79
+ }, z.core.$loose>;
80
+ declare const subscriptionSchema: z.ZodObject<{
81
+ id: z.ZodCoercedNumber<unknown>;
82
+ amount: z.ZodCoercedNumber<unknown>;
83
+ customer: z.ZodOptional<z.ZodObject<{
84
+ email: z.ZodOptional<z.ZodEmail>;
85
+ customer_email: z.ZodOptional<z.ZodEmail>;
86
+ }, z.core.$loose>>;
87
+ plan: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
88
+ status: z.ZodString;
89
+ currency: z.ZodOptional<z.ZodString>;
90
+ created_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
91
+ }, z.core.$loose>;
92
+ declare const tokenChargeInputSchema: z.ZodObject<{
93
+ token: z.ZodString;
94
+ currency: z.ZodString;
95
+ country: z.ZodOptional<z.ZodString>;
96
+ amount: z.ZodCoercedNumber<unknown>;
97
+ email: z.ZodEmail;
98
+ tx_ref: z.ZodString;
99
+ narration: z.ZodOptional<z.ZodString>;
100
+ }, z.core.$loose>;
101
+ declare const refundSchema: z.ZodObject<{
102
+ id: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
103
+ transaction_id: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
104
+ amount_refunded: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
105
+ amount: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
106
+ status: z.ZodString;
107
+ created_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
108
+ }, z.core.$loose>;
109
+ type StandardCheckoutInput = z.infer<typeof standardCheckoutInputSchema>;
110
+ type FlutterwaveCheckoutData = z.infer<typeof checkoutDataSchema>;
111
+ type FlutterwaveTransactionData = z.infer<typeof transactionSchema>;
112
+ type FlutterwavePaymentPlanData = z.infer<typeof paymentPlanSchema>;
113
+ type FlutterwaveSubscriptionData = z.infer<typeof subscriptionSchema>;
114
+ type FlutterwaveTokenChargeInput = z.infer<typeof tokenChargeInputSchema>;
115
+ type FlutterwaveRefundData = z.infer<typeof refundSchema>;
116
+ //#endregion
117
+ //#region src/flutterwave-sdk.d.ts
118
+ type SdkResult = Promise<unknown>;
119
+ /** The deliberately small, typed portion of flutterwave-node-v3 used by this package. */
120
+ interface FlutterwaveSdkClient {
121
+ Transaction: {
122
+ verify(input: {
123
+ id: number;
124
+ }): SdkResult;
125
+ verify_by_tx(input: {
126
+ tx_ref: string;
127
+ }): SdkResult;
128
+ refund(input: {
129
+ id: number;
130
+ amount?: number;
131
+ }): SdkResult;
132
+ };
133
+ PaymentPlan: {
134
+ get_all(input: Record<string, unknown>): SdkResult;
135
+ };
136
+ Subscription: {
137
+ fetch_all(input: Record<string, unknown>): SdkResult;
138
+ cancel(input: {
139
+ id: number;
140
+ }): SdkResult;
141
+ activate(input: {
142
+ id: number;
143
+ }): SdkResult;
144
+ };
145
+ Tokenized: {
146
+ charge(input: FlutterwaveTokenChargeInput): SdkResult;
147
+ };
148
+ }
149
+ interface FlutterwaveAdapterOptions {
150
+ publicKey: string;
151
+ secretKey: string;
152
+ flutterwaveClient?: FlutterwaveSdkClient;
153
+ fetch?: typeof globalThis.fetch;
154
+ apiBaseUrl?: string;
155
+ }
156
+ interface VerifyTransactionInput {
157
+ transactionId?: number;
158
+ txRef?: string;
159
+ }
160
+ interface ListSubscriptionsInput {
161
+ email?: string;
162
+ transactionId?: number;
163
+ plan?: number;
164
+ status?: string;
165
+ page?: number;
166
+ }
167
+ interface FlutterwaveAdapter {
168
+ initializePayment(input: StandardCheckoutInput): Promise<FlutterwaveCheckoutData>;
169
+ verifyTransaction(input: VerifyTransactionInput): Promise<FlutterwaveTransactionData>;
170
+ listPaymentPlans(): Promise<FlutterwavePaymentPlanData[]>;
171
+ listSubscriptions(input?: ListSubscriptionsInput): Promise<FlutterwaveSubscriptionData[]>;
172
+ cancelSubscription(subscriptionId: number): Promise<FlutterwaveSubscriptionData>;
173
+ activateSubscription(subscriptionId: number): Promise<FlutterwaveSubscriptionData>;
174
+ chargeToken(input: FlutterwaveTokenChargeInput): Promise<FlutterwaveTransactionData>;
175
+ refundTransaction(transactionId: number, amount?: number): Promise<FlutterwaveRefundData>;
176
+ }
177
+ declare class FlutterwaveAdapterError extends Error {
178
+ readonly operation: string;
179
+ readonly status?: number;
180
+ readonly cause?: unknown;
181
+ constructor(operation: string, message: string, options?: {
182
+ status?: number;
183
+ cause?: unknown;
184
+ });
185
+ }
186
+ /**
187
+ * Creates the provider boundary used by the plugin.
188
+ *
189
+ * `flutterwave-node-v3` performs always-on telemetry and writes telemetry state in
190
+ * the operating-system temporary directory. Inject `flutterwaveClient` in tests,
191
+ * serverless environments that prohibit those writes, or when custom transport is
192
+ * required. This adapter intentionally uses only the SDK's Promise API.
193
+ */
194
+ declare function createFlutterwaveAdapter(options: FlutterwaveAdapterOptions): FlutterwaveAdapter;
195
+ //#endregion
196
+ //#region src/types.d.ts
197
+ type FlutterwaveCurrency = string;
198
+ type FlutterwaveCheckoutChannel = "card" | "account" | "banktransfer" | "ussd" | "mobilemoney" | "mpesa" | "fawry" | "enaira" | "opay" | "applepay" | "googlepay";
199
+ interface FlutterwaveCustomer {
200
+ email: string;
201
+ name?: string;
202
+ phoneNumber?: string;
203
+ }
204
+ interface FlutterwaveSubaccountSplit {
205
+ id: string;
206
+ transactionSplitRatio?: number;
207
+ transactionChargeType?: "flat" | "percentage" | "flat_subaccount";
208
+ transactionCharge?: number;
209
+ }
210
+ interface FlutterwaveTransaction {
211
+ id: string;
212
+ txRef: string;
213
+ transactionId?: number | null;
214
+ flwRef?: string | null;
215
+ referenceId: string;
216
+ userId: string;
217
+ amount: number;
218
+ chargedAmount?: number | null;
219
+ currency: string;
220
+ status: string;
221
+ plan?: string | null;
222
+ product?: string | null;
223
+ paymentType?: string | null;
224
+ subaccountId?: string | null;
225
+ metadata?: string | null;
226
+ verifiedAt?: Date | null;
227
+ reconciledAt?: Date | null;
228
+ createdAt: Date;
229
+ updatedAt: Date;
230
+ }
231
+ interface FlutterwaveProduct {
232
+ id?: string;
233
+ name: string;
234
+ description?: string;
235
+ price: number;
236
+ currency: string;
237
+ quantity?: number;
238
+ unlimited?: boolean;
239
+ slug?: string;
240
+ metadata?: string | null;
241
+ createdAt?: Date;
242
+ updatedAt?: Date;
243
+ }
244
+ interface InputFlutterwaveProduct {
245
+ name: string;
246
+ description?: string;
247
+ amount: number;
248
+ currency: string;
249
+ }
250
+ interface FlutterwavePlan {
251
+ id?: string;
252
+ name: string;
253
+ description?: string;
254
+ amount?: number;
255
+ currency?: string;
256
+ interval?: string;
257
+ duration?: number;
258
+ paymentPlanId?: number;
259
+ seatAmount?: number;
260
+ seatPriceId?: number | string;
261
+ seatPlanCode?: string;
262
+ group?: string;
263
+ freeTrial?: {
264
+ days?: number;
265
+ onTrialStart?: (subscription: Subscription) => Promise<void>;
266
+ onTrialEnd?: (subscription: Subscription) => Promise<void>;
267
+ onTrialExpired?: (subscription: Subscription) => Promise<void>;
268
+ };
269
+ limits?: Record<string, unknown>;
270
+ features?: string[];
271
+ metadata?: string | null;
272
+ createdAt?: Date;
273
+ updatedAt?: Date;
274
+ }
275
+ interface FlutterwaveWebhookEvent {
276
+ event: string;
277
+ data: Record<string, unknown> & {
278
+ id?: number | string;
279
+ tx_ref?: string;
280
+ flw_ref?: string;
281
+ status?: string;
282
+ amount?: number;
283
+ charged_amount?: number;
284
+ currency?: string;
285
+ payment_type?: string;
286
+ customer?: {
287
+ email?: string;
288
+ };
289
+ };
290
+ }
291
+ type FlutterwaveWebhookPayload = FlutterwaveWebhookEvent;
292
+ interface FlutterwaveTransactionResponse {
293
+ id: number | string;
294
+ txRef: string;
295
+ flwRef?: string;
296
+ status: string;
297
+ amount: number;
298
+ chargedAmount?: number;
299
+ currency: string;
300
+ paymentType?: string;
301
+ customer?: FlutterwaveCustomer;
302
+ paymentPlanId?: number;
303
+ subscriptionId?: number;
304
+ meta?: Record<string, unknown>;
305
+ }
306
+ interface FlutterwaveInitializeResult {
307
+ kind: "checkout";
308
+ url: string;
309
+ txRef: string;
310
+ redirect: true;
311
+ }
312
+ interface SubscriptionOptions {
313
+ enabled?: boolean;
314
+ plans: FlutterwavePlan[] | (() => Promise<FlutterwavePlan[]>);
315
+ autoSyncQuantity?: boolean;
316
+ cancelBehavior?: "at_period_end" | "immediately";
317
+ requireEmailVerification?: boolean;
318
+ allowedPaymentChannels?: FlutterwaveCheckoutChannel[];
319
+ authorizeReference?: (data: {
320
+ user: User;
321
+ session: Session;
322
+ referenceId: string;
323
+ action: string;
324
+ }, ctx: GenericEndpointContext) => Promise<boolean>;
325
+ onSubscriptionComplete?: (data: {
326
+ event: FlutterwaveWebhookPayload;
327
+ subscription: Subscription;
328
+ plan: FlutterwavePlan;
329
+ }, ctx: GenericEndpointContext) => Promise<void>;
330
+ onSubscriptionCreated?: (data: {
331
+ event: FlutterwaveWebhookPayload;
332
+ subscription: Subscription;
333
+ plan: FlutterwavePlan;
334
+ }, ctx: GenericEndpointContext) => Promise<void>;
335
+ onSubscriptionUpdate?: (data: {
336
+ event: FlutterwaveWebhookPayload;
337
+ subscription: Subscription;
338
+ plan: FlutterwavePlan;
339
+ }, ctx: GenericEndpointContext) => Promise<void>;
340
+ onSubscriptionCancel?: (data: {
341
+ event: FlutterwaveWebhookPayload;
342
+ subscription: Subscription;
343
+ }, ctx: GenericEndpointContext) => Promise<void>;
344
+ }
345
+ interface FlutterwaveOptions<TFlutterwaveClient extends FlutterwaveClientLike = FlutterwaveClientLike> {
346
+ publicKey: string;
347
+ secretKey: string;
348
+ secretHash: string;
349
+ flutterwaveClient?: TFlutterwaveClient;
350
+ fetch?: typeof globalThis.fetch;
351
+ apiBaseUrl?: string;
352
+ billingPattern?: "native" | "local";
353
+ webhook?: {
354
+ secretHash?: string;
355
+ };
356
+ subscription?: SubscriptionOptions;
357
+ organization?: {
358
+ enabled?: boolean;
359
+ billingRoles?: string[];
360
+ };
361
+ products?: {
362
+ products?: FlutterwaveProduct[] | (() => Promise<FlutterwaveProduct[]>);
363
+ };
364
+ marketplace?: {
365
+ allowedSubaccountIds: string[];
366
+ defaultSplit?: FlutterwaveSubaccountSplit[];
367
+ };
368
+ onEvent?: (event: FlutterwaveWebhookEvent) => Promise<void>;
369
+ schema?: InferOptionSchema<FlutterwavePluginSchema>;
370
+ }
371
+ interface Subscription {
372
+ id: string;
373
+ userId: string;
374
+ organizationId?: string;
375
+ plan: string;
376
+ pendingPlan?: string | null;
377
+ subscriptionId?: number | null;
378
+ paymentPlanId?: number | null;
379
+ txRef?: string | null;
380
+ billingEmail?: string | null;
381
+ encryptedPaymentToken?: string | null;
382
+ status: string;
383
+ seats: number;
384
+ referenceId: string;
385
+ periodStart?: Date | null;
386
+ periodEnd?: Date | null;
387
+ cancelAtPeriodEnd: boolean;
388
+ cancelAt?: Date | null;
389
+ canceledAt?: Date | null;
390
+ endedAt?: Date | null;
391
+ billingInterval?: string | null;
392
+ trialStart?: Date | null;
393
+ trialEnd?: Date | null;
394
+ groupId?: string | null;
395
+ createdAt: Date;
396
+ updatedAt: Date;
397
+ }
398
+ type FlutterwaveSubscription = Subscription;
399
+ interface FlutterwaveRefund {
400
+ id: string;
401
+ transactionId: number;
402
+ refundId?: number | null;
403
+ txRef: string;
404
+ referenceId: string;
405
+ amount: number;
406
+ currency: string;
407
+ status: string;
408
+ reason?: string | null;
409
+ metadata?: string | null;
410
+ reconciledAt?: Date | null;
411
+ createdAt: Date;
412
+ updatedAt: Date;
413
+ }
414
+ interface FlutterwaveWebhookEventRecord {
415
+ id: string;
416
+ eventId: string;
417
+ eventType: string;
418
+ transactionId?: number | null;
419
+ txRef?: string | null;
420
+ payload: string;
421
+ status: string;
422
+ processedAt?: Date | null;
423
+ createdAt: Date;
424
+ updatedAt: Date;
425
+ }
426
+ type FlutterwaveClientLike = FlutterwaveSdkClient;
427
+ type AnyFlutterwaveOptions = FlutterwaveOptions<FlutterwaveClientLike>;
428
+ interface FlutterwaveSyncResult {
429
+ status: "success";
430
+ count: number;
431
+ }
432
+ interface ChargeRecurringSubscriptionInput {
433
+ subscriptionId: string;
434
+ amount?: number;
435
+ redirectUrl?: string;
436
+ }
437
+ interface ChargeRecurringSubscriptionResult {
438
+ status: "success" | "pending" | "failed";
439
+ data: FlutterwaveTransactionResponse | FlutterwaveInitializeResult;
440
+ }
441
+ //#endregion
442
+ //#region src/routes.d.ts
443
+ declare const initializeTransaction: <P extends string>(options: AnyFlutterwaveOptions, path: P) => import("better-call").StrictEndpoint<P, {
444
+ method: "POST";
445
+ body: z.ZodObject<{
446
+ amount: z.ZodOptional<z.ZodNumber>;
447
+ currency: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
448
+ redirectUrl: z.ZodString;
449
+ txRef: z.ZodOptional<z.ZodString>;
450
+ referenceId: z.ZodOptional<z.ZodString>;
451
+ plan: z.ZodOptional<z.ZodString>;
452
+ product: z.ZodOptional<z.ZodString>;
453
+ quantity: z.ZodDefault<z.ZodNumber>;
454
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
455
+ paymentOptions: z.ZodOptional<z.ZodString>;
456
+ subaccounts: z.ZodOptional<z.ZodArray<z.ZodObject<{
457
+ id: z.ZodString;
458
+ transactionSplitRatio: z.ZodOptional<z.ZodNumber>;
459
+ transactionChargeType: z.ZodOptional<z.ZodEnum<{
460
+ flat: "flat";
461
+ percentage: "percentage";
462
+ flat_subaccount: "flat_subaccount";
463
+ }>>;
464
+ transactionCharge: z.ZodOptional<z.ZodNumber>;
465
+ }, z.core.$strip>>>;
466
+ }, z.core.$strip>;
467
+ use: (((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
468
+ session: {
469
+ session: Record<string, any> & {
470
+ id: string;
471
+ createdAt: Date;
472
+ updatedAt: Date;
473
+ userId: string;
474
+ expiresAt: Date;
475
+ token: string;
476
+ ipAddress?: string | null | undefined;
477
+ userAgent?: string | null | undefined;
478
+ };
479
+ user: Record<string, any> & {
480
+ id: string;
481
+ createdAt: Date;
482
+ updatedAt: Date;
483
+ email: string;
484
+ emailVerified: boolean;
485
+ name: string;
486
+ image?: string | null | undefined;
487
+ };
488
+ };
489
+ }>) | ((getValue: (ctx: GenericEndpointContext) => string | string[]) => (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>))[];
490
+ }, {
491
+ kind: "checkout";
492
+ url: string;
493
+ txRef: string;
494
+ redirect: true;
495
+ }>;
496
+ declare const verifyTransaction: <P extends string>(options: AnyFlutterwaveOptions, path: P) => import("better-call").StrictEndpoint<P, {
497
+ method: "POST";
498
+ body: z.ZodObject<{
499
+ transactionId: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
500
+ txRef: z.ZodOptional<z.ZodString>;
501
+ referenceId: z.ZodOptional<z.ZodString>;
502
+ }, z.core.$strip>;
503
+ use: (((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
504
+ session: {
505
+ session: Record<string, any> & {
506
+ id: string;
507
+ createdAt: Date;
508
+ updatedAt: Date;
509
+ userId: string;
510
+ expiresAt: Date;
511
+ token: string;
512
+ ipAddress?: string | null | undefined;
513
+ userAgent?: string | null | undefined;
514
+ };
515
+ user: Record<string, any> & {
516
+ id: string;
517
+ createdAt: Date;
518
+ updatedAt: Date;
519
+ email: string;
520
+ emailVerified: boolean;
521
+ name: string;
522
+ image?: string | null | undefined;
523
+ };
524
+ };
525
+ }>) | ((getValue: (ctx: GenericEndpointContext) => string | string[]) => (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>))[];
526
+ }, {
527
+ status: string;
528
+ txRef: string;
529
+ data: FlutterwaveTransactionResponse;
530
+ }>;
531
+ declare const listTransactions: <P extends string>(options: AnyFlutterwaveOptions, path: P) => import("better-call").StrictEndpoint<P, {
532
+ method: "GET";
533
+ query: z.ZodObject<{
534
+ referenceId: z.ZodOptional<z.ZodString>;
535
+ }, z.core.$strip>;
536
+ use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
537
+ session: {
538
+ session: Record<string, any> & {
539
+ id: string;
540
+ createdAt: Date;
541
+ updatedAt: Date;
542
+ userId: string;
543
+ expiresAt: Date;
544
+ token: string;
545
+ ipAddress?: string | null | undefined;
546
+ userAgent?: string | null | undefined;
547
+ };
548
+ user: Record<string, any> & {
549
+ id: string;
550
+ createdAt: Date;
551
+ updatedAt: Date;
552
+ email: string;
553
+ emailVerified: boolean;
554
+ name: string;
555
+ image?: string | null | undefined;
556
+ };
557
+ };
558
+ }>)[];
559
+ }, {
560
+ transactions: FlutterwaveTransaction[];
561
+ }>;
562
+ declare const listSubscriptions: <P extends string>(options: AnyFlutterwaveOptions, path: P) => import("better-call").StrictEndpoint<P, {
563
+ method: "GET";
564
+ query: z.ZodObject<{
565
+ referenceId: z.ZodOptional<z.ZodString>;
566
+ }, z.core.$strip>;
567
+ use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
568
+ session: {
569
+ session: Record<string, any> & {
570
+ id: string;
571
+ createdAt: Date;
572
+ updatedAt: Date;
573
+ userId: string;
574
+ expiresAt: Date;
575
+ token: string;
576
+ ipAddress?: string | null | undefined;
577
+ userAgent?: string | null | undefined;
578
+ };
579
+ user: Record<string, any> & {
580
+ id: string;
581
+ createdAt: Date;
582
+ updatedAt: Date;
583
+ email: string;
584
+ emailVerified: boolean;
585
+ name: string;
586
+ image?: string | null | undefined;
587
+ };
588
+ };
589
+ }>)[];
590
+ }, {
591
+ subscriptions: Subscription[];
592
+ }>;
593
+ declare const cancelSubscription: <P extends string>(options: AnyFlutterwaveOptions, path: P) => import("better-call").StrictEndpoint<P, {
594
+ method: "POST";
595
+ body: z.ZodObject<{
596
+ subscriptionId: z.ZodCoercedNumber<unknown>;
597
+ atPeriodEnd: z.ZodOptional<z.ZodBoolean>;
598
+ }, z.core.$strip>;
599
+ use: (((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
600
+ session: {
601
+ session: Record<string, any> & {
602
+ id: string;
603
+ createdAt: Date;
604
+ updatedAt: Date;
605
+ userId: string;
606
+ expiresAt: Date;
607
+ token: string;
608
+ ipAddress?: string | null | undefined;
609
+ userAgent?: string | null | undefined;
610
+ };
611
+ user: Record<string, any> & {
612
+ id: string;
613
+ createdAt: Date;
614
+ updatedAt: Date;
615
+ email: string;
616
+ emailVerified: boolean;
617
+ name: string;
618
+ image?: string | null | undefined;
619
+ };
620
+ };
621
+ }>) | ((getValue: (ctx: GenericEndpointContext) => string | string[]) => (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>))[];
622
+ }, {
623
+ status: string;
624
+ }>;
625
+ declare const restoreSubscription: <P extends string>(options: AnyFlutterwaveOptions, path: P) => import("better-call").StrictEndpoint<P, {
626
+ method: "POST";
627
+ body: z.ZodObject<{
628
+ subscriptionId: z.ZodCoercedNumber<unknown>;
629
+ }, z.core.$strip>;
630
+ use: (((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
631
+ session: {
632
+ session: Record<string, any> & {
633
+ id: string;
634
+ createdAt: Date;
635
+ updatedAt: Date;
636
+ userId: string;
637
+ expiresAt: Date;
638
+ token: string;
639
+ ipAddress?: string | null | undefined;
640
+ userAgent?: string | null | undefined;
641
+ };
642
+ user: Record<string, any> & {
643
+ id: string;
644
+ createdAt: Date;
645
+ updatedAt: Date;
646
+ email: string;
647
+ emailVerified: boolean;
648
+ name: string;
649
+ image?: string | null | undefined;
650
+ };
651
+ };
652
+ }>) | ((getValue: (ctx: GenericEndpointContext) => string | string[]) => (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>))[];
653
+ }, {
654
+ status: string;
655
+ }>;
656
+ declare const createSubscription: <P extends string>(options: AnyFlutterwaveOptions, path: P) => import("better-call").StrictEndpoint<P, {
657
+ method: "POST";
658
+ body: z.ZodObject<{
659
+ amount: z.ZodOptional<z.ZodNumber>;
660
+ currency: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
661
+ redirectUrl: z.ZodString;
662
+ txRef: z.ZodOptional<z.ZodString>;
663
+ referenceId: z.ZodOptional<z.ZodString>;
664
+ plan: z.ZodOptional<z.ZodString>;
665
+ product: z.ZodOptional<z.ZodString>;
666
+ quantity: z.ZodDefault<z.ZodNumber>;
667
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
668
+ paymentOptions: z.ZodOptional<z.ZodString>;
669
+ subaccounts: z.ZodOptional<z.ZodArray<z.ZodObject<{
670
+ id: z.ZodString;
671
+ transactionSplitRatio: z.ZodOptional<z.ZodNumber>;
672
+ transactionChargeType: z.ZodOptional<z.ZodEnum<{
673
+ flat: "flat";
674
+ percentage: "percentage";
675
+ flat_subaccount: "flat_subaccount";
676
+ }>>;
677
+ transactionCharge: z.ZodOptional<z.ZodNumber>;
678
+ }, z.core.$strip>>>;
679
+ }, z.core.$strip>;
680
+ use: (((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
681
+ session: {
682
+ session: Record<string, any> & {
683
+ id: string;
684
+ createdAt: Date;
685
+ updatedAt: Date;
686
+ userId: string;
687
+ expiresAt: Date;
688
+ token: string;
689
+ ipAddress?: string | null | undefined;
690
+ userAgent?: string | null | undefined;
691
+ };
692
+ user: Record<string, any> & {
693
+ id: string;
694
+ createdAt: Date;
695
+ updatedAt: Date;
696
+ email: string;
697
+ emailVerified: boolean;
698
+ name: string;
699
+ image?: string | null | undefined;
700
+ };
701
+ };
702
+ }>) | ((getValue: (ctx: GenericEndpointContext) => string | string[]) => (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>))[];
703
+ }, {
704
+ kind: "checkout";
705
+ url: string;
706
+ txRef: string;
707
+ redirect: true;
708
+ }>;
709
+ declare const upgradeSubscription: <P extends string>(options: AnyFlutterwaveOptions, path: P) => import("better-call").StrictEndpoint<P, {
710
+ method: "POST";
711
+ body: z.ZodObject<{
712
+ amount: z.ZodOptional<z.ZodNumber>;
713
+ currency: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
714
+ redirectUrl: z.ZodString;
715
+ txRef: z.ZodOptional<z.ZodString>;
716
+ referenceId: z.ZodOptional<z.ZodString>;
717
+ plan: z.ZodOptional<z.ZodString>;
718
+ product: z.ZodOptional<z.ZodString>;
719
+ quantity: z.ZodDefault<z.ZodNumber>;
720
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
721
+ paymentOptions: z.ZodOptional<z.ZodString>;
722
+ subaccounts: z.ZodOptional<z.ZodArray<z.ZodObject<{
723
+ id: z.ZodString;
724
+ transactionSplitRatio: z.ZodOptional<z.ZodNumber>;
725
+ transactionChargeType: z.ZodOptional<z.ZodEnum<{
726
+ flat: "flat";
727
+ percentage: "percentage";
728
+ flat_subaccount: "flat_subaccount";
729
+ }>>;
730
+ transactionCharge: z.ZodOptional<z.ZodNumber>;
731
+ }, z.core.$strip>>>;
732
+ }, z.core.$strip>;
733
+ use: (((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
734
+ session: {
735
+ session: Record<string, any> & {
736
+ id: string;
737
+ createdAt: Date;
738
+ updatedAt: Date;
739
+ userId: string;
740
+ expiresAt: Date;
741
+ token: string;
742
+ ipAddress?: string | null | undefined;
743
+ userAgent?: string | null | undefined;
744
+ };
745
+ user: Record<string, any> & {
746
+ id: string;
747
+ createdAt: Date;
748
+ updatedAt: Date;
749
+ email: string;
750
+ emailVerified: boolean;
751
+ name: string;
752
+ image?: string | null | undefined;
753
+ };
754
+ };
755
+ }>) | ((getValue: (ctx: GenericEndpointContext) => string | string[]) => (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>))[];
756
+ }, {
757
+ kind: "checkout";
758
+ url: string;
759
+ txRef: string;
760
+ redirect: true;
761
+ }>;
762
+ declare const listProducts: <P extends string>(options: AnyFlutterwaveOptions, path: P) => import("better-call").StrictEndpoint<P, {
763
+ method: "GET";
764
+ }, {
765
+ products: FlutterwaveProduct[];
766
+ }>;
767
+ declare const listPlans: <P extends string>(options: AnyFlutterwaveOptions, path: P) => import("better-call").StrictEndpoint<P, {
768
+ method: "GET";
769
+ }, {
770
+ plans: FlutterwavePlan[];
771
+ }>;
772
+ declare const getConfig: <P extends string>(options: AnyFlutterwaveOptions, path: P) => import("better-call").StrictEndpoint<P, {
773
+ method: "GET";
774
+ }, {
775
+ plans: FlutterwavePlan[];
776
+ products: FlutterwaveProduct[];
777
+ subscriptions: boolean;
778
+ marketplace: boolean;
779
+ }>;
780
+ declare const flutterwaveWebhook: <P extends string>(options: AnyFlutterwaveOptions, path: P) => import("better-call").StrictEndpoint<P, {
781
+ method: "POST";
782
+ metadata: {
783
+ openapi: {
784
+ operationId: string;
785
+ };
786
+ scope: "server";
787
+ };
788
+ cloneRequest: true;
789
+ disableBody: true;
790
+ }, {
791
+ received: boolean;
792
+ }>;
793
+ //#endregion
794
+ //#region src/version.d.ts
795
+ declare const PACKAGE_VERSION = "0.1.5";
796
+ //#endregion
797
+ //#region src/metadata.d.ts
798
+ type FlutterwaveMetadata = Record<string, unknown>;
799
+ interface CheckoutMetadataInput {
800
+ referenceId: string;
801
+ userId: string;
802
+ plan?: string;
803
+ groupId?: string | null;
804
+ product?: string;
805
+ extra?: FlutterwaveMetadata;
806
+ trial: {
807
+ isTrial: boolean;
808
+ requested: boolean;
809
+ granted: boolean;
810
+ deniedReason?: "already_used";
811
+ endsAt?: Date;
812
+ };
813
+ }
814
+ interface ProrationMetadataInput {
815
+ subscriptionId: string;
816
+ referenceId: string;
817
+ newPlan: string;
818
+ oldPlan: string;
819
+ newSeatCount: number;
820
+ remainingDays: number;
821
+ }
822
+ interface RenewalMetadataInput {
823
+ subscriptionId: string;
824
+ referenceId: string;
825
+ }
826
+ declare function parseFlutterwaveMetadata(value: unknown): FlutterwaveMetadata;
827
+ declare function stringifyFlutterwaveMetadata(value: unknown): string | undefined;
828
+ declare function hasFlutterwaveMetadata(value: unknown): boolean;
829
+ declare function getMetadataString(metadata: FlutterwaveMetadata, key: string): string | undefined;
830
+ declare function getMetadataNumber(metadata: FlutterwaveMetadata, key: string): number | undefined;
831
+ declare function getMetadataBoolean(metadata: FlutterwaveMetadata, key: string): boolean;
832
+ declare function createCheckoutMetadata(input: CheckoutMetadataInput): FlutterwaveMetadata;
833
+ declare function createProrationMetadata(input: ProrationMetadataInput): FlutterwaveMetadata;
834
+ declare function createRenewalMetadata(input: RenewalMetadataInput): FlutterwaveMetadata;
835
+ //#endregion
836
+ //#region src/token-crypto.d.ts
837
+ declare function encryptPaymentToken(token: string, secret: string): Promise<string>;
838
+ declare function decryptPaymentToken(value: string, secret: string): Promise<string>;
839
+ //#endregion
840
+ //#region src/limits.d.ts
841
+ declare const checkSeatLimit: (ctx: GenericEndpointContext, organizationId: string, seatsToAdd?: number) => Promise<boolean>;
842
+ declare function getOrganizationEntitlements(ctx: GenericEndpointContext, organizationId: string, options: AnyFlutterwaveOptions): Promise<{
843
+ limits: Record<string, number>;
844
+ features: string[];
845
+ }>;
846
+ declare const checkTeamLimit: (ctx: GenericEndpointContext, organizationId: string, maxTeams: number) => Promise<boolean>;
847
+ //#endregion
848
+ //#region src/operations.d.ts
849
+ declare function syncFlutterwavePlans(ctx: GenericEndpointContext, options: AnyFlutterwaveOptions): Promise<FlutterwaveSyncResult>;
850
+ declare function chargeSubscriptionRenewal(ctx: GenericEndpointContext, options: AnyFlutterwaveOptions, input: ChargeRecurringSubscriptionInput): Promise<ChargeRecurringSubscriptionResult>;
851
+ declare function refundFlutterwaveTransaction(ctx: GenericEndpointContext, options: AnyFlutterwaveOptions, input: {
852
+ transactionId: number;
853
+ amount?: number;
854
+ reason?: string;
855
+ }): Promise<FlutterwaveRefund>;
856
+ //#endregion
857
+ //#region src/reconciliation.d.ts
858
+ type FlutterwaveReconciliationSource = "webhook" | "queue" | "admin" | "server" | "browser";
859
+ interface ReconcileFlutterwaveTransactionInput {
860
+ txRef?: string;
861
+ transactionId?: number;
862
+ source?: FlutterwaveReconciliationSource;
863
+ throwOnError?: boolean;
864
+ }
865
+ declare function reconcileFlutterwaveTransaction(ctx: GenericEndpointContext, options: AnyFlutterwaveOptions, input: ReconcileFlutterwaveTransactionInput): Promise<{
866
+ ok: false;
867
+ source: FlutterwaveReconciliationSource;
868
+ txRef: string;
869
+ error: {
870
+ code: string;
871
+ message: string;
872
+ };
873
+ status?: undefined;
874
+ data?: undefined;
875
+ } | {
876
+ ok: true;
877
+ source: FlutterwaveReconciliationSource;
878
+ txRef: string;
879
+ status: string;
880
+ data: FlutterwaveTransactionResponse;
881
+ error?: undefined;
882
+ }>;
883
+ declare function reconcileFlutterwaveRefunds(ctx: GenericEndpointContext, options: AnyFlutterwaveOptions): Promise<{
884
+ status: "success";
885
+ count: number;
886
+ }>;
887
+ //#endregion
888
+ //#region src/index.d.ts
889
+ declare module "better-auth" {
890
+ interface BetterAuthPluginRegistry<AuthOptions, Options> {
891
+ flutterwave: {
892
+ creator: typeof flutterwave;
893
+ };
894
+ }
895
+ }
896
+ declare const INTERNAL_ERROR_CODES: {
897
+ [x: string]: import("better-auth").RawError<string>;
898
+ };
899
+ type FlutterwavePluginEndpoints = {
900
+ initializeFlutterwaveTransaction: ReturnType<typeof initializeTransaction>;
901
+ verifyFlutterwaveTransaction: ReturnType<typeof verifyTransaction>;
902
+ listFlutterwaveTransactions: ReturnType<typeof listTransactions>;
903
+ listFlutterwaveSubscriptions: ReturnType<typeof listSubscriptions>;
904
+ createFlutterwaveSubscription: ReturnType<typeof createSubscription>;
905
+ upgradeFlutterwaveSubscription: ReturnType<typeof upgradeSubscription>;
906
+ cancelFlutterwaveSubscription: ReturnType<typeof cancelSubscription>;
907
+ restoreFlutterwaveSubscription: ReturnType<typeof restoreSubscription>;
908
+ listFlutterwaveProducts: ReturnType<typeof listProducts>;
909
+ listFlutterwavePlans: ReturnType<typeof listPlans>;
910
+ getFlutterwaveConfig: ReturnType<typeof getConfig>;
911
+ flutterwaveWebhook: ReturnType<typeof flutterwaveWebhook>;
912
+ };
913
+ type FlutterwavePluginInstance<O extends AnyFlutterwaveOptions> = Omit<BetterAuthPlugin, "id" | "version" | "endpoints" | "schema" | "options" | "$ERROR_CODES" | "init"> & {
914
+ id: "flutterwave";
915
+ version: typeof PACKAGE_VERSION;
916
+ endpoints: FlutterwavePluginEndpoints;
917
+ schema: ReturnType<typeof getSchema>;
918
+ options: NoInfer<O>;
919
+ $ERROR_CODES: typeof INTERNAL_ERROR_CODES;
920
+ init: (ctx: AuthContext) => {
921
+ options: Record<string, never>;
922
+ };
923
+ };
924
+ declare const flutterwave: <TFlutterwaveClient extends FlutterwaveClientLike = FlutterwaveClientLike, O extends FlutterwaveOptions<TFlutterwaveClient> = FlutterwaveOptions<TFlutterwaveClient>>(options: O) => FlutterwavePluginInstance<O>;
925
+ //#endregion
926
+ export { createFlutterwaveAdapter as $, FlutterwaveOptions as A, FlutterwaveWebhookEventRecord as B, ChargeRecurringSubscriptionInput as C, FlutterwaveCurrency as D, FlutterwaveClientLike as E, FlutterwaveSubscription as F, Session as G, InputFlutterwaveProduct as H, FlutterwaveSyncResult as I, User as J, Subscription as K, FlutterwaveTransaction as L, FlutterwaveProduct as M, FlutterwaveRefund as N, FlutterwaveCustomer as O, FlutterwaveSubaccountSplit as P, FlutterwaveSdkClient as Q, FlutterwaveTransactionResponse as R, AnyFlutterwaveOptions as S, FlutterwaveCheckoutChannel as T, Member as U, FlutterwaveWebhookPayload as V, Organization as W, FlutterwaveAdapterError as X, FlutterwaveAdapter as Y, FlutterwaveAdapterOptions as Z, getMetadataNumber as _, refundFlutterwaveTransaction as a, parseFlutterwaveMetadata as b, checkTeamLimit as c, encryptPaymentToken as d, FlutterwaveMetadata as f, getMetadataBoolean as g, createRenewalMetadata as h, chargeSubscriptionRenewal as i, FlutterwavePlan as j, FlutterwaveInitializeResult as k, getOrganizationEntitlements as l, createProrationMetadata as m, reconcileFlutterwaveRefunds as n, syncFlutterwavePlans as o, createCheckoutMetadata as p, SubscriptionOptions as q, reconcileFlutterwaveTransaction as r, checkSeatLimit as s, flutterwave as t, decryptPaymentToken as u, getMetadataString as v, ChargeRecurringSubscriptionResult as w, stringifyFlutterwaveMetadata as x, hasFlutterwaveMetadata as y, FlutterwaveWebhookEvent as z };
927
+ //# sourceMappingURL=index-Dcwl_2fw.d.mts.map