better-auth-mercadopago 0.1.1 → 0.1.3
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 +5 -5
- package/package.json +4 -1
- package/dist/client.d.mts +0 -4
- package/dist/client.d.ts +0 -4
- package/dist/client.js +0 -334
- package/dist/client.js.map +0 -1
- package/dist/client.mjs +0 -309
- package/dist/client.mjs.map +0 -1
- package/dist/index.d.mts +0 -1277
- package/dist/index.d.ts +0 -1277
- package/dist/index.js +0 -1677
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -1648
- package/dist/index.mjs.map +0 -1
package/dist/client.mjs
DELETED
|
@@ -1,309 +0,0 @@
|
|
|
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
|
package/dist/client.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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":";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;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