recurrente-js 1.0.2 → 1.0.4
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 +25 -1
- package/dist/api/recurrente.js +65 -0
- package/dist/types/globals.d.ts +112 -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, CreateRefundRequest, CreateRefundResponse } from '../types/globals';
|
|
2
2
|
/**
|
|
3
3
|
* Recurrente API utility for managing product subscriptions, cancellations, and product deletions.
|
|
4
4
|
*
|
|
@@ -15,6 +15,8 @@ import { ProductSubscription, CreateSubscriptionResponse, SubscriptionStatusResp
|
|
|
15
15
|
* @property {Function} createSubscription - Creates a new subscription for a product.
|
|
16
16
|
* @property {Function} cancelSubscription - Cancels an existing subscription by its ID.
|
|
17
17
|
* @property {Function} getSubscription - Retrieves details of a specific subscription by its ID.
|
|
18
|
+
* @property {Function} createCheckout - Creates a new checkout with provided product ID.
|
|
19
|
+
* @property {Function} createRefund - Creates a new refund for a specific payment intent.
|
|
18
20
|
*/
|
|
19
21
|
declare const recurrente: {
|
|
20
22
|
/**
|
|
@@ -127,5 +129,27 @@ declare const recurrente: {
|
|
|
127
129
|
* @see getSubscription
|
|
128
130
|
*/
|
|
129
131
|
getSubscription: (subscriptionId: string) => Promise<SubscriptionStatusResponse>;
|
|
132
|
+
/**
|
|
133
|
+
* Creates a new checkout session.
|
|
134
|
+
*
|
|
135
|
+
* @function
|
|
136
|
+
* @memberof recurrente.checkouts
|
|
137
|
+
* @see createCheckout
|
|
138
|
+
* @param {CreateCheckoutRequest} checkoutData - The details for the checkout session.
|
|
139
|
+
* @returns {Promise<CreateCheckoutResponse>} A promise that resolves with the checkout ID and URL.
|
|
140
|
+
* @throws {ErrorResponse} Throws an error if the checkout creation fails.
|
|
141
|
+
*/
|
|
142
|
+
createCheckout: (checkoutData: CreateCheckoutRequest) => Promise<CreateCheckoutResponse>;
|
|
143
|
+
/**
|
|
144
|
+
* Creates a new refund for a specific payment intent.
|
|
145
|
+
*
|
|
146
|
+
* @function
|
|
147
|
+
* @memberof recurrente
|
|
148
|
+
* @see createRefund
|
|
149
|
+
* @param {CreateRefundRequest} refundData - The data containing the paymentIntentId to refund.
|
|
150
|
+
* @returns {Promise<CreateRefundResponse>} A promise that resolves with the refund details.
|
|
151
|
+
* @throws {ErrorResponse} Throws an error if the refund creation fails.
|
|
152
|
+
*/
|
|
153
|
+
createRefund: (refundData: CreateRefundRequest) => Promise<CreateRefundResponse>;
|
|
130
154
|
};
|
|
131
155
|
export default recurrente;
|
package/dist/api/recurrente.js
CHANGED
|
@@ -15,6 +15,27 @@ 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
|
+
/**
|
|
19
|
+
* Creates a new checkout session.
|
|
20
|
+
*
|
|
21
|
+
* This function takes checkout data, including items (by product_id or details),
|
|
22
|
+
* converts it to snake_case, and sends it to the API to create a new checkout session.
|
|
23
|
+
* It returns the checkout ID and the URL for redirection.
|
|
24
|
+
*
|
|
25
|
+
* @param {CreateCheckoutRequest} checkoutData - The details for the checkout session.
|
|
26
|
+
* @returns {Promise<CreateCheckoutResponse>} The response containing the checkout ID and URL.
|
|
27
|
+
* @throws {ErrorResponse} Throws an error if the checkout creation fails.
|
|
28
|
+
*/
|
|
29
|
+
const createCheckout = (checkoutData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
try {
|
|
31
|
+
const checkoutDataInSnakeCase = (0, conversion_1.toSnakeCase)(checkoutData);
|
|
32
|
+
const response = yield axiosInstance_1.default.post('/checkouts/', checkoutDataInSnakeCase);
|
|
33
|
+
return (0, conversion_1.toCamelCase)(response.data);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
throw handleAxiosError(error);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
18
39
|
/**
|
|
19
40
|
* Creates a new product with a one-time payment.
|
|
20
41
|
*
|
|
@@ -229,6 +250,26 @@ const test = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
229
250
|
throw handleAxiosError(error);
|
|
230
251
|
}
|
|
231
252
|
});
|
|
253
|
+
/**
|
|
254
|
+
* Creates a new refund for a specific payment intent.
|
|
255
|
+
*
|
|
256
|
+
* This function takes a payment_intent_id, converts the payload to snake_case,
|
|
257
|
+
* and sends it to the API to process a refund.
|
|
258
|
+
*
|
|
259
|
+
* @param {CreateRefundRequest} refundData - The data containing the paymentIntentId to refund.
|
|
260
|
+
* @returns {Promise<CreateRefundResponse>} The response containing the details of the created refund.
|
|
261
|
+
* @throws {ErrorResponse} Throws an error if the refund creation fails.
|
|
262
|
+
*/
|
|
263
|
+
const createRefund = (refundData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
264
|
+
try {
|
|
265
|
+
const refundDataInSnakeCase = (0, conversion_1.toSnakeCase)(refundData);
|
|
266
|
+
const response = yield axiosInstance_1.default.post('/refunds/', refundDataInSnakeCase);
|
|
267
|
+
return (0, conversion_1.toCamelCase)(response.data);
|
|
268
|
+
}
|
|
269
|
+
catch (error) {
|
|
270
|
+
throw handleAxiosError(error);
|
|
271
|
+
}
|
|
272
|
+
});
|
|
232
273
|
/**
|
|
233
274
|
* Recurrente API utility for managing product subscriptions, cancellations, and product deletions.
|
|
234
275
|
*
|
|
@@ -245,6 +286,8 @@ const test = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
245
286
|
* @property {Function} createSubscription - Creates a new subscription for a product.
|
|
246
287
|
* @property {Function} cancelSubscription - Cancels an existing subscription by its ID.
|
|
247
288
|
* @property {Function} getSubscription - Retrieves details of a specific subscription by its ID.
|
|
289
|
+
* @property {Function} createCheckout - Creates a new checkout with provided product ID.
|
|
290
|
+
* @property {Function} createRefund - Creates a new refund for a specific payment intent.
|
|
248
291
|
*/
|
|
249
292
|
const recurrente = {
|
|
250
293
|
/**
|
|
@@ -351,5 +394,27 @@ const recurrente = {
|
|
|
351
394
|
* @see getSubscription
|
|
352
395
|
*/
|
|
353
396
|
getSubscription,
|
|
397
|
+
/**
|
|
398
|
+
* Creates a new checkout session.
|
|
399
|
+
*
|
|
400
|
+
* @function
|
|
401
|
+
* @memberof recurrente.checkouts
|
|
402
|
+
* @see createCheckout
|
|
403
|
+
* @param {CreateCheckoutRequest} checkoutData - The details for the checkout session.
|
|
404
|
+
* @returns {Promise<CreateCheckoutResponse>} A promise that resolves with the checkout ID and URL.
|
|
405
|
+
* @throws {ErrorResponse} Throws an error if the checkout creation fails.
|
|
406
|
+
*/
|
|
407
|
+
createCheckout,
|
|
408
|
+
/**
|
|
409
|
+
* Creates a new refund for a specific payment intent.
|
|
410
|
+
*
|
|
411
|
+
* @function
|
|
412
|
+
* @memberof recurrente
|
|
413
|
+
* @see createRefund
|
|
414
|
+
* @param {CreateRefundRequest} refundData - The data containing the paymentIntentId to refund.
|
|
415
|
+
* @returns {Promise<CreateRefundResponse>} A promise that resolves with the refund details.
|
|
416
|
+
* @throws {ErrorResponse} Throws an error if the refund creation fails.
|
|
417
|
+
*/
|
|
418
|
+
createRefund,
|
|
354
419
|
};
|
|
355
420
|
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.
|
|
@@ -1275,3 +1333,57 @@ export type RecurrenteWebhookEvent = PaymentIntentSucceeded | PaymentIntentFaile
|
|
|
1275
1333
|
* @param event - The webhook event object.
|
|
1276
1334
|
*/
|
|
1277
1335
|
export type WebhookHandler<T> = (event: T) => void;
|
|
1336
|
+
/**
|
|
1337
|
+
* Represents the payload for creating a refund.
|
|
1338
|
+
*/
|
|
1339
|
+
export interface CreateRefundRequest {
|
|
1340
|
+
/**
|
|
1341
|
+
* The ID of the payment intent (`pa_...`) to be refunded.
|
|
1342
|
+
* @required
|
|
1343
|
+
*/
|
|
1344
|
+
paymentIntentId: string;
|
|
1345
|
+
}
|
|
1346
|
+
/**
|
|
1347
|
+
* Represents the response after successfully creating a refund.
|
|
1348
|
+
*/
|
|
1349
|
+
export interface CreateRefundResponse {
|
|
1350
|
+
/**
|
|
1351
|
+
* The unique identifier for the refund object (e.g., "re_...").
|
|
1352
|
+
* @required
|
|
1353
|
+
*/
|
|
1354
|
+
id: string;
|
|
1355
|
+
/**
|
|
1356
|
+
* The status of the refund.
|
|
1357
|
+
* @required
|
|
1358
|
+
*/
|
|
1359
|
+
status: 'succeeded' | 'pending' | 'failed';
|
|
1360
|
+
/**
|
|
1361
|
+
* The customer associated with the refunded payment.
|
|
1362
|
+
* @required
|
|
1363
|
+
*/
|
|
1364
|
+
customer: {
|
|
1365
|
+
id: string;
|
|
1366
|
+
email: string;
|
|
1367
|
+
fullName: string;
|
|
1368
|
+
};
|
|
1369
|
+
/**
|
|
1370
|
+
* The amount in cents that was refunded to your account balance.
|
|
1371
|
+
* @required
|
|
1372
|
+
*/
|
|
1373
|
+
accountRefundedAmountInCents: number;
|
|
1374
|
+
/**
|
|
1375
|
+
* The amount in cents that was refunded to the customer.
|
|
1376
|
+
* @required
|
|
1377
|
+
*/
|
|
1378
|
+
customerRefundedAmountInCents: number;
|
|
1379
|
+
/**
|
|
1380
|
+
* The currency of the refund.
|
|
1381
|
+
* @required
|
|
1382
|
+
*/
|
|
1383
|
+
currency: string;
|
|
1384
|
+
/**
|
|
1385
|
+
* The timestamp of when the refund was created.
|
|
1386
|
+
* @required
|
|
1387
|
+
*/
|
|
1388
|
+
createdAt: string;
|
|
1389
|
+
}
|