node-paytmpg 8.0.4 → 8.0.5

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,25 @@ 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 query = {};
345
+ if (clientId) {
346
+ query.clientId = clientId;
347
+ }
348
+ const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
349
+ const offset = Math.max(parseInt(req.query.offset, 10) || 0, 0);
350
+ const subs = await this.db.get(this.tableNames.SUBSCRIPTION, query, {
351
+ sort: [{ field: 'createdAt', order: 'desc' }],
352
+ limit: limit, offset: offset
353
+ });
354
+ res.send({ limit, offset, count: subs.length, subscriptions: subs });
355
+ }
356
+ catch (err) {
357
+ res.status(500).send({ message: 'Error fetching subscriptions', error: err === null || err === void 0 ? void 0 : err.message });
358
+ }
359
+ }
341
360
  async cancelSubscription(req, res) {
342
361
  try {
343
362
  const id = req.params.id;
@@ -351,7 +370,7 @@ class SubscriptionController {
351
370
  res.status(400).send({ message: `Cannot cancel subscription in ${sub.status} state` });
352
371
  return;
353
372
  }
354
- const config = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req);
373
+ const config = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req, { clientId: sub.clientId });
355
374
  const provider = this.getProvider(config);
356
375
  if (provider && sub.gateway_subscription_id) {
357
376
  try {
@@ -383,6 +402,7 @@ class SubscriptionController {
383
402
  res.status(404).send({ message: 'Subscription not found' });
384
403
  return;
385
404
  }
405
+ const config = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req, { clientId: sub.clientId });
386
406
  const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
387
407
  const offset = Math.max(parseInt(req.query.offset, 10) || 0, 0);
388
408
  // 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.5",
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.5",
4
4
  "description": "Payment Gateway Integration using NodeJS",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",