tango-app-api-payment-subscription 3.0.7 → 3.0.9-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
|
@@ -15,8 +15,16 @@ export const addBilling = async ( req, res ) => {
|
|
|
15
15
|
};
|
|
16
16
|
let result = await paymentService.updateOne( { clientId: req.body.clientId }, params );
|
|
17
17
|
if ( result.modifiedCount ) {
|
|
18
|
+
let clientInfo = await paymentService.findOne( { clientId: req.body.clientId }, { 'clientName': 1, 'billingDetails.gstNumber': 1, 'billingDetails.billingAddress': 1 } );
|
|
19
|
+
let resultData = {};
|
|
20
|
+
resultData.clientName = clientInfo.clientName || '';
|
|
21
|
+
let billingDetails = {};
|
|
22
|
+
billingDetails.billingAddress = clientInfo.billingDetails.billingAddress;
|
|
23
|
+
billingDetails.gstNumber = clientInfo.billingDetails.gstNumber;
|
|
24
|
+
billingDetails.nextBillingDate = '--';
|
|
25
|
+
resultData.billingDetails = billingDetails;
|
|
18
26
|
logger.info( 'Billing Details Added Successfully' );
|
|
19
|
-
return res.sendSuccess( { message: '
|
|
27
|
+
return res.sendSuccess( { message: 'Billing Details Added Successfully', data: resultData } );
|
|
20
28
|
} else {
|
|
21
29
|
logger.error( 'Error Occurs WHile updating billing Detaisls' );
|
|
22
30
|
return res.sendError( 'Something Went Wrong', 500 );
|
|
@@ -29,7 +37,7 @@ export const addBilling = async ( req, res ) => {
|
|
|
29
37
|
};
|
|
30
38
|
|
|
31
39
|
|
|
32
|
-
export const
|
|
40
|
+
export const clientBillingSubscriptionInfo = async ( req, res, next ) => {
|
|
33
41
|
try {
|
|
34
42
|
let query = [
|
|
35
43
|
{
|
|
@@ -60,14 +68,121 @@ export const billingInfo = async ( req, res, next ) => {
|
|
|
60
68
|
if ( !clientInfo ) {
|
|
61
69
|
return res.sendError( 'no data found', 204 );
|
|
62
70
|
}
|
|
63
|
-
let storeCount = await storeService.count( { clientId: clientInfo.clientId } );
|
|
71
|
+
let storeCount = await storeService.count( { clientId: clientInfo[0].clientId } );
|
|
72
|
+
let tangoProducts = [ 'tangoTraffic', 'tangoZone', 'tangoSOP', 'prioritySupport' ];
|
|
73
|
+
let activeProducts = clientInfo[0].planDetails.product;
|
|
74
|
+
let liveProducts = [];
|
|
75
|
+
let trialProducts = [];
|
|
76
|
+
let expiredProducts = [];
|
|
77
|
+
let currentDate = new Date();
|
|
78
|
+
|
|
79
|
+
// Function to calculate the difference between two dates
|
|
80
|
+
function dateDifference( date1, date2 ) {
|
|
81
|
+
// Convert both dates to milliseconds
|
|
82
|
+
let date1ms = date1.getTime();
|
|
83
|
+
let date2ms = date2.getTime();
|
|
84
|
+
// Calculate the difference in milliseconds
|
|
85
|
+
let differencems = Math.abs( date1ms - date2ms );
|
|
86
|
+
// Convert the difference back to days
|
|
87
|
+
return Math.floor( differencems / ( 1000 * 60 * 60 * 24 ) );
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
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 } );
|
|
98
|
+
}
|
|
99
|
+
}
|
|
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' && ( 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
|
+
} );
|
|
136
|
+
|
|
137
|
+
let priceType = '';
|
|
138
|
+
if ( clientInfo[0].priceType == 'step' ) {
|
|
139
|
+
priceType = 'Step Pricing';
|
|
140
|
+
} else if ( clientInfo[0].priceType == 'standard' ) {
|
|
141
|
+
priceType = 'Standard Pricing';
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Check Due Limit from invoice //
|
|
145
|
+
let getPendingInvoice = await invoiceService.find( { clientId: clientInfo[0].clientId, status: 'pending' } );
|
|
146
|
+
let getPI = false;
|
|
147
|
+
if ( getPendingInvoice.length > 0 ) {
|
|
148
|
+
if ( getPendingInvoice[0].billingDate >= currentDate ) {
|
|
149
|
+
getPI= false;
|
|
150
|
+
} else {
|
|
151
|
+
getPI = true;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Check Client Request from client request//
|
|
156
|
+
let getClientRequest = await clientRequestService.find( { clientId: clientInfo[0].clientId, status: 'pending' } );
|
|
157
|
+
let getPCR = true;
|
|
158
|
+
if ( !getClientRequest.length ) {
|
|
159
|
+
getPCR = false;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
let currentPlanInfo = {};
|
|
163
|
+
currentPlanInfo.paymentStatus = clientInfo[0].planDetails.paymentStatus || '--';
|
|
164
|
+
currentPlanInfo.dueLimitReached = getPI;
|
|
165
|
+
currentPlanInfo.price = clientInfo[0].price || '--';
|
|
166
|
+
currentPlanInfo.priceType = priceType || '--';
|
|
167
|
+
currentPlanInfo.subscriptionType = clientInfo[0].planDetails.subscriptionType || '--';
|
|
168
|
+
currentPlanInfo.subscriptionPeriod = clientInfo[0].planDetails.subscriptionPeriod || '--';
|
|
169
|
+
currentPlanInfo.storeCount = storeCount || '--';
|
|
170
|
+
currentPlanInfo.totalCamera = clientInfo[0].planDetails.totalCamera || '--';
|
|
171
|
+
currentPlanInfo.totalStores = clientInfo[0].planDetails.totalStores || '--';
|
|
172
|
+
currentPlanInfo.storeSize = clientInfo[0].planDetails.totalStores || '--';
|
|
173
|
+
currentPlanInfo.liveProducts = liveProducts || '--';
|
|
174
|
+
currentPlanInfo.trialProducts = trialProducts || '--';
|
|
175
|
+
currentPlanInfo.expiredProducts = expiredProducts || '--';
|
|
176
|
+
currentPlanInfo.product = activeProducts || '--';
|
|
177
|
+
currentPlanInfo.pendingClientRequest = getPCR;
|
|
64
178
|
|
|
65
179
|
let data = {
|
|
66
180
|
_id: clientInfo[0]._id,
|
|
67
181
|
clientId: clientInfo[0].clientId,
|
|
68
|
-
|
|
182
|
+
clientName: clientInfo[0].clientName,
|
|
183
|
+
currentPlanInfo: currentPlanInfo,
|
|
69
184
|
billingDetails: { ...clientInfo[0].billingDetails, nextBillingDate: '--' },
|
|
70
|
-
|
|
185
|
+
bankDetails: clientInfo[0].virtualAccount,
|
|
71
186
|
};
|
|
72
187
|
|
|
73
188
|
return res.sendSuccess( data );
|
|
@@ -78,36 +193,6 @@ export const billingInfo = async ( req, res, next ) => {
|
|
|
78
193
|
}
|
|
79
194
|
};
|
|
80
195
|
|
|
81
|
-
export const getStoreList = async ( req, res ) => {
|
|
82
|
-
try {
|
|
83
|
-
let storeList = await storeService.find( { clientId: req.query.clientId, status: 'active' }, { _id: 1, storeId: 1, storeName: 1 } );
|
|
84
|
-
|
|
85
|
-
if ( !storeList.length ) {
|
|
86
|
-
return res.sendError( 'no data found', 204 );
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return res.sendSuccess( storeList );
|
|
90
|
-
} catch ( e ) {
|
|
91
|
-
logger.error( { error: e, function: 'getStoreList' } );
|
|
92
|
-
return res.sendError( e, 500 );
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
export const getClientList = async ( req, res ) => {
|
|
97
|
-
try {
|
|
98
|
-
let storeList = await paymentService.find( { status: 'active' }, { clientId: 1, _id: 1, clientName: 1 } );
|
|
99
|
-
|
|
100
|
-
if ( !storeList.length ) {
|
|
101
|
-
return res.sendError( 'no data found', 204 );
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return res.sendSuccess( storeList );
|
|
105
|
-
} catch ( e ) {
|
|
106
|
-
logger.error( { error: e, function: 'getClientList' } );
|
|
107
|
-
return res.sendError( e, 500 );
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
|
|
111
196
|
export const pricingInfo = async ( req, res ) => {
|
|
112
197
|
try {
|
|
113
198
|
let query = [
|
|
@@ -8,11 +8,7 @@ export const paymentSubscriptionRouter = express.Router();
|
|
|
8
8
|
|
|
9
9
|
paymentSubscriptionRouter.post( '/addBilling', isAllowedSessionHandler, validate( validationDtos.validateBillingParams ), validateClient, paymentController.addBilling );
|
|
10
10
|
|
|
11
|
-
paymentSubscriptionRouter.get( '/
|
|
12
|
-
|
|
13
|
-
paymentSubscriptionRouter.get( '/storeList', isAllowedSessionHandler, validate( validationDtos.validateStoreParams ), paymentController.getStoreList );
|
|
14
|
-
|
|
15
|
-
paymentSubscriptionRouter.get( '/clientList', isAllowedSessionHandler, paymentController.getClientList );
|
|
11
|
+
paymentSubscriptionRouter.get( '/clientBillingSubscriptionInfo/:clientId', isAllowedSessionHandler, validate( validationDtos.validateBrandParams ), paymentController.clientBillingSubscriptionInfo );
|
|
16
12
|
|
|
17
13
|
paymentSubscriptionRouter.post( '/basePricing', validate( validationDtos.validateProducts ), paymentController.pricingInfo );
|
|
18
14
|
|