better-auth-paystack 0.0.0 → 3.1.2

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