tango-app-api-payment-subscription 3.0.8 → 3.0.10-dev

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-payment-subscription",
3
- "version": "3.0.8",
3
+ "version": "3.0.10-dev",
4
4
  "description": "paymentSubscription",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -20,7 +20,7 @@
20
20
  "handlebars": "^4.7.8",
21
21
  "mongodb": "^6.4.0",
22
22
  "nodemon": "^3.1.0",
23
- "tango-api-schema": "^2.0.41",
23
+ "tango-api-schema": "^2.0.54",
24
24
  "tango-app-api-middleware": "^1.0.29",
25
25
  "winston": "^3.12.0",
26
26
  "winston-daily-rotate-file": "^5.0.0"
@@ -36,7 +36,6 @@ export const addBilling = async ( req, res ) => {
36
36
  }
37
37
  };
38
38
 
39
-
40
39
  export const clientBillingSubscriptionInfo = async ( req, res, next ) => {
41
40
  try {
42
41
  let query = [
@@ -69,8 +68,8 @@ export const clientBillingSubscriptionInfo = async ( req, res, next ) => {
69
68
  return res.sendError( 'no data found', 204 );
70
69
  }
71
70
  let storeCount = await storeService.count( { clientId: clientInfo[0].clientId } );
72
-
73
- let totalProducts = clientInfo[0].planDetails.product;
71
+ let tangoProducts = [ 'tangoTraffic', 'tangoZone', 'tangoSOP', 'prioritySupport' ];
72
+ let activeProducts = clientInfo[0].planDetails.product;
74
73
  let liveProducts = [];
75
74
  let trialProducts = [];
76
75
  let expiredProducts = [];
@@ -87,21 +86,57 @@ export const clientBillingSubscriptionInfo = async ( req, res, next ) => {
87
86
  return Math.floor( differencems / ( 1000 * 60 * 60 * 24 ) );
88
87
  }
89
88
 
90
- totalProducts.forEach( ( element ) => {
91
- if ( element.status == 'live' ) {
92
- liveProducts.push( { 'productName': element.productName } );
93
- element.toolTip = 'Subscribed';
94
- }
95
- if ( element.status == 'trial' && ( element.trialEndDate >= currentDate ) ) {
96
- let differenceInDays = dateDifference( element.trialEndDate, currentDate );
97
- trialProducts.push( { 'productName': element.productName, 'toolTip': differenceInDays +' days trial left' } );
98
- element.toolTip = 'On Trial';
89
+ let singleActiveProducts = [];
90
+ if ( activeProducts && activeProducts.length ) {
91
+ for ( let i = 0; i < activeProducts.length; i++ ) {
92
+ singleActiveProducts.push( activeProducts[i].productName );
99
93
  }
100
- if ( element.status == 'trial' && ( element.trialEndDate < currentDate ) ) {
101
- expiredProducts.push( { 'productName': element.productName, 'toolTip': 'Trial Expired' } );
102
- element.toolTip = 'Trial Expired';
94
+
95
+ for ( let i = 0; i < tangoProducts.length; i++ ) {
96
+ if ( !singleActiveProducts.includes( tangoProducts[i] ) ) {
97
+ activeProducts.push( { productName: tangoProducts[i], active: false } );
98
+ }
103
99
  }
104
- } );
100
+
101
+ activeProducts.forEach( ( element ) => {
102
+ switch ( element.productName ) {
103
+ case 'tangoTraffic':
104
+ element.aliseProductName = 'Tango Traffic';
105
+ break;
106
+ case 'tangoZone':
107
+ element.aliseProductName = 'Tango Zone';
108
+ break;
109
+ case 'tangoSOP':
110
+ element.aliseProductName = 'Tango SOP';
111
+ break;
112
+ case 'prioritySupport':
113
+ element.aliseProductName = 'Priority Support';
114
+ break;
115
+ default:
116
+ break;
117
+ }
118
+
119
+ if ( element.status == 'live' ) {
120
+ liveProducts.push( { 'productName': element.productName, 'aliseProductName': element.aliseProductName } );
121
+ element.toolTip = 'Subscribed';
122
+ element.active = true;
123
+ }
124
+ if ( element.status == 'trial' ) {
125
+ let differenceInDays = 14;
126
+ if ( element?.trialEndDate ) {
127
+ differenceInDays = dateDifference( element?.trialEndDate, currentDate );
128
+ }
129
+ trialProducts.push( { 'productName': element.productName, 'aliseProductName': element.aliseProductName, 'toolTip': differenceInDays +' days trial left' } );
130
+ element.toolTip = 'On Trial';
131
+ element.active = true;
132
+ }
133
+ if ( element.status == 'trial' && ( element.trialEndDate < currentDate ) ) {
134
+ expiredProducts.push( { 'productName': element.productName, 'aliseProductName': element.aliseProductName, 'toolTip': 'Trial Expired' } );
135
+ element.toolTip = 'Trial Expired';
136
+ element.active = true;
137
+ }
138
+ } );
139
+ }
105
140
 
106
141
  let priceType = '';
107
142
  if ( clientInfo[0].priceType == 'step' ) {
@@ -111,6 +146,15 @@ export const clientBillingSubscriptionInfo = async ( req, res, next ) => {
111
146
  }
112
147
 
113
148
  // Check Due Limit from invoice //
149
+ let getPendingInvoice = await invoiceService.find( { clientId: clientInfo[0].clientId, status: 'pending' } );
150
+ let getPI = false;
151
+ if ( getPendingInvoice.length > 0 ) {
152
+ if ( getPendingInvoice[0].billingDate >= currentDate ) {
153
+ getPI= false;
154
+ } else {
155
+ getPI = true;
156
+ }
157
+ }
114
158
 
115
159
  // Check Client Request from client request//
116
160
  let getClientRequest = await clientRequestService.find( { clientId: clientInfo[0].clientId, status: 'pending' } );
@@ -121,7 +165,7 @@ export const clientBillingSubscriptionInfo = async ( req, res, next ) => {
121
165
 
122
166
  let currentPlanInfo = {};
123
167
  currentPlanInfo.paymentStatus = clientInfo[0].planDetails.paymentStatus || '--';
124
- currentPlanInfo.dueLimitReached = false;
168
+ currentPlanInfo.dueLimitReached = getPI;
125
169
  currentPlanInfo.price = clientInfo[0].price || '--';
126
170
  currentPlanInfo.priceType = priceType || '--';
127
171
  currentPlanInfo.subscriptionType = clientInfo[0].planDetails.subscriptionType || '--';
@@ -133,12 +177,13 @@ export const clientBillingSubscriptionInfo = async ( req, res, next ) => {
133
177
  currentPlanInfo.liveProducts = liveProducts || '--';
134
178
  currentPlanInfo.trialProducts = trialProducts || '--';
135
179
  currentPlanInfo.expiredProducts = expiredProducts || '--';
136
- currentPlanInfo.product = totalProducts || '--';
180
+ currentPlanInfo.product = activeProducts || '--';
137
181
  currentPlanInfo.pendingClientRequest = getPCR;
138
182
 
139
183
  let data = {
140
184
  _id: clientInfo[0]._id,
141
185
  clientId: clientInfo[0].clientId,
186
+ clientName: clientInfo[0].clientName,
142
187
  currentPlanInfo: currentPlanInfo,
143
188
  billingDetails: { ...clientInfo[0].billingDetails, nextBillingDate: '--' },
144
189
  bankDetails: clientInfo[0].virtualAccount,
@@ -152,36 +197,6 @@ export const clientBillingSubscriptionInfo = async ( req, res, next ) => {
152
197
  }
153
198
  };
154
199
 
155
- export const getStoreList = async ( req, res ) => {
156
- try {
157
- let storeList = await storeService.find( { clientId: req.query.clientId, status: 'active' }, { _id: 1, storeId: 1, storeName: 1 } );
158
-
159
- if ( !storeList.length ) {
160
- return res.sendError( 'no data found', 204 );
161
- }
162
-
163
- return res.sendSuccess( storeList );
164
- } catch ( e ) {
165
- logger.error( { error: e, function: 'getStoreList' } );
166
- return res.sendError( e, 500 );
167
- }
168
- };
169
-
170
- export const getClientList = async ( req, res ) => {
171
- try {
172
- let storeList = await paymentService.find( { status: 'active' }, { clientId: 1, _id: 1, clientName: 1 } );
173
-
174
- if ( !storeList.length ) {
175
- return res.sendError( 'no data found', 204 );
176
- }
177
-
178
- return res.sendSuccess( storeList );
179
- } catch ( e ) {
180
- logger.error( { error: e, function: 'getClientList' } );
181
- return res.sendError( e, 500 );
182
- }
183
- };
184
-
185
200
  export const pricingInfo = async ( req, res ) => {
186
201
  try {
187
202
  let query = [
@@ -216,7 +231,7 @@ export const pricingInfo = async ( req, res ) => {
216
231
  }
217
232
  };
218
233
 
219
- export const updateSubscription = async ( req, res ) => {
234
+ export const updateSubscriptionOLD = async ( req, res ) => {
220
235
  try {
221
236
  if ( !req?.body?.currentPlanInfo ) {
222
237
  return res.sendError( 'Plan info detail is required', 400 );
@@ -268,6 +283,86 @@ export const updateSubscription = async ( req, res ) => {
268
283
  }
269
284
  };
270
285
 
286
+ export const updateSubscription = async ( req, res ) => {
287
+ try {
288
+ let requestBody = req.body;
289
+ if ( !req?.body?.currentPlanInfo ) {
290
+ return res.sendError( 'Plan info detail is required', 400 );
291
+ }
292
+ let price = requestBody.currentPlanInfo.price;
293
+ let priceType = requestBody.currentPlanInfo.priceType;
294
+ delete requestBody.currentPlanInfo.price;
295
+ delete requestBody.currentPlanInfo.priceType;
296
+ delete requestBody.currentPlanInfo.storeCount;
297
+
298
+ console.log( 'requestBody.currentPlanInfo.product 1=>', requestBody.currentPlanInfo.product );
299
+ for ( let i = 0; i < requestBody.currentPlanInfo.product.length; i++ ) {
300
+ if ( requestBody.currentPlanInfo.product[i].status == 'live' && requestBody.currentPlanInfo.product[i].active == true ) {};
301
+ if ( requestBody.currentPlanInfo.product[i].status == 'trial' && requestBody.currentPlanInfo.product[i].active == true ) {
302
+ if ( requestBody.currentPlanInfo.product[i].confirmation == 'subscribenow' ) {
303
+ requestBody.currentPlanInfo.product[i].subscribedDate = new Date();
304
+ requestBody.currentPlanInfo.product[i].status = 'live';
305
+ requestBody.currentPlanInfo.product[i].trialStartDate = requestBody.currentPlanInfo.product[i]?.trialStartDate || '';
306
+ requestBody.currentPlanInfo.product[i].trialEndDate = requestBody.currentPlanInfo.product[i]?.trialEndDate || '';
307
+ }
308
+ };
309
+ if ( requestBody.currentPlanInfo.product[i].active == true && !requestBody.currentPlanInfo.product[i].hasOwnProperty( 'status' ) ) {
310
+ if ( requestBody.currentPlanInfo.product[i].confirmation == 'subscribenow' ) {
311
+ requestBody.currentPlanInfo.product[i].subscribedDate = new Date();
312
+ requestBody.currentPlanInfo.product[i].status = 'live';
313
+ requestBody.currentPlanInfo.product[i].trialStartDate = requestBody.currentPlanInfo.product[i]?.trialStartDate || '';
314
+ requestBody.currentPlanInfo.product[i].trialEndDate = requestBody.currentPlanInfo.product[i]?.trialEndDate || '';
315
+ }
316
+ if ( requestBody.currentPlanInfo.product[i].confirmation == 'starttrail' ) {
317
+ requestBody.currentPlanInfo.product[i].status = 'trial';
318
+ let params = {
319
+ user: '65e966e12b1991393cf8ce30', // need to login user id here
320
+ clientId: requestBody.clientId,
321
+ name: requestBody.currentPlanInfo.product[i].productName,
322
+ description: 'Request for Trial',
323
+ category: 'Trial',
324
+ status: 'pending',
325
+ };
326
+ await clientRequestService.insert( params );
327
+ }
328
+ if ( requestBody.currentPlanInfo.product[i].confirmation == 'doitlater' ) {
329
+ console.log( 'check' );
330
+ // need to do price changes
331
+ requestBody.currentPlanInfo.product.splice( i, 1 );
332
+ }
333
+ }
334
+ }
335
+
336
+ for ( let j = 0; j < requestBody.currentPlanInfo.product.length; j++ ) {
337
+ delete requestBody.currentPlanInfo.product[j]?.aliseProductName;
338
+ delete requestBody.currentPlanInfo.product[j]?.toolTip;
339
+ delete requestBody.currentPlanInfo.product[j]?.active;
340
+ delete requestBody.currentPlanInfo.product[j]?.confirmation;
341
+ }
342
+
343
+ console.log( 'requestBody.currentPlanInfo.product 2=>', requestBody.currentPlanInfo.product );
344
+ let details = {
345
+ planDetails: requestBody.currentPlanInfo,
346
+ price: price,
347
+ priceType: priceType,
348
+ };
349
+
350
+ let result = await paymentService.updateOne( { clientId: req.params.clientId }, details );
351
+ // let storeProduct = requestBody.currentPlanInfo.product.map( ( item ) => item.productName );
352
+ // await storeService.updateMany( { clientId: req.params.clientId, status: 'active' }, { product: storeProduct } );
353
+
354
+ if ( result.modifiedCount ) {
355
+ return res.sendSuccess( { message: 'Subscription Updated Successfully' } );
356
+ } else {
357
+ return res.sendError( 'Something went wrong', 500 );
358
+ }
359
+ } catch ( e ) {
360
+ console.log( e );
361
+ logger.error( { error: e, function: 'updateSubscription' } );
362
+ return res.sendError( e, 500 );
363
+ }
364
+ };
365
+
271
366
  export const trialProductList = async ( req, res ) => {
272
367
  try {
273
368
  let query =[
@@ -983,6 +1078,8 @@ export const updatedRevisedPrice = async ( req, res ) => {
983
1078
  return res.sendError( 'no data found', 204 );
984
1079
  }
985
1080
  invoiceDetails.amount = req.body.revisedAmount;
1081
+ invoiceDetails.revisedAmount = req.body.revisedAmount;
1082
+ invoiceDetails.discount = req.body.discount;
986
1083
  invoiceDetails.save().then( () => {
987
1084
  return res.sendSuccess( 'Credit notes Updated Successfully' );
988
1085
  } );
@@ -995,7 +1092,7 @@ export const updatedRevisedPrice = async ( req, res ) => {
995
1092
 
996
1093
  export const unpaidInvoiceList = async ( req, res ) => {
997
1094
  try {
998
- let invoiceDetails = await invoiceService.find( { clientId: req.params.clientId, status: { $ne: 'paid' } } );
1095
+ let invoiceDetails = await invoiceService.find( { clientId: req.params.clientId, status: { $ne: 'paid' } }, { invoice: 1, status: 1, amount: 1, revisedAmount: 1, totalAmount: 1, discount: 1 } );
999
1096
  if ( !invoiceDetails.length ) {
1000
1097
  return res.sendError( 'no data found', 204 );
1001
1098
  }
@@ -116,6 +116,7 @@ export const revisedParams = {
116
116
  body: joi.object( {
117
117
  invoice: joi.string().required(),
118
118
  revisedAmount: joi.number().required(),
119
+ discount: joi.number().required(),
119
120
  } ),
120
121
  };
121
122