tango-app-api-payment-subscription 3.0.37-dev → 3.0.38-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.37-dev",
3
+ "version": "3.0.38-dev",
4
4
  "description": "paymentSubscription",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -464,7 +464,7 @@ export const updateSubscription = async ( req, res ) => {
464
464
  let userDetails= await userService.findOne( { clientId: requestBody.clientId, role: 'superadmin' } );
465
465
  if ( userDetails ) {
466
466
  let data = {
467
- username: userDetails.userName,
467
+ userName: userDetails.userName,
468
468
  };
469
469
  const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/trialSubscriptionEmail.hbs', 'utf8' );
470
470
  const template = Handlebars.compile( templateHtml );
@@ -817,7 +817,7 @@ export const trialApproval = async ( req, res ) => {
817
817
  requestData.status = 'completed';
818
818
  requestData.save().then( async () => {
819
819
  if ( req.body.type == 'approve' ) {
820
- let clientProducts = await paymentService.findOne( { clientId: requestData.clientId, status: 'active' }, { planDetails: 1 } );
820
+ let clientProducts = await paymentService.findOne( { clientId: requestData.clientId }, { planDetails: 1 } );
821
821
  if ( clientProducts?.planDetails.subscriptionType == 'free' ) {
822
822
  clientProducts.planDetails.subscriptionType = 'premium';
823
823
  }
@@ -848,6 +848,7 @@ export const trialApproval = async ( req, res ) => {
848
848
  let data = {
849
849
  userName: userDetails.userName,
850
850
  product: firstWord +' '+ secondWord,
851
+ domain: appConfig.url.domain,
851
852
  };
852
853
  const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/trialInitiateEmail.hbs', 'utf8' );
853
854
  const template = Handlebars.compile( templateHtml );
@@ -885,7 +886,7 @@ export const trialApproval = async ( req, res ) => {
885
886
  export const trialExtendRequestApproval = async ( req, res ) => {
886
887
  try {
887
888
  let trialDate;
888
- let clientDetails = await paymentService.findOne( { clientId: req.body.clientId, status: 'active' }, { planDetails: 1 } );
889
+ let clientDetails = await paymentService.findOne( { clientId: req.body.clientId }, { planDetails: 1 } );
889
890
  if ( !clientDetails ) {
890
891
  return res.sendError( 'no data found', 204 );
891
892
  }
@@ -910,6 +911,7 @@ export const trialExtendRequestApproval = async ( req, res ) => {
910
911
  product: firstWord +' '+secondWord,
911
912
  days: req.body.days,
912
913
  date: dayjs( trialDate ).format( 'YYYY-MM-DD' ),
914
+ domain: appConfig.url.domain,
913
915
  };
914
916
  const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/trialExtentionEmail.hbs', 'utf8' );
915
917
  const template = Handlebars.compile( templateHtml );
@@ -950,6 +952,7 @@ export const productSubscribe = async ( req, res ) => {
950
952
  let data = req.body.product;
951
953
  req.body.product = [];
952
954
  let subscriptionCount = 0;
955
+ let trialProduct = [];
953
956
  data.forEach( ( item ) => {
954
957
  if ( item.type != 'cancel' ) {
955
958
  let arr = item.name.split( ',' );
@@ -961,7 +964,7 @@ export const productSubscribe = async ( req, res ) => {
961
964
  } );
962
965
  }
963
966
  } );
964
- let clientInfo = await paymentService.findOne( { clientId: req.body.clientId, status: 'active' }, { clientId: 1, planDetails: 1 } );
967
+ let clientInfo = await paymentService.findOne( { clientId: req.body.clientId }, { clientId: 1, planDetails: 1 } );
965
968
  if ( !clientInfo ) {
966
969
  return res.sendError( 'no data found', 204 );
967
970
  }
@@ -970,11 +973,7 @@ export const productSubscribe = async ( req, res ) => {
970
973
  let productList = product.map( ( item ) => item.productName );
971
974
  for ( let item of req.body.product ) {
972
975
  if ( productList.includes( item.name ) && item.type =='unsubscribe' ) {
973
- // let findIndex = product.findIndex( ( product ) => product.productName );
974
- // product.splice( findIndex, 1 );
975
- // let requestDetails = await clientRequestService.findOne({});
976
976
  await storeService.addremoveElement( { clientId: clientInfo.clientId, product: { $in: item.name } }, { $pull: { product: item.name } } );
977
- // status: 'active',
978
977
  }
979
978
  if ( !productList.includes( item.name ) && [ 'trial', 'subscription' ].includes( item.type ) ) {
980
979
  if ( item.type == 'trial' ) {
@@ -984,6 +983,10 @@ export const productSubscribe = async ( req, res ) => {
984
983
  trialEndDate: new Date( dayjs().add( 13, 'days' ).format( 'YYYY-MM-DD' ) ),
985
984
  status: 'trial',
986
985
  } );
986
+ let [ firstWord, secondWord ] = item.name.replace( /([a-z])([A-Z])/g, '$1 $2' ).split( ' ' );
987
+ firstWord = firstWord.charAt( 0 ).toUpperCase() + firstWord.slice( 1 );
988
+ let productName =firstWord + ' ' +secondWord;
989
+ trialProduct.push( productName );
987
990
  } else {
988
991
  product.push( {
989
992
  productName: item.name,
@@ -999,29 +1002,20 @@ export const productSubscribe = async ( req, res ) => {
999
1002
  if ( item.type == 'subscription' ) {
1000
1003
  product[productIndex].subscribedDate = new Date();
1001
1004
  product[productIndex].status = 'live';
1005
+ subscriptionCount = subscriptionCount + 1;
1002
1006
  }
1003
- subscriptionCount = subscriptionCount + 1;
1004
1007
  }
1005
1008
  }
1006
1009
  }
1007
1010
  product = product.filter( ( item ) => !removeProducts.includes( item.productName ) );
1008
- // req.body = {
1009
- // 'camaraPerSqft': clientInfo.planDetails.storeSize,
1010
- // 'storesCount': clientInfo.planDetails.totalStores,
1011
- // 'planName': clientInfo.planDetails.subscriptionPeriod,
1012
- // 'products': product.map( ( item ) => item.productName ),
1013
- // 'currencyType': 'rupees',
1014
- // };
1015
- // let pricingDetails = await calculatePricing( req, res );
1016
- // clientInfo.price = pricingDetails.price;
1017
1011
  if ( product.length > 1 ) {
1018
1012
  clientInfo.planDetails.subscriptionType = 'premium';
1019
1013
  }
1014
+ let userDetails= await userService.findOne( { clientId: clientInfo.clientId, role: 'superadmin' } );
1020
1015
  if ( subscriptionCount ) {
1021
- let userDetails= await userService.findOne( { clientId: clientInfo.clientId, role: 'superadmin' } );
1022
1016
  if ( userDetails ) {
1023
1017
  let data = {
1024
- username: userDetails.userName,
1018
+ userName: userDetails.userName,
1025
1019
  };
1026
1020
  const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/trialSubscriptionEmail.hbs', 'utf8' );
1027
1021
  const template = Handlebars.compile( templateHtml );
@@ -1036,26 +1030,30 @@ export const productSubscribe = async ( req, res ) => {
1036
1030
  sendEmailWithSES( params.toEmail, params.mailSubject, params.htmlBody, params.attachment, params.sourceEmail );
1037
1031
  }
1038
1032
  }
1033
+ if ( trialProduct.length ) {
1034
+ let productEmailName = trialProduct.toString();
1035
+ if ( userDetails ) {
1036
+ let data = {
1037
+ userName: userDetails.userName,
1038
+ product: productEmailName,
1039
+ domain: appConfig.url.domain,
1040
+ };
1041
+ const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/trialInitiateEmail.hbs', 'utf8' );
1042
+ const template = Handlebars.compile( templateHtml );
1043
+ const html = template( { data: data } );
1044
+ let params = {
1045
+ toEmail: userDetails.email,
1046
+ mailSubject: 'Trial Initiated - Welcome to Tango Suite!',
1047
+ htmlBody: html,
1048
+ attachment: '',
1049
+ sourceEmail: appConfig.cloud.aws.ses.adminEmail,
1050
+ };
1051
+ sendEmailWithSES( params.toEmail, params.mailSubject, params.htmlBody, params.attachment, params.sourceEmail );
1052
+ }
1053
+ }
1039
1054
  clientInfo.planDetails.product = product;
1040
1055
  clientInfo.save().then( async () => {
1041
1056
  updatePricing( req, res, true );
1042
- // let userDetails= await userService.findOne( { clientId: clientInfo.clientId, role: 'superadmin' } );
1043
- // if ( userDetails ) {
1044
- // let data = {
1045
- // username: userDetails.userName,
1046
- // };
1047
- // const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/trialSubscriptionEmail.hbs', 'utf8' );
1048
- // const template = Handlebars.compile( templateHtml );
1049
- // const html = template( { data: data } );
1050
- // let params = {
1051
- // toEmail: userDetails.email,
1052
- // mailSubject: 'Subscribe - Tango Eye',
1053
- // htmlBody: html,
1054
- // attachment: '',
1055
- // sourceEmail: appConfig.cloud.aws.ses.adminEmail,
1056
- // };
1057
- // sendEmailWithSES( params.toEmail, params.mailSubject, params.htmlBody, params.attachment, params.sourceEmail );
1058
- // }
1059
1057
  } );
1060
1058
  const logObj = {
1061
1059
  clientId: req.body.clientId,
@@ -1084,7 +1082,7 @@ export const unsubscribeApproval = async ( req, res ) => {
1084
1082
  requestData.status = 'completed';
1085
1083
  requestData.save().then( async () => {
1086
1084
  if ( req.body.type == 'unsubscribe' ) {
1087
- let clientProducts = await paymentService.findOne( { clientId: requestData.clientId, status: 'active' }, { status: 1 } );
1085
+ let clientProducts = await paymentService.findOne( { clientId: requestData.clientId }, { status: 1 } );
1088
1086
  if ( !clientProducts ) {
1089
1087
  return res.sendError( 'no data found', 204 );
1090
1088
  }
@@ -1330,12 +1328,13 @@ export const addStoreProduct = async ( req, res ) => {
1330
1328
  } );
1331
1329
  }
1332
1330
  } );
1333
- let clientInfo = await paymentService.findOne( { clientId: req.body.clientId, status: 'active' }, { 'planDetails.product': 1 } );
1331
+ let clientInfo = await paymentService.findOne( { clientId: req.body.clientId }, { 'planDetails.product': 1 } );
1334
1332
  let productList = clientInfo.planDetails.product.map( ( product ) => product.productName );
1335
1333
  let clientProduct = [];
1336
1334
  let storeProduct = [];
1337
1335
  let removedProduct = [];
1338
1336
  let subscriptionCount = 0;
1337
+ let trialProduct = [];
1339
1338
  clientProduct = clientInfo.planDetails.product;
1340
1339
  req.body.product.forEach( ( item ) => {
1341
1340
  if ( item.type != 'unsubscribe' ) {
@@ -1356,12 +1355,17 @@ export const addStoreProduct = async ( req, res ) => {
1356
1355
  trialEndDate: new Date( dayjs().add( 13, 'days' ).format( 'YYYY-MM-DD' ) ),
1357
1356
  status: 'trial',
1358
1357
  };
1358
+ let [ firstWord, secondWord ] = item.name.replace( /([a-z])([A-Z])/g, '$1 $2' ).split( ' ' );
1359
+ firstWord = firstWord.charAt( 0 ).toUpperCase() + firstWord.slice( 1 );
1360
+ let productName =firstWord + ' ' +secondWord;
1361
+ trialProduct.push( productName );
1359
1362
  } else {
1360
1363
  clientProduct[productExistsIndex] = {
1361
1364
  productName: item.name,
1362
1365
  subscribedDate: new Date(),
1363
1366
  status: 'live',
1364
1367
  };
1368
+ subscriptionCount = subscriptionCount + 1;
1365
1369
  }
1366
1370
  } else {
1367
1371
  if ( item.type == 'trial' ) {
@@ -1371,6 +1375,10 @@ export const addStoreProduct = async ( req, res ) => {
1371
1375
  trialEndDate: new Date( dayjs().add( 13, 'days' ).format( 'YYYY-MM-DD' ) ),
1372
1376
  status: 'trial',
1373
1377
  } );
1378
+ let [ firstWord, secondWord ] = item.name.replace( /([a-z])([A-Z])/g, '$1 $2' ).split( ' ' );
1379
+ firstWord = firstWord.charAt( 0 ).toUpperCase() + firstWord.slice( 1 );
1380
+ let productName =firstWord + ' ' +secondWord;
1381
+ trialProduct.push( productName );
1374
1382
  }
1375
1383
  if ( item.type == 'subscription' ) {
1376
1384
  clientProduct.push( {
@@ -1384,11 +1392,11 @@ export const addStoreProduct = async ( req, res ) => {
1384
1392
  }
1385
1393
  },
1386
1394
  );
1395
+ let userDetails= await userService.findOne( { clientId: req.body.clientId, role: 'superadmin' } );
1387
1396
  if ( subscriptionCount ) {
1388
- let userDetails= await userService.findOne( { clientId: req.body.clientId, role: 'superadmin' } );
1389
1397
  if ( userDetails ) {
1390
1398
  let data = {
1391
- username: userDetails.userName,
1399
+ userName: userDetails.userName,
1392
1400
  };
1393
1401
  const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/trialSubscriptionEmail.hbs', 'utf8' );
1394
1402
  const template = Handlebars.compile( templateHtml );
@@ -1403,6 +1411,27 @@ export const addStoreProduct = async ( req, res ) => {
1403
1411
  sendEmailWithSES( params.toEmail, params.mailSubject, params.htmlBody, params.attachment, params.sourceEmail );
1404
1412
  }
1405
1413
  }
1414
+ if ( trialProduct.length ) {
1415
+ let productEmailName = trialProduct.toString();
1416
+ if ( userDetails ) {
1417
+ let data = {
1418
+ userName: userDetails.userName,
1419
+ product: productEmailName,
1420
+ domain: appConfig.url.domain,
1421
+ };
1422
+ const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/trialInitiateEmail.hbs', 'utf8' );
1423
+ const template = Handlebars.compile( templateHtml );
1424
+ const html = template( { data: data } );
1425
+ let params = {
1426
+ toEmail: userDetails.email,
1427
+ mailSubject: 'Trial Initiated - Welcome to Tango Suite!',
1428
+ htmlBody: html,
1429
+ attachment: '',
1430
+ sourceEmail: appConfig.cloud.aws.ses.adminEmail,
1431
+ };
1432
+ sendEmailWithSES( params.toEmail, params.mailSubject, params.htmlBody, params.attachment, params.sourceEmail );
1433
+ }
1434
+ }
1406
1435
  clientInfo.planDetails.product = clientProduct;
1407
1436
  clientInfo.save();
1408
1437
  storeDetails.forEach( async ( item ) => {
@@ -1591,7 +1620,7 @@ export const priceList = async ( req, res ) => {
1591
1620
  {
1592
1621
  $match: {
1593
1622
  clientId: req.body.clientId,
1594
- // status: 'active',
1623
+ status: 'active',
1595
1624
  },
1596
1625
  },
1597
1626
  { $unwind: '$product' },
@@ -1989,22 +2018,18 @@ export const getRemindClients = async ( req, res ) => {
1989
2018
  if ( client.planDetails?.product && client.planDetails?.product.length ) {
1990
2019
  client.planDetails.product.forEach( async ( item ) => {
1991
2020
  if ( item.status == 'trial' && item?.trialEndDate ) {
1992
- let endDate = dayjs( item.trialEndDate ).startOf( 'day' );
2021
+ let endDate = dayjs( item.trialEndDate ).startOf( 'day' ).add( 1, 'days' );
1993
2022
  let date = dayjs().startOf( 'day' );
1994
2023
  let leftDays = endDate.diff( date, 'day' );
1995
- // let date = new Date();
1996
- // let userTimezoneOffset = item.trialEndDate.getTimezoneOffset() / 60000;
1997
- // item.trialEndDate = new Date( item.trialEndDate.getTime() - userTimezoneOffset );
1998
- // item.trialEndDate.setUTCHours( 0, 0, 0, 0 );
1999
- // const diffTime = parseInt( ( item.trialEndDate - date ) / ( 1000 * 60 * 60 * 24 ), 10 ) + 1;
2000
2024
  let userDetails= await userService.findOne( { clientId: client.clientId, role: 'superadmin' } );
2001
2025
  if ( userDetails ) {
2002
2026
  if ( leftDays == 3 ) {
2003
2027
  let [ firstWord, secondWord ] = item.productName.replace( /([a-z])([A-Z])/g, '$1 $2' ).split( ' ' );
2004
2028
  firstWord = firstWord.charAt( 0 ).toUpperCase() + firstWord.slice( 1 );
2005
2029
  let data = {
2006
- username: userDetails.userName,
2030
+ userName: userDetails.userName,
2007
2031
  product: firstWord + ' ' + secondWord,
2032
+ domain: appConfig.url.domain,
2008
2033
  };
2009
2034
  const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/trialReminderEmail.hbs', 'utf8' );
2010
2035
  const template = Handlebars.compile( templateHtml );
@@ -2067,6 +2092,7 @@ export const getExpiredClientsOld = async ( req, res ) => {
2067
2092
  let data = {
2068
2093
  userName: userDetails.userName,
2069
2094
  product: firstWord +' '+secondWord,
2095
+ domain: appConfig.url.domain,
2070
2096
  };
2071
2097
  const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/trialExpiredEmail.hbs', 'utf8' );
2072
2098
  const template = Handlebars.compile( templateHtml );
@@ -2101,11 +2127,6 @@ export const getExpiredClients = async ( req, res ) => {
2101
2127
  let endDate = dayjs( item.trialEndDate ).startOf( 'day' );
2102
2128
  let date = dayjs().startOf( 'day' );
2103
2129
  let leftDays = endDate.diff( date, 'day' );
2104
- // let date = new Date();
2105
- // let userTimezoneOffset = item.trialEndDate.getTimezoneOffset() / 60000;
2106
- // item.trialEndDate = new Date( item.trialEndDate.getTime() - userTimezoneOffset );
2107
- // item.trialEndDate.setUTCHours( 0, 0, 0, 0 );
2108
- // const diffTime = parseInt( ( item.trialEndDate - date ) / ( 1000 * 60 * 60 * 24 ), 10 ) + 1;
2109
2130
  let userDetails= await userService.findOne( { clientId: client.clientId, role: 'superadmin' } );
2110
2131
  if ( userDetails ) {
2111
2132
  if ( leftDays == -1 ) {
@@ -2114,6 +2135,7 @@ export const getExpiredClients = async ( req, res ) => {
2114
2135
  let data = {
2115
2136
  userName: userDetails.userName,
2116
2137
  product: firstWord + ' ' + secondWord,
2138
+ domain: appConfig.url.domain,
2117
2139
  };
2118
2140
  const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/trialExpiredEmail.hbs', 'utf8' );
2119
2141
  const template = Handlebars.compile( templateHtml );
@@ -242,8 +242,8 @@
242
242
  <td bgcolor="#ffffff" style="padding: 20px;padding-top:10px;padding-left:30px;">
243
243
  <table border="0" cellpadding="0" cellspacing="0">
244
244
  <tr>
245
- <td align="center" bgcolor="#00A3FF" style="border-radius: 6px;">
246
- <a href="${data.uiDomainName}" target="_blank"
245
+ <td align="center" bgcolor="#00A3FF" style="border-radius: 6px;height:50px;">
246
+ <a href="{{data.domain}}" target="_blank"
247
247
  style="display: inline-block; padding: 16px 36px; font-size: 16px; color: #ffffff; text-decoration: none; border-radius: 6px;">Upgrade Now
248
248
  </a>
249
249
  </td>
@@ -148,8 +148,8 @@
148
148
  <td bgcolor="#ffffff" style="padding: 20px;padding-top:30px;padding-left:30px;">
149
149
  <table border="0" cellpadding="0" cellspacing="0">
150
150
  <tr>
151
- <td align="center" bgcolor="#00A3FF" style="border-radius: 6px;">
152
- <a href="${data.uiDomainName}" target="_blank"
151
+ <td align="center" bgcolor="#00A3FF" style="border-radius: 6px;height:50px;">
152
+ <a href="{{data.domain}}" target="_blank"
153
153
  style="display: inline-block; padding: 16px 36px; font-size: 16px; color: #ffffff; text-decoration: none; border-radius: 6px;">Upgrade Now
154
154
  </a>
155
155
  </td>
@@ -251,8 +251,8 @@
251
251
  <td bgcolor="#ffffff" style="padding: 20px;padding-top:10px;padding-left:30px;">
252
252
  <table border="0" cellpadding="0" cellspacing="0">
253
253
  <tr>
254
- <td align="center" bgcolor="#00A3FF" style="border-radius: 6px;">
255
- <a href="data.uiDomainName" target="_blank"
254
+ <td align="center" bgcolor="#00A3FF" style="border-radius: 6px;height:50px;">
255
+ <a href="{{data.domain}}" target="_blank"
256
256
  style="display: inline-block; padding: 16px 36px; font-size: 16px; color: #ffffff; text-decoration: none; border-radius: 6px;">View
257
257
  Dashboard
258
258
  </a>
@@ -242,8 +242,8 @@
242
242
  <td bgcolor="#ffffff" style="padding: 20px;padding-top:10px;padding-left:30px;">
243
243
  <table border="0" cellpadding="0" cellspacing="0">
244
244
  <tr>
245
- <td align="center" bgcolor="#00A3FF" style="border-radius: 6px;">
246
- <a href="${data.uiDomainName}" target="_blank"
245
+ <td align="center" bgcolor="#00A3FF" style="border-radius: 6px;height:50px;">
246
+ <a href="{{data.domain}}" target="_blank"
247
247
  style="display: inline-block; padding: 16px 36px; font-size: 16px; color: #ffffff; text-decoration: none; border-radius: 6px;">Upgrade Now
248
248
  </a>
249
249
  </td>
@@ -14,7 +14,7 @@ export const validateClient = async ( req, res, next ) => {
14
14
  if ( req?.params?.clientId ) {
15
15
  data = req.params.clientId;
16
16
  }
17
- let clientDetails = await clientPayment.findOne( { clientId: data, status: 'active' } );
17
+ let clientDetails = await clientPayment.findOne( { clientId: data } );
18
18
  if ( !clientDetails ) {
19
19
  return res.sendError( 'no data found', 204 );
20
20
  }