@ar-agents/mercadopago 0.4.0 → 0.6.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.cts CHANGED
@@ -487,6 +487,15 @@ interface CreatePreferenceParams {
487
487
  expires?: boolean;
488
488
  expirationDateFrom?: string;
489
489
  expirationDateTo?: string;
490
+ /**
491
+ * Marketplace split — if set, funds route to `collector_id` (the seller)
492
+ * and `marketplaceFee` (in ARS) is credited to the marketplace's MP
493
+ * account. v0.5+. See `MarketplaceParams` for details.
494
+ */
495
+ marketplace?: string;
496
+ marketplaceFee?: number;
497
+ /** Seller's MP user_id. Funds route here when set. */
498
+ collectorId?: string | number;
490
499
  }
491
500
  declare const CustomerSchema: z.ZodObject<{
492
501
  id: z.ZodString;
@@ -799,6 +808,215 @@ interface CreateWebhookParams {
799
808
  /** Topic to subscribe to. */
800
809
  topic: WebhookTopic | string;
801
810
  }
811
+ /**
812
+ * Token response from MP's OAuth `/oauth/token` endpoint. The `access_token`
813
+ * is what you use to make API calls AS the linked seller; the `refresh_token`
814
+ * is what you use to refresh the access_token before expiration (~6 hours).
815
+ *
816
+ * **Persist the refresh_token**: it does NOT expire and is the only way to
817
+ * keep the integration alive long-term.
818
+ *
819
+ * **Always store `user_id`** alongside the tokens — it identifies WHICH
820
+ * seller these tokens belong to (you'll have many in a marketplace).
821
+ */
822
+ declare const OAuthTokenSchema: z.ZodObject<{
823
+ access_token: z.ZodString;
824
+ token_type: z.ZodOptional<z.ZodString>;
825
+ expires_in: z.ZodOptional<z.ZodNumber>;
826
+ scope: z.ZodOptional<z.ZodString>;
827
+ user_id: z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>;
828
+ refresh_token: z.ZodOptional<z.ZodString>;
829
+ public_key: z.ZodOptional<z.ZodString>;
830
+ live_mode: z.ZodOptional<z.ZodBoolean>;
831
+ }, z.core.$loose>;
832
+ type OAuthToken = z.infer<typeof OAuthTokenSchema>;
833
+ /**
834
+ * Status of an Order. Distinct from Payment status — an Order can have
835
+ * multiple payments and the Order status reflects the aggregate state.
836
+ */
837
+ declare const OrderStatusSchema: z.ZodUnion<readonly [z.ZodLiteral<"created">, z.ZodLiteral<"processed">, z.ZodLiteral<"action_required">, z.ZodLiteral<"canceled">, z.ZodLiteral<"expired">, z.ZodLiteral<"refunded">, z.ZodString]>;
838
+ type OrderStatus = z.infer<typeof OrderStatusSchema>;
839
+ declare const OrderItemSchema: z.ZodObject<{
840
+ title: z.ZodString;
841
+ unit_price: z.ZodNumber;
842
+ quantity: z.ZodNumber;
843
+ description: z.ZodOptional<z.ZodString>;
844
+ id: z.ZodOptional<z.ZodString>;
845
+ category_id: z.ZodOptional<z.ZodString>;
846
+ picture_url: z.ZodOptional<z.ZodString>;
847
+ }, z.core.$loose>;
848
+ type OrderItem = z.infer<typeof OrderItemSchema>;
849
+ declare const OrderSchema: z.ZodObject<{
850
+ id: z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>;
851
+ type: z.ZodOptional<z.ZodString>;
852
+ status: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"created">, z.ZodLiteral<"processed">, z.ZodLiteral<"action_required">, z.ZodLiteral<"canceled">, z.ZodLiteral<"expired">, z.ZodLiteral<"refunded">, z.ZodString]>>;
853
+ status_detail: z.ZodOptional<z.ZodString>;
854
+ external_reference: z.ZodOptional<z.ZodString>;
855
+ total_amount: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
856
+ currency_id: z.ZodOptional<z.ZodString>;
857
+ date_created: z.ZodOptional<z.ZodString>;
858
+ date_last_updated: z.ZodOptional<z.ZodString>;
859
+ items: z.ZodOptional<z.ZodArray<z.ZodObject<{
860
+ title: z.ZodString;
861
+ unit_price: z.ZodNumber;
862
+ quantity: z.ZodNumber;
863
+ description: z.ZodOptional<z.ZodString>;
864
+ id: z.ZodOptional<z.ZodString>;
865
+ category_id: z.ZodOptional<z.ZodString>;
866
+ picture_url: z.ZodOptional<z.ZodString>;
867
+ }, z.core.$loose>>>;
868
+ transactions: z.ZodOptional<z.ZodObject<{
869
+ payments: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
870
+ refunds: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
871
+ }, z.core.$loose>>;
872
+ capture_mode: z.ZodOptional<z.ZodString>;
873
+ }, z.core.$loose>;
874
+ type Order = z.infer<typeof OrderSchema>;
875
+ interface CreateOrderParams {
876
+ /**
877
+ * Order type. Common values:
878
+ * - "online" — checkout-style (the most common)
879
+ * - "in_store" — POS QR / in-person
880
+ */
881
+ type: "online" | "in_store" | string;
882
+ /** Currency (e.g. "ARS"). */
883
+ currency_id?: string;
884
+ /** External reference for reconciliation (your internal id). */
885
+ external_reference?: string;
886
+ /** Items being ordered. */
887
+ items?: OrderItem[];
888
+ /** Total amount if you'd rather not itemize. */
889
+ total_amount?: number;
890
+ /** Customer info (payer). */
891
+ payer?: {
892
+ email?: string;
893
+ first_name?: string;
894
+ last_name?: string;
895
+ identification?: {
896
+ type?: string;
897
+ number?: string;
898
+ };
899
+ };
900
+ /**
901
+ * Capture mode:
902
+ * - "automatic" (default) — charge immediately when paid.
903
+ * - "manual" — authorize only, capture later via captureOrder().
904
+ */
905
+ capture_mode?: "automatic" | "manual";
906
+ /**
907
+ * Notification URL — MP fires webhooks for order lifecycle events here.
908
+ */
909
+ notification_url?: string;
910
+ /**
911
+ * Marketplace fee + collector — required for marketplace integrations
912
+ * where YOU collect on behalf of a third-party seller (you take a fee,
913
+ * the rest goes to the seller).
914
+ */
915
+ marketplace?: string;
916
+ marketplace_fee?: number;
917
+ collector_id?: string | number;
918
+ }
919
+ /**
920
+ * Marketplace fee + collector params, applied to a Preference or Order.
921
+ *
922
+ * **How it works**: when you create a Preference or Order with
923
+ * `collector_id` set to a SELLER's MP user_id (not yours), and you have a
924
+ * valid OAuth access_token for that seller, MP routes the funds to the
925
+ * seller's MP account, and credits `marketplace_fee` (in ARS, not %) to
926
+ * YOUR marketplace account.
927
+ *
928
+ * Used for two-sided platforms (Rappi, MercadoLibre, Tienda Nube, etc.)
929
+ * where your platform takes a fee and the seller keeps the rest.
930
+ */
931
+ interface MarketplaceParams {
932
+ /**
933
+ * Marketplace identifier — your application's marketplace name (you set
934
+ * this when registering your app in MP's dev panel).
935
+ */
936
+ marketplace?: string;
937
+ /**
938
+ * Fee in ARS (NOT a percentage) that goes to your marketplace account.
939
+ * Compute it from your own commission rate before passing.
940
+ */
941
+ marketplace_fee?: number;
942
+ /**
943
+ * The SELLER's MP user_id. The funds go to this account; the
944
+ * `marketplace_fee` is split off and goes to YOUR account.
945
+ * Get this from `OAuthToken.user_id` after the seller authorizes your app.
946
+ */
947
+ collector_id?: string | number;
948
+ /**
949
+ * Optional: split among multiple sellers. If set, `collector_id` /
950
+ * `marketplace_fee` are ignored.
951
+ */
952
+ application_fee?: number;
953
+ }
954
+ /**
955
+ * Account balance snapshot. Sum of `available + unavailable` is the seller's
956
+ * total Mercado Pago balance.
957
+ *
958
+ * - `available` — funds the seller can withdraw or pay with right now.
959
+ * - `unavailable` — funds in retention (typically 14-21 days for new sellers
960
+ * or for risk-flagged transactions). Becomes `available` automatically.
961
+ */
962
+ declare const AccountBalanceSchema: z.ZodObject<{
963
+ user_id: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>>;
964
+ available_balance: z.ZodNumber;
965
+ unavailable_balance: z.ZodNumber;
966
+ total_amount: z.ZodNumber;
967
+ currency_id: z.ZodDefault<z.ZodString>;
968
+ }, z.core.$loose>;
969
+ type AccountBalance = z.infer<typeof AccountBalanceSchema>;
970
+ /**
971
+ * Account movement (a single line in the seller's MP "movements" log).
972
+ * Includes incoming payments, outgoing transfers, refunds, holdings, etc.
973
+ */
974
+ declare const AccountMovementSchema: z.ZodObject<{
975
+ id: z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>;
976
+ type: z.ZodString;
977
+ description: z.ZodOptional<z.ZodString>;
978
+ amount: z.ZodNumber;
979
+ currency_id: z.ZodOptional<z.ZodString>;
980
+ status: z.ZodOptional<z.ZodString>;
981
+ date_created: z.ZodOptional<z.ZodString>;
982
+ date_released: z.ZodOptional<z.ZodString>;
983
+ reference_id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
984
+ payment_id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
985
+ }, z.core.$loose>;
986
+ type AccountMovement = z.infer<typeof AccountMovementSchema>;
987
+ /**
988
+ * A scheduled or completed transfer from the MP account to the seller's
989
+ * registered bank account (CBU). Settlements are the core of "when do I
990
+ * actually get paid".
991
+ */
992
+ declare const SettlementSchema: z.ZodObject<{
993
+ id: z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>;
994
+ status: z.ZodOptional<z.ZodString>;
995
+ amount: z.ZodOptional<z.ZodNumber>;
996
+ currency_id: z.ZodOptional<z.ZodString>;
997
+ date_created: z.ZodOptional<z.ZodString>;
998
+ date_scheduled: z.ZodOptional<z.ZodString>;
999
+ date_processed: z.ZodOptional<z.ZodString>;
1000
+ bank_account: z.ZodOptional<z.ZodObject<{
1001
+ cbu: z.ZodOptional<z.ZodString>;
1002
+ bank_name: z.ZodOptional<z.ZodString>;
1003
+ }, z.core.$loose>>;
1004
+ }, z.core.$loose>;
1005
+ type Settlement = z.infer<typeof SettlementSchema>;
1006
+ type ThreeDSStatus = "not_required" | "frictionless" | "challenge_required" | "rejected" | "unknown";
1007
+ interface ThreeDSInfo {
1008
+ /** High-level status — the field most agents care about. */
1009
+ status: ThreeDSStatus;
1010
+ /** Raw `three_d_secure_mode` field from the payment, if present. */
1011
+ mode: string | null;
1012
+ /**
1013
+ * URL the buyer must visit to complete the 3DS challenge, if one was
1014
+ * triggered. `null` for frictionless/not_required.
1015
+ */
1016
+ challengeUrl: string | null;
1017
+ /** Human-readable explanation suitable for surfacing to the user. */
1018
+ description: string;
1019
+ }
802
1020
 
803
1021
  interface MercadoPagoClientOptions {
804
1022
  /** Access token. TEST- prefix for sandbox, APP_USR- for production. */
@@ -837,6 +1055,20 @@ interface MercadoPagoClientOptions {
837
1055
  success: boolean;
838
1056
  }) => void;
839
1057
  }
1058
+ interface RequestOptions {
1059
+ /** Idempotency key. Required for POST/PUT to dedupe retries safely. */
1060
+ idempotencyKey?: string;
1061
+ /** Query string params. Object → URLSearchParams. */
1062
+ query?: Record<string, string | number | undefined>;
1063
+ /** Context for error classification. */
1064
+ classifyContext?: {
1065
+ preapprovalId?: string;
1066
+ paymentId?: string;
1067
+ customerId?: string;
1068
+ payerEmail?: string;
1069
+ sellerEmail?: string;
1070
+ };
1071
+ }
840
1072
  /**
841
1073
  * Thin, typed wrapper around Mercado Pago's REST API. Exposes the surface
842
1074
  * the agent layer needs: Subscriptions (Preapprovals), Payments, Checkout Pro
@@ -1097,6 +1329,75 @@ declare class MercadoPagoClient {
1097
1329
  topic?: string;
1098
1330
  }): Promise<WebhookConfig>;
1099
1331
  deleteWebhook(id: string): Promise<void>;
1332
+ /**
1333
+ * Create a new Order. Use `capture_mode: "manual"` for auth-only flows
1334
+ * where you want to capture funds later (ride-share, hotels, marketplaces).
1335
+ *
1336
+ * For marketplace splits, set `marketplace`, `marketplace_fee`,
1337
+ * `collector_id` — see `MarketplaceParams`.
1338
+ */
1339
+ createOrder(params: CreateOrderParams, options?: RequestOptions): Promise<Order>;
1340
+ getOrder(id: string): Promise<Order>;
1341
+ updateOrder(id: string, patch: Partial<CreateOrderParams>): Promise<Order>;
1342
+ /**
1343
+ * Capture a previously-authorized Order (only for orders created with
1344
+ * `capture_mode: "manual"`). Captures up to the originally-authorized
1345
+ * amount; pass `amount` for partial capture.
1346
+ */
1347
+ captureOrder(id: string, amount?: number): Promise<Order>;
1348
+ /**
1349
+ * Cancel an Order. Releases any auth-holds; marks the Order as canceled.
1350
+ * For orders that have already been captured, use `createRefund` instead.
1351
+ */
1352
+ cancelOrder(id: string): Promise<Order>;
1353
+ /**
1354
+ * Get the seller's current MP wallet balance (available + unavailable).
1355
+ * - `available_balance`: spendable / withdrawable right now.
1356
+ * - `unavailable_balance`: in retention (e.g., 14-21 days for new sellers).
1357
+ * - `total_amount` = sum of both.
1358
+ */
1359
+ getAccountBalance(): Promise<AccountBalance>;
1360
+ /**
1361
+ * List wallet movements (incoming payments, transfers, refunds, holdings).
1362
+ * Defaults to most-recent-first, paginated. Filter by date range with
1363
+ * `from`/`to` (ISO 8601).
1364
+ */
1365
+ listAccountMovements(params?: {
1366
+ from?: string;
1367
+ to?: string;
1368
+ limit?: number;
1369
+ offset?: number;
1370
+ }): Promise<{
1371
+ movements: AccountMovement[];
1372
+ paging: {
1373
+ limit: number;
1374
+ offset: number;
1375
+ total: number;
1376
+ };
1377
+ }>;
1378
+ /**
1379
+ * List settlements (transfers from MP wallet to your bank account).
1380
+ * Useful for monthly conciliation reports.
1381
+ */
1382
+ listSettlements(params?: {
1383
+ from?: string;
1384
+ to?: string;
1385
+ status?: string;
1386
+ limit?: number;
1387
+ offset?: number;
1388
+ }): Promise<{
1389
+ settlements: Settlement[];
1390
+ paging: {
1391
+ limit: number;
1392
+ offset: number;
1393
+ total: number;
1394
+ };
1395
+ }>;
1396
+ /**
1397
+ * Get a single settlement by id. Returns the full Settlement object
1398
+ * including bank_account info (CBU, bank name).
1399
+ */
1400
+ getSettlement(id: string): Promise<Settlement>;
1100
1401
  }
1101
1402
 
1102
1403
  /**
@@ -1164,8 +1465,26 @@ interface MercadoPagoToolsOptions {
1164
1465
  * Optional — MP falls back to dashboard config if not set.
1165
1466
  */
1166
1467
  notificationUrl?: string;
1468
+ /**
1469
+ * Webhook secret for the `handle_webhook` tool. Required to verify
1470
+ * incoming webhook HMAC-SHA256 signatures. Get it from MP dev panel →
1471
+ * "Notificaciones" → "Webhooks" → "Configurar notificaciones".
1472
+ * If omitted, `handle_webhook` returns `{ verified: false, error: ... }`
1473
+ * and the agent should reject the webhook.
1474
+ */
1475
+ webhookSecret?: string;
1476
+ /**
1477
+ * OAuth credentials for the marketplace flow. Required for
1478
+ * `oauth_exchange_code` and `oauth_refresh_token` (the secret cannot be
1479
+ * passed by the agent — it's a server-side secret). If omitted, those
1480
+ * tools return `{ available: false }` with setup instructions.
1481
+ */
1482
+ oauth?: {
1483
+ clientId: string;
1484
+ clientSecret: string;
1485
+ };
1167
1486
  }
1168
- 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" | "create_subscription_plan" | "list_subscription_plans" | "update_subscription_plan" | "subscribe_to_plan" | "list_subscription_payments" | "create_store" | "list_stores" | "create_pos" | "list_pos" | "list_payment_disputes" | "get_dispute" | "list_identification_types" | "list_issuers" | "list_webhooks" | "create_webhook" | "update_webhook" | "delete_webhook";
1487
+ 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" | "create_subscription_plan" | "list_subscription_plans" | "update_subscription_plan" | "subscribe_to_plan" | "list_subscription_payments" | "create_store" | "list_stores" | "create_pos" | "list_pos" | "list_payment_disputes" | "get_dispute" | "list_identification_types" | "list_issuers" | "list_webhooks" | "create_webhook" | "update_webhook" | "delete_webhook" | "handle_webhook" | "oauth_authorize_url" | "oauth_exchange_code" | "oauth_refresh_token" | "create_order" | "get_order" | "update_order" | "capture_order" | "cancel_order" | "get_account_balance" | "list_account_movements" | "list_settlements" | "get_settlement" | "analyze_payment_3ds" | "get_test_cards";
1169
1488
  /**
1170
1489
  * Build a tool set for the Vercel AI SDK that exposes Mercado Pago to an
1171
1490
  * agent. Pass directly to `Experimental_Agent`'s `tools` option, or merge with
@@ -1231,4 +1550,243 @@ declare function verifyWebhookSignature(params: {
1231
1550
  secret: string;
1232
1551
  }): boolean;
1233
1552
 
1234
- export { type AccountInfo, type AutoRecurring, type CardToken, type CreateCardTokenParams, type CreateCustomerParams, type CreatePaymentParams, type CreatePosParams, type CreatePreapprovalParams, type CreatePreferenceParams, type CreateQrPaymentParams, type CreateRefundParams, type CreateStoreParams, type CreateSubscriptionPlanParams, type CreateWebhookParams, type CurrencyId, type Customer, type CustomerCard, type Dispute, type FrequencyType, type IdentificationType, InMemoryStateAdapter, type InstallmentOffer, type Issuer, 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 Pos, type Preapproval, type PreapprovalStatus, type Preference, type PreferenceItem, type QrOrder, type Refund, type SearchPaymentsParams, type SiteId, type Store, type SubscriptionPayment, type SubscriptionPlan, type SubscriptionStateAdapter, type SubscriptionStateRecord, type WebhookBody, type WebhookConfig, type WebhookTopic, classifyError, mercadoPagoTools, parseWebhookEvent, verifyWebhookSignature };
1553
+ /**
1554
+ * Mercado Pago OAuth flow — for marketplace integrations where YOUR app
1555
+ * cobra a través de cuentas MP de terceros (sellers in your platform).
1556
+ *
1557
+ * # The flow (3 legs)
1558
+ *
1559
+ * 1. **Authorize URL** — Redirect the seller to `buildAuthorizeUrl()`. They
1560
+ * log in to MP and approve your app. MP redirects them back to your
1561
+ * `redirect_uri` with `?code=AUTH_CODE&state=YOUR_STATE`.
1562
+ * 2. **Code exchange** — Your server POSTs to `/oauth/token` via
1563
+ * `exchangeCodeForToken()` with the code. Returns `{ access_token,
1564
+ * refresh_token, user_id, expires_in (~6h), ... }`. **Persist all of it.**
1565
+ * 3. **Token refresh** — Before `expires_in` runs out (or on 401), call
1566
+ * `refreshAccessToken()` with the saved `refresh_token` to get a fresh
1567
+ * access_token. The refresh_token does NOT expire and is the only way
1568
+ * to keep the integration alive long-term.
1569
+ *
1570
+ * # Per-seller MercadoPagoClient
1571
+ *
1572
+ * Once you have an OAuth `access_token` for a seller, instantiate a
1573
+ * `MercadoPagoClient({ accessToken })` AS THAT SELLER. All API calls then
1574
+ * happen on the seller's behalf — payments, refunds, subscriptions,
1575
+ * everything.
1576
+ *
1577
+ * # Marketplace fee
1578
+ *
1579
+ * To take a fee while collecting on the seller's behalf, pass
1580
+ * `marketplace`, `marketplaceFee`, `collectorId` to `createPreference()`
1581
+ * or `createOrder()`. See `MarketplaceParams` for details.
1582
+ *
1583
+ * # Setup
1584
+ *
1585
+ * 1. Register your application in MP's dev panel
1586
+ * (https://www.mercadopago.com.ar/developers/panel/applications) to get
1587
+ * `clientId` (= application id) and `clientSecret`.
1588
+ * 2. Configure the `redirect_uri` whitelist in the same panel — MP rejects
1589
+ * redirects to URIs not whitelisted.
1590
+ * 3. Pick a `marketplace` identifier (used in fee routing).
1591
+ */
1592
+
1593
+ /**
1594
+ * Build the URL the seller visits to authorize your app. Redirect them here.
1595
+ * On approval, MP redirects them to `redirect_uri?code=...&state=...`.
1596
+ *
1597
+ * @param state Optional opaque value echoed back in the redirect — use this
1598
+ * to bind the OAuth round-trip to a specific user/session and
1599
+ * prevent CSRF. Always set it in production.
1600
+ */
1601
+ declare function buildAuthorizeUrl(params: {
1602
+ /** Your app's client ID (= application id from MP dev panel). */
1603
+ clientId: string;
1604
+ /** Where MP redirects after approval. Must be whitelisted in MP panel. */
1605
+ redirectUri: string;
1606
+ /** CSRF / session-binding token, echoed back. Strongly recommended. */
1607
+ state?: string;
1608
+ /**
1609
+ * Override the authorize endpoint base. Default points to AR; for other
1610
+ * sites use `https://auth.mercadopago.com.{br,mx,co,cl,uy}/authorization`.
1611
+ */
1612
+ authorizeUrl?: string;
1613
+ }): string;
1614
+ /**
1615
+ * Exchange the authorization code (from the OAuth redirect) for an
1616
+ * `OAuthToken`. POSTs to `/oauth/token` with `grant_type=authorization_code`.
1617
+ *
1618
+ * **Persist the entire response** — the `refresh_token` is the only way to
1619
+ * keep the integration alive long-term, and `user_id` identifies the seller.
1620
+ */
1621
+ declare function exchangeCodeForToken(params: {
1622
+ clientId: string;
1623
+ clientSecret: string;
1624
+ /** The `code` query param from the OAuth redirect. */
1625
+ code: string;
1626
+ /** Must match the `redirect_uri` used in `buildAuthorizeUrl`. */
1627
+ redirectUri: string;
1628
+ /** Override the token endpoint (testing). */
1629
+ tokenUrl?: string;
1630
+ /** Custom fetch (testing). */
1631
+ fetchImpl?: typeof fetch;
1632
+ }): Promise<OAuthToken>;
1633
+ /**
1634
+ * Refresh an access_token using the saved refresh_token. Call this
1635
+ * proactively before `expires_in` runs out, or reactively on a 401 from a
1636
+ * per-seller MercadoPagoClient.
1637
+ *
1638
+ * The new response includes a fresh `refresh_token` — **always persist it,
1639
+ * replacing the old one**, even though MP often returns the same value.
1640
+ */
1641
+ declare function refreshAccessToken(params: {
1642
+ clientId: string;
1643
+ clientSecret: string;
1644
+ refreshToken: string;
1645
+ tokenUrl?: string;
1646
+ fetchImpl?: typeof fetch;
1647
+ }): Promise<OAuthToken>;
1648
+ /**
1649
+ * Compute when an access_token will expire, given the timestamp it was
1650
+ * issued and the `expires_in` value (in seconds).
1651
+ *
1652
+ * @returns A unix-ms timestamp.
1653
+ */
1654
+ declare function expirationTimeMs(issuedAtMs: number, expiresInSeconds: number | undefined): number;
1655
+ /**
1656
+ * Check whether an access_token is close to expiring. Use this to decide
1657
+ * whether to proactively refresh BEFORE making an API call.
1658
+ *
1659
+ * @param skewSeconds Buffer to refresh early (default 5 min). MP tokens
1660
+ * typically last 6h; refreshing in the last 5 min avoids
1661
+ * races with API calls that take a few seconds.
1662
+ */
1663
+ declare function isExpiringSoon(expirationMs: number, skewSeconds?: number): boolean;
1664
+
1665
+ /**
1666
+ * MP sandbox test cards for AR (MLA) — the official numbers MP publishes for
1667
+ * its TEST environment. Use these in unit tests + integration tests to
1668
+ * exercise the create_payment / charge_saved_card flows without touching a
1669
+ * real card.
1670
+ *
1671
+ * # When this matters
1672
+ *
1673
+ * Most non-trivial dev flows hit the issue of "I want to test approved /
1674
+ * rejected / pending paths" but MP's docs scatter the test card numbers
1675
+ * across multiple pages. This module collects them so you can `import { TEST_CARDS_AR }`
1676
+ * and pick the scenario you need.
1677
+ *
1678
+ * # Source
1679
+ *
1680
+ * AR (MLA) test cards published at
1681
+ * https://www.mercadopago.com.ar/developers/es/docs/checkout-api/additional-content/test-cards
1682
+ *
1683
+ * Last sync: 2026-05.
1684
+ */
1685
+ /**
1686
+ * The full data needed to test a payment:
1687
+ * - `number` — 16 digits
1688
+ * - `cvv` — 3 digits
1689
+ * - `exp` — MM/YY (use any future date in TEST mode)
1690
+ * - `paymentMethodId` — what to pass as `payment_method_id` to create_payment
1691
+ * - `holderName` — special string that triggers the desired status
1692
+ * (e.g. "APRO" → approved, "OTHE" → rejected with bad CVV)
1693
+ */
1694
+ interface TestCard {
1695
+ brand: string;
1696
+ number: string;
1697
+ cvv: string;
1698
+ exp: string;
1699
+ paymentMethodId: string;
1700
+ /**
1701
+ * Holder-name "magic strings" — MP routes the payment to a specific
1702
+ * status_detail based on this:
1703
+ * - `APRO` → status: approved
1704
+ * - `OTHE` → rejected (status_detail: cc_rejected_other_reason)
1705
+ * - `CONT` → pending (status_detail: pending_contingency)
1706
+ * - `CALL` → rejected (status_detail: cc_rejected_call_for_authorize)
1707
+ * - `FUND` → rejected (status_detail: cc_rejected_insufficient_amount)
1708
+ * - `SECU` → rejected (status_detail: cc_rejected_bad_filled_security_code)
1709
+ * - `EXPI` → rejected (status_detail: cc_rejected_bad_filled_date)
1710
+ * - `FORM` → rejected (status_detail: cc_rejected_bad_filled_other)
1711
+ */
1712
+ holderNameToTest: Record<string, string>;
1713
+ }
1714
+ /**
1715
+ * The MP-published test cards for AR. Pass `holderName: "APRO"` for an
1716
+ * approved payment, `"OTHE"` for a rejected one, etc.
1717
+ */
1718
+ declare const TEST_CARDS_AR: Record<string, TestCard>;
1719
+ /**
1720
+ * Pre-built payer objects that MP recognizes as test buyers. Pair with
1721
+ * an APRO test card → status: approved.
1722
+ *
1723
+ * **Use a NEW email per call** if you don't want MP's idempotency-on-email
1724
+ * to dedupe — append a timestamp.
1725
+ */
1726
+ declare const TEST_PAYERS_AR: {
1727
+ readonly approvedBuyer: () => {
1728
+ email: string;
1729
+ identification: {
1730
+ type: string;
1731
+ number: string;
1732
+ };
1733
+ };
1734
+ };
1735
+ /**
1736
+ * Resolve a `(card, scenario)` pair to a ready-to-use `CreatePaymentParams`-like
1737
+ * object. Reduces boilerplate in test files.
1738
+ *
1739
+ * @example
1740
+ * ```ts
1741
+ * const card = buildTestCardScenario("VISA_CREDIT", "APRO", 1500);
1742
+ * await client.createPayment({ ...card, externalReference: "test-1" });
1743
+ * ```
1744
+ */
1745
+ declare function buildTestCardScenario(cardKey: keyof typeof TEST_CARDS_AR, scenario: string, amountArs: number): {
1746
+ transactionAmount: number;
1747
+ paymentMethodId: string;
1748
+ payerEmail: string;
1749
+ description: string;
1750
+ installments: number;
1751
+ /**
1752
+ * Magic holder name — pass to MP frontend's CardForm `cardholderName`
1753
+ * field. (For server-side create_payment, pass via additional_info.)
1754
+ */
1755
+ holderName: string;
1756
+ };
1757
+
1758
+ /**
1759
+ * 3DS (Strong Customer Authentication) analyzer for Mercado Pago Payments.
1760
+ *
1761
+ * # Background
1762
+ *
1763
+ * 3DS (3-D Secure / "verified by Visa", "Mastercard SecureCode") is the
1764
+ * issuer-side 2FA layer for card payments. MP triggers it automatically when:
1765
+ * - The card's issuer requires it (driven by MCC + amount + risk).
1766
+ * - The buyer's country mandates it (MX, BR, several EU countries).
1767
+ *
1768
+ * In Argentina (MLA), 3DS is OPTIONAL but strongly recommended for
1769
+ * high-value transactions and is required for some FCE MiPyMEs flows.
1770
+ *
1771
+ * # What this module does
1772
+ *
1773
+ * Given a `Payment` returned by `getPayment()` or `createPayment()`, derive
1774
+ * a normalized `ThreeDSInfo` telling you:
1775
+ * - Whether 3DS was triggered at all
1776
+ * - Whether it was frictionless (no buyer interaction) or required a challenge
1777
+ * - The challenge URL (if any) you must redirect the buyer to
1778
+ * - A human-readable description suitable for surfacing to the user
1779
+ *
1780
+ * # When to use
1781
+ *
1782
+ * Call `analyze3DS(payment)` after EVERY `createPayment()` for credit cards.
1783
+ * If `info.challengeUrl !== null`, you MUST redirect the buyer there before
1784
+ * the payment can complete — otherwise it stays in `pending` forever.
1785
+ */
1786
+
1787
+ /**
1788
+ * Analyze a Payment's 3DS state. Pure function, no I/O.
1789
+ */
1790
+ declare function analyze3DS(payment: Payment): ThreeDSInfo;
1791
+
1792
+ export { type AccountBalance, type AccountInfo, type AccountMovement, type AutoRecurring, type CardToken, type CreateCardTokenParams, type CreateCustomerParams, type CreateOrderParams, type CreatePaymentParams, type CreatePosParams, type CreatePreapprovalParams, type CreatePreferenceParams, type CreateQrPaymentParams, type CreateRefundParams, type CreateStoreParams, type CreateSubscriptionPlanParams, type CreateWebhookParams, type CurrencyId, type Customer, type CustomerCard, type Dispute, type FrequencyType, type IdentificationType, InMemoryStateAdapter, type InstallmentOffer, type Issuer, type MarketplaceParams, MercadoPagoAccountTypeMismatchError, MercadoPagoAuthError, MercadoPagoAuthorizeForbiddenError, MercadoPagoBackUrlInvalidError, MercadoPagoClient, type MercadoPagoClientOptions, MercadoPagoError, MercadoPagoOverloadedError, MercadoPagoPaymentRejectedError, MercadoPagoRateLimitError, MercadoPagoSelfPaymentError, MercadoPagoTimeoutError, type MercadoPagoToolsOptions, type OAuthToken, type Order, type OrderItem, type OrderStatus, type ParsedWebhookEvent, type Payment, type PaymentMethod, type PaymentStatus, type PaymentsSearchResult, type Pos, type Preapproval, type PreapprovalStatus, type Preference, type PreferenceItem, type QrOrder, type Refund, type SearchPaymentsParams, type Settlement, type SiteId, type Store, type SubscriptionPayment, type SubscriptionPlan, type SubscriptionStateAdapter, type SubscriptionStateRecord, TEST_CARDS_AR, TEST_PAYERS_AR, type TestCard, type ThreeDSInfo, type ThreeDSStatus, type WebhookBody, type WebhookConfig, type WebhookTopic, analyze3DS, buildAuthorizeUrl, buildTestCardScenario, classifyError, exchangeCodeForToken, expirationTimeMs, isExpiringSoon, mercadoPagoTools, parseWebhookEvent, refreshAccessToken, verifyWebhookSignature };