tango-app-api-payment-subscription 3.0.9-dev → 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.9-dev",
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 = [
@@ -88,51 +87,56 @@ export const clientBillingSubscriptionInfo = async ( req, res, next ) => {
88
87
  }
89
88
 
90
89
  let singleActiveProducts = [];
91
- for ( let i = 0; i < activeProducts.length; i++ ) {
92
- singleActiveProducts.push( activeProducts[i].productName );
93
- }
94
-
95
- for ( let i = 0; i < tangoProducts.length; i++ ) {
96
- if ( !singleActiveProducts.includes( tangoProducts[i] ) ) {
97
- activeProducts.push( { productName: tangoProducts[i], active: false } );
90
+ if ( activeProducts && activeProducts.length ) {
91
+ for ( let i = 0; i < activeProducts.length; i++ ) {
92
+ singleActiveProducts.push( activeProducts[i].productName );
98
93
  }
99
- }
100
94
 
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;
95
+ for ( let i = 0; i < tangoProducts.length; i++ ) {
96
+ if ( !singleActiveProducts.includes( tangoProducts[i] ) ) {
97
+ activeProducts.push( { productName: tangoProducts[i], active: false } );
98
+ }
117
99
  }
118
100
 
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' && ( element.trialEndDate >= currentDate ) ) {
125
- let differenceInDays = dateDifference( element.trialEndDate, currentDate );
126
- trialProducts.push( { 'productName': element.productName, 'aliseProductName': element.aliseProductName, 'toolTip': differenceInDays +' days trial left' } );
127
- element.toolTip = 'On Trial';
128
- element.active = true;
129
- }
130
- if ( element.status == 'trial' && ( element.trialEndDate < currentDate ) ) {
131
- expiredProducts.push( { 'productName': element.productName, 'aliseProductName': element.aliseProductName, 'toolTip': 'Trial Expired' } );
132
- element.toolTip = 'Trial Expired';
133
- element.active = true;
134
- }
135
- } );
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
+ }
136
140
 
137
141
  let priceType = '';
138
142
  if ( clientInfo[0].priceType == 'step' ) {
@@ -227,7 +231,7 @@ export const pricingInfo = async ( req, res ) => {
227
231
  }
228
232
  };
229
233
 
230
- export const updateSubscription = async ( req, res ) => {
234
+ export const updateSubscriptionOLD = async ( req, res ) => {
231
235
  try {
232
236
  if ( !req?.body?.currentPlanInfo ) {
233
237
  return res.sendError( 'Plan info detail is required', 400 );
@@ -279,6 +283,86 @@ export const updateSubscription = async ( req, res ) => {
279
283
  }
280
284
  };
281
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
+
282
366
  export const trialProductList = async ( req, res ) => {
283
367
  try {
284
368
  let query =[
@@ -994,6 +1078,8 @@ export const updatedRevisedPrice = async ( req, res ) => {
994
1078
  return res.sendError( 'no data found', 204 );
995
1079
  }
996
1080
  invoiceDetails.amount = req.body.revisedAmount;
1081
+ invoiceDetails.revisedAmount = req.body.revisedAmount;
1082
+ invoiceDetails.discount = req.body.discount;
997
1083
  invoiceDetails.save().then( () => {
998
1084
  return res.sendSuccess( 'Credit notes Updated Successfully' );
999
1085
  } );
@@ -1006,7 +1092,7 @@ export const updatedRevisedPrice = async ( req, res ) => {
1006
1092
 
1007
1093
  export const unpaidInvoiceList = async ( req, res ) => {
1008
1094
  try {
1009
- 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 } );
1010
1096
  if ( !invoiceDetails.length ) {
1011
1097
  return res.sendError( 'no data found', 204 );
1012
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