@ar-agents/mercadopago 0.1.0 → 0.3.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.
package/dist/index.d.ts CHANGED
@@ -66,6 +66,23 @@ declare class MercadoPagoRateLimitError extends MercadoPagoError {
66
66
  retryAfterSeconds: number | null;
67
67
  constructor(endpoint: string, retryAfterSeconds: number | null, body?: unknown);
68
68
  }
69
+ /**
70
+ * Thrown when MP is overloaded and serves an HTML 503 page instead of a JSON
71
+ * error. The library detects content-type !== application/json on 5xx and
72
+ * raises this typed error so retry logic + agent UX can branch correctly.
73
+ */
74
+ declare class MercadoPagoOverloadedError extends MercadoPagoError {
75
+ constructor(endpoint: string, status: number);
76
+ }
77
+ /**
78
+ * Thrown when a request exceeds the configured `requestTimeoutMs`. Retried
79
+ * automatically up to `maxRetries`; this surfaces only when the budget runs
80
+ * out.
81
+ */
82
+ declare class MercadoPagoTimeoutError extends MercadoPagoError {
83
+ readonly timeoutMs: number;
84
+ constructor(endpoint: string, timeoutMs: number);
85
+ }
69
86
  /**
70
87
  * Maps an MP error response body to the most specific known error class. Falls
71
88
  * back to the generic MercadoPagoError when no specific pattern matches.
@@ -217,6 +234,391 @@ interface ParsedWebhookEvent {
217
234
  /** Raw body MP sent, for caller inspection / debugging. */
218
235
  raw: WebhookBody;
219
236
  }
237
+ /**
238
+ * Top-level lifecycle status of a payment. MP-canonical values; widened to
239
+ * string for forward compatibility.
240
+ */
241
+ declare const PaymentStatusSchema: z.ZodUnion<readonly [z.ZodLiteral<"pending">, z.ZodLiteral<"approved">, z.ZodLiteral<"authorized">, z.ZodLiteral<"in_process">, z.ZodLiteral<"in_mediation">, z.ZodLiteral<"rejected">, z.ZodLiteral<"cancelled">, z.ZodLiteral<"refunded">, z.ZodLiteral<"charged_back">, z.ZodString]>;
242
+ type PaymentStatus = z.infer<typeof PaymentStatusSchema>;
243
+ /**
244
+ * The full Payment object MP returns. Many fields are optional because they
245
+ * vary by payment method, status, and integration mode (Checkout Pro vs API).
246
+ */
247
+ declare const PaymentSchema: z.ZodObject<{
248
+ id: z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>;
249
+ status: z.ZodUnion<readonly [z.ZodLiteral<"pending">, z.ZodLiteral<"approved">, z.ZodLiteral<"authorized">, z.ZodLiteral<"in_process">, z.ZodLiteral<"in_mediation">, z.ZodLiteral<"rejected">, z.ZodLiteral<"cancelled">, z.ZodLiteral<"refunded">, z.ZodLiteral<"charged_back">, z.ZodString]>;
250
+ status_detail: z.ZodOptional<z.ZodNullable<z.ZodString>>;
251
+ date_created: z.ZodOptional<z.ZodNullable<z.ZodString>>;
252
+ date_approved: z.ZodOptional<z.ZodNullable<z.ZodString>>;
253
+ date_last_updated: z.ZodOptional<z.ZodNullable<z.ZodString>>;
254
+ transaction_amount: z.ZodNumber;
255
+ currency_id: z.ZodString;
256
+ installments: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
257
+ payment_method_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
258
+ payment_type_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
259
+ external_reference: z.ZodOptional<z.ZodNullable<z.ZodString>>;
260
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
261
+ payer: z.ZodOptional<z.ZodObject<{
262
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
263
+ email: z.ZodOptional<z.ZodNullable<z.ZodString>>;
264
+ identification: z.ZodOptional<z.ZodNullable<z.ZodObject<{
265
+ type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
266
+ number: z.ZodOptional<z.ZodNullable<z.ZodString>>;
267
+ }, z.core.$strip>>>;
268
+ }, z.core.$loose>>;
269
+ transaction_details: z.ZodOptional<z.ZodObject<{
270
+ net_received_amount: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
271
+ total_paid_amount: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
272
+ installment_amount: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
273
+ }, z.core.$loose>>;
274
+ }, z.core.$loose>;
275
+ type Payment = z.infer<typeof PaymentSchema>;
276
+ /** Params for creating a payment (Checkout API / transparent flow). */
277
+ interface CreatePaymentParams {
278
+ /** Amount in account currency. ARS for Argentina. */
279
+ transactionAmount: number;
280
+ /** Number of installments. Use 1 for no cuotas; AR cards typically allow up to 12. */
281
+ installments?: number;
282
+ /** MP payment_method_id — `visa`, `master`, `naranja`, `account_money`, etc. */
283
+ paymentMethodId: string;
284
+ /** Payer email — REQUIRED. Cannot equal seller email. */
285
+ payerEmail: string;
286
+ /** Card token from MP frontend SDK (Cardform). Required for credit/debit; omit for `account_money` etc. */
287
+ token?: string;
288
+ /** Description shown in payer's MP statement. */
289
+ description?: string;
290
+ /** Your-system identifier for correlation. */
291
+ externalReference?: string;
292
+ /** Optional payer identification (DNI/CUIT) — required for some payment types. */
293
+ identification?: {
294
+ type: "DNI" | "CUIT" | "CUIL";
295
+ number: string;
296
+ };
297
+ /** Webhook override URL. Falls back to dashboard config if omitted. */
298
+ notificationUrl?: string;
299
+ /** AFIP/ARCA discount/fee/tax additions. Used to discriminate IVA, marketplace fees, etc. */
300
+ additionalInfo?: {
301
+ items?: Array<{
302
+ id?: string;
303
+ title: string;
304
+ quantity: number;
305
+ unit_price: number;
306
+ description?: string;
307
+ }>;
308
+ };
309
+ /** Statement descriptor — what shows on the buyer's card statement. Max 13 chars. */
310
+ statementDescriptor?: string;
311
+ /** When true, capture is deferred (only for credit cards) — useful for hold flows. */
312
+ capture?: boolean;
313
+ /** Idempotency key — pass the same value on retries to dedupe. Required for non-GET. */
314
+ idempotencyKey?: string;
315
+ }
316
+ interface SearchPaymentsParams {
317
+ /** Filter by external_reference (your-system id). */
318
+ externalReference?: string;
319
+ /** Filter by payment status. */
320
+ status?: PaymentStatus;
321
+ /** Filter by payer email. */
322
+ payerEmail?: string;
323
+ /** Date range for date_created (ISO 8601). */
324
+ beginDate?: string;
325
+ endDate?: string;
326
+ /** Result page (default 0). */
327
+ offset?: number;
328
+ /** Page size (default 30, max 100). */
329
+ limit?: number;
330
+ /** Sort: e.g. "date_created" desc. */
331
+ sort?: string;
332
+ criteria?: "asc" | "desc";
333
+ }
334
+ declare const PaymentsSearchResultSchema: z.ZodObject<{
335
+ paging: z.ZodObject<{
336
+ total: z.ZodNumber;
337
+ limit: z.ZodNumber;
338
+ offset: z.ZodNumber;
339
+ }, z.core.$strip>;
340
+ results: z.ZodArray<z.ZodObject<{
341
+ id: z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>;
342
+ status: z.ZodUnion<readonly [z.ZodLiteral<"pending">, z.ZodLiteral<"approved">, z.ZodLiteral<"authorized">, z.ZodLiteral<"in_process">, z.ZodLiteral<"in_mediation">, z.ZodLiteral<"rejected">, z.ZodLiteral<"cancelled">, z.ZodLiteral<"refunded">, z.ZodLiteral<"charged_back">, z.ZodString]>;
343
+ status_detail: z.ZodOptional<z.ZodNullable<z.ZodString>>;
344
+ date_created: z.ZodOptional<z.ZodNullable<z.ZodString>>;
345
+ date_approved: z.ZodOptional<z.ZodNullable<z.ZodString>>;
346
+ date_last_updated: z.ZodOptional<z.ZodNullable<z.ZodString>>;
347
+ transaction_amount: z.ZodNumber;
348
+ currency_id: z.ZodString;
349
+ installments: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
350
+ payment_method_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
351
+ payment_type_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
352
+ external_reference: z.ZodOptional<z.ZodNullable<z.ZodString>>;
353
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
354
+ payer: z.ZodOptional<z.ZodObject<{
355
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
356
+ email: z.ZodOptional<z.ZodNullable<z.ZodString>>;
357
+ identification: z.ZodOptional<z.ZodNullable<z.ZodObject<{
358
+ type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
359
+ number: z.ZodOptional<z.ZodNullable<z.ZodString>>;
360
+ }, z.core.$strip>>>;
361
+ }, z.core.$loose>>;
362
+ transaction_details: z.ZodOptional<z.ZodObject<{
363
+ net_received_amount: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
364
+ total_paid_amount: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
365
+ installment_amount: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
366
+ }, z.core.$loose>>;
367
+ }, z.core.$loose>>;
368
+ }, z.core.$strip>;
369
+ type PaymentsSearchResult = z.infer<typeof PaymentsSearchResultSchema>;
370
+ declare const RefundSchema: z.ZodObject<{
371
+ id: z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>;
372
+ payment_id: z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>;
373
+ amount: z.ZodNumber;
374
+ source: z.ZodOptional<z.ZodNullable<z.ZodObject<{
375
+ id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
376
+ name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
377
+ type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
378
+ }, z.core.$strip>>>;
379
+ date_created: z.ZodOptional<z.ZodNullable<z.ZodString>>;
380
+ status: z.ZodOptional<z.ZodNullable<z.ZodString>>;
381
+ }, z.core.$loose>;
382
+ type Refund = z.infer<typeof RefundSchema>;
383
+ interface CreateRefundParams {
384
+ paymentId: string;
385
+ /** Partial refund amount. Omit for full refund. */
386
+ amount?: number;
387
+ /** Idempotency key — required for retry-safety. */
388
+ idempotencyKey?: string;
389
+ }
390
+ declare const PreferenceItemSchema: z.ZodObject<{
391
+ id: z.ZodOptional<z.ZodString>;
392
+ title: z.ZodString;
393
+ description: z.ZodOptional<z.ZodString>;
394
+ picture_url: z.ZodOptional<z.ZodString>;
395
+ category_id: z.ZodOptional<z.ZodString>;
396
+ quantity: z.ZodNumber;
397
+ unit_price: z.ZodNumber;
398
+ currency_id: z.ZodOptional<z.ZodEnum<{
399
+ ARS: "ARS";
400
+ USD: "USD";
401
+ BRL: "BRL";
402
+ MXN: "MXN";
403
+ }>>;
404
+ }, z.core.$strip>;
405
+ type PreferenceItem = z.infer<typeof PreferenceItemSchema>;
406
+ declare const PreferenceSchema: z.ZodObject<{
407
+ id: z.ZodString;
408
+ init_point: z.ZodOptional<z.ZodString>;
409
+ sandbox_init_point: z.ZodOptional<z.ZodString>;
410
+ client_id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
411
+ collector_id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
412
+ items: z.ZodOptional<z.ZodArray<z.ZodObject<{
413
+ id: z.ZodOptional<z.ZodString>;
414
+ title: z.ZodString;
415
+ description: z.ZodOptional<z.ZodString>;
416
+ picture_url: z.ZodOptional<z.ZodString>;
417
+ category_id: z.ZodOptional<z.ZodString>;
418
+ quantity: z.ZodNumber;
419
+ unit_price: z.ZodNumber;
420
+ currency_id: z.ZodOptional<z.ZodEnum<{
421
+ ARS: "ARS";
422
+ USD: "USD";
423
+ BRL: "BRL";
424
+ MXN: "MXN";
425
+ }>>;
426
+ }, z.core.$strip>>>;
427
+ external_reference: z.ZodOptional<z.ZodNullable<z.ZodString>>;
428
+ date_created: z.ZodOptional<z.ZodNullable<z.ZodString>>;
429
+ expires: z.ZodOptional<z.ZodBoolean>;
430
+ expiration_date_from: z.ZodOptional<z.ZodNullable<z.ZodString>>;
431
+ expiration_date_to: z.ZodOptional<z.ZodNullable<z.ZodString>>;
432
+ }, z.core.$loose>;
433
+ type Preference = z.infer<typeof PreferenceSchema>;
434
+ interface CreatePreferenceParams {
435
+ items: Array<{
436
+ title: string;
437
+ quantity: number;
438
+ unit_price: number;
439
+ currency_id?: CurrencyId;
440
+ description?: string;
441
+ picture_url?: string;
442
+ }>;
443
+ payer?: {
444
+ name?: string;
445
+ surname?: string;
446
+ email?: string;
447
+ phone?: {
448
+ area_code?: string;
449
+ number?: string;
450
+ };
451
+ identification?: {
452
+ type: string;
453
+ number: string;
454
+ };
455
+ address?: {
456
+ street_name?: string;
457
+ street_number?: number;
458
+ zip_code?: string;
459
+ };
460
+ };
461
+ /** Where to send the buyer after success/failure/pending. */
462
+ backUrls?: {
463
+ success?: string;
464
+ failure?: string;
465
+ pending?: string;
466
+ };
467
+ /** "approved" → auto-redirect on success; "all" → always; "" → never. */
468
+ autoReturn?: "approved" | "all";
469
+ /** Webhook URL. */
470
+ notificationUrl?: string;
471
+ /** Your-system id for correlation. */
472
+ externalReference?: string;
473
+ /** Max installments offered. Defaults to MP account config. */
474
+ paymentMethods?: {
475
+ excluded_payment_types?: Array<{
476
+ id: string;
477
+ }>;
478
+ excluded_payment_methods?: Array<{
479
+ id: string;
480
+ }>;
481
+ installments?: number;
482
+ default_installments?: number;
483
+ };
484
+ /** Statement descriptor — shows on buyer's card statement. */
485
+ statementDescriptor?: string;
486
+ /** Expiration window for the link itself. */
487
+ expires?: boolean;
488
+ expirationDateFrom?: string;
489
+ expirationDateTo?: string;
490
+ }
491
+ declare const CustomerSchema: z.ZodObject<{
492
+ id: z.ZodString;
493
+ email: z.ZodString;
494
+ first_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
495
+ last_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
496
+ phone: z.ZodOptional<z.ZodNullable<z.ZodObject<{
497
+ area_code: z.ZodOptional<z.ZodNullable<z.ZodString>>;
498
+ number: z.ZodOptional<z.ZodNullable<z.ZodString>>;
499
+ }, z.core.$strip>>>;
500
+ identification: z.ZodOptional<z.ZodNullable<z.ZodObject<{
501
+ type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
502
+ number: z.ZodOptional<z.ZodNullable<z.ZodString>>;
503
+ }, z.core.$strip>>>;
504
+ date_created: z.ZodOptional<z.ZodNullable<z.ZodString>>;
505
+ date_last_updated: z.ZodOptional<z.ZodNullable<z.ZodString>>;
506
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
507
+ }, z.core.$loose>;
508
+ type Customer = z.infer<typeof CustomerSchema>;
509
+ declare const CustomerCardSchema: z.ZodObject<{
510
+ id: z.ZodString;
511
+ customer_id: z.ZodString;
512
+ expiration_month: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
513
+ expiration_year: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
514
+ first_six_digits: z.ZodOptional<z.ZodNullable<z.ZodString>>;
515
+ last_four_digits: z.ZodOptional<z.ZodNullable<z.ZodString>>;
516
+ payment_method: z.ZodOptional<z.ZodNullable<z.ZodObject<{
517
+ id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
518
+ name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
519
+ payment_type_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
520
+ }, z.core.$strip>>>;
521
+ date_created: z.ZodOptional<z.ZodNullable<z.ZodString>>;
522
+ }, z.core.$loose>;
523
+ type CustomerCard = z.infer<typeof CustomerCardSchema>;
524
+ interface CreateCustomerParams {
525
+ email: string;
526
+ firstName?: string;
527
+ lastName?: string;
528
+ phone?: {
529
+ areaCode?: string;
530
+ number?: string;
531
+ };
532
+ identification?: {
533
+ type: "DNI" | "CUIT" | "CUIL";
534
+ number: string;
535
+ };
536
+ description?: string;
537
+ }
538
+ declare const PaymentMethodSchema: z.ZodObject<{
539
+ id: z.ZodString;
540
+ name: z.ZodString;
541
+ payment_type_id: z.ZodString;
542
+ status: z.ZodString;
543
+ thumbnail: z.ZodOptional<z.ZodNullable<z.ZodString>>;
544
+ secure_thumbnail: z.ZodOptional<z.ZodNullable<z.ZodString>>;
545
+ min_allowed_amount: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
546
+ max_allowed_amount: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
547
+ }, z.core.$loose>;
548
+ type PaymentMethod = z.infer<typeof PaymentMethodSchema>;
549
+ declare const InstallmentOfferSchema: z.ZodObject<{
550
+ payment_method_id: z.ZodString;
551
+ payment_type_id: z.ZodString;
552
+ issuer: z.ZodOptional<z.ZodNullable<z.ZodObject<{
553
+ id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
554
+ name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
555
+ }, z.core.$strip>>>;
556
+ payer_costs: z.ZodArray<z.ZodObject<{
557
+ installments: z.ZodNumber;
558
+ installment_rate: z.ZodNumber;
559
+ discount_rate: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
560
+ installment_amount: z.ZodNumber;
561
+ total_amount: z.ZodNumber;
562
+ recommended_message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
563
+ }, z.core.$loose>>;
564
+ }, z.core.$loose>;
565
+ type InstallmentOffer = z.infer<typeof InstallmentOfferSchema>;
566
+ declare const QrOrderSchema: z.ZodObject<{
567
+ in_store_order_id: z.ZodString;
568
+ qr_data: z.ZodString;
569
+ }, z.core.$loose>;
570
+ type QrOrder = z.infer<typeof QrOrderSchema>;
571
+ interface CreateQrPaymentParams {
572
+ /** Pre-configured POS external_id from MP dashboard. Required. */
573
+ externalPosId: string;
574
+ /** Total amount in ARS. */
575
+ totalAmount: number;
576
+ /** Display title shown to the buyer when scanning. */
577
+ title: string;
578
+ description?: string;
579
+ /** Webhook URL — MP fires `point_integration_wh` then `payment` topic. */
580
+ notificationUrl?: string;
581
+ /** Your-system identifier for correlation. */
582
+ externalReference?: string;
583
+ /** ISO 8601 expiration (default 10 min from now). */
584
+ expirationDate?: string;
585
+ /** Itemized line items (optional but improves analytics). */
586
+ items?: Array<{
587
+ title: string;
588
+ quantity: number;
589
+ unit_price: number;
590
+ unit_measure?: string;
591
+ total_amount?: number;
592
+ }>;
593
+ }
594
+ declare const CardTokenSchema: z.ZodObject<{
595
+ id: z.ZodString;
596
+ status: z.ZodOptional<z.ZodString>;
597
+ date_due: z.ZodOptional<z.ZodString>;
598
+ card_id: z.ZodOptional<z.ZodString>;
599
+ cardholder: z.ZodOptional<z.ZodUnknown>;
600
+ }, z.core.$loose>;
601
+ type CardToken = z.infer<typeof CardTokenSchema>;
602
+ interface CreateCardTokenParams {
603
+ /** Saved card id (from list_customer_cards). */
604
+ cardId: string;
605
+ /** Customer that owns the card. */
606
+ customerId: string;
607
+ /** CVV — required for AR; MP doesn't store CVV. */
608
+ securityCode: string;
609
+ }
610
+ declare const AccountInfoSchema: z.ZodObject<{
611
+ id: z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>;
612
+ email: z.ZodOptional<z.ZodNullable<z.ZodString>>;
613
+ nickname: z.ZodOptional<z.ZodNullable<z.ZodString>>;
614
+ country_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
615
+ site_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
616
+ user_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
617
+ status: z.ZodOptional<z.ZodNullable<z.ZodObject<{
618
+ user_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
619
+ }, z.core.$loose>>>;
620
+ }, z.core.$loose>;
621
+ type AccountInfo = z.infer<typeof AccountInfoSchema>;
220
622
 
221
623
  interface MercadoPagoClientOptions {
222
624
  /** Access token. TEST- prefix for sandbox, APP_USR- for production. */
@@ -231,16 +633,44 @@ interface MercadoPagoClientOptions {
231
633
  * inject your own retry/instrumentation layer or to test with MSW.
232
634
  */
233
635
  fetch?: typeof fetch;
636
+ /**
637
+ * Per-request timeout in ms. Aborts the request and throws if exceeded.
638
+ * Default 30_000 (30s). MP can be slow under load; 30s is a safe upper bound.
639
+ */
640
+ requestTimeoutMs?: number;
641
+ /**
642
+ * Number of retries on 5xx + network errors. Default 1 (single retry).
643
+ * 4xx errors are NEVER retried (they're user/config errors). Each retry
644
+ * uses exponential backoff: 250ms, 500ms, 1000ms, ...
645
+ */
646
+ maxRetries?: number;
647
+ /**
648
+ * Observability hook fired AFTER every request (success or failure).
649
+ * Useful for logging, metrics, tracing. Synchronous, fire-and-forget.
650
+ */
651
+ onCall?: (event: {
652
+ method: string;
653
+ path: string;
654
+ durationMs: number;
655
+ httpStatus: number | null;
656
+ retried: number;
657
+ success: boolean;
658
+ }) => void;
234
659
  }
235
660
  /**
236
- * Thin, typed wrapper around Mercado Pago's REST API. Only the endpoints the
237
- * agent layer needs are exposed; this is deliberately narrow rather than a
238
- * full SDK rebuild.
661
+ * Thin, typed wrapper around Mercado Pago's REST API. Exposes the surface
662
+ * the agent layer needs: Subscriptions (Preapprovals), Payments, Checkout Pro
663
+ * (Preferences), Customers + saved Cards, Refunds, Payment Methods +
664
+ * Installments, and Account info. Deliberately narrower than a full SDK
665
+ * rebuild — we add endpoints when the agent layer needs them.
239
666
  */
240
667
  declare class MercadoPagoClient {
241
668
  private readonly accessToken;
242
669
  private readonly baseUrl;
243
670
  private readonly fetchImpl;
671
+ private readonly requestTimeoutMs;
672
+ private readonly maxRetries;
673
+ private readonly onCall;
244
674
  constructor(options: MercadoPagoClientOptions);
245
675
  private request;
246
676
  /**
@@ -249,28 +679,147 @@ declare class MercadoPagoClient {
249
679
  * CVV — there is no API path that bypasses this human step.
250
680
  */
251
681
  createPreapproval(params: CreatePreapprovalParams): Promise<Preapproval>;
682
+ getPreapproval(id: string): Promise<Preapproval>;
683
+ cancelPreapproval(id: string): Promise<Preapproval>;
684
+ pausePreapproval(id: string): Promise<Preapproval>;
685
+ resumePreapproval(id: string): Promise<Preapproval>;
252
686
  /**
253
- * Fetch the current state of a preapproval. Useful to confirm whether the
254
- * buyer has completed the first payment (`status: 'authorized'`) or whether
255
- * the subscription was cancelled.
687
+ * Create a payment. Two main flows:
688
+ * - **Card payment**: pass `token` (from MP frontend Cardform) + payment_method_id.
689
+ * - **Account money / cash**: omit token, pass payment_method_id like "account_money", "rapipago", "pagofacil".
690
+ *
691
+ * For credit card payments where you don't have a card token (i.e., you only
692
+ * have a payer email and want to send them a payment link), use
693
+ * `createPreference` (Checkout Pro) instead.
694
+ *
695
+ * Idempotency: pass `idempotencyKey` to safely retry. Required for production
696
+ * to dedupe network-failed requests.
256
697
  */
257
- getPreapproval(id: string): Promise<Preapproval>;
698
+ createPayment(params: CreatePaymentParams): Promise<Payment>;
699
+ /** Fetch a payment by ID. */
700
+ getPayment(id: string): Promise<Payment>;
258
701
  /**
259
- * Cancel an active preapproval. Irreversible: MP will not charge the buyer
260
- * again and the subscription cannot be reactivated.
702
+ * Search payments with filters. Common: by external_reference (your-system
703
+ * id), by status, by date range. Pagination via offset + limit (max 100).
261
704
  */
262
- cancelPreapproval(id: string): Promise<Preapproval>;
705
+ searchPayments(params?: SearchPaymentsParams): Promise<PaymentsSearchResult>;
263
706
  /**
264
- * Pause an authorized preapproval. The subscription stops auto-charging but
265
- * can be re-activated. Note: MP only allows pausing subs that are currently
266
- * `authorized` — pending/cancelled subs reject this.
707
+ * Capture a previously authorized payment. Only works for credit-card
708
+ * payments created with `capture: false`. Optional partial capture amount.
267
709
  */
268
- pausePreapproval(id: string): Promise<Preapproval>;
710
+ capturePayment(id: string, amount?: number): Promise<Payment>;
269
711
  /**
270
- * Re-activate a paused preapproval. Charges resume on the next scheduled
271
- * date.
712
+ * Cancel a pending or in_process payment. Once approved, you must use
713
+ * `createRefund` instead.
272
714
  */
273
- resumePreapproval(id: string): Promise<Preapproval>;
715
+ cancelPayment(id: string): Promise<Payment>;
716
+ /**
717
+ * Refund a payment fully (omit `amount`) or partially. Idempotency key
718
+ * recommended — refunds can fail mid-flight and you don't want double-refunds
719
+ * on retry.
720
+ */
721
+ createRefund(params: CreateRefundParams): Promise<Refund>;
722
+ listRefunds(paymentId: string): Promise<Refund[]>;
723
+ getRefund(paymentId: string, refundId: string): Promise<Refund>;
724
+ /**
725
+ * Create a payment preference for Checkout Pro. Returns `init_point` URL
726
+ * where the buyer completes payment on MP-hosted form. This is the
727
+ * recommended flow when you don't have a card token (most common path for
728
+ * agents — you don't want to handle PCI data).
729
+ *
730
+ * Sandbox: use `sandbox_init_point` instead of `init_point`.
731
+ */
732
+ createPreference(params: CreatePreferenceParams): Promise<Preference>;
733
+ getPreference(id: string): Promise<Preference>;
734
+ updatePreference(id: string, patch: Partial<CreatePreferenceParams>): Promise<Preference>;
735
+ createCustomer(params: CreateCustomerParams): Promise<Customer>;
736
+ getCustomer(id: string): Promise<Customer>;
737
+ /**
738
+ * Search customers. Most common: by email (returns 0 or 1 result).
739
+ * Note: MP's `/v1/customers/search` returns a paginated wrapper, not a flat array.
740
+ */
741
+ searchCustomers(params?: {
742
+ email?: string;
743
+ limit?: number;
744
+ offset?: number;
745
+ }): Promise<{
746
+ paging: {
747
+ total: number;
748
+ limit: number;
749
+ offset: number;
750
+ };
751
+ results: Customer[];
752
+ }>;
753
+ listCustomerCards(customerId: string): Promise<CustomerCard[]>;
754
+ getCustomerCard(customerId: string, cardId: string): Promise<CustomerCard>;
755
+ deleteCustomerCard(customerId: string, cardId: string): Promise<void>;
756
+ /** List all payment methods enabled for the account's site (MLA = Argentina). */
757
+ listPaymentMethods(): Promise<PaymentMethod[]>;
758
+ /**
759
+ * Get installment options for an amount. THE killer AR feature — returns
760
+ * `payer_costs` with `recommended_message` strings like "12 cuotas sin
761
+ * interés de $X" that you should surface verbatim to the user.
762
+ *
763
+ * Pass `bin` (first 6 digits of card) for issuer-specific offers (e.g.,
764
+ * Naranja's interest-free promotions). Without bin, returns generic offers.
765
+ */
766
+ getInstallments(params: {
767
+ amount: number;
768
+ paymentMethodId?: string;
769
+ bin?: string;
770
+ issuerId?: string;
771
+ }): Promise<InstallmentOffer[]>;
772
+ /** Get info about the account that owns this access token. */
773
+ getMe(): Promise<AccountInfo>;
774
+ /**
775
+ * Create a single-use card token from a saved card. This is the server-side
776
+ * retokenization path (PCI-safe because the card data lives in MP's vault,
777
+ * we only pass the saved card_id + customer_id + the user-supplied CVV).
778
+ *
779
+ * Tokens expire in 7 days but typically burn on first use. AR currently
780
+ * REQUIRES CVV on every charge (MP doesn't store it); skipping CVV requires
781
+ * a private MP product enablement, not a public API.
782
+ */
783
+ createCardToken(params: CreateCardTokenParams): Promise<CardToken>;
784
+ /**
785
+ * High-level helper: charge a saved card in 3 steps.
786
+ * 1. Mint a card token from {customer_id, card_id, security_code}
787
+ * 2. Lookup card to fill payment_method_id (avoids agent guessing)
788
+ * 3. Create the payment with the token + idempotency key
789
+ *
790
+ * Returns the resulting Payment. Uses deterministic idempotency from
791
+ * (card_id, amount, externalReference) so retries dedupe on MP's side.
792
+ */
793
+ chargeSavedCard(params: {
794
+ customerId: string;
795
+ cardId: string;
796
+ securityCode: string;
797
+ amount: number;
798
+ description: string;
799
+ installments?: number;
800
+ externalReference?: string;
801
+ statementDescriptor?: string;
802
+ idempotencyKey?: string;
803
+ }): Promise<Payment>;
804
+ /**
805
+ * Create a dynamic in-store QR order. Returns `qr_data` (EMVCo TLV string)
806
+ * + `in_store_order_id`. The buyer scans the QR with any AR wallet (Modo,
807
+ * BNA+, Cuenta DNI, Naranja X, etc. — interop is mandated by Transferencias
808
+ * 3.0). On payment, MP fires `point_integration_wh` then `payment` topics.
809
+ *
810
+ * Requires a pre-configured POS (`external_pos_id` from MP dashboard or
811
+ * `POST /pos`). The seller's `user_id` is auto-fetched from `/users/me`.
812
+ *
813
+ * The lib does NOT render the QR image — pass `qr_data` to a QR renderer
814
+ * (e.g., `qrcode` package) to get a data URL. The agent tool layer wraps
815
+ * this and returns both raw + data URL.
816
+ */
817
+ createQrPayment(userId: string, params: CreateQrPaymentParams): Promise<QrOrder>;
818
+ /**
819
+ * Cancel a pending QR order on a POS. Necessary if the buyer never scans
820
+ * — otherwise the next `createQrPayment` on the same POS returns 409.
821
+ */
822
+ cancelQrPayment(userId: string, externalPosId: string): Promise<void>;
274
823
  }
275
824
 
276
825
  /**
@@ -333,12 +882,17 @@ interface MercadoPagoToolsOptions {
333
882
  * Useful for localizing the agent's tool reasoning.
334
883
  */
335
884
  descriptions?: Partial<Record<ToolName, string>>;
885
+ /**
886
+ * Default notification webhook URL used when callers don't supply one.
887
+ * Optional — MP falls back to dashboard config if not set.
888
+ */
889
+ notificationUrl?: string;
336
890
  }
337
- type ToolName = "create_subscription" | "get_subscription_status" | "cancel_subscription" | "pause_subscription" | "resume_subscription";
891
+ type ToolName = "create_subscription" | "get_subscription_status" | "cancel_subscription" | "pause_subscription" | "resume_subscription" | "create_payment" | "get_payment" | "search_payments" | "cancel_payment" | "capture_payment" | "refund_payment" | "list_refunds" | "create_payment_preference" | "get_payment_preference" | "create_customer" | "find_customer_by_email" | "list_customer_cards" | "delete_customer_card" | "list_payment_methods" | "calculate_installments" | "get_account_info" | "charge_saved_card" | "create_qr_payment" | "cancel_qr_payment";
338
892
  /**
339
- * Build a tool set for the Vercel AI SDK that exposes Mercado Pago Subscriptions
340
- * to an agent. Pass directly to `Experimental_Agent`'s `tools` option, or merge
341
- * with other tool sets.
893
+ * Build a tool set for the Vercel AI SDK that exposes Mercado Pago to an
894
+ * agent. Pass directly to `Experimental_Agent`'s `tools` option, or merge with
895
+ * other tool sets.
342
896
  *
343
897
  * @example
344
898
  * ```ts
@@ -400,4 +954,4 @@ declare function verifyWebhookSignature(params: {
400
954
  secret: string;
401
955
  }): boolean;
402
956
 
403
- export { type AutoRecurring, type CreatePreapprovalParams, type CurrencyId, type FrequencyType, InMemoryStateAdapter, MercadoPagoAccountTypeMismatchError, MercadoPagoAuthError, MercadoPagoAuthorizeForbiddenError, MercadoPagoBackUrlInvalidError, MercadoPagoClient, type MercadoPagoClientOptions, MercadoPagoError, MercadoPagoPaymentRejectedError, MercadoPagoRateLimitError, MercadoPagoSelfPaymentError, type MercadoPagoToolsOptions, type ParsedWebhookEvent, type Preapproval, type PreapprovalStatus, type SiteId, type SubscriptionStateAdapter, type SubscriptionStateRecord, type WebhookBody, classifyError, mercadoPagoTools, parseWebhookEvent, verifyWebhookSignature };
957
+ export { type AccountInfo, type AutoRecurring, type CardToken, type CreateCardTokenParams, type CreateCustomerParams, type CreatePaymentParams, type CreatePreapprovalParams, type CreatePreferenceParams, type CreateQrPaymentParams, type CreateRefundParams, type CurrencyId, type Customer, type CustomerCard, type FrequencyType, InMemoryStateAdapter, type InstallmentOffer, MercadoPagoAccountTypeMismatchError, MercadoPagoAuthError, MercadoPagoAuthorizeForbiddenError, MercadoPagoBackUrlInvalidError, MercadoPagoClient, type MercadoPagoClientOptions, MercadoPagoError, MercadoPagoOverloadedError, MercadoPagoPaymentRejectedError, MercadoPagoRateLimitError, MercadoPagoSelfPaymentError, MercadoPagoTimeoutError, type MercadoPagoToolsOptions, type ParsedWebhookEvent, type Payment, type PaymentMethod, type PaymentStatus, type PaymentsSearchResult, type Preapproval, type PreapprovalStatus, type Preference, type PreferenceItem, type QrOrder, type Refund, type SearchPaymentsParams, type SiteId, type SubscriptionStateAdapter, type SubscriptionStateRecord, type WebhookBody, classifyError, mercadoPagoTools, parseWebhookEvent, verifyWebhookSignature };