better-auth-mercadopago 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ import 'better-auth/client';
2
+ export { MercadoPagoClient, MercadoPagoClientActions, mercadoPagoClient } from './index.mjs';
3
+ import 'better-auth';
4
+ import 'zod';
@@ -0,0 +1,4 @@
1
+ import 'better-auth/client';
2
+ export { MercadoPagoClient, MercadoPagoClientActions, mercadoPagoClient } from './index.js';
3
+ import 'better-auth';
4
+ import 'zod';
package/dist/client.js ADDED
@@ -0,0 +1,301 @@
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
+ mercadoPagoClient: () => mercadoPagoClient
24
+ });
25
+ module.exports = __toCommonJS(client_exports);
26
+ var mercadoPagoClient = () => {
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
+ mercadoPagoClient
300
+ });
301
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../client.ts"],"sourcesContent":["import type {\n\tBetterAuthClientPlugin,\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\n// Export the actions type for Better Auth type inference\nexport type MercadoPagoClient = MercadoPagoClientActions;\n\nexport const mercadoPagoClient = () => {\n\treturn {\n\t\tid: \"mercadoPago\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof mercadoPagoPlugin>,\n\n\t\tgetActions: ($fetch: any): 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\t\t\t},\n\t\t}),\n\t} satisfies BetterAuthClientPlugin;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2HO,IAAM,oBAAoB,MAAM;AACtC,SAAO;AAAA,IACN,IAAI;AAAA,IACJ,oBAAoB,CAAC;AAAA,IAErB,YAAY,CAAC,YAA2C;AAAA;AAAA;AAAA;AAAA,MAIvD,qBAAqB,OACpB,MAKA,iBACI;AACJ,eA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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAkBA,aAAa,OACZ,QACA,iBACI;AACJ,cAAM,QAAQ,IAAI,gBAAgB;AAClC,cAAM,IAAI,eAAe,OAAO,WAAW;AAE3C,eAAO,MAAM;AAAA,UACZ,iCAAiC,MAAM,SAAS,CAAC;AAAA,UACjD;AAAA,YACC,QAAQ;AAAA,YACR,GAAG;AAAA,UACJ;AAAA,QACD;AAAA,MACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAsBA,mBAAmB,OAClB,MACA,iBACI;AACJ,eAAO,MAAM,OAAO,gCAAgC;AAAA,UACnD,QAAQ;AAAA,UACR,MAAM;AAAA,UACN,GAAG;AAAA,QACJ,CAAC;AAAA,MACF;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
@@ -0,0 +1,276 @@
1
+ // client.ts
2
+ var mercadoPagoClient = () => {
3
+ return {
4
+ id: "mercadoPago",
5
+ $InferServerPlugin: {},
6
+ getActions: ($fetch) => ({
7
+ /**
8
+ * Get or create a Mercado Pago customer for the authenticated user
9
+ */
10
+ getOrCreateCustomer: async (data, fetchOptions) => {
11
+ return await $fetch("/mercado-pago/customer", {
12
+ method: "POST",
13
+ body: data || {},
14
+ ...fetchOptions
15
+ });
16
+ },
17
+ /**
18
+ * Create a payment and get checkout URL
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const { data } = await authClient.mercadoPago.createPayment({
23
+ * items: [{
24
+ * title: "Premium Plan",
25
+ * quantity: 1,
26
+ * unitPrice: 99.90,
27
+ * currencyId: "ARS"
28
+ * }]
29
+ * });
30
+ *
31
+ * // Redirect user to checkout
32
+ * window.location.href = data.checkoutUrl;
33
+ * ```
34
+ */
35
+ createPayment: async (data, fetchOptions) => {
36
+ return await $fetch("/mercado-pago/payment/create", {
37
+ method: "POST",
38
+ body: data,
39
+ ...fetchOptions
40
+ });
41
+ },
42
+ /**
43
+ * Create a marketplace payment with automatic split
44
+ *
45
+ * You need to have the seller's MP User ID (collector_id) which they get
46
+ * after authorizing your app via OAuth.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * const { data } = await authClient.mercadoPago.createPayment({
51
+ * items: [{
52
+ * title: "Product from Seller",
53
+ * quantity: 1,
54
+ * unitPrice: 100
55
+ * }],
56
+ * marketplace: {
57
+ * collectorId: "123456789", // Seller's MP User ID
58
+ * applicationFeePercentage: 10 // Platform keeps 10%
59
+ * }
60
+ * });
61
+ * ```
62
+ */
63
+ createMarketplacePayment: async (data, fetchOptions) => {
64
+ return await $fetch("/mercado-pago/payment/create", {
65
+ method: "POST",
66
+ body: data,
67
+ ...fetchOptions
68
+ });
69
+ },
70
+ /**
71
+ * Create a subscription with recurring payments
72
+ *
73
+ * Supports two modes:
74
+ * 1. With preapproval plan (reusable): Pass preapprovalPlanId
75
+ * 2. Direct subscription (one-off): Pass reason + autoRecurring
76
+ *
77
+ * @example With plan
78
+ * ```ts
79
+ * const { data } = await authClient.mercadoPago.createSubscription({
80
+ * preapprovalPlanId: "plan_abc123"
81
+ * });
82
+ * ```
83
+ *
84
+ * @example Direct (without plan)
85
+ * ```ts
86
+ * const { data } = await authClient.mercadoPago.createSubscription({
87
+ * reason: "Premium Monthly Plan",
88
+ * autoRecurring: {
89
+ * frequency: 1,
90
+ * frequencyType: "months",
91
+ * transactionAmount: 99.90,
92
+ * currencyId: "ARS"
93
+ * }
94
+ * });
95
+ * ```
96
+ */
97
+ createSubscription: async (data, fetchOptions) => {
98
+ return await $fetch("/mercado-pago/subscription/create", {
99
+ method: "POST",
100
+ body: data,
101
+ ...fetchOptions
102
+ });
103
+ },
104
+ /**
105
+ * Cancel a subscription
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * await authClient.mercadoPago.cancelSubscription({
110
+ * subscriptionId: "sub_123"
111
+ * });
112
+ * ```
113
+ */
114
+ cancelSubscription: async (data, fetchOptions) => {
115
+ return await $fetch("/mercado-pago/subscription/cancel", {
116
+ method: "POST",
117
+ body: data,
118
+ ...fetchOptions
119
+ });
120
+ },
121
+ /**
122
+ * Create a reusable preapproval plan (subscription template)
123
+ *
124
+ * Plans can be reused for multiple subscriptions. Create once,
125
+ * use many times with createSubscription({ preapprovalPlanId })
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * const { data } = await authClient.mercadoPago.createPreapprovalPlan({
130
+ * reason: "Premium Monthly",
131
+ * autoRecurring: {
132
+ * frequency: 1,
133
+ * frequencyType: "months",
134
+ * transactionAmount: 99.90,
135
+ * freeTrial: {
136
+ * frequency: 7,
137
+ * frequencyType: "days"
138
+ * }
139
+ * },
140
+ * repetitions: 12 // 12 months, omit for infinite
141
+ * });
142
+ *
143
+ * // Use the plan
144
+ * const planId = data.plan.mercadoPagoPlanId;
145
+ * ```
146
+ */
147
+ createPreapprovalPlan: async (data, fetchOptions) => {
148
+ return await $fetch("/mercado-pago/plan/create", {
149
+ method: "POST",
150
+ body: data,
151
+ ...fetchOptions
152
+ });
153
+ },
154
+ /**
155
+ * List all preapproval plans
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * const { data } = await authClient.mercadoPago.listPreapprovalPlans();
160
+ *
161
+ * data.plans.forEach(plan => {
162
+ * console.log(plan.reason); // "Premium Monthly"
163
+ * console.log(plan.transactionAmount); // 99.90
164
+ * });
165
+ * ```
166
+ */
167
+ listPreapprovalPlans: async (fetchOptions) => {
168
+ return await $fetch("/mercado-pago/plans", {
169
+ method: "GET",
170
+ ...fetchOptions
171
+ });
172
+ },
173
+ /**
174
+ * Get payment by ID
175
+ */
176
+ getPayment: async (paymentId, fetchOptions) => {
177
+ return await $fetch(`/mercado-pago/payment/${paymentId}`, {
178
+ method: "GET",
179
+ ...fetchOptions
180
+ });
181
+ },
182
+ /**
183
+ * List all payments for the authenticated user
184
+ *
185
+ * @example
186
+ * ```ts
187
+ * const { data } = await authClient.mercadoPago.listPayments({
188
+ * limit: 20,
189
+ * offset: 0
190
+ * });
191
+ * ```
192
+ */
193
+ listPayments: async (params, fetchOptions) => {
194
+ const query = new URLSearchParams();
195
+ if (params?.limit) query.set("limit", params.limit.toString());
196
+ if (params?.offset) query.set("offset", params.offset.toString());
197
+ return await $fetch(`/mercado-pago/payments?${query.toString()}`, {
198
+ method: "GET",
199
+ ...fetchOptions
200
+ });
201
+ },
202
+ /**
203
+ * List all subscriptions for the authenticated user
204
+ *
205
+ * @example
206
+ * ```ts
207
+ * const { data } = await authClient.mercadoPago.listSubscriptions();
208
+ * ```
209
+ */
210
+ listSubscriptions: async (fetchOptions) => {
211
+ return await $fetch(`/mercado-pago/subscriptions`, {
212
+ method: "GET",
213
+ ...fetchOptions
214
+ });
215
+ },
216
+ /**
217
+ * Get OAuth authorization URL for marketplace sellers
218
+ *
219
+ * This is Step 1 of OAuth flow. Redirect the seller to this URL so they
220
+ * can authorize your app to process payments on their behalf.
221
+ *
222
+ * @example
223
+ * ```ts
224
+ * const { data } = await authClient.mercadoPago.getOAuthUrl({
225
+ * redirectUri: "https://myapp.com/oauth/callback"
226
+ * });
227
+ *
228
+ * // Redirect seller to authorize
229
+ * window.location.href = data.authUrl;
230
+ * ```
231
+ */
232
+ getOAuthUrl: async (params, fetchOptions) => {
233
+ const query = new URLSearchParams();
234
+ query.set("redirectUri", params.redirectUri);
235
+ return await $fetch(
236
+ `/mercado-pago/oauth/authorize?${query.toString()}`,
237
+ {
238
+ method: "GET",
239
+ ...fetchOptions
240
+ }
241
+ );
242
+ },
243
+ /**
244
+ * Exchange OAuth code for access token
245
+ *
246
+ * This is Step 2 of OAuth flow. After the seller authorizes and MP redirects
247
+ * them back with a code, exchange that code for an access token.
248
+ *
249
+ * @example
250
+ * ```ts
251
+ * // In your /oauth/callback page:
252
+ * const code = new URLSearchParams(window.location.search).get("code");
253
+ *
254
+ * const { data } = await authClient.mercadoPago.exchangeOAuthCode({
255
+ * code,
256
+ * redirectUri: "https://myapp.com/oauth/callback"
257
+ * });
258
+ *
259
+ * // Now you have the seller's MP User ID
260
+ * console.log(data.oauthToken.mercadoPagoUserId);
261
+ * ```
262
+ */
263
+ exchangeOAuthCode: async (data, fetchOptions) => {
264
+ return await $fetch("/mercado-pago/oauth/callback", {
265
+ method: "POST",
266
+ body: data,
267
+ ...fetchOptions
268
+ });
269
+ }
270
+ })
271
+ };
272
+ };
273
+ export {
274
+ mercadoPagoClient
275
+ };
276
+ //# sourceMappingURL=client.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../client.ts"],"sourcesContent":["import type {\n\tBetterAuthClientPlugin,\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\n// Export the actions type for Better Auth type inference\nexport type MercadoPagoClient = MercadoPagoClientActions;\n\nexport const mercadoPagoClient = () => {\n\treturn {\n\t\tid: \"mercadoPago\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof mercadoPagoPlugin>,\n\n\t\tgetActions: ($fetch: any): 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\t\t\t},\n\t\t}),\n\t} satisfies BetterAuthClientPlugin;\n};\n"],"mappings":";AA2HO,IAAM,oBAAoB,MAAM;AACtC,SAAO;AAAA,IACN,IAAI;AAAA,IACJ,oBAAoB,CAAC;AAAA,IAErB,YAAY,CAAC,YAA2C;AAAA;AAAA;AAAA;AAAA,MAIvD,qBAAqB,OACpB,MAKA,iBACI;AACJ,eAAO,MAAM,OAAO,0BAA0B;AAAA,UAC7C,QAAQ;AAAA,UACR,MAAM,QAAQ,CAAC;AAAA,UACf,GAAG;AAAA,QACJ,CAAC;AAAA,MACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAoBA,eAAe,OACd,MACA,iBACI;AACJ,eAAO,MAAM,OAAO,gCAAgC;AAAA,UACnD,QAAQ;AAAA,UACR,MAAM;AAAA,UACN,GAAG;AAAA,QACJ,CAAC;AAAA,MACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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