better-auth-mercadopago 0.1.3 → 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.
@@ -0,0 +1,1278 @@
1
+ import * as better_auth_client from 'better-auth/client';
2
+ import { BetterFetchOption } from 'better-auth/client';
3
+ import * as better_auth from 'better-auth';
4
+ import { z } from 'zod';
5
+
6
+ /** biome-ignore-all lint/suspicious/noExplicitAny: <no need to use any> */
7
+ interface MercadoPagoPluginOptions {
8
+ /**
9
+ * Your Mercado Pago access token
10
+ */
11
+ accessToken: string;
12
+ /**
13
+ * Base URL for redirects and webhooks
14
+ * @default process.env.APP_URL
15
+ */
16
+ baseUrl?: string;
17
+ /**
18
+ * Webhook secret for signature verification (optional)
19
+ */
20
+ webhookSecret?: string;
21
+ /**
22
+ * App ID for OAuth (required for marketplace features)
23
+ * Get it from: https://www.mercadopago.com/developers/panel/app
24
+ */
25
+ appId?: string;
26
+ /**
27
+ * App Secret for OAuth (required for marketplace features)
28
+ */
29
+ appSecret?: string;
30
+ /**
31
+ * Trusted origins for OAuth redirects
32
+ */
33
+ trustedOrigins?: string[];
34
+ /**
35
+ * Callback executed when a payment status changes
36
+ */
37
+ onPaymentUpdate?: (data: {
38
+ payment: MercadoPagoPaymentRecord;
39
+ status: string;
40
+ statusDetail: string;
41
+ mpPayment: MercadoPagoPaymentResponse;
42
+ }) => void | Promise<void>;
43
+ /**
44
+ * Callback executed when a subscription status changes
45
+ */
46
+ onSubscriptionUpdate?: (data: {
47
+ subscription: MercadoPagoSubscriptionRecord;
48
+ status: string;
49
+ reason: string;
50
+ mpPreapproval: MercadoPagoPreApprovalResponse;
51
+ }) => void | Promise<void>;
52
+ /**
53
+ * Callback executed when a recurring payment is processed (monthly, etc.)
54
+ */
55
+ onSubscriptionPayment?: (data: {
56
+ subscription: MercadoPagoSubscriptionRecord;
57
+ payment: MercadoPagoPaymentResponse;
58
+ status: string;
59
+ }) => void | Promise<void>;
60
+ }
61
+ interface MercadoPagoCustomerRecord {
62
+ id: string;
63
+ userId: string;
64
+ mercadoPagoId: string;
65
+ email: string;
66
+ createdAt: Date;
67
+ updatedAt: Date;
68
+ }
69
+ interface MercadoPagoPaymentRecord {
70
+ id: string;
71
+ userId: string;
72
+ mercadoPagoPaymentId: string;
73
+ preferenceId: string;
74
+ status: string;
75
+ amount: number;
76
+ currency: string;
77
+ metadata?: string;
78
+ createdAt: Date;
79
+ updatedAt: Date;
80
+ }
81
+ interface MercadoPagoSubscriptionRecord {
82
+ id: string;
83
+ userId: string;
84
+ mercadoPagoSubscriptionId: string;
85
+ planId: string;
86
+ status: string;
87
+ reason?: string;
88
+ nextPaymentDate?: Date;
89
+ lastPaymentDate?: Date;
90
+ summarized?: string;
91
+ metadata?: string;
92
+ createdAt: Date;
93
+ updatedAt: Date;
94
+ }
95
+ interface MercadoPagoMarketplaceSplitRecord {
96
+ id: string;
97
+ paymentId: string;
98
+ collectorId: string;
99
+ collectorEmail: string;
100
+ applicationFeeAmount?: number;
101
+ applicationFeePercentage?: number;
102
+ netAmount: number;
103
+ metadata?: string;
104
+ createdAt: Date;
105
+ }
106
+ interface MercadoPagoOAuthTokenRecord {
107
+ id: string;
108
+ userId: string;
109
+ accessToken: string;
110
+ refreshToken: string;
111
+ publicKey: string;
112
+ mercadoPagoUserId: string;
113
+ expiresAt: Date;
114
+ createdAt: Date;
115
+ updatedAt: Date;
116
+ }
117
+ interface MercadoPagoPreapprovalPlanRecord {
118
+ id: string;
119
+ mercadoPagoPlanId: string;
120
+ reason: string;
121
+ frequency: number;
122
+ frequencyType: string;
123
+ transactionAmount: number;
124
+ currencyId: string;
125
+ repetitions?: number;
126
+ freeTrial?: string;
127
+ metadata?: string;
128
+ createdAt: Date;
129
+ updatedAt: Date;
130
+ }
131
+ interface PaymentItem {
132
+ id: string;
133
+ title: string;
134
+ quantity: number;
135
+ unitPrice: number;
136
+ currencyId?: string;
137
+ }
138
+ interface MarketplaceConfig {
139
+ collectorId: string;
140
+ applicationFee?: number;
141
+ applicationFeePercentage?: number;
142
+ }
143
+ interface CreatePaymentParams {
144
+ items: PaymentItem[];
145
+ metadata?: Record<string, any>;
146
+ marketplace?: MarketplaceConfig;
147
+ successUrl?: string;
148
+ failureUrl?: string;
149
+ pendingUrl?: string;
150
+ }
151
+ interface CreateSubscriptionParams {
152
+ preapprovalPlanId?: string;
153
+ reason?: string;
154
+ autoRecurring?: {
155
+ frequency: number;
156
+ frequencyType: "days" | "months";
157
+ transactionAmount: number;
158
+ currencyId?: string;
159
+ startDate?: string;
160
+ endDate?: string;
161
+ freeTrial?: {
162
+ frequency: number;
163
+ frequencyType: "days" | "months";
164
+ };
165
+ };
166
+ backUrl?: string;
167
+ metadata?: Record<string, any>;
168
+ }
169
+ interface CreatePreapprovalPlanParams {
170
+ reason: string;
171
+ autoRecurring: {
172
+ frequency: number;
173
+ frequencyType: "days" | "months";
174
+ transactionAmount: number;
175
+ currencyId?: string;
176
+ freeTrial?: {
177
+ frequency: number;
178
+ frequencyType: "days" | "months";
179
+ };
180
+ };
181
+ repetitions?: number;
182
+ backUrl?: string;
183
+ metadata?: Record<string, any>;
184
+ }
185
+ interface CreatePreapprovalPlanResponse {
186
+ plan: MercadoPagoPreapprovalPlanRecord;
187
+ }
188
+ interface CreatePaymentResponse {
189
+ checkoutUrl: string;
190
+ preferenceId: string;
191
+ payment: MercadoPagoPaymentRecord;
192
+ }
193
+ interface CreateSubscriptionResponse {
194
+ checkoutUrl: string;
195
+ subscription: MercadoPagoSubscriptionRecord;
196
+ }
197
+ interface OAuthUrlResponse {
198
+ authUrl: string;
199
+ }
200
+ interface OAuthTokenResponse {
201
+ success: boolean;
202
+ oauthToken: {
203
+ id: string;
204
+ mercadoPagoUserId: string;
205
+ expiresAt: Date;
206
+ };
207
+ }
208
+ interface MercadoPagoPaymentResponse {
209
+ id: number;
210
+ date_created: string;
211
+ date_approved: string;
212
+ date_last_updated: string;
213
+ money_release_date: string;
214
+ payment_method_id: string;
215
+ payment_type_id: string;
216
+ status: string;
217
+ status_detail: string;
218
+ currency_id: string;
219
+ description: string;
220
+ live_mode: boolean;
221
+ sponsor_id: number;
222
+ authorization_code: string;
223
+ integrator_id: string;
224
+ taxes_amount: number;
225
+ counter_currency: string;
226
+ operation_type: string;
227
+ additional_info: {
228
+ items: {
229
+ id: string;
230
+ title: string;
231
+ description: string;
232
+ picture_url: string;
233
+ category_id: string;
234
+ quantity: string;
235
+ unit_price: string;
236
+ }[];
237
+ payer: {
238
+ first_name: string;
239
+ last_name: string;
240
+ phone: {
241
+ area_code: string;
242
+ number: string;
243
+ };
244
+ };
245
+ ip_address: string;
246
+ };
247
+ external_reference: string;
248
+ transaction_amount: number;
249
+ transaction_amount_refunded: number;
250
+ coupon_amount: number;
251
+ installments: number;
252
+ transaction_details: {
253
+ net_received_amount: number;
254
+ total_paid_amount: number;
255
+ overpaid_amount: number;
256
+ external_resource_url: string;
257
+ installment_amount: number;
258
+ financial_institution: string;
259
+ payment_method_reference_id: string;
260
+ };
261
+ }
262
+ interface MercadoPagoPreApprovalResponse {
263
+ id: string;
264
+ payer_id: number;
265
+ payer_email: string;
266
+ back_url: string;
267
+ collector_id: number;
268
+ application_id: number;
269
+ status: string;
270
+ reason: string;
271
+ external_reference: string;
272
+ date_created: string;
273
+ last_modified: string;
274
+ init_point: string;
275
+ auto_recurring: {
276
+ frequency: number;
277
+ frequency_type: string;
278
+ transaction_amount: number;
279
+ currency_id: string;
280
+ start_date: string;
281
+ end_date: string;
282
+ free_trial?: {
283
+ frequency: number;
284
+ frequency_type: string;
285
+ };
286
+ };
287
+ summarized?: {
288
+ quotas: number;
289
+ charged_quantity: number;
290
+ pending_charge_quantity: number;
291
+ charged_amount: number;
292
+ pending_charge_amount: number;
293
+ semester: number;
294
+ year: number;
295
+ };
296
+ next_payment_date: string;
297
+ payment_method_id: string;
298
+ }
299
+
300
+ declare const mercadoPagoPlugin: (options: MercadoPagoPluginOptions) => {
301
+ trustedOrigins?: string[] | undefined;
302
+ id: "mercado-pago";
303
+ schema: {
304
+ mercadoPagoCustomer: {
305
+ fields: {
306
+ id: {
307
+ type: "string";
308
+ required: true;
309
+ };
310
+ userId: {
311
+ type: "string";
312
+ required: true;
313
+ references: {
314
+ model: string;
315
+ field: string;
316
+ onDelete: "cascade";
317
+ };
318
+ };
319
+ mercadoPagoId: {
320
+ type: "string";
321
+ required: true;
322
+ unique: true;
323
+ };
324
+ email: {
325
+ type: "string";
326
+ required: true;
327
+ };
328
+ createdAt: {
329
+ type: "date";
330
+ required: true;
331
+ };
332
+ updatedAt: {
333
+ type: "date";
334
+ required: true;
335
+ };
336
+ };
337
+ };
338
+ mercadoPagoPayment: {
339
+ fields: {
340
+ id: {
341
+ type: "string";
342
+ required: true;
343
+ };
344
+ userId: {
345
+ type: "string";
346
+ required: true;
347
+ references: {
348
+ model: string;
349
+ field: string;
350
+ onDelete: "cascade";
351
+ };
352
+ };
353
+ mercadoPagoPaymentId: {
354
+ type: "string";
355
+ required: true;
356
+ unique: true;
357
+ };
358
+ preferenceId: {
359
+ type: "string";
360
+ required: true;
361
+ };
362
+ status: {
363
+ type: "string";
364
+ required: true;
365
+ };
366
+ statusDetail: {
367
+ type: "string";
368
+ };
369
+ amount: {
370
+ type: "number";
371
+ required: true;
372
+ };
373
+ currency: {
374
+ type: "string";
375
+ required: true;
376
+ };
377
+ paymentMethodId: {
378
+ type: "string";
379
+ };
380
+ paymentTypeId: {
381
+ type: "string";
382
+ };
383
+ metadata: {
384
+ type: "string";
385
+ };
386
+ createdAt: {
387
+ type: "date";
388
+ required: true;
389
+ };
390
+ updatedAt: {
391
+ type: "date";
392
+ required: true;
393
+ };
394
+ };
395
+ };
396
+ mercadoPagoSubscription: {
397
+ fields: {
398
+ id: {
399
+ type: "string";
400
+ required: true;
401
+ };
402
+ userId: {
403
+ type: "string";
404
+ required: true;
405
+ references: {
406
+ model: string;
407
+ field: string;
408
+ onDelete: "cascade";
409
+ };
410
+ };
411
+ mercadoPagoSubscriptionId: {
412
+ type: "string";
413
+ required: true;
414
+ unique: true;
415
+ };
416
+ planId: {
417
+ type: "string";
418
+ required: true;
419
+ };
420
+ status: {
421
+ type: "string";
422
+ required: true;
423
+ };
424
+ reason: {
425
+ type: "string";
426
+ };
427
+ nextPaymentDate: {
428
+ type: "date";
429
+ };
430
+ lastPaymentDate: {
431
+ type: "date";
432
+ };
433
+ summarized: {
434
+ type: "string";
435
+ };
436
+ metadata: {
437
+ type: "string";
438
+ };
439
+ createdAt: {
440
+ type: "date";
441
+ required: true;
442
+ };
443
+ updatedAt: {
444
+ type: "date";
445
+ required: true;
446
+ };
447
+ };
448
+ };
449
+ mercadoPagoPreapprovalPlan: {
450
+ fields: {
451
+ id: {
452
+ type: "string";
453
+ required: true;
454
+ };
455
+ mercadoPagoPlanId: {
456
+ type: "string";
457
+ required: true;
458
+ unique: true;
459
+ };
460
+ reason: {
461
+ type: "string";
462
+ required: true;
463
+ };
464
+ frequency: {
465
+ type: "number";
466
+ required: true;
467
+ };
468
+ frequencyType: {
469
+ type: "string";
470
+ required: true;
471
+ };
472
+ transactionAmount: {
473
+ type: "number";
474
+ required: true;
475
+ };
476
+ currencyId: {
477
+ type: "string";
478
+ required: true;
479
+ };
480
+ repetitions: {
481
+ type: "number";
482
+ };
483
+ freeTrial: {
484
+ type: "string";
485
+ };
486
+ metadata: {
487
+ type: "string";
488
+ };
489
+ createdAt: {
490
+ type: "date";
491
+ required: true;
492
+ };
493
+ updatedAt: {
494
+ type: "date";
495
+ required: true;
496
+ };
497
+ };
498
+ };
499
+ mercadoPagoMarketplaceSplit: {
500
+ fields: {
501
+ id: {
502
+ type: "string";
503
+ required: true;
504
+ };
505
+ paymentId: {
506
+ type: "string";
507
+ required: true;
508
+ references: {
509
+ model: string;
510
+ field: string;
511
+ onDelete: "cascade";
512
+ };
513
+ };
514
+ collectorId: {
515
+ type: "string";
516
+ required: true;
517
+ };
518
+ collectorEmail: {
519
+ type: "string";
520
+ required: true;
521
+ };
522
+ applicationFeeAmount: {
523
+ type: "number";
524
+ };
525
+ applicationFeePercentage: {
526
+ type: "number";
527
+ };
528
+ netAmount: {
529
+ type: "number";
530
+ required: true;
531
+ };
532
+ metadata: {
533
+ type: "string";
534
+ };
535
+ createdAt: {
536
+ type: "date";
537
+ required: true;
538
+ };
539
+ };
540
+ };
541
+ mercadoPagoOAuthToken: {
542
+ fields: {
543
+ id: {
544
+ type: "string";
545
+ required: true;
546
+ };
547
+ userId: {
548
+ type: "string";
549
+ required: true;
550
+ references: {
551
+ model: string;
552
+ field: string;
553
+ onDelete: "cascade";
554
+ };
555
+ };
556
+ accessToken: {
557
+ type: "string";
558
+ required: true;
559
+ };
560
+ refreshToken: {
561
+ type: "string";
562
+ required: true;
563
+ };
564
+ publicKey: {
565
+ type: "string";
566
+ required: true;
567
+ };
568
+ mercadoPagoUserId: {
569
+ type: "string";
570
+ required: true;
571
+ unique: true;
572
+ };
573
+ expiresAt: {
574
+ type: "date";
575
+ required: true;
576
+ };
577
+ createdAt: {
578
+ type: "date";
579
+ required: true;
580
+ };
581
+ updatedAt: {
582
+ type: "date";
583
+ required: true;
584
+ };
585
+ };
586
+ };
587
+ };
588
+ endpoints: {
589
+ getOrCreateCustomer: better_auth.StrictEndpoint<"/mercado-pago/customer", {
590
+ method: "POST";
591
+ requireAuth: boolean;
592
+ body: z.ZodObject<{
593
+ email: z.ZodOptional<z.ZodString>;
594
+ firstName: z.ZodOptional<z.ZodString>;
595
+ lastName: z.ZodOptional<z.ZodString>;
596
+ }, "strip", z.ZodTypeAny, {
597
+ email?: string | undefined;
598
+ firstName?: string | undefined;
599
+ lastName?: string | undefined;
600
+ }, {
601
+ email?: string | undefined;
602
+ firstName?: string | undefined;
603
+ lastName?: string | undefined;
604
+ }>;
605
+ }, {
606
+ customer: {};
607
+ }>;
608
+ getOAuthUrl: better_auth.StrictEndpoint<"/mercado-pago/oauth/authorize", {
609
+ method: "GET";
610
+ requireAuth: boolean;
611
+ query: z.ZodObject<{
612
+ redirectUri: z.ZodString;
613
+ }, "strip", z.ZodTypeAny, {
614
+ redirectUri: string;
615
+ }, {
616
+ redirectUri: string;
617
+ }>;
618
+ }, {
619
+ authUrl: string;
620
+ }>;
621
+ exchangeOAuthCode: better_auth.StrictEndpoint<"/mercado-pago/oauth/callback", {
622
+ method: "POST";
623
+ requireAuth: boolean;
624
+ body: z.ZodObject<{
625
+ code: z.ZodString;
626
+ redirectUri: z.ZodString;
627
+ }, "strip", z.ZodTypeAny, {
628
+ code: string;
629
+ redirectUri: string;
630
+ }, {
631
+ code: string;
632
+ redirectUri: string;
633
+ }>;
634
+ }, {
635
+ success: boolean;
636
+ oauthToken: {
637
+ id: any;
638
+ mercadoPagoUserId: any;
639
+ expiresAt: any;
640
+ };
641
+ }>;
642
+ createPreapprovalPlan: better_auth.StrictEndpoint<"/mercado-pago/plan/create", {
643
+ method: "POST";
644
+ body: z.ZodObject<{
645
+ reason: z.ZodString;
646
+ autoRecurring: z.ZodObject<{
647
+ frequency: z.ZodNumber;
648
+ frequencyType: z.ZodEnum<["days", "months"]>;
649
+ transactionAmount: z.ZodNumber;
650
+ currencyId: z.ZodDefault<z.ZodString>;
651
+ freeTrial: z.ZodOptional<z.ZodObject<{
652
+ frequency: z.ZodNumber;
653
+ frequencyType: z.ZodEnum<["days", "months"]>;
654
+ }, "strip", z.ZodTypeAny, {
655
+ frequency: number;
656
+ frequencyType: "days" | "months";
657
+ }, {
658
+ frequency: number;
659
+ frequencyType: "days" | "months";
660
+ }>>;
661
+ }, "strip", z.ZodTypeAny, {
662
+ frequency: number;
663
+ frequencyType: "days" | "months";
664
+ transactionAmount: number;
665
+ currencyId: string;
666
+ freeTrial?: {
667
+ frequency: number;
668
+ frequencyType: "days" | "months";
669
+ } | undefined;
670
+ }, {
671
+ frequency: number;
672
+ frequencyType: "days" | "months";
673
+ transactionAmount: number;
674
+ currencyId?: string | undefined;
675
+ freeTrial?: {
676
+ frequency: number;
677
+ frequencyType: "days" | "months";
678
+ } | undefined;
679
+ }>;
680
+ repetitions: z.ZodOptional<z.ZodNumber>;
681
+ backUrl: z.ZodOptional<z.ZodString>;
682
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
683
+ }, "strip", z.ZodTypeAny, {
684
+ reason: string;
685
+ autoRecurring: {
686
+ frequency: number;
687
+ frequencyType: "days" | "months";
688
+ transactionAmount: number;
689
+ currencyId: string;
690
+ freeTrial?: {
691
+ frequency: number;
692
+ frequencyType: "days" | "months";
693
+ } | undefined;
694
+ };
695
+ metadata?: Record<string, any> | undefined;
696
+ repetitions?: number | undefined;
697
+ backUrl?: string | undefined;
698
+ }, {
699
+ reason: string;
700
+ autoRecurring: {
701
+ frequency: number;
702
+ frequencyType: "days" | "months";
703
+ transactionAmount: number;
704
+ currencyId?: string | undefined;
705
+ freeTrial?: {
706
+ frequency: number;
707
+ frequencyType: "days" | "months";
708
+ } | undefined;
709
+ };
710
+ metadata?: Record<string, any> | undefined;
711
+ repetitions?: number | undefined;
712
+ backUrl?: string | undefined;
713
+ }>;
714
+ }, {
715
+ plan: Record<string, any>;
716
+ }>;
717
+ listPreapprovalPlans: better_auth.StrictEndpoint<"/mercado-pago/plans", {
718
+ method: "GET";
719
+ }, {
720
+ plans: unknown[];
721
+ }>;
722
+ createPayment: better_auth.StrictEndpoint<"/mercado-pago/payment/create", {
723
+ method: "POST";
724
+ requireAuth: boolean;
725
+ body: z.ZodObject<{
726
+ items: z.ZodArray<z.ZodObject<{
727
+ id: z.ZodString;
728
+ title: z.ZodString;
729
+ quantity: z.ZodNumber;
730
+ unitPrice: z.ZodNumber;
731
+ currencyId: z.ZodDefault<z.ZodString>;
732
+ }, "strip", z.ZodTypeAny, {
733
+ id: string;
734
+ currencyId: string;
735
+ title: string;
736
+ quantity: number;
737
+ unitPrice: number;
738
+ }, {
739
+ id: string;
740
+ title: string;
741
+ quantity: number;
742
+ unitPrice: number;
743
+ currencyId?: string | undefined;
744
+ }>, "many">;
745
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
746
+ marketplace: z.ZodOptional<z.ZodObject<{
747
+ collectorId: z.ZodString;
748
+ applicationFee: z.ZodOptional<z.ZodNumber>;
749
+ applicationFeePercentage: z.ZodOptional<z.ZodNumber>;
750
+ }, "strip", z.ZodTypeAny, {
751
+ collectorId: string;
752
+ applicationFeePercentage?: number | undefined;
753
+ applicationFee?: number | undefined;
754
+ }, {
755
+ collectorId: string;
756
+ applicationFeePercentage?: number | undefined;
757
+ applicationFee?: number | undefined;
758
+ }>>;
759
+ successUrl: z.ZodOptional<z.ZodString>;
760
+ failureUrl: z.ZodOptional<z.ZodString>;
761
+ pendingUrl: z.ZodOptional<z.ZodString>;
762
+ idempotencyKey: z.ZodOptional<z.ZodString>;
763
+ }, "strip", z.ZodTypeAny, {
764
+ items: {
765
+ id: string;
766
+ currencyId: string;
767
+ title: string;
768
+ quantity: number;
769
+ unitPrice: number;
770
+ }[];
771
+ metadata?: Record<string, any> | undefined;
772
+ marketplace?: {
773
+ collectorId: string;
774
+ applicationFeePercentage?: number | undefined;
775
+ applicationFee?: number | undefined;
776
+ } | undefined;
777
+ successUrl?: string | undefined;
778
+ failureUrl?: string | undefined;
779
+ pendingUrl?: string | undefined;
780
+ idempotencyKey?: string | undefined;
781
+ }, {
782
+ items: {
783
+ id: string;
784
+ title: string;
785
+ quantity: number;
786
+ unitPrice: number;
787
+ currencyId?: string | undefined;
788
+ }[];
789
+ metadata?: Record<string, any> | undefined;
790
+ marketplace?: {
791
+ collectorId: string;
792
+ applicationFeePercentage?: number | undefined;
793
+ applicationFee?: number | undefined;
794
+ } | undefined;
795
+ successUrl?: string | undefined;
796
+ failureUrl?: string | undefined;
797
+ pendingUrl?: string | undefined;
798
+ idempotencyKey?: string | undefined;
799
+ }>;
800
+ }, any>;
801
+ createSubscription: better_auth.StrictEndpoint<"/mercado-pago/subscription/create", {
802
+ method: "POST";
803
+ requireAuth: boolean;
804
+ body: z.ZodObject<{
805
+ preapprovalPlanId: z.ZodOptional<z.ZodString>;
806
+ reason: z.ZodOptional<z.ZodString>;
807
+ autoRecurring: z.ZodOptional<z.ZodObject<{
808
+ frequency: z.ZodNumber;
809
+ frequencyType: z.ZodEnum<["days", "months"]>;
810
+ transactionAmount: z.ZodNumber;
811
+ currencyId: z.ZodDefault<z.ZodString>;
812
+ startDate: z.ZodOptional<z.ZodString>;
813
+ endDate: z.ZodOptional<z.ZodString>;
814
+ freeTrial: z.ZodOptional<z.ZodObject<{
815
+ frequency: z.ZodNumber;
816
+ frequencyType: z.ZodEnum<["days", "months"]>;
817
+ }, "strip", z.ZodTypeAny, {
818
+ frequency: number;
819
+ frequencyType: "days" | "months";
820
+ }, {
821
+ frequency: number;
822
+ frequencyType: "days" | "months";
823
+ }>>;
824
+ }, "strip", z.ZodTypeAny, {
825
+ frequency: number;
826
+ frequencyType: "days" | "months";
827
+ transactionAmount: number;
828
+ currencyId: string;
829
+ freeTrial?: {
830
+ frequency: number;
831
+ frequencyType: "days" | "months";
832
+ } | undefined;
833
+ startDate?: string | undefined;
834
+ endDate?: string | undefined;
835
+ }, {
836
+ frequency: number;
837
+ frequencyType: "days" | "months";
838
+ transactionAmount: number;
839
+ currencyId?: string | undefined;
840
+ freeTrial?: {
841
+ frequency: number;
842
+ frequencyType: "days" | "months";
843
+ } | undefined;
844
+ startDate?: string | undefined;
845
+ endDate?: string | undefined;
846
+ }>>;
847
+ backUrl: z.ZodOptional<z.ZodString>;
848
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
849
+ }, "strip", z.ZodTypeAny, {
850
+ metadata?: Record<string, any> | undefined;
851
+ reason?: string | undefined;
852
+ autoRecurring?: {
853
+ frequency: number;
854
+ frequencyType: "days" | "months";
855
+ transactionAmount: number;
856
+ currencyId: string;
857
+ freeTrial?: {
858
+ frequency: number;
859
+ frequencyType: "days" | "months";
860
+ } | undefined;
861
+ startDate?: string | undefined;
862
+ endDate?: string | undefined;
863
+ } | undefined;
864
+ backUrl?: string | undefined;
865
+ preapprovalPlanId?: string | undefined;
866
+ }, {
867
+ metadata?: Record<string, any> | undefined;
868
+ reason?: string | undefined;
869
+ autoRecurring?: {
870
+ frequency: number;
871
+ frequencyType: "days" | "months";
872
+ transactionAmount: number;
873
+ currencyId?: string | undefined;
874
+ freeTrial?: {
875
+ frequency: number;
876
+ frequencyType: "days" | "months";
877
+ } | undefined;
878
+ startDate?: string | undefined;
879
+ endDate?: string | undefined;
880
+ } | undefined;
881
+ backUrl?: string | undefined;
882
+ preapprovalPlanId?: string | undefined;
883
+ }>;
884
+ }, {
885
+ checkoutUrl: string | undefined;
886
+ subscription: Record<string, any>;
887
+ }>;
888
+ cancelSubscription: better_auth.StrictEndpoint<"/mercado-pago/subscription/cancel", {
889
+ method: "POST";
890
+ requireAuth: boolean;
891
+ body: z.ZodObject<{
892
+ subscriptionId: z.ZodString;
893
+ }, "strip", z.ZodTypeAny, {
894
+ subscriptionId: string;
895
+ }, {
896
+ subscriptionId: string;
897
+ }>;
898
+ }, {
899
+ success: boolean;
900
+ }>;
901
+ getPayment: better_auth.StrictEndpoint<"/mercado-pago/payment/:id", {
902
+ method: "GET";
903
+ requireAuth: boolean;
904
+ }, {
905
+ payment: MercadoPagoPaymentRecord;
906
+ }>;
907
+ listPayments: better_auth.StrictEndpoint<"/mercado-pago/payments", {
908
+ method: "GET";
909
+ requireAuth: boolean;
910
+ query: z.ZodObject<{
911
+ limit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
912
+ offset: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
913
+ }, "strip", z.ZodTypeAny, {
914
+ limit: number;
915
+ offset: number;
916
+ }, {
917
+ limit?: number | undefined;
918
+ offset?: number | undefined;
919
+ }>;
920
+ }, {
921
+ payments: unknown[];
922
+ }>;
923
+ listSubscriptions: better_auth.StrictEndpoint<"/mercado-pago/subscriptions", {
924
+ method: "GET";
925
+ requireAuth: boolean;
926
+ }, {
927
+ subscriptions: unknown[];
928
+ }>;
929
+ webhook: better_auth.StrictEndpoint<"/mercado-pago/webhook", {
930
+ method: "POST";
931
+ }, {
932
+ received: boolean;
933
+ }>;
934
+ };
935
+ };
936
+
937
+ declare const mercadoPagoClient: () => {
938
+ id: "mercado-pago";
939
+ $InferServerPlugin: ReturnType<typeof mercadoPagoPlugin>;
940
+ getActions: ($fetch: better_auth_client.BetterFetch) => {
941
+ /**
942
+ * Get or create a Mercado Pago customer for the authenticated user
943
+ */
944
+ getOrCreateCustomer: (data?: {
945
+ email?: string;
946
+ firstName?: string;
947
+ lastName?: string;
948
+ }, fetchOptions?: BetterFetchOption) => Promise<{
949
+ data: {
950
+ customer: MercadoPagoCustomerRecord;
951
+ };
952
+ error: null;
953
+ } | {
954
+ data: null;
955
+ error: {
956
+ message?: string | undefined;
957
+ status: number;
958
+ statusText: string;
959
+ };
960
+ }>;
961
+ /**
962
+ * Create a payment and get checkout URL
963
+ *
964
+ * @example
965
+ * ```ts
966
+ * const { data } = await authClient.mercadoPago.createPayment({
967
+ * items: [{
968
+ * title: "Premium Plan",
969
+ * quantity: 1,
970
+ * unitPrice: 99.90,
971
+ * currencyId: "ARS"
972
+ * }]
973
+ * });
974
+ *
975
+ * // Redirect user to checkout
976
+ * window.location.href = data.checkoutUrl;
977
+ * ```
978
+ */
979
+ createPayment: (data: CreatePaymentParams, fetchOptions?: BetterFetchOption) => Promise<{
980
+ data: null;
981
+ error: {
982
+ message?: string | undefined;
983
+ status: number;
984
+ statusText: string;
985
+ };
986
+ } | {
987
+ data: CreatePaymentResponse;
988
+ error: null;
989
+ }>;
990
+ /**
991
+ * Create a marketplace payment with automatic split
992
+ *
993
+ * You need to have the seller's MP User ID (collector_id) which they get
994
+ * after authorizing your app via OAuth.
995
+ *
996
+ * @example
997
+ * ```ts
998
+ * const { data } = await authClient.mercadoPago.createPayment({
999
+ * items: [{
1000
+ * title: "Product from Seller",
1001
+ * quantity: 1,
1002
+ * unitPrice: 100
1003
+ * }],
1004
+ * marketplace: {
1005
+ * collectorId: "123456789", // Seller's MP User ID
1006
+ * applicationFeePercentage: 10 // Platform keeps 10%
1007
+ * }
1008
+ * });
1009
+ * ```
1010
+ */
1011
+ createMarketplacePayment: (data: CreatePaymentParams, fetchOptions?: BetterFetchOption) => Promise<{
1012
+ data: null;
1013
+ error: {
1014
+ message?: string | undefined;
1015
+ status: number;
1016
+ statusText: string;
1017
+ };
1018
+ } | {
1019
+ data: CreatePaymentResponse;
1020
+ error: null;
1021
+ }>;
1022
+ /**
1023
+ * Create a subscription with recurring payments
1024
+ *
1025
+ * Supports two modes:
1026
+ * 1. With preapproval plan (reusable): Pass preapprovalPlanId
1027
+ * 2. Direct subscription (one-off): Pass reason + autoRecurring
1028
+ *
1029
+ * @example With plan
1030
+ * ```ts
1031
+ * const { data } = await authClient.mercadoPago.createSubscription({
1032
+ * preapprovalPlanId: "plan_abc123"
1033
+ * });
1034
+ * ```
1035
+ *
1036
+ * @example Direct (without plan)
1037
+ * ```ts
1038
+ * const { data } = await authClient.mercadoPago.createSubscription({
1039
+ * reason: "Premium Monthly Plan",
1040
+ * autoRecurring: {
1041
+ * frequency: 1,
1042
+ * frequencyType: "months",
1043
+ * transactionAmount: 99.90,
1044
+ * currencyId: "ARS"
1045
+ * }
1046
+ * });
1047
+ * ```
1048
+ */
1049
+ createSubscription: (data: CreateSubscriptionParams, fetchOptions?: BetterFetchOption) => Promise<{
1050
+ data: null;
1051
+ error: {
1052
+ message?: string | undefined;
1053
+ status: number;
1054
+ statusText: string;
1055
+ };
1056
+ } | {
1057
+ data: CreateSubscriptionResponse;
1058
+ error: null;
1059
+ }>;
1060
+ /**
1061
+ * Cancel a subscription
1062
+ *
1063
+ * @example
1064
+ * ```ts
1065
+ * await authClient.mercadoPago.cancelSubscription({
1066
+ * subscriptionId: "sub_123"
1067
+ * });
1068
+ * ```
1069
+ */
1070
+ cancelSubscription: (data: {
1071
+ subscriptionId: string;
1072
+ }, fetchOptions?: BetterFetchOption) => Promise<{
1073
+ data: null;
1074
+ error: {
1075
+ message?: string | undefined;
1076
+ status: number;
1077
+ statusText: string;
1078
+ };
1079
+ } | {
1080
+ data: {
1081
+ success: boolean;
1082
+ };
1083
+ error: null;
1084
+ }>;
1085
+ /**
1086
+ * Create a reusable preapproval plan (subscription template)
1087
+ *
1088
+ * Plans can be reused for multiple subscriptions. Create once,
1089
+ * use many times with createSubscription({ preapprovalPlanId })
1090
+ *
1091
+ * @example
1092
+ * ```ts
1093
+ * const { data } = await authClient.mercadoPago.createPreapprovalPlan({
1094
+ * reason: "Premium Monthly",
1095
+ * autoRecurring: {
1096
+ * frequency: 1,
1097
+ * frequencyType: "months",
1098
+ * transactionAmount: 99.90,
1099
+ * freeTrial: {
1100
+ * frequency: 7,
1101
+ * frequencyType: "days"
1102
+ * }
1103
+ * },
1104
+ * repetitions: 12 // 12 months, omit for infinite
1105
+ * });
1106
+ *
1107
+ * // Use the plan
1108
+ * const planId = data.plan.mercadoPagoPlanId;
1109
+ * ```
1110
+ */
1111
+ createPreapprovalPlan: (data: CreatePreapprovalPlanParams, fetchOptions?: BetterFetchOption) => Promise<{
1112
+ data: null;
1113
+ error: {
1114
+ message?: string | undefined;
1115
+ status: number;
1116
+ statusText: string;
1117
+ };
1118
+ } | {
1119
+ data: CreatePreapprovalPlanResponse;
1120
+ error: null;
1121
+ }>;
1122
+ /**
1123
+ * List all preapproval plans
1124
+ *
1125
+ * @example
1126
+ * ```ts
1127
+ * const { data } = await authClient.mercadoPago.listPreapprovalPlans();
1128
+ *
1129
+ * data.plans.forEach(plan => {
1130
+ * console.log(plan.reason); // "Premium Monthly"
1131
+ * console.log(plan.transactionAmount); // 99.90
1132
+ * });
1133
+ * ```
1134
+ */
1135
+ listPreapprovalPlans: (fetchOptions?: BetterFetchOption) => Promise<{
1136
+ data: null;
1137
+ error: {
1138
+ message?: string | undefined;
1139
+ status: number;
1140
+ statusText: string;
1141
+ };
1142
+ } | {
1143
+ data: {
1144
+ plans: MercadoPagoPreapprovalPlanRecord[];
1145
+ };
1146
+ error: null;
1147
+ }>;
1148
+ /**
1149
+ * Get payment by ID
1150
+ */
1151
+ getPayment: (paymentId: string, fetchOptions?: BetterFetchOption) => Promise<{
1152
+ data: null;
1153
+ error: {
1154
+ message?: string | undefined;
1155
+ status: number;
1156
+ statusText: string;
1157
+ };
1158
+ } | {
1159
+ data: {
1160
+ payment: MercadoPagoPaymentRecord;
1161
+ };
1162
+ error: null;
1163
+ }>;
1164
+ /**
1165
+ * List all payments for the authenticated user
1166
+ *
1167
+ * @example
1168
+ * ```ts
1169
+ * const { data } = await authClient.mercadoPago.listPayments({
1170
+ * limit: 20,
1171
+ * offset: 0
1172
+ * });
1173
+ * ```
1174
+ */
1175
+ listPayments: (params?: {
1176
+ limit?: number;
1177
+ offset?: number;
1178
+ }, fetchOptions?: BetterFetchOption) => Promise<{
1179
+ data: null;
1180
+ error: {
1181
+ message?: string | undefined;
1182
+ status: number;
1183
+ statusText: string;
1184
+ };
1185
+ } | {
1186
+ data: {
1187
+ payments: MercadoPagoPaymentRecord[];
1188
+ };
1189
+ error: null;
1190
+ }>;
1191
+ /**
1192
+ * List all subscriptions for the authenticated user
1193
+ *
1194
+ * @example
1195
+ * ```ts
1196
+ * const { data } = await authClient.mercadoPago.listSubscriptions();
1197
+ * ```
1198
+ */
1199
+ listSubscriptions: (fetchOptions?: BetterFetchOption) => Promise<{
1200
+ data: null;
1201
+ error: {
1202
+ message?: string | undefined;
1203
+ status: number;
1204
+ statusText: string;
1205
+ };
1206
+ } | {
1207
+ data: {
1208
+ subscriptions: MercadoPagoSubscriptionRecord[];
1209
+ };
1210
+ error: null;
1211
+ }>;
1212
+ /**
1213
+ * Get OAuth authorization URL for marketplace sellers
1214
+ *
1215
+ * This is Step 1 of OAuth flow. Redirect the seller to this URL so they
1216
+ * can authorize your app to process payments on their behalf.
1217
+ *
1218
+ * @example
1219
+ * ```ts
1220
+ * const { data } = await authClient.mercadoPago.getOAuthUrl({
1221
+ * redirectUri: "https://myapp.com/oauth/callback"
1222
+ * });
1223
+ *
1224
+ * // Redirect seller to authorize
1225
+ * window.location.href = data.authUrl;
1226
+ * ```
1227
+ */
1228
+ getOAuthUrl: (params: {
1229
+ redirectUri: string;
1230
+ }, fetchOptions?: BetterFetchOption) => Promise<{
1231
+ data: null;
1232
+ error: {
1233
+ message?: string | undefined;
1234
+ status: number;
1235
+ statusText: string;
1236
+ };
1237
+ } | {
1238
+ data: OAuthUrlResponse;
1239
+ error: null;
1240
+ }>;
1241
+ /**
1242
+ * Exchange OAuth code for access token
1243
+ *
1244
+ * This is Step 2 of OAuth flow. After the seller authorizes and MP redirects
1245
+ * them back with a code, exchange that code for an access token.
1246
+ *
1247
+ * @example
1248
+ * ```ts
1249
+ * // In your /oauth/callback page:
1250
+ * const code = new URLSearchParams(window.location.search).get("code");
1251
+ *
1252
+ * const { data } = await authClient.mercadoPago.exchangeOAuthCode({
1253
+ * code,
1254
+ * redirectUri: "https://myapp.com/oauth/callback"
1255
+ * });
1256
+ *
1257
+ * // Now you have the seller's MP User ID
1258
+ * console.log(data.oauthToken.mercadoPagoUserId);
1259
+ * ```
1260
+ */
1261
+ exchangeOAuthCode: (data: {
1262
+ code: string;
1263
+ redirectUri: string;
1264
+ }, fetchOptions?: BetterFetchOption) => Promise<{
1265
+ data: null;
1266
+ error: {
1267
+ message?: string | undefined;
1268
+ status: number;
1269
+ statusText: string;
1270
+ };
1271
+ } | {
1272
+ data: OAuthTokenResponse;
1273
+ error: null;
1274
+ }>;
1275
+ };
1276
+ };
1277
+
1278
+ export { type CreatePaymentParams, type CreatePaymentResponse, type CreatePreapprovalPlanParams, type CreatePreapprovalPlanResponse, type CreateSubscriptionParams, type CreateSubscriptionResponse, type MarketplaceConfig, type MercadoPagoCustomerRecord, type MercadoPagoMarketplaceSplitRecord, type MercadoPagoOAuthTokenRecord, type MercadoPagoPaymentRecord, type MercadoPagoPaymentResponse, type MercadoPagoPluginOptions, type MercadoPagoPreApprovalResponse, type MercadoPagoPreapprovalPlanRecord, type MercadoPagoSubscriptionRecord, type OAuthTokenResponse, type OAuthUrlResponse, type PaymentItem, mercadoPagoClient, mercadoPagoPlugin };