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/client.d.mts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +52 -85
- package/dist/client.js.map +1 -1
- package/dist/client.mjs +52 -85
- package/dist/client.mjs.map +1 -1
- package/dist/index.d.mts +81 -340
- package/dist/index.d.ts +81 -340
- package/dist/index.js +53 -86
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -86
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
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: "
|
|
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: "
|
|
1014
|
+
id: "mercadopago";
|
|
939
1015
|
$InferServerPlugin: ReturnType<typeof mercadoPagoPlugin>;
|
|
940
|
-
getActions: ($fetch:
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -250,21 +250,18 @@ var ValidationRules = {
|
|
|
250
250
|
// client.ts
|
|
251
251
|
var mercadoPagoClient = () => {
|
|
252
252
|
return {
|
|
253
|
-
id: "
|
|
253
|
+
id: "mercadopago",
|
|
254
254
|
$InferServerPlugin: {},
|
|
255
255
|
getActions: ($fetch) => ({
|
|
256
256
|
/**
|
|
257
257
|
* Get or create a Mercado Pago customer for the authenticated user
|
|
258
258
|
*/
|
|
259
259
|
getOrCreateCustomer: async (data, fetchOptions) => {
|
|
260
|
-
return await $fetch(
|
|
261
|
-
"
|
|
262
|
-
{
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
...fetchOptions
|
|
266
|
-
}
|
|
267
|
-
);
|
|
260
|
+
return await $fetch("/mercado-pago/customer", {
|
|
261
|
+
method: "POST",
|
|
262
|
+
body: data || {},
|
|
263
|
+
...fetchOptions
|
|
264
|
+
});
|
|
268
265
|
},
|
|
269
266
|
/**
|
|
270
267
|
* Create a payment and get checkout URL
|
|
@@ -285,14 +282,11 @@ var mercadoPagoClient = () => {
|
|
|
285
282
|
* ```
|
|
286
283
|
*/
|
|
287
284
|
createPayment: async (data, fetchOptions) => {
|
|
288
|
-
return await $fetch(
|
|
289
|
-
"
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
...fetchOptions
|
|
294
|
-
}
|
|
295
|
-
);
|
|
285
|
+
return await $fetch("/mercado-pago/payment/create", {
|
|
286
|
+
method: "POST",
|
|
287
|
+
body: data,
|
|
288
|
+
...fetchOptions
|
|
289
|
+
});
|
|
296
290
|
},
|
|
297
291
|
/**
|
|
298
292
|
* Create a marketplace payment with automatic split
|
|
@@ -316,14 +310,11 @@ var mercadoPagoClient = () => {
|
|
|
316
310
|
* ```
|
|
317
311
|
*/
|
|
318
312
|
createMarketplacePayment: async (data, fetchOptions) => {
|
|
319
|
-
return await $fetch(
|
|
320
|
-
"
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
...fetchOptions
|
|
325
|
-
}
|
|
326
|
-
);
|
|
313
|
+
return await $fetch("/mercado-pago/payment/create", {
|
|
314
|
+
method: "POST",
|
|
315
|
+
body: data,
|
|
316
|
+
...fetchOptions
|
|
317
|
+
});
|
|
327
318
|
},
|
|
328
319
|
/**
|
|
329
320
|
* Create a subscription with recurring payments
|
|
@@ -353,14 +344,11 @@ var mercadoPagoClient = () => {
|
|
|
353
344
|
* ```
|
|
354
345
|
*/
|
|
355
346
|
createSubscription: async (data, fetchOptions) => {
|
|
356
|
-
return await $fetch(
|
|
357
|
-
"
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
...fetchOptions
|
|
362
|
-
}
|
|
363
|
-
);
|
|
347
|
+
return await $fetch("/mercado-pago/subscription/create", {
|
|
348
|
+
method: "POST",
|
|
349
|
+
body: data,
|
|
350
|
+
...fetchOptions
|
|
351
|
+
});
|
|
364
352
|
},
|
|
365
353
|
/**
|
|
366
354
|
* Cancel a subscription
|
|
@@ -373,14 +361,11 @@ var mercadoPagoClient = () => {
|
|
|
373
361
|
* ```
|
|
374
362
|
*/
|
|
375
363
|
cancelSubscription: async (data, fetchOptions) => {
|
|
376
|
-
return await $fetch(
|
|
377
|
-
"
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
...fetchOptions
|
|
382
|
-
}
|
|
383
|
-
);
|
|
364
|
+
return await $fetch("/mercado-pago/subscription/cancel", {
|
|
365
|
+
method: "POST",
|
|
366
|
+
body: data,
|
|
367
|
+
...fetchOptions
|
|
368
|
+
});
|
|
384
369
|
},
|
|
385
370
|
/**
|
|
386
371
|
* Create a reusable preapproval plan (subscription template)
|
|
@@ -409,14 +394,11 @@ var mercadoPagoClient = () => {
|
|
|
409
394
|
* ```
|
|
410
395
|
*/
|
|
411
396
|
createPreapprovalPlan: async (data, fetchOptions) => {
|
|
412
|
-
return await $fetch(
|
|
413
|
-
"
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
...fetchOptions
|
|
418
|
-
}
|
|
419
|
-
);
|
|
397
|
+
return await $fetch("/mercado-pago/plan/create", {
|
|
398
|
+
method: "POST",
|
|
399
|
+
body: data,
|
|
400
|
+
...fetchOptions
|
|
401
|
+
});
|
|
420
402
|
},
|
|
421
403
|
/**
|
|
422
404
|
* List all preapproval plans
|
|
@@ -432,25 +414,19 @@ var mercadoPagoClient = () => {
|
|
|
432
414
|
* ```
|
|
433
415
|
*/
|
|
434
416
|
listPreapprovalPlans: async (fetchOptions) => {
|
|
435
|
-
return await $fetch(
|
|
436
|
-
"
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
...fetchOptions
|
|
440
|
-
}
|
|
441
|
-
);
|
|
417
|
+
return await $fetch("/mercado-pago/plans", {
|
|
418
|
+
method: "GET",
|
|
419
|
+
...fetchOptions
|
|
420
|
+
});
|
|
442
421
|
},
|
|
443
422
|
/**
|
|
444
423
|
* Get payment by ID
|
|
445
424
|
*/
|
|
446
425
|
getPayment: async (paymentId, fetchOptions) => {
|
|
447
|
-
return await $fetch(
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
...fetchOptions
|
|
452
|
-
}
|
|
453
|
-
);
|
|
426
|
+
return await $fetch(`/mercado-pago/payment/${paymentId}`, {
|
|
427
|
+
method: "GET",
|
|
428
|
+
...fetchOptions
|
|
429
|
+
});
|
|
454
430
|
},
|
|
455
431
|
/**
|
|
456
432
|
* List all payments for the authenticated user
|
|
@@ -467,13 +443,10 @@ var mercadoPagoClient = () => {
|
|
|
467
443
|
const query = new URLSearchParams();
|
|
468
444
|
if (params?.limit) query.set("limit", params.limit.toString());
|
|
469
445
|
if (params?.offset) query.set("offset", params.offset.toString());
|
|
470
|
-
return await $fetch(
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
...fetchOptions
|
|
475
|
-
}
|
|
476
|
-
);
|
|
446
|
+
return await $fetch(`/mercado-pago/payments?${query.toString()}`, {
|
|
447
|
+
method: "GET",
|
|
448
|
+
...fetchOptions
|
|
449
|
+
});
|
|
477
450
|
},
|
|
478
451
|
/**
|
|
479
452
|
* List all subscriptions for the authenticated user
|
|
@@ -484,13 +457,10 @@ var mercadoPagoClient = () => {
|
|
|
484
457
|
* ```
|
|
485
458
|
*/
|
|
486
459
|
listSubscriptions: async (fetchOptions) => {
|
|
487
|
-
return await $fetch(
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
...fetchOptions
|
|
492
|
-
}
|
|
493
|
-
);
|
|
460
|
+
return await $fetch(`/mercado-pago/subscriptions`, {
|
|
461
|
+
method: "GET",
|
|
462
|
+
...fetchOptions
|
|
463
|
+
});
|
|
494
464
|
},
|
|
495
465
|
/**
|
|
496
466
|
* Get OAuth authorization URL for marketplace sellers
|
|
@@ -540,14 +510,11 @@ var mercadoPagoClient = () => {
|
|
|
540
510
|
* ```
|
|
541
511
|
*/
|
|
542
512
|
exchangeOAuthCode: async (data, fetchOptions) => {
|
|
543
|
-
return await $fetch(
|
|
544
|
-
"
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
...fetchOptions
|
|
549
|
-
}
|
|
550
|
-
);
|
|
513
|
+
return await $fetch("/mercado-pago/oauth/callback", {
|
|
514
|
+
method: "POST",
|
|
515
|
+
body: data,
|
|
516
|
+
...fetchOptions
|
|
517
|
+
});
|
|
551
518
|
}
|
|
552
519
|
})
|
|
553
520
|
};
|
|
@@ -564,7 +531,7 @@ var mercadoPagoPlugin = (options) => {
|
|
|
564
531
|
const preApprovalClient = new import_mercadopago.PreApproval(client);
|
|
565
532
|
const preApprovalPlanClient = new import_mercadopago.PreApprovalPlan(client);
|
|
566
533
|
return {
|
|
567
|
-
id: "
|
|
534
|
+
id: "mercadopago",
|
|
568
535
|
schema: {
|
|
569
536
|
// Customer table - stores MP customer info
|
|
570
537
|
mercadoPagoCustomer: {
|