@ar-agents/mercadopago 0.6.0 → 0.8.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/AGENTS.md +10 -1
- package/CHANGELOG.md +89 -0
- package/README.md +64 -2
- package/cookbook/01-checkout-pro-basic.ts +99 -0
- package/cookbook/02-saas-subscription.ts +137 -0
- package/cookbook/03-webhook-handler.ts +162 -0
- package/cookbook/04-marketplace-split.ts +194 -0
- package/cookbook/05-qr-in-store.ts +142 -0
- package/cookbook/06-3ds-challenge.ts +139 -0
- package/cookbook/07-auth-only-order.ts +127 -0
- package/cookbook/08-recovery-patterns.ts +191 -0
- package/cookbook/README.md +36 -0
- package/dist/index.cjs +1039 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +319 -50
- package/dist/index.d.ts +319 -50
- package/dist/index.js +1036 -14
- package/dist/index.js.map +1 -1
- package/dist/state-C6Wzb_XX.d.cts +106 -0
- package/dist/state-C6Wzb_XX.d.ts +106 -0
- package/dist/vercel-kv.cjs +92 -0
- package/dist/vercel-kv.cjs.map +1 -0
- package/dist/vercel-kv.d.cts +107 -0
- package/dist/vercel-kv.d.ts +107 -0
- package/dist/vercel-kv.js +88 -0
- package/dist/vercel-kv.js.map +1 -0
- package/package.json +27 -4
- package/tools.manifest.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ToolSet } from 'ai';
|
|
3
|
+
import { S as SubscriptionStateAdapter } from './state-C6Wzb_XX.js';
|
|
4
|
+
export { I as IdempotencyCache, a as InMemoryIdempotencyCache, b as InMemoryOAuthTokenStore, c as InMemoryStateAdapter, O as OAuthTokenRecord, d as OAuthTokenStore, e as SubscriptionStateRecord } from './state-C6Wzb_XX.js';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Base class for any error originating from the Mercado Pago integration. All
|
|
@@ -1017,6 +1019,79 @@ interface ThreeDSInfo {
|
|
|
1017
1019
|
/** Human-readable explanation suitable for surfacing to the user. */
|
|
1018
1020
|
description: string;
|
|
1019
1021
|
}
|
|
1022
|
+
declare const MerchantOrderSchema: z.ZodObject<{
|
|
1023
|
+
id: z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>;
|
|
1024
|
+
status: z.ZodOptional<z.ZodString>;
|
|
1025
|
+
external_reference: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1026
|
+
preference_id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
1027
|
+
payments: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
|
|
1028
|
+
shipments: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
|
|
1029
|
+
payer: z.ZodOptional<z.ZodUnknown>;
|
|
1030
|
+
collector: z.ZodOptional<z.ZodUnknown>;
|
|
1031
|
+
marketplace: z.ZodOptional<z.ZodString>;
|
|
1032
|
+
total_amount: z.ZodOptional<z.ZodNumber>;
|
|
1033
|
+
paid_amount: z.ZodOptional<z.ZodNumber>;
|
|
1034
|
+
refunded_amount: z.ZodOptional<z.ZodNumber>;
|
|
1035
|
+
shipping_cost: z.ZodOptional<z.ZodNumber>;
|
|
1036
|
+
date_created: z.ZodOptional<z.ZodString>;
|
|
1037
|
+
last_updated: z.ZodOptional<z.ZodString>;
|
|
1038
|
+
site_id: z.ZodOptional<z.ZodString>;
|
|
1039
|
+
order_status: z.ZodOptional<z.ZodString>;
|
|
1040
|
+
}, z.core.$loose>;
|
|
1041
|
+
type MerchantOrder = z.infer<typeof MerchantOrderSchema>;
|
|
1042
|
+
declare const BankAccountSchema: z.ZodObject<{
|
|
1043
|
+
id: z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>;
|
|
1044
|
+
cbu: z.ZodOptional<z.ZodString>;
|
|
1045
|
+
alias: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1046
|
+
bank_name: z.ZodOptional<z.ZodString>;
|
|
1047
|
+
account_type: z.ZodOptional<z.ZodString>;
|
|
1048
|
+
status: z.ZodOptional<z.ZodString>;
|
|
1049
|
+
is_default: z.ZodOptional<z.ZodBoolean>;
|
|
1050
|
+
date_created: z.ZodOptional<z.ZodString>;
|
|
1051
|
+
}, z.core.$loose>;
|
|
1052
|
+
type BankAccount = z.infer<typeof BankAccountSchema>;
|
|
1053
|
+
declare const PointDeviceSchema: z.ZodObject<{
|
|
1054
|
+
id: z.ZodString;
|
|
1055
|
+
pos_id: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
1056
|
+
store_id: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
1057
|
+
external_pos_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1058
|
+
operating_mode: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"PDV">, z.ZodLiteral<"STANDALONE">, z.ZodString]>>;
|
|
1059
|
+
}, z.core.$loose>;
|
|
1060
|
+
type PointDevice = z.infer<typeof PointDeviceSchema>;
|
|
1061
|
+
type PointPaymentIntentState = "OPEN" | "PROCESSING" | "FINISHED" | "CANCELED" | "ERROR" | string;
|
|
1062
|
+
declare const PointPaymentIntentSchema: z.ZodObject<{
|
|
1063
|
+
id: z.ZodString;
|
|
1064
|
+
device_id: z.ZodOptional<z.ZodString>;
|
|
1065
|
+
amount: z.ZodOptional<z.ZodNumber>;
|
|
1066
|
+
state: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"OPEN">, z.ZodLiteral<"PROCESSING">, z.ZodLiteral<"FINISHED">, z.ZodLiteral<"CANCELED">, z.ZodLiteral<"ERROR">, z.ZodString]>>;
|
|
1067
|
+
payment: z.ZodOptional<z.ZodObject<{
|
|
1068
|
+
id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
1069
|
+
type: z.ZodOptional<z.ZodString>;
|
|
1070
|
+
installments: z.ZodOptional<z.ZodNumber>;
|
|
1071
|
+
installments_cost: z.ZodOptional<z.ZodString>;
|
|
1072
|
+
print_on_terminal: z.ZodOptional<z.ZodBoolean>;
|
|
1073
|
+
}, z.core.$loose>>;
|
|
1074
|
+
additional_info: z.ZodOptional<z.ZodUnknown>;
|
|
1075
|
+
}, z.core.$loose>;
|
|
1076
|
+
type PointPaymentIntent = z.infer<typeof PointPaymentIntentSchema>;
|
|
1077
|
+
interface CreatePointPaymentIntentParams {
|
|
1078
|
+
/** Amount in centavos (yes, centavos — Point API differs from Payments API). */
|
|
1079
|
+
amount: number;
|
|
1080
|
+
/** Description shown on the device screen + the buyer's receipt. */
|
|
1081
|
+
description?: string;
|
|
1082
|
+
/** Your-system reference (echoed back in the resulting Payment). */
|
|
1083
|
+
externalReference?: string;
|
|
1084
|
+
/** Number of installments (default 1). */
|
|
1085
|
+
installments?: number;
|
|
1086
|
+
/** "seller" or "buyer" — who pays the installment cost. */
|
|
1087
|
+
installmentsCost?: "seller" | "buyer";
|
|
1088
|
+
/**
|
|
1089
|
+
* Print receipt on the terminal (default true). Some kiosks set false.
|
|
1090
|
+
*/
|
|
1091
|
+
printOnTerminal?: boolean;
|
|
1092
|
+
/** Ticket number (your sequential receipt number). */
|
|
1093
|
+
ticketNumber?: string;
|
|
1094
|
+
}
|
|
1020
1095
|
|
|
1021
1096
|
interface MercadoPagoClientOptions {
|
|
1022
1097
|
/** Access token. TEST- prefix for sandbox, APP_USR- for production. */
|
|
@@ -1398,52 +1473,158 @@ declare class MercadoPagoClient {
|
|
|
1398
1473
|
* including bank_account info (CBU, bank name).
|
|
1399
1474
|
*/
|
|
1400
1475
|
getSettlement(id: string): Promise<Settlement>;
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
}
|
|
1424
|
-
/**
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1476
|
+
/**
|
|
1477
|
+
* Update a customer's profile (name, last name, address, etc.). MP merges
|
|
1478
|
+
* the patch — fields you don't send remain unchanged.
|
|
1479
|
+
*/
|
|
1480
|
+
updateCustomer(id: string, patch: Partial<{
|
|
1481
|
+
first_name: string;
|
|
1482
|
+
last_name: string;
|
|
1483
|
+
phone: {
|
|
1484
|
+
area_code?: string;
|
|
1485
|
+
number?: string;
|
|
1486
|
+
};
|
|
1487
|
+
identification: {
|
|
1488
|
+
type: string;
|
|
1489
|
+
number: string;
|
|
1490
|
+
};
|
|
1491
|
+
address: {
|
|
1492
|
+
street_name?: string;
|
|
1493
|
+
street_number?: number;
|
|
1494
|
+
zip_code?: string;
|
|
1495
|
+
};
|
|
1496
|
+
description: string;
|
|
1497
|
+
default_card?: string;
|
|
1498
|
+
}>): Promise<Customer>;
|
|
1499
|
+
/**
|
|
1500
|
+
* Add a saved card to a customer using a card token (one-time, get from
|
|
1501
|
+
* MP's frontend Cardform). The card is then chargeable with charge_saved_card.
|
|
1502
|
+
*/
|
|
1503
|
+
createCustomerCard(customerId: string, cardToken: string): Promise<CustomerCard>;
|
|
1504
|
+
/**
|
|
1505
|
+
* Update an existing subscription. Common patches:
|
|
1506
|
+
* - `transaction_amount` to change the recurring amount
|
|
1507
|
+
* - `card_token_id` to switch payment method (e.g., expired card)
|
|
1508
|
+
* - `status: "cancelled" | "paused"` (alternative to dedicated cancel/pause endpoints)
|
|
1509
|
+
* - `reason` to update the description shown to the buyer
|
|
1510
|
+
*/
|
|
1511
|
+
updatePreapproval(id: string, patch: Partial<{
|
|
1512
|
+
transaction_amount: number;
|
|
1513
|
+
card_token_id: string;
|
|
1514
|
+
status: "authorized" | "paused" | "cancelled";
|
|
1515
|
+
reason: string;
|
|
1516
|
+
external_reference: string;
|
|
1517
|
+
}>): Promise<Preapproval>;
|
|
1518
|
+
/**
|
|
1519
|
+
* Search subscriptions across the seller's account. Common filters:
|
|
1520
|
+
* `status` (pending/authorized/paused/cancelled), `payer_email`,
|
|
1521
|
+
* `external_reference`. Paginated.
|
|
1522
|
+
*/
|
|
1523
|
+
searchPreapprovals(params?: {
|
|
1524
|
+
status?: string;
|
|
1525
|
+
payerEmail?: string;
|
|
1526
|
+
externalReference?: string;
|
|
1527
|
+
preapproval_plan_id?: string;
|
|
1528
|
+
limit?: number;
|
|
1529
|
+
offset?: number;
|
|
1530
|
+
}): Promise<{
|
|
1531
|
+
results: Preapproval[];
|
|
1532
|
+
paging: {
|
|
1533
|
+
limit: number;
|
|
1534
|
+
offset: number;
|
|
1535
|
+
total: number;
|
|
1536
|
+
};
|
|
1537
|
+
}>;
|
|
1538
|
+
/**
|
|
1539
|
+
* Get a merchant_order with all its associated payments + shipments.
|
|
1540
|
+
* Useful for reconciling "which payments belong to which preference"
|
|
1541
|
+
* — typical webhook handler use case.
|
|
1542
|
+
*/
|
|
1543
|
+
getMerchantOrder(id: string): Promise<MerchantOrder>;
|
|
1544
|
+
/**
|
|
1545
|
+
* Search merchant_orders by external_reference, preference_id, or status.
|
|
1546
|
+
*/
|
|
1547
|
+
searchMerchantOrders(params?: {
|
|
1548
|
+
preferenceId?: string;
|
|
1549
|
+
externalReference?: string;
|
|
1550
|
+
status?: string;
|
|
1551
|
+
limit?: number;
|
|
1552
|
+
offset?: number;
|
|
1553
|
+
}): Promise<{
|
|
1554
|
+
elements: MerchantOrder[];
|
|
1555
|
+
paging: {
|
|
1556
|
+
limit: number;
|
|
1557
|
+
offset: number;
|
|
1558
|
+
total: number;
|
|
1559
|
+
};
|
|
1560
|
+
}>;
|
|
1561
|
+
/**
|
|
1562
|
+
* Update a merchant_order — typically to add items or update shipping.
|
|
1563
|
+
*/
|
|
1564
|
+
updateMerchantOrder(id: string, patch: Record<string, unknown>): Promise<MerchantOrder>;
|
|
1565
|
+
getStore(userId: string, storeId: string): Promise<Store>;
|
|
1566
|
+
updateStore(userId: string, storeId: string, patch: Partial<CreateStoreParams>): Promise<Store>;
|
|
1567
|
+
deleteStore(userId: string, storeId: string): Promise<void>;
|
|
1568
|
+
getPos(posId: string): Promise<Pos>;
|
|
1569
|
+
updatePos(posId: string, patch: Partial<CreatePosParams>): Promise<Pos>;
|
|
1570
|
+
deletePos(posId: string): Promise<void>;
|
|
1571
|
+
/**
|
|
1572
|
+
* List bank accounts registered by the seller. The default is the one
|
|
1573
|
+
* that receives `release_money` settlements.
|
|
1574
|
+
*/
|
|
1575
|
+
listBankAccounts(): Promise<BankAccount[]>;
|
|
1576
|
+
/**
|
|
1577
|
+
* Register a new bank account (CBU) for the seller. Note: MP usually
|
|
1578
|
+
* requires this through the dashboard for compliance — this endpoint may
|
|
1579
|
+
* not work for all sellers.
|
|
1580
|
+
*/
|
|
1581
|
+
registerBankAccount(params: {
|
|
1582
|
+
cbu: string;
|
|
1583
|
+
alias?: string;
|
|
1584
|
+
}): Promise<BankAccount>;
|
|
1585
|
+
/**
|
|
1586
|
+
* List the Point devices linked to the seller's MP account. Each device
|
|
1587
|
+
* has an id (the device serial), an operating_mode (PDV vs STANDALONE),
|
|
1588
|
+
* and an optional pos_id (when bound to a logical POS).
|
|
1589
|
+
*/
|
|
1590
|
+
listPointDevices(params?: {
|
|
1591
|
+
posId?: string | number;
|
|
1592
|
+
limit?: number;
|
|
1593
|
+
offset?: number;
|
|
1594
|
+
}): Promise<{
|
|
1595
|
+
devices: PointDevice[];
|
|
1596
|
+
paging: {
|
|
1597
|
+
total: number;
|
|
1598
|
+
limit: number;
|
|
1599
|
+
offset: number;
|
|
1600
|
+
};
|
|
1601
|
+
}>;
|
|
1602
|
+
/**
|
|
1603
|
+
* Switch a Point device's operating mode:
|
|
1604
|
+
* - "PDV": device is bound to a logical Pos and only takes payments
|
|
1605
|
+
* triggered through that Pos (typical for cash-register integrations).
|
|
1606
|
+
* - "STANDALONE": device works independently, accepts any payment.
|
|
1607
|
+
*/
|
|
1608
|
+
updatePointDeviceOperatingMode(deviceId: string, operatingMode: "PDV" | "STANDALONE"): Promise<PointDevice>;
|
|
1609
|
+
/**
|
|
1610
|
+
* Create a payment intent on a Point device — the device prompts the buyer
|
|
1611
|
+
* to tap/insert/swipe. Returns immediately with intent id; query state via
|
|
1612
|
+
* `getPointPaymentIntent()` or wait for `point_integration_wh` webhook.
|
|
1613
|
+
*
|
|
1614
|
+
* NOTE: amount is in CENTAVOS (Point API differs from Payments API which
|
|
1615
|
+
* uses pesos). 100 = $1 ARS, 1000 = $10, 10000 = $100, etc.
|
|
1616
|
+
*/
|
|
1617
|
+
createPointPaymentIntent(deviceId: string, params: CreatePointPaymentIntentParams): Promise<PointPaymentIntent>;
|
|
1618
|
+
/** Get the current state of a Point payment intent. */
|
|
1619
|
+
getPointPaymentIntent(intentId: string): Promise<PointPaymentIntent>;
|
|
1620
|
+
/**
|
|
1621
|
+
* Cancel an OPEN payment intent before the buyer interacts with the device.
|
|
1622
|
+
* Only works while state is "OPEN" — once the buyer taps, you can't cancel.
|
|
1623
|
+
*/
|
|
1624
|
+
cancelPointPaymentIntent(deviceId: string, intentId: string): Promise<{
|
|
1625
|
+
id: string;
|
|
1626
|
+
canceled: true;
|
|
1627
|
+
}>;
|
|
1447
1628
|
}
|
|
1448
1629
|
|
|
1449
1630
|
interface MercadoPagoToolsOptions {
|
|
@@ -1484,7 +1665,7 @@ interface MercadoPagoToolsOptions {
|
|
|
1484
1665
|
clientSecret: string;
|
|
1485
1666
|
};
|
|
1486
1667
|
}
|
|
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";
|
|
1668
|
+
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" | "get_customer" | "update_customer" | "create_customer_card" | "get_customer_card" | "get_subscription_plan" | "update_subscription" | "search_subscriptions" | "get_refund" | "update_payment_preference" | "get_merchant_order" | "search_merchant_orders" | "update_merchant_order" | "get_store" | "update_store" | "delete_store" | "get_pos" | "update_pos" | "delete_pos" | "list_bank_accounts" | "register_bank_account" | "list_point_devices" | "update_point_device_mode" | "create_point_payment_intent" | "get_point_payment_intent" | "cancel_point_payment_intent" | "compute_marketplace_fee" | "explain_payment_status";
|
|
1488
1669
|
/**
|
|
1489
1670
|
* Build a tool set for the Vercel AI SDK that exposes Mercado Pago to an
|
|
1490
1671
|
* agent. Pass directly to `Experimental_Agent`'s `tools` option, or merge with
|
|
@@ -1508,12 +1689,26 @@ type ToolName = "create_subscription" | "get_subscription_status" | "cancel_subs
|
|
|
1508
1689
|
*/
|
|
1509
1690
|
declare function mercadoPagoTools(client: MercadoPagoClient, options: MercadoPagoToolsOptions): ToolSet;
|
|
1510
1691
|
|
|
1692
|
+
/**
|
|
1693
|
+
* Webhook helpers — parse incoming MP notifications and verify the
|
|
1694
|
+
* HMAC-SHA256 signature MP sends in the `x-signature` header.
|
|
1695
|
+
*
|
|
1696
|
+
* # Edge Runtime
|
|
1697
|
+
*
|
|
1698
|
+
* Both `verifyWebhookSignature` and `parseWebhookEvent` work in Vercel
|
|
1699
|
+
* Edge Runtime, Cloudflare Workers, Deno, browsers, and Node 18+. The
|
|
1700
|
+
* HMAC verification uses Web Crypto under the hood (see `./crypto.ts`)
|
|
1701
|
+
* and is **async** — make sure to `await` the call.
|
|
1702
|
+
*/
|
|
1703
|
+
|
|
1511
1704
|
/**
|
|
1512
1705
|
* Parse a Mercado Pago webhook from the raw request body and URL search params.
|
|
1513
1706
|
* MP sends the topic and resource id in EITHER the URL query string OR the
|
|
1514
1707
|
* body, depending on integration version — this normalizes both shapes into a
|
|
1515
1708
|
* single structure.
|
|
1516
1709
|
*
|
|
1710
|
+
* **Pure function — synchronous, no I/O.**
|
|
1711
|
+
*
|
|
1517
1712
|
* @example
|
|
1518
1713
|
* ```ts
|
|
1519
1714
|
* export async function POST(req: Request) {
|
|
@@ -1530,25 +1725,34 @@ declare function parseWebhookEvent(body: unknown, searchParams?: URLSearchParams
|
|
|
1530
1725
|
/**
|
|
1531
1726
|
* Verify the HMAC-SHA256 signature MP sends in the `x-signature` header for
|
|
1532
1727
|
* webhook authenticity. Returns true if the signature matches the expected
|
|
1533
|
-
* value derived from the integration's secret key
|
|
1728
|
+
* value derived from the integration's secret key AND the timestamp is
|
|
1729
|
+
* within the replay-tolerance window.
|
|
1730
|
+
*
|
|
1731
|
+
* **Async** — runs on Web Crypto under the hood, works in Edge Runtime.
|
|
1534
1732
|
*
|
|
1535
1733
|
* @param requestId The value of the `x-request-id` request header.
|
|
1536
1734
|
* @param dataId The id of the resource the webhook is about (from query or body).
|
|
1537
1735
|
* @param signatureHeader The full `x-signature` header value MP sent.
|
|
1538
1736
|
* @param secret Your integration's webhook secret (configured in MP dev panel).
|
|
1737
|
+
* @param replayToleranceSeconds Optional override. Default 300s (5 min).
|
|
1539
1738
|
*
|
|
1540
1739
|
* @remarks
|
|
1541
1740
|
* MP's `x-signature` header has the form: `ts=NNNNNNNN,v1=HEXSIGNATURE`. We
|
|
1542
1741
|
* extract the timestamp and the v1 signature, then compute
|
|
1543
1742
|
* `HMAC-SHA256(secret, "id:${dataId};request-id:${requestId};ts:${ts};")`
|
|
1544
1743
|
* and compare with constant-time equality.
|
|
1744
|
+
*
|
|
1745
|
+
* **Replay protection**: rejects signatures whose `ts` is older than
|
|
1746
|
+
* `replayToleranceSeconds` (default 5min) — prevents an attacker who
|
|
1747
|
+
* captured a valid webhook from replaying it later.
|
|
1545
1748
|
*/
|
|
1546
1749
|
declare function verifyWebhookSignature(params: {
|
|
1547
1750
|
requestId: string | null;
|
|
1548
1751
|
dataId: string;
|
|
1549
1752
|
signatureHeader: string | null;
|
|
1550
1753
|
secret: string;
|
|
1551
|
-
|
|
1754
|
+
replayToleranceSeconds?: number;
|
|
1755
|
+
}): Promise<boolean>;
|
|
1552
1756
|
|
|
1553
1757
|
/**
|
|
1554
1758
|
* Mercado Pago OAuth flow — for marketplace integrations where YOUR app
|
|
@@ -1789,4 +1993,69 @@ declare function buildTestCardScenario(cardKey: keyof typeof TEST_CARDS_AR, scen
|
|
|
1789
1993
|
*/
|
|
1790
1994
|
declare function analyze3DS(payment: Payment): ThreeDSInfo;
|
|
1791
1995
|
|
|
1792
|
-
|
|
1996
|
+
/**
|
|
1997
|
+
* Pure helpers — no I/O, deterministic, fast. Importable directly from the
|
|
1998
|
+
* package root or used via the agent tools (`compute_marketplace_fee`,
|
|
1999
|
+
* `explain_payment_status`).
|
|
2000
|
+
*/
|
|
2001
|
+
|
|
2002
|
+
interface MarketplaceFeeRule {
|
|
2003
|
+
/** Fixed fee in ARS (added on top of percentage). */
|
|
2004
|
+
flatArs?: number;
|
|
2005
|
+
/** Percentage of the transaction amount (0-100). */
|
|
2006
|
+
percent?: number;
|
|
2007
|
+
/** Minimum fee floor in ARS. */
|
|
2008
|
+
minArs?: number;
|
|
2009
|
+
/** Maximum fee cap in ARS. */
|
|
2010
|
+
maxArs?: number;
|
|
2011
|
+
/** Round to nearest peso (default true). */
|
|
2012
|
+
round?: boolean;
|
|
2013
|
+
}
|
|
2014
|
+
/**
|
|
2015
|
+
* Compute the exact `marketplace_fee` (in ARS) to pass to `create_order` /
|
|
2016
|
+
* `create_payment_preference` for a given transaction amount and fee rule.
|
|
2017
|
+
*
|
|
2018
|
+
* @example
|
|
2019
|
+
* // 5% fee with $50 floor and $5000 cap
|
|
2020
|
+
* computeMarketplaceFee(10000, { percent: 5, minArs: 50, maxArs: 5000 })
|
|
2021
|
+
* // → 500
|
|
2022
|
+
*
|
|
2023
|
+
* computeMarketplaceFee(500, { percent: 5, minArs: 50 })
|
|
2024
|
+
* // → 50 (would be 25 by percent, floor lifts to 50)
|
|
2025
|
+
*
|
|
2026
|
+
* @example
|
|
2027
|
+
* // Flat $200 + 2%
|
|
2028
|
+
* computeMarketplaceFee(10000, { flatArs: 200, percent: 2 })
|
|
2029
|
+
* // → 400
|
|
2030
|
+
*/
|
|
2031
|
+
declare function computeMarketplaceFee(amountArs: number, rule: MarketplaceFeeRule): number;
|
|
2032
|
+
interface PaymentStatusExplanation {
|
|
2033
|
+
/** Spanish summary of the current state — surface to user. */
|
|
2034
|
+
summary: string;
|
|
2035
|
+
/** What the agent should do next. Actionable guidance. */
|
|
2036
|
+
recommendedAction: string;
|
|
2037
|
+
/**
|
|
2038
|
+
* Whether this state is FINAL (no further changes) or transient
|
|
2039
|
+
* (can still flip with another webhook).
|
|
2040
|
+
*/
|
|
2041
|
+
final: boolean;
|
|
2042
|
+
/** Whether the buyer paid successfully (approved). */
|
|
2043
|
+
paid: boolean;
|
|
2044
|
+
/**
|
|
2045
|
+
* Whether this is a recoverable rejection (user can retry with another
|
|
2046
|
+
* card / different installments) vs a hard rejection (stop trying).
|
|
2047
|
+
*/
|
|
2048
|
+
retryable: boolean;
|
|
2049
|
+
}
|
|
2050
|
+
/**
|
|
2051
|
+
* Human-readable explanation of a Payment's current state — derives summary,
|
|
2052
|
+
* recommended action, finality, and whether the rejection is retryable from
|
|
2053
|
+
* `payment.status` + `payment.status_detail`.
|
|
2054
|
+
*
|
|
2055
|
+
* Pure function. Use the output to drive agent decisions ("¿reintento?
|
|
2056
|
+
* ¿le digo al cliente que cambie de tarjeta?") without having to memorize
|
|
2057
|
+
* every MP status_detail code.
|
|
2058
|
+
*/
|
|
2059
|
+
declare function explainPaymentStatus(payment: Payment): PaymentStatusExplanation;
|
|
2060
|
+
|
|
2061
|
+
export { type AccountBalance, type AccountInfo, type AccountMovement, type AutoRecurring, type BankAccount, type CardToken, type CreateCardTokenParams, type CreateCustomerParams, type CreateOrderParams, type CreatePaymentParams, type CreatePointPaymentIntentParams, 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, type InstallmentOffer, type Issuer, type MarketplaceFeeRule, type MarketplaceParams, MercadoPagoAccountTypeMismatchError, MercadoPagoAuthError, MercadoPagoAuthorizeForbiddenError, MercadoPagoBackUrlInvalidError, MercadoPagoClient, type MercadoPagoClientOptions, MercadoPagoError, MercadoPagoOverloadedError, MercadoPagoPaymentRejectedError, MercadoPagoRateLimitError, MercadoPagoSelfPaymentError, MercadoPagoTimeoutError, type MercadoPagoToolsOptions, type MerchantOrder, type OAuthToken, type Order, type OrderItem, type OrderStatus, type ParsedWebhookEvent, type Payment, type PaymentMethod, type PaymentStatus, type PaymentStatusExplanation, type PaymentsSearchResult, type PointDevice, type PointPaymentIntent, type PointPaymentIntentState, 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, SubscriptionStateAdapter, TEST_CARDS_AR, TEST_PAYERS_AR, type TestCard, type ThreeDSInfo, type ThreeDSStatus, type WebhookBody, type WebhookConfig, type WebhookTopic, analyze3DS, buildAuthorizeUrl, buildTestCardScenario, classifyError, computeMarketplaceFee, exchangeCodeForToken, expirationTimeMs, explainPaymentStatus, isExpiringSoon, mercadoPagoTools, parseWebhookEvent, refreshAccessToken, verifyWebhookSignature };
|