better-auth-mercadopago 0.1.3 → 0.1.5

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Mercado Pago Plugin for Better Auth
2
2
 
3
- ![CI Status](https://github.com/ivantsxx/better-auth-mercadopago/actions/workflows/ci.yml/badge.svg)
3
+ ![CI Status](https://github.com/IvanTsxx/better-auth-mercadopago-plugin/actions/workflows/ci.yml/badge.svg)
4
4
  ![NPM Version](https://img.shields.io/npm/v/better-auth-mercadopago)
5
5
  ![License](https://img.shields.io/npm/l/better-auth-mercadopago)
6
6
 
@@ -0,0 +1,4 @@
1
+ import 'better-auth/client';
2
+ export { mercadoPagoClient } from './index.mjs';
3
+ import 'better-auth';
4
+ import 'zod';
@@ -0,0 +1,4 @@
1
+ import 'better-auth/client';
2
+ export { mercadoPagoClient } from './index.js';
3
+ import 'better-auth';
4
+ import 'zod';
package/dist/client.js ADDED
@@ -0,0 +1,334 @@
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: "mercado-pago",
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(
36
+ "/mercado-pago/customer",
37
+ {
38
+ method: "POST",
39
+ body: data || {},
40
+ ...fetchOptions
41
+ }
42
+ );
43
+ },
44
+ /**
45
+ * Create a payment and get checkout URL
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * const { data } = await authClient.mercadoPago.createPayment({
50
+ * items: [{
51
+ * title: "Premium Plan",
52
+ * quantity: 1,
53
+ * unitPrice: 99.90,
54
+ * currencyId: "ARS"
55
+ * }]
56
+ * });
57
+ *
58
+ * // Redirect user to checkout
59
+ * window.location.href = data.checkoutUrl;
60
+ * ```
61
+ */
62
+ createPayment: async (data, fetchOptions) => {
63
+ return await $fetch(
64
+ "/mercado-pago/payment/create",
65
+ {
66
+ method: "POST",
67
+ body: data,
68
+ ...fetchOptions
69
+ }
70
+ );
71
+ },
72
+ /**
73
+ * Create a marketplace payment with automatic split
74
+ *
75
+ * You need to have the seller's MP User ID (collector_id) which they get
76
+ * after authorizing your app via OAuth.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * const { data } = await authClient.mercadoPago.createPayment({
81
+ * items: [{
82
+ * title: "Product from Seller",
83
+ * quantity: 1,
84
+ * unitPrice: 100
85
+ * }],
86
+ * marketplace: {
87
+ * collectorId: "123456789", // Seller's MP User ID
88
+ * applicationFeePercentage: 10 // Platform keeps 10%
89
+ * }
90
+ * });
91
+ * ```
92
+ */
93
+ createMarketplacePayment: async (data, fetchOptions) => {
94
+ return await $fetch(
95
+ "/mercado-pago/payment/create",
96
+ {
97
+ method: "POST",
98
+ body: data,
99
+ ...fetchOptions
100
+ }
101
+ );
102
+ },
103
+ /**
104
+ * Create a subscription with recurring payments
105
+ *
106
+ * Supports two modes:
107
+ * 1. With preapproval plan (reusable): Pass preapprovalPlanId
108
+ * 2. Direct subscription (one-off): Pass reason + autoRecurring
109
+ *
110
+ * @example With plan
111
+ * ```ts
112
+ * const { data } = await authClient.mercadoPago.createSubscription({
113
+ * preapprovalPlanId: "plan_abc123"
114
+ * });
115
+ * ```
116
+ *
117
+ * @example Direct (without plan)
118
+ * ```ts
119
+ * const { data } = await authClient.mercadoPago.createSubscription({
120
+ * reason: "Premium Monthly Plan",
121
+ * autoRecurring: {
122
+ * frequency: 1,
123
+ * frequencyType: "months",
124
+ * transactionAmount: 99.90,
125
+ * currencyId: "ARS"
126
+ * }
127
+ * });
128
+ * ```
129
+ */
130
+ createSubscription: async (data, fetchOptions) => {
131
+ return await $fetch(
132
+ "/mercado-pago/subscription/create",
133
+ {
134
+ method: "POST",
135
+ body: data,
136
+ ...fetchOptions
137
+ }
138
+ );
139
+ },
140
+ /**
141
+ * Cancel a subscription
142
+ *
143
+ * @example
144
+ * ```ts
145
+ * await authClient.mercadoPago.cancelSubscription({
146
+ * subscriptionId: "sub_123"
147
+ * });
148
+ * ```
149
+ */
150
+ cancelSubscription: async (data, fetchOptions) => {
151
+ return await $fetch(
152
+ "/mercado-pago/subscription/cancel",
153
+ {
154
+ method: "POST",
155
+ body: data,
156
+ ...fetchOptions
157
+ }
158
+ );
159
+ },
160
+ /**
161
+ * Create a reusable preapproval plan (subscription template)
162
+ *
163
+ * Plans can be reused for multiple subscriptions. Create once,
164
+ * use many times with createSubscription({ preapprovalPlanId })
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * const { data } = await authClient.mercadoPago.createPreapprovalPlan({
169
+ * reason: "Premium Monthly",
170
+ * autoRecurring: {
171
+ * frequency: 1,
172
+ * frequencyType: "months",
173
+ * transactionAmount: 99.90,
174
+ * freeTrial: {
175
+ * frequency: 7,
176
+ * frequencyType: "days"
177
+ * }
178
+ * },
179
+ * repetitions: 12 // 12 months, omit for infinite
180
+ * });
181
+ *
182
+ * // Use the plan
183
+ * const planId = data.plan.mercadoPagoPlanId;
184
+ * ```
185
+ */
186
+ createPreapprovalPlan: async (data, fetchOptions) => {
187
+ return await $fetch(
188
+ "/mercado-pago/plan/create",
189
+ {
190
+ method: "POST",
191
+ body: data,
192
+ ...fetchOptions
193
+ }
194
+ );
195
+ },
196
+ /**
197
+ * List all preapproval plans
198
+ *
199
+ * @example
200
+ * ```ts
201
+ * const { data } = await authClient.mercadoPago.listPreapprovalPlans();
202
+ *
203
+ * data.plans.forEach(plan => {
204
+ * console.log(plan.reason); // "Premium Monthly"
205
+ * console.log(plan.transactionAmount); // 99.90
206
+ * });
207
+ * ```
208
+ */
209
+ listPreapprovalPlans: async (fetchOptions) => {
210
+ return await $fetch(
211
+ "/mercado-pago/plans",
212
+ {
213
+ method: "GET",
214
+ ...fetchOptions
215
+ }
216
+ );
217
+ },
218
+ /**
219
+ * Get payment by ID
220
+ */
221
+ getPayment: async (paymentId, fetchOptions) => {
222
+ return await $fetch(
223
+ `/mercado-pago/payment/${paymentId}`,
224
+ {
225
+ method: "GET",
226
+ ...fetchOptions
227
+ }
228
+ );
229
+ },
230
+ /**
231
+ * List all payments for the authenticated user
232
+ *
233
+ * @example
234
+ * ```ts
235
+ * const { data } = await authClient.mercadoPago.listPayments({
236
+ * limit: 20,
237
+ * offset: 0
238
+ * });
239
+ * ```
240
+ */
241
+ listPayments: async (params, fetchOptions) => {
242
+ const query = new URLSearchParams();
243
+ if (params?.limit) query.set("limit", params.limit.toString());
244
+ if (params?.offset) query.set("offset", params.offset.toString());
245
+ return await $fetch(
246
+ `/mercado-pago/payments?${query.toString()}`,
247
+ {
248
+ method: "GET",
249
+ ...fetchOptions
250
+ }
251
+ );
252
+ },
253
+ /**
254
+ * List all subscriptions for the authenticated user
255
+ *
256
+ * @example
257
+ * ```ts
258
+ * const { data } = await authClient.mercadoPago.listSubscriptions();
259
+ * ```
260
+ */
261
+ listSubscriptions: async (fetchOptions) => {
262
+ return await $fetch(
263
+ `/mercado-pago/subscriptions`,
264
+ {
265
+ method: "GET",
266
+ ...fetchOptions
267
+ }
268
+ );
269
+ },
270
+ /**
271
+ * Get OAuth authorization URL for marketplace sellers
272
+ *
273
+ * This is Step 1 of OAuth flow. Redirect the seller to this URL so they
274
+ * can authorize your app to process payments on their behalf.
275
+ *
276
+ * @example
277
+ * ```ts
278
+ * const { data } = await authClient.mercadoPago.getOAuthUrl({
279
+ * redirectUri: "https://myapp.com/oauth/callback"
280
+ * });
281
+ *
282
+ * // Redirect seller to authorize
283
+ * window.location.href = data.authUrl;
284
+ * ```
285
+ */
286
+ getOAuthUrl: async (params, fetchOptions) => {
287
+ const query = new URLSearchParams();
288
+ query.set("redirectUri", params.redirectUri);
289
+ return await $fetch(
290
+ `/mercado-pago/oauth/authorize?${query.toString()}`,
291
+ {
292
+ method: "GET",
293
+ ...fetchOptions
294
+ }
295
+ );
296
+ },
297
+ /**
298
+ * Exchange OAuth code for access token
299
+ *
300
+ * This is Step 2 of OAuth flow. After the seller authorizes and MP redirects
301
+ * them back with a code, exchange that code for an access token.
302
+ *
303
+ * @example
304
+ * ```ts
305
+ * // In your /oauth/callback page:
306
+ * const code = new URLSearchParams(window.location.search).get("code");
307
+ *
308
+ * const { data } = await authClient.mercadoPago.exchangeOAuthCode({
309
+ * code,
310
+ * redirectUri: "https://myapp.com/oauth/callback"
311
+ * });
312
+ *
313
+ * // Now you have the seller's MP User ID
314
+ * console.log(data.oauthToken.mercadoPagoUserId);
315
+ * ```
316
+ */
317
+ exchangeOAuthCode: async (data, fetchOptions) => {
318
+ return await $fetch(
319
+ "/mercado-pago/oauth/callback",
320
+ {
321
+ method: "POST",
322
+ body: data,
323
+ ...fetchOptions
324
+ }
325
+ );
326
+ }
327
+ })
328
+ };
329
+ };
330
+ // Annotate the CommonJS export names for ESM import in node:
331
+ 0 && (module.exports = {
332
+ mercadoPagoClient
333
+ });
334
+ //# 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 const mercadoPagoClient = () => {\n\treturn {\n\t\tid: \"mercado-pago\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof mercadoPagoPlugin>,\n\n\t\tgetActions: ($fetch) => ({\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<{ customer: MercadoPagoCustomerRecord }>(\n\t\t\t\t\t\"/mercado-pago/customer\",\n\t\t\t\t\t{\n\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\tbody: data || {},\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 * 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<CreatePaymentResponse>(\n\t\t\t\t\t\"/mercado-pago/payment/create\",\n\t\t\t\t\t{\n\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\tbody: data,\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 * 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<CreatePaymentResponse>(\n\t\t\t\t\t\"/mercado-pago/payment/create\",\n\t\t\t\t\t{\n\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\tbody: data,\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 * 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<CreateSubscriptionResponse>(\n\t\t\t\t\t\"/mercado-pago/subscription/create\",\n\t\t\t\t\t{\n\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\tbody: data,\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 * 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<{ success: boolean }>(\n\t\t\t\t\t\"/mercado-pago/subscription/cancel\",\n\t\t\t\t\t{\n\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\tbody: data,\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 * 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<CreatePreapprovalPlanResponse>(\n\t\t\t\t\t\"/mercado-pago/plan/create\",\n\t\t\t\t\t{\n\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\tbody: data,\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 * 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<{ plans: MercadoPagoPreapprovalPlanRecord[] }>(\n\t\t\t\t\t\"/mercado-pago/plans\",\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 * 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<{ payment: MercadoPagoPaymentRecord }>(\n\t\t\t\t\t`/mercado-pago/payment/${paymentId}`,\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 * 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<{ payments: MercadoPagoPaymentRecord[] }>(\n\t\t\t\t\t`/mercado-pago/payments?${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 * 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<{ subscriptions: MercadoPagoSubscriptionRecord[] }>(\n\t\t\t\t\t`/mercado-pago/subscriptions`,\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 * 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<OAuthUrlResponse>(\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<OAuthTokenResponse>(\n\t\t\t\t\t\"/mercado-pago/oauth/callback\",\n\t\t\t\t\t{\n\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\tbody: data,\n\t\t\t\t\t\t...fetchOptions,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t},\n\t\t}),\n\t} satisfies BetterAuthClientPlugin;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBO,IAAM,oBAAoB,MAAM;AACtC,SAAO;AAAA,IACN,IAAI;AAAA,IACJ,oBAAoB,CAAC;AAAA,IAErB,YAAY,CAAC,YAAY;AAAA;AAAA;AAAA;AAAA,MAIxB,qBAAqB,OACpB,MAKA,iBACI;AACJ,eAAO,MAAM;AAAA,UACZ;AAAA,UACA;AAAA,YACC,QAAQ;AAAA,YACR,MAAM,QAAQ,CAAC;AAAA,YACf,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,MAoBA,eAAe,OACd,MACA,iBACI;AACJ,eAAO,MAAM;AAAA,UACZ;AAAA,UACA;AAAA,YACC,QAAQ;AAAA,YACR,MAAM;AAAA,YACN,GAAG;AAAA,UACJ;AAAA,QACD;AAAA,MACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAsBA,mBAAmB,OAClB,MACA,iBACI;AACJ,eAAO,MAAM;AAAA,UACZ;AAAA,UACA;AAAA,YACC,QAAQ;AAAA,YACR,MAAM;AAAA,YACN,GAAG;AAAA,UACJ;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
@@ -0,0 +1,309 @@
1
+ // client.ts
2
+ var mercadoPagoClient = () => {
3
+ return {
4
+ id: "mercado-pago",
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(
12
+ "/mercado-pago/customer",
13
+ {
14
+ method: "POST",
15
+ body: data || {},
16
+ ...fetchOptions
17
+ }
18
+ );
19
+ },
20
+ /**
21
+ * Create a payment and get checkout URL
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * const { data } = await authClient.mercadoPago.createPayment({
26
+ * items: [{
27
+ * title: "Premium Plan",
28
+ * quantity: 1,
29
+ * unitPrice: 99.90,
30
+ * currencyId: "ARS"
31
+ * }]
32
+ * });
33
+ *
34
+ * // Redirect user to checkout
35
+ * window.location.href = data.checkoutUrl;
36
+ * ```
37
+ */
38
+ createPayment: async (data, fetchOptions) => {
39
+ return await $fetch(
40
+ "/mercado-pago/payment/create",
41
+ {
42
+ method: "POST",
43
+ body: data,
44
+ ...fetchOptions
45
+ }
46
+ );
47
+ },
48
+ /**
49
+ * Create a marketplace payment with automatic split
50
+ *
51
+ * You need to have the seller's MP User ID (collector_id) which they get
52
+ * after authorizing your app via OAuth.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * const { data } = await authClient.mercadoPago.createPayment({
57
+ * items: [{
58
+ * title: "Product from Seller",
59
+ * quantity: 1,
60
+ * unitPrice: 100
61
+ * }],
62
+ * marketplace: {
63
+ * collectorId: "123456789", // Seller's MP User ID
64
+ * applicationFeePercentage: 10 // Platform keeps 10%
65
+ * }
66
+ * });
67
+ * ```
68
+ */
69
+ createMarketplacePayment: async (data, fetchOptions) => {
70
+ return await $fetch(
71
+ "/mercado-pago/payment/create",
72
+ {
73
+ method: "POST",
74
+ body: data,
75
+ ...fetchOptions
76
+ }
77
+ );
78
+ },
79
+ /**
80
+ * Create a subscription with recurring payments
81
+ *
82
+ * Supports two modes:
83
+ * 1. With preapproval plan (reusable): Pass preapprovalPlanId
84
+ * 2. Direct subscription (one-off): Pass reason + autoRecurring
85
+ *
86
+ * @example With plan
87
+ * ```ts
88
+ * const { data } = await authClient.mercadoPago.createSubscription({
89
+ * preapprovalPlanId: "plan_abc123"
90
+ * });
91
+ * ```
92
+ *
93
+ * @example Direct (without plan)
94
+ * ```ts
95
+ * const { data } = await authClient.mercadoPago.createSubscription({
96
+ * reason: "Premium Monthly Plan",
97
+ * autoRecurring: {
98
+ * frequency: 1,
99
+ * frequencyType: "months",
100
+ * transactionAmount: 99.90,
101
+ * currencyId: "ARS"
102
+ * }
103
+ * });
104
+ * ```
105
+ */
106
+ createSubscription: async (data, fetchOptions) => {
107
+ return await $fetch(
108
+ "/mercado-pago/subscription/create",
109
+ {
110
+ method: "POST",
111
+ body: data,
112
+ ...fetchOptions
113
+ }
114
+ );
115
+ },
116
+ /**
117
+ * Cancel a subscription
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * await authClient.mercadoPago.cancelSubscription({
122
+ * subscriptionId: "sub_123"
123
+ * });
124
+ * ```
125
+ */
126
+ cancelSubscription: async (data, fetchOptions) => {
127
+ return await $fetch(
128
+ "/mercado-pago/subscription/cancel",
129
+ {
130
+ method: "POST",
131
+ body: data,
132
+ ...fetchOptions
133
+ }
134
+ );
135
+ },
136
+ /**
137
+ * Create a reusable preapproval plan (subscription template)
138
+ *
139
+ * Plans can be reused for multiple subscriptions. Create once,
140
+ * use many times with createSubscription({ preapprovalPlanId })
141
+ *
142
+ * @example
143
+ * ```ts
144
+ * const { data } = await authClient.mercadoPago.createPreapprovalPlan({
145
+ * reason: "Premium Monthly",
146
+ * autoRecurring: {
147
+ * frequency: 1,
148
+ * frequencyType: "months",
149
+ * transactionAmount: 99.90,
150
+ * freeTrial: {
151
+ * frequency: 7,
152
+ * frequencyType: "days"
153
+ * }
154
+ * },
155
+ * repetitions: 12 // 12 months, omit for infinite
156
+ * });
157
+ *
158
+ * // Use the plan
159
+ * const planId = data.plan.mercadoPagoPlanId;
160
+ * ```
161
+ */
162
+ createPreapprovalPlan: async (data, fetchOptions) => {
163
+ return await $fetch(
164
+ "/mercado-pago/plan/create",
165
+ {
166
+ method: "POST",
167
+ body: data,
168
+ ...fetchOptions
169
+ }
170
+ );
171
+ },
172
+ /**
173
+ * List all preapproval plans
174
+ *
175
+ * @example
176
+ * ```ts
177
+ * const { data } = await authClient.mercadoPago.listPreapprovalPlans();
178
+ *
179
+ * data.plans.forEach(plan => {
180
+ * console.log(plan.reason); // "Premium Monthly"
181
+ * console.log(plan.transactionAmount); // 99.90
182
+ * });
183
+ * ```
184
+ */
185
+ listPreapprovalPlans: async (fetchOptions) => {
186
+ return await $fetch(
187
+ "/mercado-pago/plans",
188
+ {
189
+ method: "GET",
190
+ ...fetchOptions
191
+ }
192
+ );
193
+ },
194
+ /**
195
+ * Get payment by ID
196
+ */
197
+ getPayment: async (paymentId, fetchOptions) => {
198
+ return await $fetch(
199
+ `/mercado-pago/payment/${paymentId}`,
200
+ {
201
+ method: "GET",
202
+ ...fetchOptions
203
+ }
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(
222
+ `/mercado-pago/payments?${query.toString()}`,
223
+ {
224
+ method: "GET",
225
+ ...fetchOptions
226
+ }
227
+ );
228
+ },
229
+ /**
230
+ * List all subscriptions for the authenticated user
231
+ *
232
+ * @example
233
+ * ```ts
234
+ * const { data } = await authClient.mercadoPago.listSubscriptions();
235
+ * ```
236
+ */
237
+ listSubscriptions: async (fetchOptions) => {
238
+ return await $fetch(
239
+ `/mercado-pago/subscriptions`,
240
+ {
241
+ method: "GET",
242
+ ...fetchOptions
243
+ }
244
+ );
245
+ },
246
+ /**
247
+ * Get OAuth authorization URL for marketplace sellers
248
+ *
249
+ * This is Step 1 of OAuth flow. Redirect the seller to this URL so they
250
+ * can authorize your app to process payments on their behalf.
251
+ *
252
+ * @example
253
+ * ```ts
254
+ * const { data } = await authClient.mercadoPago.getOAuthUrl({
255
+ * redirectUri: "https://myapp.com/oauth/callback"
256
+ * });
257
+ *
258
+ * // Redirect seller to authorize
259
+ * window.location.href = data.authUrl;
260
+ * ```
261
+ */
262
+ getOAuthUrl: async (params, fetchOptions) => {
263
+ const query = new URLSearchParams();
264
+ query.set("redirectUri", params.redirectUri);
265
+ return await $fetch(
266
+ `/mercado-pago/oauth/authorize?${query.toString()}`,
267
+ {
268
+ method: "GET",
269
+ ...fetchOptions
270
+ }
271
+ );
272
+ },
273
+ /**
274
+ * Exchange OAuth code for access token
275
+ *
276
+ * This is Step 2 of OAuth flow. After the seller authorizes and MP redirects
277
+ * them back with a code, exchange that code for an access token.
278
+ *
279
+ * @example
280
+ * ```ts
281
+ * // In your /oauth/callback page:
282
+ * const code = new URLSearchParams(window.location.search).get("code");
283
+ *
284
+ * const { data } = await authClient.mercadoPago.exchangeOAuthCode({
285
+ * code,
286
+ * redirectUri: "https://myapp.com/oauth/callback"
287
+ * });
288
+ *
289
+ * // Now you have the seller's MP User ID
290
+ * console.log(data.oauthToken.mercadoPagoUserId);
291
+ * ```
292
+ */
293
+ exchangeOAuthCode: async (data, fetchOptions) => {
294
+ return await $fetch(
295
+ "/mercado-pago/oauth/callback",
296
+ {
297
+ method: "POST",
298
+ body: data,
299
+ ...fetchOptions
300
+ }
301
+ );
302
+ }
303
+ })
304
+ };
305
+ };
306
+ export {
307
+ mercadoPagoClient
308
+ };
309
+ //# sourceMappingURL=client.mjs.map