node-paytmpg 8.0.4 → 8.0.6

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.
@@ -17,6 +17,7 @@ export declare class SubscriptionController {
17
17
  initSubscription(req: Request, res: Response): Promise<void>;
18
18
  checkoutSubscription(req: Request, res: Response): Promise<void>;
19
19
  getSubscription(req: Request, res: Response): Promise<void>;
20
+ getSubscriptions(req: Request, res: Response): Promise<void>;
20
21
  cancelSubscription(req: Request, res: Response): Promise<void>;
21
22
  getSubscriptionPayments(req: Request, res: Response): Promise<void>;
22
23
  }
@@ -303,7 +303,7 @@ class SubscriptionController {
303
303
  }
304
304
  // Optionally sync from provider
305
305
  if (req.query.sync && sub.gateway_subscription_id) {
306
- const config = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req);
306
+ const config = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req, { clientId: sub.clientId });
307
307
  const provider = this.getProvider(config);
308
308
  if (provider) {
309
309
  try {
@@ -338,6 +338,40 @@ class SubscriptionController {
338
338
  res.status(500).send({ message: 'Error fetching subscription', error: err === null || err === void 0 ? void 0 : err.message });
339
339
  }
340
340
  }
341
+ async getSubscriptions(req, res) {
342
+ try {
343
+ const clientId = req.query.clientId || req.query.client_id || req.headers['x-client-id'] || '';
344
+ const userId = req.query.userId || req.query.user_id || req.query.cusId;
345
+ const userEmail = req.query.userEmail || req.query.user_email || req.query.email;
346
+ const query = {};
347
+ if (clientId) {
348
+ query.clientId = clientId;
349
+ }
350
+ if (userId) {
351
+ query.cusId = userId;
352
+ }
353
+ if (userEmail) {
354
+ const user = await this.db.getOne(this.tableNames.USER, { email: userEmail }).catch(() => null);
355
+ if (user) {
356
+ query.cusId = user.id;
357
+ }
358
+ else {
359
+ res.send({ limit: 20, offset: 0, count: 0, subscriptions: [] });
360
+ return;
361
+ }
362
+ }
363
+ const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
364
+ const offset = Math.max(parseInt(req.query.offset, 10) || 0, 0);
365
+ const subs = await this.db.get(this.tableNames.SUBSCRIPTION, query, {
366
+ sort: [{ field: 'createdAt', order: 'desc' }],
367
+ limit: limit, offset: offset
368
+ });
369
+ res.send({ limit, offset, count: subs.length, subscriptions: subs });
370
+ }
371
+ catch (err) {
372
+ res.status(500).send({ message: 'Error fetching subscriptions', error: err === null || err === void 0 ? void 0 : err.message });
373
+ }
374
+ }
341
375
  async cancelSubscription(req, res) {
342
376
  try {
343
377
  const id = req.params.id;
@@ -351,7 +385,7 @@ class SubscriptionController {
351
385
  res.status(400).send({ message: `Cannot cancel subscription in ${sub.status} state` });
352
386
  return;
353
387
  }
354
- const config = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req);
388
+ const config = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req, { clientId: sub.clientId });
355
389
  const provider = this.getProvider(config);
356
390
  if (provider && sub.gateway_subscription_id) {
357
391
  try {
@@ -383,6 +417,7 @@ class SubscriptionController {
383
417
  res.status(404).send({ message: 'Subscription not found' });
384
418
  return;
385
419
  }
420
+ const config = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req, { clientId: sub.clientId });
386
421
  const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
387
422
  const offset = Math.max(parseInt(req.query.offset, 10) || 0, 0);
388
423
  // Fetch transactions linked to this subscription
@@ -12,6 +12,7 @@ const subscriptionRoute = function (app, express, callbacks) {
12
12
  router.patch('/plans/:id', (req, res) => sc.updatePlan(req, res));
13
13
  router.delete('/plans/:id', (req, res) => sc.deletePlan(req, res));
14
14
  // Subscription Management
15
+ router.get('/', (req, res) => sc.getSubscriptions(req, res));
15
16
  router.post('/init', (req, res) => sc.initSubscription(req, res));
16
17
  router.post('/createTxn', (req, res) => sc.initSubscription(req, res));
17
18
  router.post('/createTxn/token', (req, res) => sc.initSubscription(req, res));
package/dist/index.js CHANGED
@@ -118,6 +118,7 @@ function createPaymentMiddleware(app, userConfig, db, callbacks, authenticationM
118
118
  subApp.get('/api/plans/:id', authenticationMiddleware, (req, res) => sc.getPlan(req, res));
119
119
  subApp.patch('/api/plans/:id', authenticationMiddleware, (req, res) => sc.updatePlan(req, res));
120
120
  subApp.delete('/api/plans/:id', authenticationMiddleware, (req, res) => sc.deletePlan(req, res));
121
+ subApp.get('/api/sub', authenticationMiddleware, (req, res) => sc.getSubscriptions(req, res));
121
122
  subApp.post('/api/sub/init', authenticationMiddleware, (req, res) => sc.initSubscription(req, res));
122
123
  subApp.post('/api/sub/createTxn', authenticationMiddleware, (req, res) => sc.initSubscription(req, res));
123
124
  subApp.post('/api/sub/createTxn/token', authenticationMiddleware, (req, res) => sc.initSubscription(req, res));
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-paytmpg",
3
- "version": "8.0.4",
3
+ "version": "8.0.6",
4
4
  "description": "Payment Gateway Integration using NodeJS",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-paytmpg",
3
- "version": "8.0.4",
3
+ "version": "8.0.6",
4
4
  "description": "Payment Gateway Integration using NodeJS",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",