recurrente-js 1.0.2 → 1.0.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/dist/api/recurrente.d.ts +12 -1
- package/dist/api/recurrente.js +33 -0
- package/dist/types/globals.d.ts +58 -0
- package/package.json +1 -1
package/dist/api/recurrente.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProductSubscription, CreateSubscriptionResponse, SubscriptionStatusResponse, CreateProductRequest, CreateProductResponse, GetProductResponse, GetAllProductsResponse, UpdateProductRequest } from '../types/globals';
|
|
1
|
+
import { ProductSubscription, CreateSubscriptionResponse, SubscriptionStatusResponse, CreateProductRequest, CreateProductResponse, GetProductResponse, GetAllProductsResponse, UpdateProductRequest, CreateCheckoutRequest, CreateCheckoutResponse } from '../types/globals';
|
|
2
2
|
/**
|
|
3
3
|
* Recurrente API utility for managing product subscriptions, cancellations, and product deletions.
|
|
4
4
|
*
|
|
@@ -127,5 +127,16 @@ declare const recurrente: {
|
|
|
127
127
|
* @see getSubscription
|
|
128
128
|
*/
|
|
129
129
|
getSubscription: (subscriptionId: string) => Promise<SubscriptionStatusResponse>;
|
|
130
|
+
/**
|
|
131
|
+
* Creates a new checkout session.
|
|
132
|
+
*
|
|
133
|
+
* @function
|
|
134
|
+
* @memberof recurrente.checkouts
|
|
135
|
+
* @see createCheckout
|
|
136
|
+
* @param {CreateCheckoutRequest} checkoutData - The details for the checkout session.
|
|
137
|
+
* @returns {Promise<CreateCheckoutResponse>} A promise that resolves with the checkout ID and URL.
|
|
138
|
+
* @throws {ErrorResponse} Throws an error if the checkout creation fails.
|
|
139
|
+
*/
|
|
140
|
+
createCheckout: (checkoutData: CreateCheckoutRequest) => Promise<CreateCheckoutResponse>;
|
|
130
141
|
};
|
|
131
142
|
export default recurrente;
|
package/dist/api/recurrente.js
CHANGED
|
@@ -15,6 +15,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const axios_1 = __importDefault(require("axios"));
|
|
16
16
|
const axiosInstance_1 = __importDefault(require("../config/axiosInstance"));
|
|
17
17
|
const conversion_1 = require("../utils/conversion");
|
|
18
|
+
// TODO: Implement namespaces
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new checkout session.
|
|
21
|
+
*
|
|
22
|
+
* This function takes checkout data, including items (by product_id or details),
|
|
23
|
+
* converts it to snake_case, and sends it to the API to create a new checkout session.
|
|
24
|
+
* It returns the checkout ID and the URL for redirection.
|
|
25
|
+
*
|
|
26
|
+
* @param {CreateCheckoutRequest} checkoutData - The details for the checkout session.
|
|
27
|
+
* @returns {Promise<CreateCheckoutResponse>} The response containing the checkout ID and URL.
|
|
28
|
+
* @throws {ErrorResponse} Throws an error if the checkout creation fails.
|
|
29
|
+
*/
|
|
30
|
+
const createCheckout = (checkoutData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
+
try {
|
|
32
|
+
const checkoutDataInSnakeCase = (0, conversion_1.toSnakeCase)(checkoutData);
|
|
33
|
+
const response = yield axiosInstance_1.default.post('/checkouts/', checkoutDataInSnakeCase);
|
|
34
|
+
return (0, conversion_1.toCamelCase)(response.data);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
throw handleAxiosError(error);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
18
40
|
/**
|
|
19
41
|
* Creates a new product with a one-time payment.
|
|
20
42
|
*
|
|
@@ -351,5 +373,16 @@ const recurrente = {
|
|
|
351
373
|
* @see getSubscription
|
|
352
374
|
*/
|
|
353
375
|
getSubscription,
|
|
376
|
+
/**
|
|
377
|
+
* Creates a new checkout session.
|
|
378
|
+
*
|
|
379
|
+
* @function
|
|
380
|
+
* @memberof recurrente.checkouts
|
|
381
|
+
* @see createCheckout
|
|
382
|
+
* @param {CreateCheckoutRequest} checkoutData - The details for the checkout session.
|
|
383
|
+
* @returns {Promise<CreateCheckoutResponse>} A promise that resolves with the checkout ID and URL.
|
|
384
|
+
* @throws {ErrorResponse} Throws an error if the checkout creation fails.
|
|
385
|
+
*/
|
|
386
|
+
createCheckout,
|
|
354
387
|
};
|
|
355
388
|
exports.default = recurrente;
|
package/dist/types/globals.d.ts
CHANGED
|
@@ -1262,6 +1262,64 @@ export interface SubscriptionCancel {
|
|
|
1262
1262
|
*/
|
|
1263
1263
|
customerName: string;
|
|
1264
1264
|
}
|
|
1265
|
+
/**
|
|
1266
|
+
* Represents the payload for creating a checkout session.
|
|
1267
|
+
*/
|
|
1268
|
+
export interface CreateCheckoutRequest {
|
|
1269
|
+
/**
|
|
1270
|
+
* An array of items to be included in the checkout.
|
|
1271
|
+
* Each item can be defined by its product_id or by its details.
|
|
1272
|
+
* @required
|
|
1273
|
+
*/
|
|
1274
|
+
items: {
|
|
1275
|
+
/**
|
|
1276
|
+
* The ID of a pre-existing product. Use this to create a checkout for a master plan.
|
|
1277
|
+
* @optional
|
|
1278
|
+
*/
|
|
1279
|
+
productId?: string;
|
|
1280
|
+
}[];
|
|
1281
|
+
/**
|
|
1282
|
+
* URL to redirect the user after a successful transaction.
|
|
1283
|
+
* @optional
|
|
1284
|
+
*/
|
|
1285
|
+
successUrl?: string;
|
|
1286
|
+
/**
|
|
1287
|
+
* URL to redirect the user after canceling the transaction.
|
|
1288
|
+
* @optional
|
|
1289
|
+
*/
|
|
1290
|
+
cancelUrl?: string;
|
|
1291
|
+
/**
|
|
1292
|
+
* The ID of the user to whom the checkout belongs.
|
|
1293
|
+
* Pre-populates user information fields.
|
|
1294
|
+
* @optional
|
|
1295
|
+
*/
|
|
1296
|
+
userId?: string;
|
|
1297
|
+
/**
|
|
1298
|
+
* Optional metadata for additional information.
|
|
1299
|
+
* @optional
|
|
1300
|
+
*/
|
|
1301
|
+
metadata?: Record<string, any>;
|
|
1302
|
+
/**
|
|
1303
|
+
* Optional expiration date for the checkout in ISO 8601 format.
|
|
1304
|
+
* @optional
|
|
1305
|
+
*/
|
|
1306
|
+
expiresAt?: string;
|
|
1307
|
+
}
|
|
1308
|
+
/**
|
|
1309
|
+
* Represents the response after creating a checkout session.
|
|
1310
|
+
*/
|
|
1311
|
+
export interface CreateCheckoutResponse {
|
|
1312
|
+
/**
|
|
1313
|
+
* The unique identifier for the checkout session (e.g., "ch_...").
|
|
1314
|
+
* @required
|
|
1315
|
+
*/
|
|
1316
|
+
id: string;
|
|
1317
|
+
/**
|
|
1318
|
+
* The URL to which you should redirect your user to complete the payment.
|
|
1319
|
+
* @required
|
|
1320
|
+
*/
|
|
1321
|
+
checkoutUrl: string;
|
|
1322
|
+
}
|
|
1265
1323
|
/**
|
|
1266
1324
|
* Represents the possible webhook events that can be triggered in the Recurrente system.
|
|
1267
1325
|
* These events correspond to various stages of the payment or subscription lifecycle.
|