better-auth-mercadopago 0.1.8 → 0.1.9

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/CHANGELOG.md ADDED
@@ -0,0 +1,48 @@
1
+ # better-auth-mercadopago
2
+
3
+ ## 0.1.8
4
+
5
+ ### Patch Changes
6
+
7
+ - 79b98d9: rename and type plugin client
8
+
9
+ ## 0.1.7
10
+
11
+ ### Patch Changes
12
+
13
+ - Fix plugin ID casing so the plugin is mounted under `authClient.mercadopago` instead of `authClient.mercadoPago`.
14
+
15
+ This fixes a bug where the plugin ID used camelCase which caused mismatches with expected client property names. Tests were added/updated to validate the plugin structure.
16
+
17
+ ## 0.1.6
18
+
19
+ ### Patch Changes
20
+
21
+ - Fix client plugin structure to properly expose methods through getActions. This resolves the issue where authClient.mercadoPago.createSubscription and other methods were not accessible, even though they were available when destructuring.
22
+
23
+ ## 0.1.4
24
+
25
+ ### Patch Changes
26
+
27
+ - 31a0418: fix-github-action
28
+
29
+ ## 0.1.3
30
+
31
+ ### Patch Changes
32
+
33
+ - 9438e75: Fixed linting errors reported by Biome without breaking any functionality:
34
+ - Replaced non-null assertions with proper conditional checks
35
+ - Added explicit types to avoid implicit `any`
36
+ - Fixed TypeScript type assertions in test files
37
+
38
+ ## 0.1.2
39
+
40
+ ### Patch Changes
41
+
42
+ - docs: correct package name in readme
43
+
44
+ ## 0.1.1
45
+
46
+ ### Patch Changes
47
+
48
+ - Initial release: Fixed build issues and updated package name.
package/package.json CHANGED
@@ -1,23 +1,16 @@
1
1
  {
2
2
  "name": "better-auth-mercadopago",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Mercado Pago plugin for Better Auth - Simple payments, subscriptions and split payments",
5
- "publishConfig": {
6
- "access": "public"
7
- },
8
5
  "main": "./dist/index.js",
9
- "module": "./dist/index.mjs",
6
+ "module": "./dist/index.js",
10
7
  "types": "./dist/index.d.ts",
8
+ "type": "module",
11
9
  "exports": {
12
10
  ".": {
13
11
  "types": "./dist/index.d.ts",
14
- "import": "./dist/index.mjs",
12
+ "import": "./dist/index.js",
15
13
  "require": "./dist/index.js"
16
- },
17
- "./client": {
18
- "types": "./dist/client.d.ts",
19
- "import": "./dist/client.mjs",
20
- "require": "./dist/client.js"
21
14
  }
22
15
  },
23
16
  "repository": {
@@ -53,18 +46,20 @@
53
46
  "@changesets/cli": "^2.29.8",
54
47
  "@types/node": "^20.0.0",
55
48
  "better-auth": "^1.0.0",
56
- "tsup": "^8.0.0",
57
49
  "typescript": "^5.3.0",
58
50
  "vitest": "^4.0.18"
59
51
  },
60
52
  "files": [
61
53
  "dist",
62
54
  "README.md",
63
- "SECURITY.md"
55
+ "SECURITY.md",
56
+ "CHANGELOG.md"
64
57
  ],
58
+ "publishConfig": {
59
+ "access": "public"
60
+ },
65
61
  "scripts": {
66
- "build": "tsup",
67
- "dev": "tsup --watch",
62
+ "build": "tsc -p tsconfig.json",
68
63
  "typecheck": "tsc --noEmit",
69
64
  "format": "biome check --write",
70
65
  "lint": "biome check",
package/dist/client.d.mts DELETED
@@ -1,4 +0,0 @@
1
- import 'better-auth/client';
2
- export { MercadoPagoClient, MercadoPagoClientActions, mercadoPagoClientPlugin } from './index.mjs';
3
- import 'better-auth';
4
- import 'zod';
package/dist/client.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import 'better-auth/client';
2
- export { MercadoPagoClient, MercadoPagoClientActions, mercadoPagoClientPlugin } from './index.js';
3
- import 'better-auth';
4
- import 'zod';
package/dist/client.js DELETED
@@ -1,301 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // client.ts
21
- var client_exports = {};
22
- __export(client_exports, {
23
- mercadoPagoClientPlugin: () => mercadoPagoClientPlugin
24
- });
25
- module.exports = __toCommonJS(client_exports);
26
- var mercadoPagoClientPlugin = () => {
27
- return {
28
- id: "mercadopago",
29
- $InferServerPlugin: {},
30
- getActions: ($fetch) => ({
31
- /**
32
- * Get or create a Mercado Pago customer for the authenticated user
33
- */
34
- getOrCreateCustomer: async (data, fetchOptions) => {
35
- return await $fetch("/mercado-pago/customer", {
36
- method: "POST",
37
- body: data || {},
38
- ...fetchOptions
39
- });
40
- },
41
- /**
42
- * Create a payment and get checkout URL
43
- *
44
- * @example
45
- * ```ts
46
- * const { data } = await authClient.mercadoPago.createPayment({
47
- * items: [{
48
- * title: "Premium Plan",
49
- * quantity: 1,
50
- * unitPrice: 99.90,
51
- * currencyId: "ARS"
52
- * }]
53
- * });
54
- *
55
- * // Redirect user to checkout
56
- * window.location.href = data.checkoutUrl;
57
- * ```
58
- */
59
- createPayment: async (data, fetchOptions) => {
60
- return await $fetch("/mercado-pago/payment/create", {
61
- method: "POST",
62
- body: data,
63
- ...fetchOptions
64
- });
65
- },
66
- /**
67
- * Create a marketplace payment with automatic split
68
- *
69
- * You need to have the seller's MP User ID (collector_id) which they get
70
- * after authorizing your app via OAuth.
71
- *
72
- * @example
73
- * ```ts
74
- * const { data } = await authClient.mercadoPago.createPayment({
75
- * items: [{
76
- * title: "Product from Seller",
77
- * quantity: 1,
78
- * unitPrice: 100
79
- * }],
80
- * marketplace: {
81
- * collectorId: "123456789", // Seller's MP User ID
82
- * applicationFeePercentage: 10 // Platform keeps 10%
83
- * }
84
- * });
85
- * ```
86
- */
87
- createMarketplacePayment: async (data, fetchOptions) => {
88
- return await $fetch("/mercado-pago/payment/create", {
89
- method: "POST",
90
- body: data,
91
- ...fetchOptions
92
- });
93
- },
94
- /**
95
- * Create a subscription with recurring payments
96
- *
97
- * Supports two modes:
98
- * 1. With preapproval plan (reusable): Pass preapprovalPlanId
99
- * 2. Direct subscription (one-off): Pass reason + autoRecurring
100
- *
101
- * @example With plan
102
- * ```ts
103
- * const { data } = await authClient.mercadoPago.createSubscription({
104
- * preapprovalPlanId: "plan_abc123"
105
- * });
106
- * ```
107
- *
108
- * @example Direct (without plan)
109
- * ```ts
110
- * const { data } = await authClient.mercadoPago.createSubscription({
111
- * reason: "Premium Monthly Plan",
112
- * autoRecurring: {
113
- * frequency: 1,
114
- * frequencyType: "months",
115
- * transactionAmount: 99.90,
116
- * currencyId: "ARS"
117
- * }
118
- * });
119
- * ```
120
- */
121
- createSubscription: async (data, fetchOptions) => {
122
- return await $fetch("/mercado-pago/subscription/create", {
123
- method: "POST",
124
- body: data,
125
- ...fetchOptions
126
- });
127
- },
128
- /**
129
- * Cancel a subscription
130
- *
131
- * @example
132
- * ```ts
133
- * await authClient.mercadoPago.cancelSubscription({
134
- * subscriptionId: "sub_123"
135
- * });
136
- * ```
137
- */
138
- cancelSubscription: async (data, fetchOptions) => {
139
- return await $fetch("/mercado-pago/subscription/cancel", {
140
- method: "POST",
141
- body: data,
142
- ...fetchOptions
143
- });
144
- },
145
- /**
146
- * Create a reusable preapproval plan (subscription template)
147
- *
148
- * Plans can be reused for multiple subscriptions. Create once,
149
- * use many times with createSubscription({ preapprovalPlanId })
150
- *
151
- * @example
152
- * ```ts
153
- * const { data } = await authClient.mercadoPago.createPreapprovalPlan({
154
- * reason: "Premium Monthly",
155
- * autoRecurring: {
156
- * frequency: 1,
157
- * frequencyType: "months",
158
- * transactionAmount: 99.90,
159
- * freeTrial: {
160
- * frequency: 7,
161
- * frequencyType: "days"
162
- * }
163
- * },
164
- * repetitions: 12 // 12 months, omit for infinite
165
- * });
166
- *
167
- * // Use the plan
168
- * const planId = data.plan.mercadoPagoPlanId;
169
- * ```
170
- */
171
- createPreapprovalPlan: async (data, fetchOptions) => {
172
- return await $fetch("/mercado-pago/plan/create", {
173
- method: "POST",
174
- body: data,
175
- ...fetchOptions
176
- });
177
- },
178
- /**
179
- * List all preapproval plans
180
- *
181
- * @example
182
- * ```ts
183
- * const { data } = await authClient.mercadoPago.listPreapprovalPlans();
184
- *
185
- * data.plans.forEach(plan => {
186
- * console.log(plan.reason); // "Premium Monthly"
187
- * console.log(plan.transactionAmount); // 99.90
188
- * });
189
- * ```
190
- */
191
- listPreapprovalPlans: async (fetchOptions) => {
192
- return await $fetch("/mercado-pago/plans", {
193
- method: "GET",
194
- ...fetchOptions
195
- });
196
- },
197
- /**
198
- * Get payment by ID
199
- */
200
- getPayment: async (paymentId, fetchOptions) => {
201
- return await $fetch(`/mercado-pago/payment/${paymentId}`, {
202
- method: "GET",
203
- ...fetchOptions
204
- });
205
- },
206
- /**
207
- * List all payments for the authenticated user
208
- *
209
- * @example
210
- * ```ts
211
- * const { data } = await authClient.mercadoPago.listPayments({
212
- * limit: 20,
213
- * offset: 0
214
- * });
215
- * ```
216
- */
217
- listPayments: async (params, fetchOptions) => {
218
- const query = new URLSearchParams();
219
- if (params?.limit) query.set("limit", params.limit.toString());
220
- if (params?.offset) query.set("offset", params.offset.toString());
221
- return await $fetch(`/mercado-pago/payments?${query.toString()}`, {
222
- method: "GET",
223
- ...fetchOptions
224
- });
225
- },
226
- /**
227
- * List all subscriptions for the authenticated user
228
- *
229
- * @example
230
- * ```ts
231
- * const { data } = await authClient.mercadoPago.listSubscriptions();
232
- * ```
233
- */
234
- listSubscriptions: async (fetchOptions) => {
235
- return await $fetch(`/mercado-pago/subscriptions`, {
236
- method: "GET",
237
- ...fetchOptions
238
- });
239
- },
240
- /**
241
- * Get OAuth authorization URL for marketplace sellers
242
- *
243
- * This is Step 1 of OAuth flow. Redirect the seller to this URL so they
244
- * can authorize your app to process payments on their behalf.
245
- *
246
- * @example
247
- * ```ts
248
- * const { data } = await authClient.mercadoPago.getOAuthUrl({
249
- * redirectUri: "https://myapp.com/oauth/callback"
250
- * });
251
- *
252
- * // Redirect seller to authorize
253
- * window.location.href = data.authUrl;
254
- * ```
255
- */
256
- getOAuthUrl: async (params, fetchOptions) => {
257
- const query = new URLSearchParams();
258
- query.set("redirectUri", params.redirectUri);
259
- return await $fetch(
260
- `/mercado-pago/oauth/authorize?${query.toString()}`,
261
- {
262
- method: "GET",
263
- ...fetchOptions
264
- }
265
- );
266
- },
267
- /**
268
- * Exchange OAuth code for access token
269
- *
270
- * This is Step 2 of OAuth flow. After the seller authorizes and MP redirects
271
- * them back with a code, exchange that code for an access token.
272
- *
273
- * @example
274
- * ```ts
275
- * // In your /oauth/callback page:
276
- * const code = new URLSearchParams(window.location.search).get("code");
277
- *
278
- * const { data } = await authClient.mercadoPago.exchangeOAuthCode({
279
- * code,
280
- * redirectUri: "https://myapp.com/oauth/callback"
281
- * });
282
- *
283
- * // Now you have the seller's MP User ID
284
- * console.log(data.oauthToken.mercadoPagoUserId);
285
- * ```
286
- */
287
- exchangeOAuthCode: async (data, fetchOptions) => {
288
- return await $fetch("/mercado-pago/oauth/callback", {
289
- method: "POST",
290
- body: data,
291
- ...fetchOptions
292
- });
293
- }
294
- })
295
- };
296
- };
297
- // Annotate the CommonJS export names for ESM import in node:
298
- 0 && (module.exports = {
299
- mercadoPagoClientPlugin
300
- });
301
- //# sourceMappingURL=client.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../client.ts"],"sourcesContent":["import type {\n\tBetterAuthClientPlugin,\n\tBetterFetch,\n\tBetterFetchOption,\n} from \"better-auth/client\";\nimport type { mercadoPagoPlugin } from \"./index\";\nimport type {\n\tCreatePaymentParams,\n\tCreatePaymentResponse,\n\tCreatePreapprovalPlanParams,\n\tCreatePreapprovalPlanResponse,\n\tCreateSubscriptionParams,\n\tCreateSubscriptionResponse,\n\tMercadoPagoCustomerRecord,\n\tMercadoPagoPaymentRecord,\n\tMercadoPagoPreapprovalPlanRecord,\n\tMercadoPagoSubscriptionRecord,\n\tOAuthTokenResponse,\n\tOAuthUrlResponse,\n} from \"./types\";\n\nexport interface MercadoPagoClientActions {\n\t/**\n\t * Get or create a Mercado Pago customer for the authenticated user\n\t */\n\tgetOrCreateCustomer: (\n\t\tdata?: {\n\t\t\temail?: string;\n\t\t\tfirstName?: string;\n\t\t\tlastName?: string;\n\t\t},\n\t\tfetchOptions?: BetterFetchOption,\n\t) => Promise<{ customer: MercadoPagoCustomerRecord }>;\n\n\t/**\n\t * Create a payment and get checkout URL\n\t */\n\tcreatePayment: (\n\t\tdata: CreatePaymentParams,\n\t\tfetchOptions?: BetterFetchOption,\n\t) => Promise<CreatePaymentResponse>;\n\n\t/**\n\t * Create a marketplace payment with automatic split\n\t */\n\tcreateMarketplacePayment: (\n\t\tdata: CreatePaymentParams,\n\t\tfetchOptions?: BetterFetchOption,\n\t) => Promise<CreatePaymentResponse>;\n\n\t/**\n\t * Create a subscription with recurring payments\n\t */\n\tcreateSubscription: (\n\t\tdata: CreateSubscriptionParams,\n\t\tfetchOptions?: BetterFetchOption,\n\t) => Promise<CreateSubscriptionResponse>;\n\n\t/**\n\t * Cancel a subscription\n\t */\n\tcancelSubscription: (\n\t\tdata: { subscriptionId: string },\n\t\tfetchOptions?: BetterFetchOption,\n\t) => Promise<{ success: boolean }>;\n\n\t/**\n\t * Create a reusable preapproval plan (subscription template)\n\t */\n\tcreatePreapprovalPlan: (\n\t\tdata: CreatePreapprovalPlanParams,\n\t\tfetchOptions?: BetterFetchOption,\n\t) => Promise<CreatePreapprovalPlanResponse>;\n\n\t/**\n\t * List all preapproval plans\n\t */\n\tlistPreapprovalPlans: (\n\t\tfetchOptions?: BetterFetchOption,\n\t) => Promise<{ plans: MercadoPagoPreapprovalPlanRecord[] }>;\n\n\t/**\n\t * Get payment by ID\n\t */\n\tgetPayment: (\n\t\tpaymentId: string,\n\t\tfetchOptions?: BetterFetchOption,\n\t) => Promise<{ payment: MercadoPagoPaymentRecord }>;\n\n\t/**\n\t * List all payments for the authenticated user\n\t */\n\tlistPayments: (\n\t\tparams?: { limit?: number; offset?: number },\n\t\tfetchOptions?: BetterFetchOption,\n\t) => Promise<{ payments: MercadoPagoPaymentRecord[] }>;\n\n\t/**\n\t * List all subscriptions for the authenticated user\n\t */\n\tlistSubscriptions: (\n\t\tfetchOptions?: BetterFetchOption,\n\t) => Promise<{ subscriptions: MercadoPagoSubscriptionRecord[] }>;\n\n\t/**\n\t * Get OAuth authorization URL for marketplace sellers\n\t */\n\tgetOAuthUrl: (\n\t\tparams: { redirectUri: string },\n\t\tfetchOptions?: BetterFetchOption,\n\t) => Promise<OAuthUrlResponse>;\n\n\t/**\n\t * Exchange OAuth code for access token\n\t */\n\texchangeOAuthCode: (\n\t\tdata: { code: string; redirectUri: string },\n\t\tfetchOptions?: BetterFetchOption,\n\t) => Promise<OAuthTokenResponse>;\n}\n\ntype mercadopagoPlugin = typeof mercadoPagoPlugin;\n\n// Export the actions type for Better Auth type inference\nexport type MercadoPagoClient = MercadoPagoClientActions;\n\nexport const mercadoPagoClientPlugin = () => {\n\treturn {\n\t\tid: \"mercadopago\",\n\t\t$InferServerPlugin: {} as ReturnType<mercadopagoPlugin>,\n\n\t\tgetActions: ($fetch: BetterFetch): MercadoPagoClientActions => ({\n\t\t\t/**\n\t\t\t * Get or create a Mercado Pago customer for the authenticated user\n\t\t\t */\n\t\t\tgetOrCreateCustomer: async (\n\t\t\t\tdata?: {\n\t\t\t\t\temail?: string;\n\t\t\t\t\tfirstName?: string;\n\t\t\t\t\tlastName?: string;\n\t\t\t\t},\n\t\t\t\tfetchOptions?: BetterFetchOption,\n\t\t\t) => {\n\t\t\t\treturn await $fetch(\"/mercado-pago/customer\", {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: data || {},\n\t\t\t\t\t...fetchOptions,\n\t\t\t\t});\n\t\t\t},\n\n\t\t\t/**\n\t\t\t * Create a payment and get checkout URL\n\t\t\t *\n\t\t\t * @example\n\t\t\t * ```ts\n\t\t\t * const { data } = await authClient.mercadoPago.createPayment({\n\t\t\t * items: [{\n\t\t\t * title: \"Premium Plan\",\n\t\t\t * quantity: 1,\n\t\t\t * unitPrice: 99.90,\n\t\t\t * currencyId: \"ARS\"\n\t\t\t * }]\n\t\t\t * });\n\t\t\t *\n\t\t\t * // Redirect user to checkout\n\t\t\t * window.location.href = data.checkoutUrl;\n\t\t\t * ```\n\t\t\t */\n\t\t\tcreatePayment: async (\n\t\t\t\tdata: CreatePaymentParams,\n\t\t\t\tfetchOptions?: BetterFetchOption,\n\t\t\t) => {\n\t\t\t\treturn await $fetch(\"/mercado-pago/payment/create\", {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: data,\n\t\t\t\t\t...fetchOptions,\n\t\t\t\t});\n\t\t\t},\n\n\t\t\t/**\n\t\t\t * Create a marketplace payment with automatic split\n\t\t\t *\n\t\t\t * You need to have the seller's MP User ID (collector_id) which they get\n\t\t\t * after authorizing your app via OAuth.\n\t\t\t *\n\t\t\t * @example\n\t\t\t * ```ts\n\t\t\t * const { data } = await authClient.mercadoPago.createPayment({\n\t\t\t * items: [{\n\t\t\t * title: \"Product from Seller\",\n\t\t\t * quantity: 1,\n\t\t\t * unitPrice: 100\n\t\t\t * }],\n\t\t\t * marketplace: {\n\t\t\t * collectorId: \"123456789\", // Seller's MP User ID\n\t\t\t * applicationFeePercentage: 10 // Platform keeps 10%\n\t\t\t * }\n\t\t\t * });\n\t\t\t * ```\n\t\t\t */\n\t\t\tcreateMarketplacePayment: async (\n\t\t\t\tdata: CreatePaymentParams,\n\t\t\t\tfetchOptions?: BetterFetchOption,\n\t\t\t) => {\n\t\t\t\treturn await $fetch(\"/mercado-pago/payment/create\", {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: data,\n\t\t\t\t\t...fetchOptions,\n\t\t\t\t});\n\t\t\t},\n\n\t\t\t/**\n\t\t\t * Create a subscription with recurring payments\n\t\t\t *\n\t\t\t * Supports two modes:\n\t\t\t * 1. With preapproval plan (reusable): Pass preapprovalPlanId\n\t\t\t * 2. Direct subscription (one-off): Pass reason + autoRecurring\n\t\t\t *\n\t\t\t * @example With plan\n\t\t\t * ```ts\n\t\t\t * const { data } = await authClient.mercadoPago.createSubscription({\n\t\t\t * preapprovalPlanId: \"plan_abc123\"\n\t\t\t * });\n\t\t\t * ```\n\t\t\t *\n\t\t\t * @example Direct (without plan)\n\t\t\t * ```ts\n\t\t\t * const { data } = await authClient.mercadoPago.createSubscription({\n\t\t\t * reason: \"Premium Monthly Plan\",\n\t\t\t * autoRecurring: {\n\t\t\t * frequency: 1,\n\t\t\t * frequencyType: \"months\",\n\t\t\t * transactionAmount: 99.90,\n\t\t\t * currencyId: \"ARS\"\n\t\t\t * }\n\t\t\t * });\n\t\t\t * ```\n\t\t\t */\n\t\t\tcreateSubscription: async (\n\t\t\t\tdata: CreateSubscriptionParams,\n\t\t\t\tfetchOptions?: BetterFetchOption,\n\t\t\t) => {\n\t\t\t\treturn await $fetch(\"/mercado-pago/subscription/create\", {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: data,\n\t\t\t\t\t...fetchOptions,\n\t\t\t\t});\n\t\t\t},\n\n\t\t\t/**\n\t\t\t * Cancel a subscription\n\t\t\t *\n\t\t\t * @example\n\t\t\t * ```ts\n\t\t\t * await authClient.mercadoPago.cancelSubscription({\n\t\t\t * subscriptionId: \"sub_123\"\n\t\t\t * });\n\t\t\t * ```\n\t\t\t */\n\t\t\tcancelSubscription: async (\n\t\t\t\tdata: { subscriptionId: string },\n\t\t\t\tfetchOptions?: BetterFetchOption,\n\t\t\t) => {\n\t\t\t\treturn await $fetch(\"/mercado-pago/subscription/cancel\", {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: data,\n\t\t\t\t\t...fetchOptions,\n\t\t\t\t});\n\t\t\t},\n\n\t\t\t/**\n\t\t\t * Create a reusable preapproval plan (subscription template)\n\t\t\t *\n\t\t\t * Plans can be reused for multiple subscriptions. Create once,\n\t\t\t * use many times with createSubscription({ preapprovalPlanId })\n\t\t\t *\n\t\t\t * @example\n\t\t\t * ```ts\n\t\t\t * const { data } = await authClient.mercadoPago.createPreapprovalPlan({\n\t\t\t * reason: \"Premium Monthly\",\n\t\t\t * autoRecurring: {\n\t\t\t * frequency: 1,\n\t\t\t * frequencyType: \"months\",\n\t\t\t * transactionAmount: 99.90,\n\t\t\t * freeTrial: {\n\t\t\t * frequency: 7,\n\t\t\t * frequencyType: \"days\"\n\t\t\t * }\n\t\t\t * },\n\t\t\t * repetitions: 12 // 12 months, omit for infinite\n\t\t\t * });\n\t\t\t *\n\t\t\t * // Use the plan\n\t\t\t * const planId = data.plan.mercadoPagoPlanId;\n\t\t\t * ```\n\t\t\t */\n\t\t\tcreatePreapprovalPlan: async (\n\t\t\t\tdata: CreatePreapprovalPlanParams,\n\t\t\t\tfetchOptions?: BetterFetchOption,\n\t\t\t) => {\n\t\t\t\treturn await $fetch(\"/mercado-pago/plan/create\", {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: data,\n\t\t\t\t\t...fetchOptions,\n\t\t\t\t});\n\t\t\t},\n\n\t\t\t/**\n\t\t\t * List all preapproval plans\n\t\t\t *\n\t\t\t * @example\n\t\t\t * ```ts\n\t\t\t * const { data } = await authClient.mercadoPago.listPreapprovalPlans();\n\t\t\t *\n\t\t\t * data.plans.forEach(plan => {\n\t\t\t * console.log(plan.reason); // \"Premium Monthly\"\n\t\t\t * console.log(plan.transactionAmount); // 99.90\n\t\t\t * });\n\t\t\t * ```\n\t\t\t */\n\t\t\tlistPreapprovalPlans: async (fetchOptions?: BetterFetchOption) => {\n\t\t\t\treturn await $fetch(\"/mercado-pago/plans\", {\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\t...fetchOptions,\n\t\t\t\t});\n\t\t\t},\n\n\t\t\t/**\n\t\t\t * Get payment by ID\n\t\t\t */\n\t\t\tgetPayment: async (\n\t\t\t\tpaymentId: string,\n\t\t\t\tfetchOptions?: BetterFetchOption,\n\t\t\t) => {\n\t\t\t\treturn await $fetch(`/mercado-pago/payment/${paymentId}`, {\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\t...fetchOptions,\n\t\t\t\t});\n\t\t\t},\n\n\t\t\t/**\n\t\t\t * List all payments for the authenticated user\n\t\t\t *\n\t\t\t * @example\n\t\t\t * ```ts\n\t\t\t * const { data } = await authClient.mercadoPago.listPayments({\n\t\t\t * limit: 20,\n\t\t\t * offset: 0\n\t\t\t * });\n\t\t\t * ```\n\t\t\t */\n\t\t\tlistPayments: async (\n\t\t\t\tparams?: { limit?: number; offset?: number },\n\t\t\t\tfetchOptions?: BetterFetchOption,\n\t\t\t) => {\n\t\t\t\tconst query = new URLSearchParams();\n\t\t\t\tif (params?.limit) query.set(\"limit\", params.limit.toString());\n\t\t\t\tif (params?.offset) query.set(\"offset\", params.offset.toString());\n\n\t\t\t\treturn await $fetch(`/mercado-pago/payments?${query.toString()}`, {\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\t...fetchOptions,\n\t\t\t\t});\n\t\t\t},\n\n\t\t\t/**\n\t\t\t * List all subscriptions for the authenticated user\n\t\t\t *\n\t\t\t * @example\n\t\t\t * ```ts\n\t\t\t * const { data } = await authClient.mercadoPago.listSubscriptions();\n\t\t\t * ```\n\t\t\t */\n\t\t\tlistSubscriptions: async (fetchOptions?: BetterFetchOption) => {\n\t\t\t\treturn await $fetch(`/mercado-pago/subscriptions`, {\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\t...fetchOptions,\n\t\t\t\t});\n\t\t\t},\n\n\t\t\t/**\n\t\t\t * Get OAuth authorization URL for marketplace sellers\n\t\t\t *\n\t\t\t * This is Step 1 of OAuth flow. Redirect the seller to this URL so they\n\t\t\t * can authorize your app to process payments on their behalf.\n\t\t\t *\n\t\t\t * @example\n\t\t\t * ```ts\n\t\t\t * const { data } = await authClient.mercadoPago.getOAuthUrl({\n\t\t\t * redirectUri: \"https://myapp.com/oauth/callback\"\n\t\t\t * });\n\t\t\t *\n\t\t\t * // Redirect seller to authorize\n\t\t\t * window.location.href = data.authUrl;\n\t\t\t * ```\n\t\t\t */\n\t\t\tgetOAuthUrl: async (\n\t\t\t\tparams: { redirectUri: string },\n\t\t\t\tfetchOptions?: BetterFetchOption,\n\t\t\t) => {\n\t\t\t\tconst query = new URLSearchParams();\n\t\t\t\tquery.set(\"redirectUri\", params.redirectUri);\n\n\t\t\t\treturn await $fetch(\n\t\t\t\t\t`/mercado-pago/oauth/authorize?${query.toString()}`,\n\t\t\t\t\t{\n\t\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\t\t...fetchOptions,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t},\n\n\t\t\t/**\n\t\t\t * Exchange OAuth code for access token\n\t\t\t *\n\t\t\t * This is Step 2 of OAuth flow. After the seller authorizes and MP redirects\n\t\t\t * them back with a code, exchange that code for an access token.\n\t\t\t *\n\t\t\t * @example\n\t\t\t * ```ts\n\t\t\t * // In your /oauth/callback page:\n\t\t\t * const code = new URLSearchParams(window.location.search).get(\"code\");\n\t\t\t *\n\t\t\t * const { data } = await authClient.mercadoPago.exchangeOAuthCode({\n\t\t\t * code,\n\t\t\t * redirectUri: \"https://myapp.com/oauth/callback\"\n\t\t\t * });\n\t\t\t *\n\t\t\t * // Now you have the seller's MP User ID\n\t\t\t * console.log(data.oauthToken.mercadoPagoUserId);\n\t\t\t * ```\n\t\t\t */\n\t\t\texchangeOAuthCode: async (\n\t\t\t\tdata: { code: string; redirectUri: string },\n\t\t\t\tfetchOptions?: BetterFetchOption,\n\t\t\t) => {\n\t\t\t\treturn await $fetch(\"/mercado-pago/oauth/callback\", {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: data,\n\t\t\t\t\t...fetchOptions,\n\t\t\t\t});\n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