better-auth-mp 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,574 @@
1
+ import { MercadoPagoPluginOptions, PlanOutput, SubscriptionOutput, PreferenceOutput, PaymentOutput, PaginatedPayments } from './types.cjs';
2
+ import * as better_auth from 'better-auth';
3
+ import * as zod from 'zod';
4
+
5
+ /**
6
+ * Helper function to get payment result type
7
+ */
8
+ declare function getPaymentResultType(mpStatus: string): "success" | "pending" | "error";
9
+
10
+ declare const mercadoPagoPlugin: (options: MercadoPagoPluginOptions) => {
11
+ endpoints: {
12
+ cancelSubscription: better_auth.StrictEndpoint<"/mercado-pago/cancel-subscription", {
13
+ body: zod.ZodObject<{
14
+ subscriptionId: zod.ZodString;
15
+ }, "strip", zod.ZodTypeAny, {
16
+ subscriptionId: string;
17
+ }, {
18
+ subscriptionId: string;
19
+ }>;
20
+ method: "POST";
21
+ }, {
22
+ success: boolean;
23
+ }>;
24
+ createPlan: better_auth.StrictEndpoint<"/mercado-pago/create-plan", {
25
+ body: zod.ZodObject<{
26
+ autoRecurring: zod.ZodObject<{
27
+ currencyId: zod.ZodString;
28
+ frequency: zod.ZodNumber;
29
+ frequencyType: zod.ZodEnum<["days", "weeks", "months"]>;
30
+ transactionAmount: zod.ZodNumber;
31
+ }, "strip", zod.ZodTypeAny, {
32
+ currencyId: string;
33
+ frequency: number;
34
+ frequencyType: "days" | "weeks" | "months";
35
+ transactionAmount: number;
36
+ }, {
37
+ currencyId: string;
38
+ frequency: number;
39
+ frequencyType: "days" | "weeks" | "months";
40
+ transactionAmount: number;
41
+ }>;
42
+ description: zod.ZodOptional<zod.ZodString>;
43
+ metadata: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodAny>>;
44
+ name: zod.ZodString;
45
+ }, "strip", zod.ZodTypeAny, {
46
+ autoRecurring: {
47
+ currencyId: string;
48
+ frequency: number;
49
+ frequencyType: "days" | "weeks" | "months";
50
+ transactionAmount: number;
51
+ };
52
+ name: string;
53
+ description?: string | undefined;
54
+ metadata?: Record<string, any> | undefined;
55
+ }, {
56
+ autoRecurring: {
57
+ currencyId: string;
58
+ frequency: number;
59
+ frequencyType: "days" | "weeks" | "months";
60
+ transactionAmount: number;
61
+ };
62
+ name: string;
63
+ description?: string | undefined;
64
+ metadata?: Record<string, any> | undefined;
65
+ }>;
66
+ method: "POST";
67
+ }, PlanOutput>;
68
+ createSubscription: better_auth.StrictEndpoint<"/mercado-pago/create-subscription", {
69
+ body: zod.ZodObject<{
70
+ autoRecurring: zod.ZodObject<{
71
+ currencyId: zod.ZodString;
72
+ endDate: zod.ZodOptional<zod.ZodString>;
73
+ frequency: zod.ZodNumber;
74
+ frequencyType: zod.ZodEnum<["days", "weeks", "months"]>;
75
+ startDate: zod.ZodOptional<zod.ZodString>;
76
+ transactionAmount: zod.ZodNumber;
77
+ }, "strip", zod.ZodTypeAny, {
78
+ currencyId: string;
79
+ frequency: number;
80
+ frequencyType: "days" | "weeks" | "months";
81
+ transactionAmount: number;
82
+ endDate?: string | undefined;
83
+ startDate?: string | undefined;
84
+ }, {
85
+ currencyId: string;
86
+ frequency: number;
87
+ frequencyType: "days" | "weeks" | "months";
88
+ transactionAmount: number;
89
+ endDate?: string | undefined;
90
+ startDate?: string | undefined;
91
+ }>;
92
+ backUrl: zod.ZodOptional<zod.ZodString>;
93
+ idempotencyKey: zod.ZodOptional<zod.ZodString>;
94
+ metadata: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodAny>>;
95
+ payerEmail: zod.ZodString;
96
+ reason: zod.ZodString;
97
+ }, "strip", zod.ZodTypeAny, {
98
+ autoRecurring: {
99
+ currencyId: string;
100
+ frequency: number;
101
+ frequencyType: "days" | "weeks" | "months";
102
+ transactionAmount: number;
103
+ endDate?: string | undefined;
104
+ startDate?: string | undefined;
105
+ };
106
+ payerEmail: string;
107
+ reason: string;
108
+ metadata?: Record<string, any> | undefined;
109
+ idempotencyKey?: string | undefined;
110
+ backUrl?: string | undefined;
111
+ }, {
112
+ autoRecurring: {
113
+ currencyId: string;
114
+ frequency: number;
115
+ frequencyType: "days" | "weeks" | "months";
116
+ transactionAmount: number;
117
+ endDate?: string | undefined;
118
+ startDate?: string | undefined;
119
+ };
120
+ payerEmail: string;
121
+ reason: string;
122
+ metadata?: Record<string, any> | undefined;
123
+ idempotencyKey?: string | undefined;
124
+ backUrl?: string | undefined;
125
+ }>;
126
+ method: "POST";
127
+ }, SubscriptionOutput>;
128
+ createSubscriptionWithPlan: better_auth.StrictEndpoint<"/mercado-pago/create-subscription-with-plan", {
129
+ body: zod.ZodObject<{
130
+ cardTokenId: zod.ZodString;
131
+ idempotencyKey: zod.ZodOptional<zod.ZodString>;
132
+ identification: zod.ZodOptional<zod.ZodObject<{
133
+ number: zod.ZodString;
134
+ type: zod.ZodString;
135
+ }, "strip", zod.ZodTypeAny, {
136
+ number: string;
137
+ type: string;
138
+ }, {
139
+ number: string;
140
+ type: string;
141
+ }>>;
142
+ metadata: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodAny>>;
143
+ payerEmail: zod.ZodString;
144
+ planId: zod.ZodString;
145
+ }, "strip", zod.ZodTypeAny, {
146
+ payerEmail: string;
147
+ cardTokenId: string;
148
+ planId: string;
149
+ metadata?: Record<string, any> | undefined;
150
+ idempotencyKey?: string | undefined;
151
+ identification?: {
152
+ number: string;
153
+ type: string;
154
+ } | undefined;
155
+ }, {
156
+ payerEmail: string;
157
+ cardTokenId: string;
158
+ planId: string;
159
+ metadata?: Record<string, any> | undefined;
160
+ idempotencyKey?: string | undefined;
161
+ identification?: {
162
+ number: string;
163
+ type: string;
164
+ } | undefined;
165
+ }>;
166
+ method: "POST";
167
+ }, SubscriptionOutput>;
168
+ getPlan: better_auth.StrictEndpoint<"/mercado-pago/get-plan", {
169
+ body: zod.ZodObject<{
170
+ planId: zod.ZodString;
171
+ }, "strip", zod.ZodTypeAny, {
172
+ planId: string;
173
+ }, {
174
+ planId: string;
175
+ }>;
176
+ method: "POST";
177
+ }, {}>;
178
+ getPlans: better_auth.StrictEndpoint<"/mercado-pago/get-plans", {
179
+ body: zod.ZodObject<{
180
+ limit: zod.ZodDefault<zod.ZodNumber>;
181
+ offset: zod.ZodDefault<zod.ZodNumber>;
182
+ }, "strip", zod.ZodTypeAny, {
183
+ limit: number;
184
+ offset: number;
185
+ }, {
186
+ limit?: number | undefined;
187
+ offset?: number | undefined;
188
+ }>;
189
+ method: "POST";
190
+ }, {
191
+ limit: number;
192
+ offset: number;
193
+ plans: unknown[];
194
+ total: number;
195
+ }>;
196
+ getSubscription: better_auth.StrictEndpoint<"/mercado-pago/get-subscription", {
197
+ body: zod.ZodObject<{
198
+ subscriptionId: zod.ZodString;
199
+ }, "strip", zod.ZodTypeAny, {
200
+ subscriptionId: string;
201
+ }, {
202
+ subscriptionId: string;
203
+ }>;
204
+ method: "POST";
205
+ }, {
206
+ id: string;
207
+ }>;
208
+ getSubscriptions: better_auth.StrictEndpoint<"/mercado-pago/get-subscriptions", {
209
+ body: zod.ZodOptional<zod.ZodObject<{
210
+ filters: zod.ZodOptional<zod.ZodObject<{
211
+ planId: zod.ZodOptional<zod.ZodString>;
212
+ status: zod.ZodOptional<zod.ZodEnum<["pending", "authorized", "paused", "cancelled", "expired", "unpaid"]>>;
213
+ }, "strip", zod.ZodTypeAny, {
214
+ status?: "pending" | "authorized" | "cancelled" | "paused" | "expired" | "unpaid" | undefined;
215
+ planId?: string | undefined;
216
+ }, {
217
+ status?: "pending" | "authorized" | "cancelled" | "paused" | "expired" | "unpaid" | undefined;
218
+ planId?: string | undefined;
219
+ }>>;
220
+ limit: zod.ZodOptional<zod.ZodNumber>;
221
+ offset: zod.ZodOptional<zod.ZodNumber>;
222
+ }, "strip", zod.ZodTypeAny, {
223
+ filters?: {
224
+ status?: "pending" | "authorized" | "cancelled" | "paused" | "expired" | "unpaid" | undefined;
225
+ planId?: string | undefined;
226
+ } | undefined;
227
+ limit?: number | undefined;
228
+ offset?: number | undefined;
229
+ }, {
230
+ filters?: {
231
+ status?: "pending" | "authorized" | "cancelled" | "paused" | "expired" | "unpaid" | undefined;
232
+ planId?: string | undefined;
233
+ } | undefined;
234
+ limit?: number | undefined;
235
+ offset?: number | undefined;
236
+ }>>;
237
+ method: "POST";
238
+ }, {
239
+ limit: number;
240
+ offset: number;
241
+ subscriptions: unknown[];
242
+ total: number;
243
+ }>;
244
+ updateSubscription: better_auth.StrictEndpoint<"/mercado-pago/update-subscription", {
245
+ body: zod.ZodObject<{
246
+ status: zod.ZodEnum<["paused", "authorized"]>;
247
+ subscriptionId: zod.ZodString;
248
+ }, "strip", zod.ZodTypeAny, {
249
+ status: "authorized" | "paused";
250
+ subscriptionId: string;
251
+ }, {
252
+ status: "authorized" | "paused";
253
+ subscriptionId: string;
254
+ }>;
255
+ method: "POST";
256
+ }, {
257
+ status: "authorized" | "paused";
258
+ success: boolean;
259
+ }>;
260
+ webhook: better_auth.StrictEndpoint<"/mercado-pago/webhook", {
261
+ method: "POST";
262
+ secured: boolean;
263
+ }, unknown>;
264
+ createPayment: better_auth.StrictEndpoint<"/mercado-pago/create-payment", {
265
+ body: zod.ZodObject<{
266
+ idempotencyKey: zod.ZodOptional<zod.ZodString>;
267
+ backUrls: zod.ZodOptional<zod.ZodObject<{
268
+ failure: zod.ZodOptional<zod.ZodString>;
269
+ pending: zod.ZodOptional<zod.ZodString>;
270
+ success: zod.ZodOptional<zod.ZodString>;
271
+ }, "strip", zod.ZodTypeAny, {
272
+ failure?: string | undefined;
273
+ pending?: string | undefined;
274
+ success?: string | undefined;
275
+ }, {
276
+ failure?: string | undefined;
277
+ pending?: string | undefined;
278
+ success?: string | undefined;
279
+ }>>;
280
+ items: zod.ZodArray<zod.ZodObject<{
281
+ categoryId: zod.ZodOptional<zod.ZodString>;
282
+ currencyId: zod.ZodString;
283
+ description: zod.ZodOptional<zod.ZodString>;
284
+ id: zod.ZodString;
285
+ pictureUrl: zod.ZodOptional<zod.ZodString>;
286
+ quantity: zod.ZodNumber;
287
+ title: zod.ZodString;
288
+ unitPrice: zod.ZodNumber;
289
+ }, "strip", zod.ZodTypeAny, {
290
+ currencyId: string;
291
+ id: string;
292
+ quantity: number;
293
+ title: string;
294
+ unitPrice: number;
295
+ categoryId?: string | undefined;
296
+ description?: string | undefined;
297
+ pictureUrl?: string | undefined;
298
+ }, {
299
+ currencyId: string;
300
+ id: string;
301
+ quantity: number;
302
+ title: string;
303
+ unitPrice: number;
304
+ categoryId?: string | undefined;
305
+ description?: string | undefined;
306
+ pictureUrl?: string | undefined;
307
+ }>, "many">;
308
+ metadata: zod.ZodOptional<zod.ZodEffects<zod.ZodEffects<zod.ZodRecord<zod.ZodString, zod.ZodUnion<[zod.ZodString, zod.ZodNumber, zod.ZodBoolean]>>, Record<string, string | number | boolean>, Record<string, string | number | boolean>>, Record<string, string | number | boolean>, Record<string, string | number | boolean>>>;
309
+ }, "strip", zod.ZodTypeAny, {
310
+ items: {
311
+ currencyId: string;
312
+ id: string;
313
+ quantity: number;
314
+ title: string;
315
+ unitPrice: number;
316
+ categoryId?: string | undefined;
317
+ description?: string | undefined;
318
+ pictureUrl?: string | undefined;
319
+ }[];
320
+ backUrls?: {
321
+ failure?: string | undefined;
322
+ pending?: string | undefined;
323
+ success?: string | undefined;
324
+ } | undefined;
325
+ metadata?: Record<string, string | number | boolean> | undefined;
326
+ idempotencyKey?: string | undefined;
327
+ }, {
328
+ items: {
329
+ currencyId: string;
330
+ id: string;
331
+ quantity: number;
332
+ title: string;
333
+ unitPrice: number;
334
+ categoryId?: string | undefined;
335
+ description?: string | undefined;
336
+ pictureUrl?: string | undefined;
337
+ }[];
338
+ backUrls?: {
339
+ failure?: string | undefined;
340
+ pending?: string | undefined;
341
+ success?: string | undefined;
342
+ } | undefined;
343
+ metadata?: Record<string, string | number | boolean> | undefined;
344
+ idempotencyKey?: string | undefined;
345
+ }>;
346
+ method: "POST";
347
+ }, PreferenceOutput>;
348
+ getPayment: better_auth.StrictEndpoint<"/mercado-pago/get-payment", {
349
+ body: zod.ZodObject<{
350
+ externalReference: zod.ZodString;
351
+ }, "strip", zod.ZodTypeAny, {
352
+ externalReference: string;
353
+ }, {
354
+ externalReference: string;
355
+ }>;
356
+ method: "POST";
357
+ }, PaymentOutput>;
358
+ getPayments: better_auth.StrictEndpoint<"/mercado-pago/get-payments", {
359
+ body: zod.ZodObject<{
360
+ filters: zod.ZodOptional<zod.ZodObject<{
361
+ dateCreatedFrom: zod.ZodOptional<zod.ZodString>;
362
+ dateCreatedTo: zod.ZodOptional<zod.ZodString>;
363
+ status: zod.ZodOptional<zod.ZodEnum<["pending", "approved", "authorized", "in_process", "in_mediation", "rejected", "cancelled", "refunded", "charged_back"]>>;
364
+ }, "strip", zod.ZodTypeAny, {
365
+ status?: "pending" | "approved" | "authorized" | "in_process" | "in_mediation" | "rejected" | "cancelled" | "refunded" | "charged_back" | undefined;
366
+ dateCreatedFrom?: string | undefined;
367
+ dateCreatedTo?: string | undefined;
368
+ }, {
369
+ status?: "pending" | "approved" | "authorized" | "in_process" | "in_mediation" | "rejected" | "cancelled" | "refunded" | "charged_back" | undefined;
370
+ dateCreatedFrom?: string | undefined;
371
+ dateCreatedTo?: string | undefined;
372
+ }>>;
373
+ limit: zod.ZodDefault<zod.ZodNumber>;
374
+ offset: zod.ZodDefault<zod.ZodNumber>;
375
+ }, "strip", zod.ZodTypeAny, {
376
+ limit: number;
377
+ offset: number;
378
+ filters?: {
379
+ status?: "pending" | "approved" | "authorized" | "in_process" | "in_mediation" | "rejected" | "cancelled" | "refunded" | "charged_back" | undefined;
380
+ dateCreatedFrom?: string | undefined;
381
+ dateCreatedTo?: string | undefined;
382
+ } | undefined;
383
+ }, {
384
+ filters?: {
385
+ status?: "pending" | "approved" | "authorized" | "in_process" | "in_mediation" | "rejected" | "cancelled" | "refunded" | "charged_back" | undefined;
386
+ dateCreatedFrom?: string | undefined;
387
+ dateCreatedTo?: string | undefined;
388
+ } | undefined;
389
+ limit?: number | undefined;
390
+ offset?: number | undefined;
391
+ }>;
392
+ method: "POST";
393
+ }, PaginatedPayments>;
394
+ };
395
+ id: "mercado-pago";
396
+ schema: {
397
+ mercadoPagoPayment: {
398
+ fields: {
399
+ amount: {
400
+ required: true;
401
+ type: "number";
402
+ };
403
+ createdAt: {
404
+ required: true;
405
+ type: "date";
406
+ };
407
+ currency: {
408
+ required: true;
409
+ type: "string";
410
+ };
411
+ externalReference: {
412
+ required: true;
413
+ type: "string";
414
+ unique: true;
415
+ };
416
+ id: {
417
+ required: true;
418
+ type: "string";
419
+ };
420
+ mercadoPagoPaymentId: {
421
+ required: false;
422
+ type: "string";
423
+ unique: true;
424
+ };
425
+ metadata: {
426
+ type: "string";
427
+ };
428
+ paymentMethodId: {
429
+ type: "string";
430
+ };
431
+ paymentTypeId: {
432
+ type: "string";
433
+ };
434
+ preferenceId: {
435
+ required: true;
436
+ type: "string";
437
+ };
438
+ status: {
439
+ required: true;
440
+ type: "string";
441
+ };
442
+ statusDetail: {
443
+ type: "string";
444
+ };
445
+ updatedAt: {
446
+ required: true;
447
+ type: "date";
448
+ };
449
+ userId: {
450
+ references: {
451
+ field: string;
452
+ model: string;
453
+ };
454
+ required: true;
455
+ type: "string";
456
+ };
457
+ };
458
+ };
459
+ mercadoPagoPlan: {
460
+ fields: {
461
+ autoRecurringFrequency: {
462
+ required: true;
463
+ type: "number";
464
+ };
465
+ autoRecurringFrequencyType: {
466
+ required: true;
467
+ type: "string";
468
+ };
469
+ createdAt: {
470
+ required: true;
471
+ type: "date";
472
+ };
473
+ currencyId: {
474
+ required: true;
475
+ type: "string";
476
+ };
477
+ description: {
478
+ type: "string";
479
+ };
480
+ id: {
481
+ required: true;
482
+ type: "string";
483
+ };
484
+ metadata: {
485
+ type: "string";
486
+ };
487
+ mpPlanId: {
488
+ required: true;
489
+ type: "string";
490
+ unique: true;
491
+ };
492
+ name: {
493
+ required: true;
494
+ type: "string";
495
+ };
496
+ transactionAmount: {
497
+ required: true;
498
+ type: "number";
499
+ };
500
+ updatedAt: {
501
+ required: true;
502
+ type: "date";
503
+ };
504
+ };
505
+ };
506
+ mercadoPagoSubscription: {
507
+ fields: {
508
+ autoRecurringFrequency: {
509
+ type: "number";
510
+ };
511
+ autoRecurringFrequencyType: {
512
+ type: "string";
513
+ };
514
+ createdAt: {
515
+ required: true;
516
+ type: "date";
517
+ };
518
+ currencyId: {
519
+ type: "string";
520
+ };
521
+ externalReference: {
522
+ required: true;
523
+ type: "string";
524
+ unique: true;
525
+ };
526
+ id: {
527
+ required: true;
528
+ type: "string";
529
+ };
530
+ metadata: {
531
+ type: "string";
532
+ };
533
+ mpSubscriptionId: {
534
+ required: false;
535
+ type: "string";
536
+ unique: true;
537
+ };
538
+ nextPaymentDate: {
539
+ type: "date";
540
+ };
541
+ payerEmail: {
542
+ type: "string";
543
+ };
544
+ planId: {
545
+ type: "string";
546
+ };
547
+ reason: {
548
+ type: "string";
549
+ };
550
+ status: {
551
+ required: true;
552
+ type: "string";
553
+ };
554
+ transactionAmount: {
555
+ type: "number";
556
+ };
557
+ updatedAt: {
558
+ required: true;
559
+ type: "date";
560
+ };
561
+ userId: {
562
+ references: {
563
+ field: string;
564
+ model: string;
565
+ };
566
+ required: true;
567
+ type: "string";
568
+ };
569
+ };
570
+ };
571
+ };
572
+ };
573
+
574
+ export { MercadoPagoPluginOptions, getPaymentResultType, mercadoPagoPlugin };