better-auth-paystack 0.0.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +919 -0
  3. package/dist/client.d.mts +151 -0
  4. package/dist/client.d.mts.map +1 -0
  5. package/dist/client.mjs +129 -0
  6. package/dist/client.mjs.map +1 -0
  7. package/dist/index-CXuHlFoy.d.mts +858 -0
  8. package/dist/index-CXuHlFoy.d.mts.map +1 -0
  9. package/dist/index.d.mts +2 -0
  10. package/dist/index.mjs +3288 -0
  11. package/dist/index.mjs.map +1 -0
  12. package/dist/version-BYbIySEf.mjs +73 -0
  13. package/dist/version-BYbIySEf.mjs.map +1 -0
  14. package/package.json +118 -8
  15. package/skills/better-auth-paystack-setup/SKILL.md +144 -0
  16. package/skills/better-auth-paystack-setup/agents/openai.yaml +6 -0
  17. package/skills/paystack-billing-flows/SKILL.md +154 -0
  18. package/skills/paystack-billing-flows/agents/openai.yaml +6 -0
  19. package/skills/paystack-catalog-limits/SKILL.md +183 -0
  20. package/skills/paystack-catalog-limits/agents/openai.yaml +6 -0
  21. package/skills/paystack-client-api/SKILL.md +120 -0
  22. package/skills/paystack-client-api/agents/openai.yaml +6 -0
  23. package/skills/paystack-local-subscriptions/SKILL.md +97 -0
  24. package/skills/paystack-local-subscriptions/agents/openai.yaml +6 -0
  25. package/skills/paystack-organization-billing/SKILL.md +159 -0
  26. package/skills/paystack-organization-billing/agents/openai.yaml +6 -0
  27. package/skills/paystack-schema-migrations/SKILL.md +94 -0
  28. package/skills/paystack-schema-migrations/agents/openai.yaml +6 -0
  29. package/skills/paystack-tanstack-start/SKILL.md +170 -0
  30. package/skills/paystack-tanstack-start/agents/openai.yaml +6 -0
  31. package/skills/paystack-testing-fixtures/SKILL.md +97 -0
  32. package/skills/paystack-testing-fixtures/agents/openai.yaml +6 -0
  33. package/skills/paystack-webhooks-events/SKILL.md +106 -0
  34. package/skills/paystack-webhooks-events/agents/openai.yaml +6 -0
  35. package/index.js +0 -1
@@ -0,0 +1,858 @@
1
+ import { AuthContext, BetterAuthPlugin, GenericEndpointContext, InferOptionSchema, MiddlewareInputContext, MiddlewareOptions, Session, StrictEndpoint, User, defineErrorCodes } from "better-auth";
2
+ import { z } from "zod";
3
+ import { PaystackCustomerClient, PaystackPlanClient, PaystackProductClient, PaystackSubscriptionClient, PaystackTransactionClient, PaystackWebhookEvent, TransactionChargeAuthorizationResponseData, TransactionVerifyResponseData } from "@alexasomba/paystack-node";
4
+ import { BetterAuthPluginDBSchema, DBFieldAttribute } from "better-auth/db";
5
+ import "better-auth/plugins/organization";
6
+ //#region src/schema.d.ts
7
+ type PluginSchemaTable<TableName extends string, FieldName extends string> = Record<TableName, {
8
+ fields: Record<FieldName, DBFieldAttribute>;
9
+ disableMigration?: boolean;
10
+ modelName?: string;
11
+ }>;
12
+ type TransactionsSchema = PluginSchemaTable<"paystackTransaction", "reference" | "paystackId" | "referenceId" | "userId" | "amount" | "currency" | "status" | "plan" | "product" | "metadata" | "createdAt" | "updatedAt">;
13
+ type WebhookEventsSchema = PluginSchemaTable<"paystackWebhookEvent", "eventId" | "eventType" | "reference" | "payload" | "status" | "processedAt" | "createdAt" | "updatedAt">;
14
+ type SubscriptionsSchema = PluginSchemaTable<"paystackSubscription", "plan" | "referenceId" | "userId" | "customerCode" | "subscriptionCode" | "transactionReference" | "planCode" | "status" | "periodStart" | "periodEnd" | "trialStart" | "trialEnd" | "cancelAtPeriodEnd" | "cancelAt" | "canceledAt" | "endedAt" | "billingInterval" | "groupId" | "seats" | "pendingPlan" | "createdAt" | "updatedAt">;
15
+ type CustomerSchema = PluginSchemaTable<"paystackCustomer", "referenceType" | "referenceId" | "referenceKey" | "customerCode" | "email" | "createdAt" | "updatedAt">;
16
+ type PaymentCredentialsSchema = PluginSchemaTable<"paystackPaymentCredential", "subscriptionId" | "authorizationCodeEncrypted" | "emailTokenEncrypted" | "createdAt" | "updatedAt">;
17
+ type UserSchema = PluginSchemaTable<"user", never>;
18
+ type OrganizationSchema = PluginSchemaTable<"organization", "email">;
19
+ type ProductsSchema = PluginSchemaTable<"paystackProduct", "name" | "description" | "price" | "currency" | "quantity" | "unlimited" | "paystackId" | "slug" | "metadata" | "createdAt" | "updatedAt">;
20
+ type PlansSchema = PluginSchemaTable<"paystackPlan", "name" | "description" | "amount" | "currency" | "interval" | "group" | "planCode" | "paystackId" | "metadata" | "createdAt" | "updatedAt">;
21
+ type PaystackPluginSchema = SubscriptionsSchema & TransactionsSchema & CustomerSchema & PaymentCredentialsSchema & UserSchema & OrganizationSchema & ProductsSchema & PlansSchema & WebhookEventsSchema;
22
+ declare const getSchema: (options: PaystackOptions) => BetterAuthPluginDBSchema;
23
+ //#endregion
24
+ //#region src/types.d.ts
25
+ type PaystackCheckoutChannel = "card" | "bank" | "ussd" | "qr" | "mobile_money" | "bank_transfer" | "eft" | "apple_pay";
26
+ /**
27
+ * Custom models for Paystack Plugin
28
+ * These align with the database schema in src/schema.ts
29
+ */
30
+ interface PaystackTransaction {
31
+ id: string;
32
+ reference: string;
33
+ paystackId?: string;
34
+ referenceId: string;
35
+ userId: string;
36
+ amount: number;
37
+ currency: string;
38
+ status: string;
39
+ plan?: string | null;
40
+ product?: string | null;
41
+ metadata?: string | null;
42
+ createdAt: Date;
43
+ updatedAt: Date;
44
+ }
45
+ interface PaystackWebhookEventRecord {
46
+ id: string;
47
+ eventId: string;
48
+ eventType: string;
49
+ reference?: string | null;
50
+ payload: string;
51
+ status: string;
52
+ processedAt?: Date | null;
53
+ createdAt: Date;
54
+ updatedAt: Date;
55
+ }
56
+ interface PaystackCustomer {
57
+ id: string;
58
+ referenceType: "user" | "organization";
59
+ referenceId: string;
60
+ /** Internal unique key used to enforce referenceType/referenceId uniqueness. */
61
+ referenceKey: string;
62
+ customerCode: string;
63
+ email?: string | null;
64
+ createdAt: Date;
65
+ updatedAt: Date;
66
+ }
67
+ /** Public credential metadata. Plaintext and encrypted values are intentionally omitted. */
68
+ interface PaystackPaymentCredential {
69
+ id: string;
70
+ subscriptionId: string;
71
+ createdAt: Date;
72
+ updatedAt: Date;
73
+ }
74
+ interface PaystackProduct {
75
+ id?: string;
76
+ name: string;
77
+ description?: string;
78
+ price: number;
79
+ currency: string;
80
+ quantity?: number;
81
+ unlimited?: boolean;
82
+ paystackId?: string;
83
+ slug?: string;
84
+ metadata?: string | null;
85
+ createdAt?: Date;
86
+ updatedAt?: Date;
87
+ }
88
+ interface PaystackPlan {
89
+ id?: string;
90
+ name: string;
91
+ description?: string;
92
+ amount?: number;
93
+ currency?: string;
94
+ interval?: string;
95
+ planCode?: string;
96
+ paystackId?: string;
97
+ seatAmount?: number;
98
+ /**
99
+ * Deprecated legacy alias for `seatAmount`.
100
+ * If used, it must still be a numeric amount in the smallest currency unit.
101
+ */
102
+ seatPriceId?: number | string;
103
+ seatPlanCode?: string;
104
+ invoiceLimit?: number;
105
+ /**
106
+ * Optional subscription group. A reference may hold one active or trialing
107
+ * subscription per normalized group. Omitted values use the legacy default group.
108
+ */
109
+ group?: string;
110
+ freeTrial?: {
111
+ days?: number;
112
+ onTrialStart?: (subscription: Subscription) => Promise<void>;
113
+ onTrialEnd?: (subscription: Subscription) => Promise<void>;
114
+ onTrialExpired?: (subscription: Subscription) => Promise<void>;
115
+ };
116
+ limits?: Record<string, unknown>;
117
+ features?: string[];
118
+ metadata?: string | null;
119
+ createdAt?: Date;
120
+ updatedAt?: Date;
121
+ }
122
+ /**
123
+ * Paystack Webhook Payload structure
124
+ */
125
+ type PaystackWebhookPayload = PaystackWebhookEvent;
126
+ /**
127
+ * Paystack SDK Result types
128
+ */
129
+ type PaystackTransactionResponse = TransactionVerifyResponseData;
130
+ type PaystackChargeAuthorizationResponse = TransactionChargeAuthorizationResponseData;
131
+ type PaystackInitializeResult = {
132
+ kind: "checkout";
133
+ url: string;
134
+ reference: string;
135
+ accessCode: string;
136
+ redirect: true;
137
+ } | {
138
+ kind: "scheduled";
139
+ status: "success";
140
+ message: string;
141
+ scheduled: true;
142
+ } | {
143
+ kind: "prorated";
144
+ status: "success";
145
+ message: string;
146
+ prorated: true;
147
+ };
148
+ interface SubscriptionOptions {
149
+ /**
150
+ * Enable subscriptions
151
+ */
152
+ enabled?: boolean;
153
+ /**
154
+ * Plans configuration
155
+ */
156
+ plans: PaystackPlan[] | (() => Promise<PaystackPlan[]>);
157
+ /**
158
+ * Automatically sync quantity from local DB to Paystack (if seats are used)
159
+ */
160
+ autoSyncQuantity?: boolean;
161
+ /**
162
+ * Handling of subscription cancellation
163
+ * @default "at_period_end"
164
+ */
165
+ cancelBehavior?: "at_period_end" | "immediately";
166
+ /**
167
+ * Handlers for subscription events
168
+ */
169
+ onSubscriptionComplete?: (data: {
170
+ event: PaystackWebhookPayload;
171
+ subscription: Subscription;
172
+ plan: PaystackPlan;
173
+ }, ctx: GenericEndpointContext) => Promise<void>;
174
+ onSubscriptionCreated?: (data: {
175
+ event: PaystackWebhookPayload;
176
+ subscription: Subscription;
177
+ plan: PaystackPlan;
178
+ }, ctx: GenericEndpointContext) => Promise<void>;
179
+ onSubscriptionUpdate?: (data: {
180
+ event: PaystackWebhookPayload;
181
+ subscription: Subscription;
182
+ plan: PaystackPlan;
183
+ }, ctx: GenericEndpointContext) => Promise<void>;
184
+ onSubscriptionCancel?: (data: {
185
+ event: PaystackWebhookPayload;
186
+ subscription: Subscription;
187
+ }, ctx: GenericEndpointContext) => Promise<void>;
188
+ /**
189
+ * Authorization handler for reference checks
190
+ */
191
+ authorizeReference?: (data: {
192
+ user: User;
193
+ session: Session;
194
+ referenceId: string;
195
+ action: string;
196
+ }, ctx: GenericEndpointContext) => Promise<boolean>;
197
+ /**
198
+ * Require email verification before subscription
199
+ */
200
+ requireEmailVerification?: boolean;
201
+ /**
202
+ * Restrict checkout to specific Paystack channels for subscription flows.
203
+ * Use `["card"]` to enforce card-only subscriptions.
204
+ */
205
+ allowedPaymentChannels?: PaystackCheckoutChannel[];
206
+ }
207
+ interface PaystackOptions<TPaystackClient extends PaystackClientLike = PaystackClientLike> {
208
+ /**
209
+ * Paystack Secret Key
210
+ */
211
+ secretKey: string;
212
+ /**
213
+ * Key used to encrypt Paystack payment credentials with AES-256-GCM.
214
+ * Recommended for production. `secretKey` is used as a compatibility fallback.
215
+ */
216
+ credentialEncryptionKey?: string;
217
+ /**
218
+ * @deprecated Paystack signs webhooks with `secretKey`; this option is ignored.
219
+ */
220
+ paystackWebhookSecret?: string;
221
+ /**
222
+ * Paystack Client Instance
223
+ * If provided, will be used instead of creating a new one with secretKey
224
+ */
225
+ paystackClient?: TPaystackClient;
226
+ /**
227
+ * Webhook configuration
228
+ */
229
+ webhook?: {
230
+ /**
231
+ * @deprecated Paystack signs webhooks with `secretKey`; this option is ignored.
232
+ */
233
+ secret?: string;
234
+ /**
235
+ * Whether to verify the request origin IP address
236
+ * @default false
237
+ */
238
+ verifyIP?: boolean;
239
+ /**
240
+ * List of trusted IP addresses for webhooks.
241
+ * Defaults to official Paystack IPs if verifyIP is true and this is empty.
242
+ */
243
+ trustedIPs?: string[];
244
+ };
245
+ /**
246
+ * Subscription configuration
247
+ */
248
+ subscription?: SubscriptionOptions;
249
+ /**
250
+ * Billing pattern
251
+ * @default "native"
252
+ */
253
+ billingPattern?: "native" | "local";
254
+ /**
255
+ * Global event handler
256
+ */
257
+ onEvent?: (event: PaystackWebhookEvent) => Promise<void>;
258
+ /**
259
+ * Organization billing configuration
260
+ */
261
+ organization?: {
262
+ enabled?: boolean;
263
+ /**
264
+ * Organization member roles allowed to manage billing when `subscription.authorizeReference`
265
+ * is not provided.
266
+ *
267
+ * @default ["owner", "admin"]
268
+ */
269
+ billingRoles?: string[];
270
+ getCustomerCreateParams?: (org: {
271
+ id: string;
272
+ name: string;
273
+ email?: string | null;
274
+ }, ctx: GenericEndpointContext) => Promise<Record<string, unknown>>;
275
+ onCustomerCreate?: (data: {
276
+ paystackCustomer: Record<string, unknown>;
277
+ organization: unknown;
278
+ }, ctx: GenericEndpointContext) => Promise<void>;
279
+ };
280
+ /**
281
+ * Products configuration
282
+ */
283
+ products?: {
284
+ products?: PaystackProduct[] | (() => Promise<PaystackProduct[]>);
285
+ };
286
+ createCustomerOnSignUp?: boolean;
287
+ onCustomerCreate?: (data: {
288
+ paystackCustomer: Record<string, unknown>;
289
+ user: unknown;
290
+ }, ctx: GenericEndpointContext) => Promise<void>;
291
+ /**
292
+ * Custom database schema / model names
293
+ */
294
+ schema?: InferOptionSchema<PaystackPluginSchema>;
295
+ }
296
+ interface PaystackSubscription {
297
+ id: string;
298
+ userId: string;
299
+ organizationId?: string;
300
+ plan: string;
301
+ referenceId: string;
302
+ customerCode?: string | null;
303
+ subscriptionCode?: string | null;
304
+ transactionReference?: string | null;
305
+ planCode?: string | null;
306
+ pendingPlan?: string | null;
307
+ status: string;
308
+ seats?: number | null;
309
+ periodStart?: Date | null;
310
+ periodEnd?: Date | null;
311
+ cancelAtPeriodEnd: boolean;
312
+ cancelAt?: Date | null;
313
+ canceledAt?: Date | null;
314
+ endedAt?: Date | null;
315
+ billingInterval?: string | null;
316
+ trialStart?: Date | null;
317
+ trialEnd?: Date | null;
318
+ groupId?: string | null;
319
+ createdAt: Date;
320
+ updatedAt: Date;
321
+ }
322
+ /**
323
+ * @deprecated Use `PaystackSubscription`. These aliases are retained for source
324
+ * compatibility while storage uses provider-local canonical field names.
325
+ */
326
+ type Subscription = PaystackSubscription & {
327
+ /** @deprecated Use `subscriptionCode`. */
328
+ paystackSubscriptionCode?: string | null;
329
+ /** @deprecated Use `customerCode`. */
330
+ paystackCustomerCode?: string | null;
331
+ /** @deprecated Use `planCode`. */
332
+ paystackPlanCode?: string | null;
333
+ /** @deprecated Use `transactionReference`. */
334
+ paystackTransactionReference?: string | null;
335
+ };
336
+ interface ChargeRecurringSubscriptionInput {
337
+ subscriptionId: string;
338
+ amount?: number;
339
+ }
340
+ interface ChargeRecurringSubscriptionResult {
341
+ status: "success" | "failed";
342
+ data: PaystackChargeAuthorizationResponse;
343
+ }
344
+ interface PaystackSyncResult {
345
+ status: "success";
346
+ count: number;
347
+ }
348
+ type AnyPaystackOptions = PaystackOptions<PaystackClientLike>;
349
+ /**
350
+ * Exact grouped SDK slices used by this plugin.
351
+ * This deliberately matches the official SDK surface instead of a handwritten approximation.
352
+ */
353
+ interface PaystackClientLike {
354
+ transaction: Pick<PaystackTransactionClient, "initialize" | "verify" | "chargeAuthorization">;
355
+ customer: Pick<PaystackCustomerClient, "create" | "update" | "fetch">;
356
+ subscription: Pick<PaystackSubscriptionClient, "create" | "fetch" | "disable" | "enable" | "manageLink">;
357
+ product: Pick<PaystackProductClient, "fetch" | "list">;
358
+ plan: Pick<PaystackPlanClient, "list" | "create">;
359
+ }
360
+ //#endregion
361
+ //#region src/routes.d.ts
362
+ declare const paystackWebhook: <P extends string = "/webhook">(options: AnyPaystackOptions, path?: P) => StrictEndpoint<P, {
363
+ method: "POST";
364
+ metadata: {
365
+ openapi: {
366
+ operationId: string;
367
+ };
368
+ scope: "server";
369
+ };
370
+ cloneRequest: true;
371
+ disableBody: true;
372
+ }, {
373
+ received: boolean;
374
+ }>;
375
+ declare const initializeTransaction: <P extends string = "/initialize-transaction">(options: AnyPaystackOptions, path?: P) => StrictEndpoint<P, {
376
+ method: "POST";
377
+ body: z.ZodObject<{
378
+ plan: z.ZodOptional<z.ZodString>;
379
+ product: z.ZodOptional<z.ZodString>;
380
+ amount: z.ZodOptional<z.ZodNumber>;
381
+ currency: z.ZodOptional<z.ZodString>;
382
+ email: z.ZodOptional<z.ZodString>;
383
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
384
+ referenceId: z.ZodOptional<z.ZodString>;
385
+ subscriptionId: z.ZodOptional<z.ZodString>;
386
+ callbackURL: z.ZodOptional<z.ZodString>;
387
+ quantity: z.ZodOptional<z.ZodNumber>;
388
+ scheduleAtPeriodEnd: z.ZodOptional<z.ZodBoolean>;
389
+ cancelAtPeriodEnd: z.ZodOptional<z.ZodBoolean>;
390
+ prorateAndCharge: z.ZodOptional<z.ZodBoolean>;
391
+ }, z.core.$strip>;
392
+ use: (((getValue: (ctx: GenericEndpointContext) => string | string[]) => (inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<void>) | ((inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<unknown>))[];
393
+ }, PaystackInitializeResult | undefined>;
394
+ declare const createSubscription: <P extends string = "/create-subscription">(options: AnyPaystackOptions, path?: P) => StrictEndpoint<P, {
395
+ method: "POST";
396
+ body: z.ZodObject<{
397
+ plan: z.ZodOptional<z.ZodString>;
398
+ product: z.ZodOptional<z.ZodString>;
399
+ amount: z.ZodOptional<z.ZodNumber>;
400
+ currency: z.ZodOptional<z.ZodString>;
401
+ email: z.ZodOptional<z.ZodString>;
402
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
403
+ referenceId: z.ZodOptional<z.ZodString>;
404
+ subscriptionId: z.ZodOptional<z.ZodString>;
405
+ callbackURL: z.ZodOptional<z.ZodString>;
406
+ quantity: z.ZodOptional<z.ZodNumber>;
407
+ scheduleAtPeriodEnd: z.ZodOptional<z.ZodBoolean>;
408
+ cancelAtPeriodEnd: z.ZodOptional<z.ZodBoolean>;
409
+ prorateAndCharge: z.ZodOptional<z.ZodBoolean>;
410
+ }, z.core.$strip>;
411
+ use: (((getValue: (ctx: GenericEndpointContext) => string | string[]) => (inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<void>) | ((inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<unknown>))[];
412
+ }, PaystackInitializeResult | undefined>;
413
+ declare const upgradeSubscription: <P extends string = "/upgrade-subscription">(options: AnyPaystackOptions, path?: P) => StrictEndpoint<P, {
414
+ method: "POST";
415
+ body: z.ZodObject<{
416
+ plan: z.ZodOptional<z.ZodString>;
417
+ product: z.ZodOptional<z.ZodString>;
418
+ amount: z.ZodOptional<z.ZodNumber>;
419
+ currency: z.ZodOptional<z.ZodString>;
420
+ email: z.ZodOptional<z.ZodString>;
421
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
422
+ referenceId: z.ZodOptional<z.ZodString>;
423
+ subscriptionId: z.ZodOptional<z.ZodString>;
424
+ callbackURL: z.ZodOptional<z.ZodString>;
425
+ quantity: z.ZodOptional<z.ZodNumber>;
426
+ scheduleAtPeriodEnd: z.ZodOptional<z.ZodBoolean>;
427
+ cancelAtPeriodEnd: z.ZodOptional<z.ZodBoolean>;
428
+ prorateAndCharge: z.ZodOptional<z.ZodBoolean>;
429
+ }, z.core.$strip>;
430
+ use: (((getValue: (ctx: GenericEndpointContext) => string | string[]) => (inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<void>) | ((inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<unknown>))[];
431
+ }, PaystackInitializeResult | undefined>;
432
+ declare const cancelSubscription: <P extends string = "/cancel-subscription">(options: AnyPaystackOptions, path?: P) => StrictEndpoint<P, {
433
+ method: "POST";
434
+ body: z.ZodObject<{
435
+ referenceId: z.ZodOptional<z.ZodString>;
436
+ subscriptionCode: z.ZodString;
437
+ emailToken: z.ZodOptional<z.ZodString>;
438
+ atPeriodEnd: z.ZodOptional<z.ZodBoolean>;
439
+ }, z.core.$strip>;
440
+ use: (((getValue: (ctx: GenericEndpointContext) => string | string[]) => (inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<void>) | ((inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<unknown>))[];
441
+ }, {
442
+ status: string;
443
+ }>;
444
+ declare const restoreSubscription: <P extends string = "/restore-subscription">(options: AnyPaystackOptions, path?: P) => StrictEndpoint<P, {
445
+ method: "POST";
446
+ body: z.ZodObject<{
447
+ referenceId: z.ZodOptional<z.ZodString>;
448
+ subscriptionCode: z.ZodString;
449
+ emailToken: z.ZodOptional<z.ZodString>;
450
+ atPeriodEnd: z.ZodOptional<z.ZodBoolean>;
451
+ }, z.core.$strip>;
452
+ use: (((getValue: (ctx: GenericEndpointContext) => string | string[]) => (inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<void>) | ((inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<unknown>))[];
453
+ }, {
454
+ status: string;
455
+ }>;
456
+ declare const verifyTransaction: <P extends string = "/verify-transaction">(options: AnyPaystackOptions, path?: P) => StrictEndpoint<P, {
457
+ method: "POST";
458
+ body: z.ZodObject<{
459
+ reference: z.ZodString;
460
+ }, z.core.$strip>;
461
+ use: (((getValue: (ctx: GenericEndpointContext) => string | string[]) => (inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<void>) | ((inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<unknown>))[];
462
+ }, {
463
+ status: string;
464
+ reference: string;
465
+ data: {
466
+ id: number;
467
+ domain: string;
468
+ status: string;
469
+ reference: string;
470
+ receipt_number: string | null;
471
+ amount: number;
472
+ message: string | null;
473
+ gateway_response: string;
474
+ channel: string;
475
+ currency: string;
476
+ ip_address: string | null;
477
+ metadata: (string | Record<string, never> | number) | null;
478
+ log: {
479
+ start_time: number;
480
+ time_spent: number;
481
+ attempts: number;
482
+ errors: number;
483
+ success: boolean;
484
+ mobile: boolean;
485
+ input: unknown[];
486
+ history: {
487
+ type: string;
488
+ message: string;
489
+ time: number;
490
+ }[];
491
+ } | null;
492
+ fees: number | null;
493
+ fees_split: unknown;
494
+ authorization: {
495
+ authorization_code?: string;
496
+ bin?: string | null;
497
+ last4?: string;
498
+ exp_month?: string;
499
+ exp_year?: string;
500
+ channel?: string;
501
+ card_type?: string;
502
+ bank?: string;
503
+ country_code?: string;
504
+ brand?: string;
505
+ reusable?: boolean;
506
+ signature?: string;
507
+ account_name?: string | null;
508
+ receiver_bank_account_number?: string | null;
509
+ receiver_bank?: string | null;
510
+ };
511
+ customer: {
512
+ id: number;
513
+ first_name: string | null;
514
+ last_name: string | null;
515
+ email: string;
516
+ customer_code: string;
517
+ phone: string | null;
518
+ metadata: Record<string, never> | null;
519
+ risk_action: string;
520
+ international_format_phone?: string | null;
521
+ };
522
+ plan: (string | Record<string, never>) | null;
523
+ split: Record<string, never> | null;
524
+ order_id: unknown;
525
+ paidAt: string | null;
526
+ createdAt: string;
527
+ requested_amount: number;
528
+ pos_transaction_data: unknown;
529
+ source: unknown;
530
+ fees_breakdown: unknown;
531
+ connect: unknown;
532
+ transaction_date: string;
533
+ plan_object: {
534
+ id?: number;
535
+ name?: string;
536
+ plan_code?: string;
537
+ description?: unknown;
538
+ amount?: number;
539
+ interval?: string;
540
+ send_invoices?: boolean;
541
+ send_sms?: boolean;
542
+ currency?: string;
543
+ };
544
+ subaccount: Record<string, never> | null;
545
+ };
546
+ }>;
547
+ declare const listSubscriptions: <P extends string = "/list-subscriptions">(options: AnyPaystackOptions, path?: P) => StrictEndpoint<P, {
548
+ method: "GET";
549
+ query: z.ZodObject<{
550
+ referenceId: z.ZodOptional<z.ZodString>;
551
+ }, z.core.$strip>;
552
+ use: (((getValue: (ctx: GenericEndpointContext) => string | string[]) => (inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<void>) | ((inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<unknown>))[];
553
+ }, {
554
+ subscriptions: Subscription[];
555
+ }>;
556
+ declare const listTransactions: <P extends string = "/list-transactions">(options: AnyPaystackOptions, path?: P) => StrictEndpoint<P, {
557
+ method: "GET";
558
+ query: z.ZodObject<{
559
+ referenceId: z.ZodOptional<z.ZodString>;
560
+ }, z.core.$strip>;
561
+ use: (((getValue: (ctx: GenericEndpointContext) => string | string[]) => (inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<void>) | ((inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<unknown>))[];
562
+ }, {
563
+ transactions: PaystackTransaction[];
564
+ }>;
565
+ declare const disablePaystackSubscription: <P extends string = "/disable-subscription">(options: AnyPaystackOptions, path?: P) => StrictEndpoint<P, {
566
+ method: "POST";
567
+ body: z.ZodObject<{
568
+ referenceId: z.ZodOptional<z.ZodString>;
569
+ subscriptionCode: z.ZodString;
570
+ emailToken: z.ZodOptional<z.ZodString>;
571
+ atPeriodEnd: z.ZodOptional<z.ZodBoolean>;
572
+ }, z.core.$strip>;
573
+ use: (((getValue: (ctx: GenericEndpointContext) => string | string[]) => (inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<void>) | ((inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<unknown>))[];
574
+ }, {
575
+ status: string;
576
+ }>;
577
+ declare const enablePaystackSubscription: <P extends string = "/enable-subscription">(options: AnyPaystackOptions, path?: P) => StrictEndpoint<P, {
578
+ method: "POST";
579
+ body: z.ZodObject<{
580
+ referenceId: z.ZodOptional<z.ZodString>;
581
+ subscriptionCode: z.ZodString;
582
+ emailToken: z.ZodOptional<z.ZodString>;
583
+ atPeriodEnd: z.ZodOptional<z.ZodBoolean>;
584
+ }, z.core.$strip>;
585
+ use: (((getValue: (ctx: GenericEndpointContext) => string | string[]) => (inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<void>) | ((inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<unknown>))[];
586
+ }, {
587
+ status: string;
588
+ }>;
589
+ declare const getSubscriptionManageLink: <P extends string = "/subscription-manage-link">(options: AnyPaystackOptions, path?: P) => StrictEndpoint<P, {
590
+ method: "GET";
591
+ query: z.ZodObject<{
592
+ subscriptionCode: z.ZodString;
593
+ }, z.core.$strip>;
594
+ use: (((getValue: (ctx: GenericEndpointContext) => string | string[]) => (inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<void>) | ((inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<unknown>))[];
595
+ }, {
596
+ link: string | null;
597
+ }>;
598
+ declare const listProducts: <P extends string = "/list-products">(_options: AnyPaystackOptions, path?: P) => StrictEndpoint<P, {
599
+ method: "GET";
600
+ metadata: {
601
+ openapi: {
602
+ operationId: string;
603
+ };
604
+ };
605
+ }, {
606
+ products: PaystackProduct[];
607
+ }>;
608
+ declare const listPlans: <P extends string = "/list-plans">(_options: AnyPaystackOptions, path?: P) => StrictEndpoint<P, {
609
+ method: "GET";
610
+ metadata: {
611
+ scope: "server";
612
+ };
613
+ use: ((inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<{
614
+ session: {
615
+ session: Record<string, unknown> & {
616
+ id: string;
617
+ createdAt: Date;
618
+ updatedAt: Date;
619
+ userId: string;
620
+ expiresAt: Date;
621
+ token: string;
622
+ ipAddress?: string | null | undefined;
623
+ userAgent?: string | null | undefined;
624
+ };
625
+ user: Record<string, unknown> & {
626
+ id: string;
627
+ createdAt: Date;
628
+ updatedAt: Date;
629
+ email: string;
630
+ emailVerified: boolean;
631
+ name: string;
632
+ image?: string | null | undefined;
633
+ };
634
+ };
635
+ }>)[];
636
+ }, {
637
+ plans: PaystackPlan[];
638
+ }>;
639
+ declare const getConfig: <P extends string = "/get-config">(options: AnyPaystackOptions, path?: P) => StrictEndpoint<P, {
640
+ method: "GET";
641
+ metadata: {
642
+ openapi: {
643
+ operationId: string;
644
+ };
645
+ };
646
+ }, {
647
+ plans: PaystackPlan[];
648
+ products: PaystackProduct[];
649
+ }>;
650
+ //#endregion
651
+ //#region src/version.d.ts
652
+ declare const PACKAGE_VERSION = "3.2.0";
653
+ //#endregion
654
+ //#region src/metadata.d.ts
655
+ type PaystackMetadata = Record<string, unknown>;
656
+ interface CheckoutMetadataInput {
657
+ referenceId: string;
658
+ userId: string;
659
+ plan?: string;
660
+ groupId?: string | null;
661
+ product?: string;
662
+ extra?: PaystackMetadata;
663
+ trial: {
664
+ isTrial: boolean;
665
+ requested: boolean;
666
+ granted: boolean;
667
+ deniedReason?: "already_used";
668
+ endsAt?: Date;
669
+ };
670
+ }
671
+ interface ProrationMetadataInput {
672
+ subscriptionId: string;
673
+ referenceId: string;
674
+ newPlan: string;
675
+ oldPlan: string;
676
+ newSeatCount: number;
677
+ remainingDays: number;
678
+ }
679
+ interface RenewalMetadataInput {
680
+ subscriptionId: string;
681
+ referenceId: string;
682
+ }
683
+ declare function parsePaystackMetadata(value: unknown): PaystackMetadata;
684
+ declare function stringifyPaystackMetadata(value: unknown): string | undefined;
685
+ declare function hasPaystackMetadata(value: unknown): boolean;
686
+ declare function getMetadataString(metadata: PaystackMetadata, key: string): string | undefined;
687
+ declare function getMetadataNumber(metadata: PaystackMetadata, key: string): number | undefined;
688
+ declare function getMetadataBoolean(metadata: PaystackMetadata, key: string): boolean;
689
+ declare function createCheckoutMetadata(input: CheckoutMetadataInput): PaystackMetadata;
690
+ declare function createProrationMetadata(input: ProrationMetadataInput): PaystackMetadata;
691
+ declare function createRenewalMetadata(input: RenewalMetadataInput): PaystackMetadata;
692
+ //#endregion
693
+ //#region src/operations.d.ts
694
+ declare function syncPaystackProducts(ctx: GenericEndpointContext, options: AnyPaystackOptions): Promise<PaystackSyncResult>;
695
+ declare function syncPaystackPlans(ctx: GenericEndpointContext, options: AnyPaystackOptions): Promise<PaystackSyncResult>;
696
+ declare function chargeSubscriptionRenewal(ctx: GenericEndpointContext, options: AnyPaystackOptions, input: ChargeRecurringSubscriptionInput): Promise<ChargeRecurringSubscriptionResult>;
697
+ //#endregion
698
+ //#region src/limits.d.ts
699
+ declare function getOrganizationEntitlements(ctx: GenericEndpointContext, organizationId: string, options: AnyPaystackOptions): Promise<{
700
+ limits: Record<string, number>;
701
+ features: string[];
702
+ }>;
703
+ //#endregion
704
+ //#region src/reconciliation.d.ts
705
+ type PaystackReconciliationSource = "webhook" | "queue" | "admin" | "server" | "browser";
706
+ interface ReconcilePaystackTransactionInput {
707
+ reference: string;
708
+ source?: PaystackReconciliationSource;
709
+ referenceId?: string;
710
+ actor?: {
711
+ user: User;
712
+ session: Session;
713
+ };
714
+ throwOnError?: boolean;
715
+ }
716
+ interface PaystackReconciliationError {
717
+ code: string;
718
+ message: string;
719
+ status?: number;
720
+ }
721
+ interface PaystackReconciliationSummary {
722
+ transaction: {
723
+ found: boolean;
724
+ updated: boolean;
725
+ referenceId?: string;
726
+ previousStatus?: string;
727
+ status?: string;
728
+ };
729
+ subscription: {
730
+ found: boolean;
731
+ updated: boolean;
732
+ id?: string;
733
+ status?: string;
734
+ prorationApplied: boolean;
735
+ };
736
+ customer: {
737
+ saved: boolean;
738
+ referenceId?: string;
739
+ customerCode?: string;
740
+ model?: "user" | "organization";
741
+ };
742
+ product: {
743
+ synced: boolean;
744
+ name?: string;
745
+ };
746
+ }
747
+ interface ReconcilePaystackTransactionSuccess extends PaystackReconciliationSummary {
748
+ ok: true;
749
+ source: PaystackReconciliationSource;
750
+ status: string;
751
+ reference: string;
752
+ data: PaystackTransactionResponse;
753
+ error?: undefined;
754
+ }
755
+ interface ReconcilePaystackTransactionFailure extends PaystackReconciliationSummary {
756
+ ok: false;
757
+ source: PaystackReconciliationSource;
758
+ status: string;
759
+ reference: string;
760
+ data: PaystackTransactionResponse | null;
761
+ error: PaystackReconciliationError;
762
+ }
763
+ type ReconcilePaystackTransactionResult = ReconcilePaystackTransactionSuccess | ReconcilePaystackTransactionFailure;
764
+ declare function reconcilePaystackTransaction(ctx: GenericEndpointContext, options: AnyPaystackOptions, input: ReconcilePaystackTransactionInput): Promise<ReconcilePaystackTransactionResult>;
765
+ //#endregion
766
+ //#region src/migrations.d.ts
767
+ interface PaystackSchemaMigrationFailure {
768
+ kind: "subscription" | "customer" | "credential";
769
+ id: string;
770
+ message: string;
771
+ }
772
+ interface PaystackSchemaMigrationReport {
773
+ status: "complete" | "partial";
774
+ subscriptions: {
775
+ migrated: number;
776
+ skipped: number;
777
+ failed: number;
778
+ };
779
+ customers: {
780
+ migrated: number;
781
+ skipped: number;
782
+ failed: number;
783
+ };
784
+ credentials: {
785
+ migrated: number;
786
+ skipped: number;
787
+ failed: number;
788
+ };
789
+ skipped: number;
790
+ failures: PaystackSchemaMigrationFailure[];
791
+ }
792
+ declare function migratePaystackSubscriptionSchema(ctx: GenericEndpointContext, options: AnyPaystackOptions): Promise<PaystackSchemaMigrationReport>;
793
+ //#endregion
794
+ //#region src/index.d.ts
795
+ declare module "better-auth" {
796
+ interface BetterAuthPluginRegistry<AuthOptions, Options> {
797
+ paystack: {
798
+ creator: typeof paystack;
799
+ };
800
+ }
801
+ }
802
+ declare const INTERNAL_ERROR_CODES: ReturnType<typeof defineErrorCodes>;
803
+ /**
804
+ * Must stay a `type` rather than an `interface`.
805
+ *
806
+ * `BetterAuthPlugin["endpoints"]` is `{ [key: string]: Endpoint }`, and only object literal
807
+ * *type aliases* get TypeScript's implicit index signature — interfaces do not. Declaring
808
+ * this as `interface ... extends Record<string, Endpoint>` satisfies that constraint but
809
+ * gives the plugin a real string index signature. Better Auth merges every plugin's
810
+ * endpoints into `auth.api`, so that signature spreads across the whole API surface and,
811
+ * under `noUncheckedIndexedAccess`, makes *every* `auth.api.*` call possibly `undefined`.
812
+ */
813
+ type PaystackPluginEndpoints = {
814
+ initializeTransaction: ReturnType<typeof initializeTransaction>;
815
+ verifyTransaction: ReturnType<typeof verifyTransaction>;
816
+ listSubscriptions: ReturnType<typeof listSubscriptions>;
817
+ paystackWebhook: ReturnType<typeof paystackWebhook>;
818
+ listTransactions: ReturnType<typeof listTransactions>;
819
+ getConfig: ReturnType<typeof getConfig>;
820
+ disableSubscription: ReturnType<typeof disablePaystackSubscription>;
821
+ enableSubscription: ReturnType<typeof enablePaystackSubscription>;
822
+ getSubscriptionManageLink: ReturnType<typeof getSubscriptionManageLink>;
823
+ subscriptionManageLink: ReturnType<typeof getSubscriptionManageLink>;
824
+ createSubscription: ReturnType<typeof createSubscription>;
825
+ upgradeSubscription: ReturnType<typeof upgradeSubscription>;
826
+ cancelSubscription: ReturnType<typeof cancelSubscription>;
827
+ restoreSubscription: ReturnType<typeof restoreSubscription>;
828
+ listProducts: ReturnType<typeof listProducts>;
829
+ listPlans: ReturnType<typeof listPlans>;
830
+ };
831
+ type PaystackHookHandler = (...args: unknown[]) => unknown;
832
+ interface PaystackPluginInitResult {
833
+ options: {
834
+ databaseHooks: Record<string, unknown> & {
835
+ organization: {
836
+ create: {
837
+ after: PaystackHookHandler;
838
+ };
839
+ };
840
+ };
841
+ };
842
+ }
843
+ type PaystackPluginInit = ((ctx: AuthContext) => PaystackPluginInitResult) & NonNullable<BetterAuthPlugin["init"]>;
844
+ type PaystackPluginInstance<O extends AnyPaystackOptions> = Omit<BetterAuthPlugin, "id" | "version" | "endpoints" | "schema" | "init" | "$ERROR_CODES" | "options"> & {
845
+ id: "paystack";
846
+ version: typeof PACKAGE_VERSION;
847
+ endpoints: PaystackPluginEndpoints;
848
+ schema: ReturnType<typeof getSchema>;
849
+ init: PaystackPluginInit;
850
+ $ERROR_CODES: typeof INTERNAL_ERROR_CODES;
851
+ options: NoInfer<O>;
852
+ };
853
+ declare const createPaystackPlugin: <TPaystackClient extends PaystackClientLike = PaystackClientLike, O extends PaystackOptions<TPaystackClient> = PaystackOptions<TPaystackClient>>(options: O) => PaystackPluginInstance<O>;
854
+ declare const paystack: typeof createPaystackPlugin;
855
+ type PaystackPlugin<TPaystackClient extends PaystackClientLike = PaystackClientLike, O extends PaystackOptions<TPaystackClient> = PaystackOptions<TPaystackClient>> = ReturnType<typeof paystack<TPaystackClient, O>>;
856
+ //#endregion
857
+ export { PaystackClientLike as A, PaystackTransactionResponse as B, getMetadataNumber as C, stringifyPaystackMetadata as D, parsePaystackMetadata as E, PaystackPlan as F, Subscription as H, PaystackProduct as I, PaystackSubscription as L, PaystackInitializeResult as M, PaystackOptions as N, AnyPaystackOptions as O, PaystackPaymentCredential as P, PaystackSyncResult as R, getMetadataBoolean as S, hasPaystackMetadata as T, SubscriptionOptions as U, PaystackWebhookEventRecord as V, syncPaystackProducts as _, migratePaystackSubscriptionSchema as a, createProrationMetadata as b, PaystackReconciliationSummary as c, ReconcilePaystackTransactionResult as d, ReconcilePaystackTransactionSuccess as f, syncPaystackPlans as g, chargeSubscriptionRenewal as h, PaystackSchemaMigrationReport as i, PaystackCustomer as j, ChargeRecurringSubscriptionResult as k, ReconcilePaystackTransactionFailure as l, getOrganizationEntitlements as m, paystack as n, PaystackReconciliationError as o, reconcilePaystackTransaction as p, PaystackSchemaMigrationFailure as r, PaystackReconciliationSource as s, PaystackPlugin as t, ReconcilePaystackTransactionInput as u, PaystackMetadata as v, getMetadataString as w, createRenewalMetadata as x, createCheckoutMetadata as y, PaystackTransaction as z };
858
+ //# sourceMappingURL=index-CXuHlFoy.d.mts.map