better-auth-mercadopago 0.1.5 → 0.1.7

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/dist/index.d.mts CHANGED
@@ -1,4 +1,3 @@
1
- import * as better_auth_client from 'better-auth/client';
2
1
  import { BetterFetchOption } from 'better-auth/client';
3
2
  import * as better_auth from 'better-auth';
4
3
  import { z } from 'zod';
@@ -299,7 +298,7 @@ interface MercadoPagoPreApprovalResponse {
299
298
 
300
299
  declare const mercadoPagoPlugin: (options: MercadoPagoPluginOptions) => {
301
300
  trustedOrigins?: string[] | undefined;
302
- id: "mercado-pago";
301
+ id: "mercadopago";
303
302
  schema: {
304
303
  mercadoPagoCustomer: {
305
304
  fields: {
@@ -934,345 +933,87 @@ declare const mercadoPagoPlugin: (options: MercadoPagoPluginOptions) => {
934
933
  };
935
934
  };
936
935
 
936
+ interface MercadoPagoClientActions {
937
+ /**
938
+ * Get or create a Mercado Pago customer for the authenticated user
939
+ */
940
+ getOrCreateCustomer: (data?: {
941
+ email?: string;
942
+ firstName?: string;
943
+ lastName?: string;
944
+ }, fetchOptions?: BetterFetchOption) => Promise<{
945
+ customer: MercadoPagoCustomerRecord;
946
+ }>;
947
+ /**
948
+ * Create a payment and get checkout URL
949
+ */
950
+ createPayment: (data: CreatePaymentParams, fetchOptions?: BetterFetchOption) => Promise<CreatePaymentResponse>;
951
+ /**
952
+ * Create a marketplace payment with automatic split
953
+ */
954
+ createMarketplacePayment: (data: CreatePaymentParams, fetchOptions?: BetterFetchOption) => Promise<CreatePaymentResponse>;
955
+ /**
956
+ * Create a subscription with recurring payments
957
+ */
958
+ createSubscription: (data: CreateSubscriptionParams, fetchOptions?: BetterFetchOption) => Promise<CreateSubscriptionResponse>;
959
+ /**
960
+ * Cancel a subscription
961
+ */
962
+ cancelSubscription: (data: {
963
+ subscriptionId: string;
964
+ }, fetchOptions?: BetterFetchOption) => Promise<{
965
+ success: boolean;
966
+ }>;
967
+ /**
968
+ * Create a reusable preapproval plan (subscription template)
969
+ */
970
+ createPreapprovalPlan: (data: CreatePreapprovalPlanParams, fetchOptions?: BetterFetchOption) => Promise<CreatePreapprovalPlanResponse>;
971
+ /**
972
+ * List all preapproval plans
973
+ */
974
+ listPreapprovalPlans: (fetchOptions?: BetterFetchOption) => Promise<{
975
+ plans: MercadoPagoPreapprovalPlanRecord[];
976
+ }>;
977
+ /**
978
+ * Get payment by ID
979
+ */
980
+ getPayment: (paymentId: string, fetchOptions?: BetterFetchOption) => Promise<{
981
+ payment: MercadoPagoPaymentRecord;
982
+ }>;
983
+ /**
984
+ * List all payments for the authenticated user
985
+ */
986
+ listPayments: (params?: {
987
+ limit?: number;
988
+ offset?: number;
989
+ }, fetchOptions?: BetterFetchOption) => Promise<{
990
+ payments: MercadoPagoPaymentRecord[];
991
+ }>;
992
+ /**
993
+ * List all subscriptions for the authenticated user
994
+ */
995
+ listSubscriptions: (fetchOptions?: BetterFetchOption) => Promise<{
996
+ subscriptions: MercadoPagoSubscriptionRecord[];
997
+ }>;
998
+ /**
999
+ * Get OAuth authorization URL for marketplace sellers
1000
+ */
1001
+ getOAuthUrl: (params: {
1002
+ redirectUri: string;
1003
+ }, fetchOptions?: BetterFetchOption) => Promise<OAuthUrlResponse>;
1004
+ /**
1005
+ * Exchange OAuth code for access token
1006
+ */
1007
+ exchangeOAuthCode: (data: {
1008
+ code: string;
1009
+ redirectUri: string;
1010
+ }, fetchOptions?: BetterFetchOption) => Promise<OAuthTokenResponse>;
1011
+ }
1012
+ type MercadoPagoClient = MercadoPagoClientActions;
937
1013
  declare const mercadoPagoClient: () => {
938
- id: "mercado-pago";
1014
+ id: "mercadopago";
939
1015
  $InferServerPlugin: ReturnType<typeof mercadoPagoPlugin>;
940
- getActions: ($fetch: better_auth_client.BetterFetch) => {
941
- /**
942
- * Get or create a Mercado Pago customer for the authenticated user
943
- */
944
- getOrCreateCustomer: (data?: {
945
- email?: string;
946
- firstName?: string;
947
- lastName?: string;
948
- }, fetchOptions?: BetterFetchOption) => Promise<{
949
- data: {
950
- customer: MercadoPagoCustomerRecord;
951
- };
952
- error: null;
953
- } | {
954
- data: null;
955
- error: {
956
- message?: string | undefined;
957
- status: number;
958
- statusText: string;
959
- };
960
- }>;
961
- /**
962
- * Create a payment and get checkout URL
963
- *
964
- * @example
965
- * ```ts
966
- * const { data } = await authClient.mercadoPago.createPayment({
967
- * items: [{
968
- * title: "Premium Plan",
969
- * quantity: 1,
970
- * unitPrice: 99.90,
971
- * currencyId: "ARS"
972
- * }]
973
- * });
974
- *
975
- * // Redirect user to checkout
976
- * window.location.href = data.checkoutUrl;
977
- * ```
978
- */
979
- createPayment: (data: CreatePaymentParams, fetchOptions?: BetterFetchOption) => Promise<{
980
- data: null;
981
- error: {
982
- message?: string | undefined;
983
- status: number;
984
- statusText: string;
985
- };
986
- } | {
987
- data: CreatePaymentResponse;
988
- error: null;
989
- }>;
990
- /**
991
- * Create a marketplace payment with automatic split
992
- *
993
- * You need to have the seller's MP User ID (collector_id) which they get
994
- * after authorizing your app via OAuth.
995
- *
996
- * @example
997
- * ```ts
998
- * const { data } = await authClient.mercadoPago.createPayment({
999
- * items: [{
1000
- * title: "Product from Seller",
1001
- * quantity: 1,
1002
- * unitPrice: 100
1003
- * }],
1004
- * marketplace: {
1005
- * collectorId: "123456789", // Seller's MP User ID
1006
- * applicationFeePercentage: 10 // Platform keeps 10%
1007
- * }
1008
- * });
1009
- * ```
1010
- */
1011
- createMarketplacePayment: (data: CreatePaymentParams, fetchOptions?: BetterFetchOption) => Promise<{
1012
- data: null;
1013
- error: {
1014
- message?: string | undefined;
1015
- status: number;
1016
- statusText: string;
1017
- };
1018
- } | {
1019
- data: CreatePaymentResponse;
1020
- error: null;
1021
- }>;
1022
- /**
1023
- * Create a subscription with recurring payments
1024
- *
1025
- * Supports two modes:
1026
- * 1. With preapproval plan (reusable): Pass preapprovalPlanId
1027
- * 2. Direct subscription (one-off): Pass reason + autoRecurring
1028
- *
1029
- * @example With plan
1030
- * ```ts
1031
- * const { data } = await authClient.mercadoPago.createSubscription({
1032
- * preapprovalPlanId: "plan_abc123"
1033
- * });
1034
- * ```
1035
- *
1036
- * @example Direct (without plan)
1037
- * ```ts
1038
- * const { data } = await authClient.mercadoPago.createSubscription({
1039
- * reason: "Premium Monthly Plan",
1040
- * autoRecurring: {
1041
- * frequency: 1,
1042
- * frequencyType: "months",
1043
- * transactionAmount: 99.90,
1044
- * currencyId: "ARS"
1045
- * }
1046
- * });
1047
- * ```
1048
- */
1049
- createSubscription: (data: CreateSubscriptionParams, fetchOptions?: BetterFetchOption) => Promise<{
1050
- data: null;
1051
- error: {
1052
- message?: string | undefined;
1053
- status: number;
1054
- statusText: string;
1055
- };
1056
- } | {
1057
- data: CreateSubscriptionResponse;
1058
- error: null;
1059
- }>;
1060
- /**
1061
- * Cancel a subscription
1062
- *
1063
- * @example
1064
- * ```ts
1065
- * await authClient.mercadoPago.cancelSubscription({
1066
- * subscriptionId: "sub_123"
1067
- * });
1068
- * ```
1069
- */
1070
- cancelSubscription: (data: {
1071
- subscriptionId: string;
1072
- }, fetchOptions?: BetterFetchOption) => Promise<{
1073
- data: null;
1074
- error: {
1075
- message?: string | undefined;
1076
- status: number;
1077
- statusText: string;
1078
- };
1079
- } | {
1080
- data: {
1081
- success: boolean;
1082
- };
1083
- error: null;
1084
- }>;
1085
- /**
1086
- * Create a reusable preapproval plan (subscription template)
1087
- *
1088
- * Plans can be reused for multiple subscriptions. Create once,
1089
- * use many times with createSubscription({ preapprovalPlanId })
1090
- *
1091
- * @example
1092
- * ```ts
1093
- * const { data } = await authClient.mercadoPago.createPreapprovalPlan({
1094
- * reason: "Premium Monthly",
1095
- * autoRecurring: {
1096
- * frequency: 1,
1097
- * frequencyType: "months",
1098
- * transactionAmount: 99.90,
1099
- * freeTrial: {
1100
- * frequency: 7,
1101
- * frequencyType: "days"
1102
- * }
1103
- * },
1104
- * repetitions: 12 // 12 months, omit for infinite
1105
- * });
1106
- *
1107
- * // Use the plan
1108
- * const planId = data.plan.mercadoPagoPlanId;
1109
- * ```
1110
- */
1111
- createPreapprovalPlan: (data: CreatePreapprovalPlanParams, fetchOptions?: BetterFetchOption) => Promise<{
1112
- data: null;
1113
- error: {
1114
- message?: string | undefined;
1115
- status: number;
1116
- statusText: string;
1117
- };
1118
- } | {
1119
- data: CreatePreapprovalPlanResponse;
1120
- error: null;
1121
- }>;
1122
- /**
1123
- * List all preapproval plans
1124
- *
1125
- * @example
1126
- * ```ts
1127
- * const { data } = await authClient.mercadoPago.listPreapprovalPlans();
1128
- *
1129
- * data.plans.forEach(plan => {
1130
- * console.log(plan.reason); // "Premium Monthly"
1131
- * console.log(plan.transactionAmount); // 99.90
1132
- * });
1133
- * ```
1134
- */
1135
- listPreapprovalPlans: (fetchOptions?: BetterFetchOption) => Promise<{
1136
- data: null;
1137
- error: {
1138
- message?: string | undefined;
1139
- status: number;
1140
- statusText: string;
1141
- };
1142
- } | {
1143
- data: {
1144
- plans: MercadoPagoPreapprovalPlanRecord[];
1145
- };
1146
- error: null;
1147
- }>;
1148
- /**
1149
- * Get payment by ID
1150
- */
1151
- getPayment: (paymentId: string, fetchOptions?: BetterFetchOption) => Promise<{
1152
- data: null;
1153
- error: {
1154
- message?: string | undefined;
1155
- status: number;
1156
- statusText: string;
1157
- };
1158
- } | {
1159
- data: {
1160
- payment: MercadoPagoPaymentRecord;
1161
- };
1162
- error: null;
1163
- }>;
1164
- /**
1165
- * List all payments for the authenticated user
1166
- *
1167
- * @example
1168
- * ```ts
1169
- * const { data } = await authClient.mercadoPago.listPayments({
1170
- * limit: 20,
1171
- * offset: 0
1172
- * });
1173
- * ```
1174
- */
1175
- listPayments: (params?: {
1176
- limit?: number;
1177
- offset?: number;
1178
- }, fetchOptions?: BetterFetchOption) => Promise<{
1179
- data: null;
1180
- error: {
1181
- message?: string | undefined;
1182
- status: number;
1183
- statusText: string;
1184
- };
1185
- } | {
1186
- data: {
1187
- payments: MercadoPagoPaymentRecord[];
1188
- };
1189
- error: null;
1190
- }>;
1191
- /**
1192
- * List all subscriptions for the authenticated user
1193
- *
1194
- * @example
1195
- * ```ts
1196
- * const { data } = await authClient.mercadoPago.listSubscriptions();
1197
- * ```
1198
- */
1199
- listSubscriptions: (fetchOptions?: BetterFetchOption) => Promise<{
1200
- data: null;
1201
- error: {
1202
- message?: string | undefined;
1203
- status: number;
1204
- statusText: string;
1205
- };
1206
- } | {
1207
- data: {
1208
- subscriptions: MercadoPagoSubscriptionRecord[];
1209
- };
1210
- error: null;
1211
- }>;
1212
- /**
1213
- * Get OAuth authorization URL for marketplace sellers
1214
- *
1215
- * This is Step 1 of OAuth flow. Redirect the seller to this URL so they
1216
- * can authorize your app to process payments on their behalf.
1217
- *
1218
- * @example
1219
- * ```ts
1220
- * const { data } = await authClient.mercadoPago.getOAuthUrl({
1221
- * redirectUri: "https://myapp.com/oauth/callback"
1222
- * });
1223
- *
1224
- * // Redirect seller to authorize
1225
- * window.location.href = data.authUrl;
1226
- * ```
1227
- */
1228
- getOAuthUrl: (params: {
1229
- redirectUri: string;
1230
- }, fetchOptions?: BetterFetchOption) => Promise<{
1231
- data: null;
1232
- error: {
1233
- message?: string | undefined;
1234
- status: number;
1235
- statusText: string;
1236
- };
1237
- } | {
1238
- data: OAuthUrlResponse;
1239
- error: null;
1240
- }>;
1241
- /**
1242
- * Exchange OAuth code for access token
1243
- *
1244
- * This is Step 2 of OAuth flow. After the seller authorizes and MP redirects
1245
- * them back with a code, exchange that code for an access token.
1246
- *
1247
- * @example
1248
- * ```ts
1249
- * // In your /oauth/callback page:
1250
- * const code = new URLSearchParams(window.location.search).get("code");
1251
- *
1252
- * const { data } = await authClient.mercadoPago.exchangeOAuthCode({
1253
- * code,
1254
- * redirectUri: "https://myapp.com/oauth/callback"
1255
- * });
1256
- *
1257
- * // Now you have the seller's MP User ID
1258
- * console.log(data.oauthToken.mercadoPagoUserId);
1259
- * ```
1260
- */
1261
- exchangeOAuthCode: (data: {
1262
- code: string;
1263
- redirectUri: string;
1264
- }, fetchOptions?: BetterFetchOption) => Promise<{
1265
- data: null;
1266
- error: {
1267
- message?: string | undefined;
1268
- status: number;
1269
- statusText: string;
1270
- };
1271
- } | {
1272
- data: OAuthTokenResponse;
1273
- error: null;
1274
- }>;
1275
- };
1016
+ getActions: ($fetch: any) => MercadoPagoClientActions;
1276
1017
  };
1277
1018
 
1278
- export { type CreatePaymentParams, type CreatePaymentResponse, type CreatePreapprovalPlanParams, type CreatePreapprovalPlanResponse, type CreateSubscriptionParams, type CreateSubscriptionResponse, type MarketplaceConfig, type MercadoPagoCustomerRecord, type MercadoPagoMarketplaceSplitRecord, type MercadoPagoOAuthTokenRecord, type MercadoPagoPaymentRecord, type MercadoPagoPaymentResponse, type MercadoPagoPluginOptions, type MercadoPagoPreApprovalResponse, type MercadoPagoPreapprovalPlanRecord, type MercadoPagoSubscriptionRecord, type OAuthTokenResponse, type OAuthUrlResponse, type PaymentItem, mercadoPagoClient, mercadoPagoPlugin };
1019
+ export { type CreatePaymentParams, type CreatePaymentResponse, type CreatePreapprovalPlanParams, type CreatePreapprovalPlanResponse, type CreateSubscriptionParams, type CreateSubscriptionResponse, type MarketplaceConfig, type MercadoPagoClient, type MercadoPagoClientActions, type MercadoPagoCustomerRecord, type MercadoPagoMarketplaceSplitRecord, type MercadoPagoOAuthTokenRecord, type MercadoPagoPaymentRecord, type MercadoPagoPaymentResponse, type MercadoPagoPluginOptions, type MercadoPagoPreApprovalResponse, type MercadoPagoPreapprovalPlanRecord, type MercadoPagoSubscriptionRecord, type OAuthTokenResponse, type OAuthUrlResponse, type PaymentItem, mercadoPagoClient, mercadoPagoPlugin };