@traxionpay/cbsmiddleware 0.0.2 → 0.0.3

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.
@@ -123,8 +123,8 @@ let WelcomeBankService = class WelcomeBankService {
123
123
  if (!refreshToken) {
124
124
  throw new common_1.HttpException({
125
125
  statusCode: common_1.HttpStatus.BAD_REQUEST,
126
- code: 400020206,
127
- message: 'Bank token should not be empty.',
126
+ code: 400020205,
127
+ message: 'Refresh token is required.',
128
128
  data: { refreshToken }
129
129
  }, common_1.HttpStatus.BAD_REQUEST);
130
130
  }
@@ -144,6 +144,14 @@ let WelcomeBankService = class WelcomeBankService {
144
144
  httpsAgent,
145
145
  });
146
146
  this.logger.log({ responseData: response }, 'Welcome Bank Refresh Token Successful');
147
+ if (response.data.message === "Unable to Process this request. Please check your payload.") {
148
+ throw new common_1.HttpException({
149
+ statusCode: common_1.HttpStatus.BAD_REQUEST,
150
+ code: 400020206,
151
+ message: 'Invalid refresh token.',
152
+ data: { refreshToken }
153
+ }, common_1.HttpStatus.BAD_REQUEST);
154
+ }
147
155
  return {
148
156
  success: true,
149
157
  ...response.data,
@@ -167,15 +175,15 @@ let WelcomeBankService = class WelcomeBankService {
167
175
  throw new common_1.HttpException({
168
176
  statusCode: common_1.HttpStatus.BAD_REQUEST,
169
177
  code: 400020304,
170
- message: 'Bank account number should not be empty.',
178
+ message: 'Account number is required.',
171
179
  data: { accountDto }
172
180
  }, common_1.HttpStatus.BAD_REQUEST);
173
181
  }
174
182
  if (!accountType) {
175
183
  throw new common_1.HttpException({
176
184
  statusCode: common_1.HttpStatus.BAD_REQUEST,
177
- code: 4400020306,
178
- message: 'Bank account type should not be empty.',
185
+ code: 400020306,
186
+ message: 'Account type is required.',
179
187
  data: { accountDto }
180
188
  }, common_1.HttpStatus.BAD_REQUEST);
181
189
  }
@@ -183,7 +191,7 @@ let WelcomeBankService = class WelcomeBankService {
183
191
  throw new common_1.HttpException({
184
192
  statusCode: common_1.HttpStatus.BAD_REQUEST,
185
193
  code: 4000203009,
186
- message: 'Mobile Number should not be empty.',
194
+ message: 'Mobile number is required.',
187
195
  data: { accountDto }
188
196
  }, common_1.HttpStatus.BAD_REQUEST);
189
197
  }
@@ -194,6 +202,7 @@ let WelcomeBankService = class WelcomeBankService {
194
202
  const totpPrevious = this.generateTOTP(timeInSeconds - 30);
195
203
  this.logger.log(`TOTP GENERATED FOR WELCOMEBANK LINK ACCOUNT: ${totp}, For Time stamp: ${isoTimestamp}`);
196
204
  this.logger.log(`TOTP GENERATED FOR PREVIOUS TIME: ${totpPrevious}`);
205
+ let responseData;
197
206
  try {
198
207
  const headers = {
199
208
  'Authorization': `Bearer ${token}`,
@@ -204,13 +213,17 @@ let WelcomeBankService = class WelcomeBankService {
204
213
  rejectUnauthorized: false,
205
214
  });
206
215
  let response;
216
+ let formattedMobile = mobile;
217
+ if (mobile.startsWith("63") && mobile.length > 2) {
218
+ formattedMobile = "0" + mobile.slice(2);
219
+ }
207
220
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
208
221
  let payload;
209
222
  payload = {
210
223
  "acc": account,
211
224
  "br": branch,
212
225
  "accType": accountType,
213
- "mobile": mobile
226
+ "mobile": formattedMobile
214
227
  };
215
228
  payload = this.encryptPayloadWithOTP(payload, totp);
216
229
  const encodedPayload = encodeURIComponent(payload);
@@ -220,43 +233,68 @@ let WelcomeBankService = class WelcomeBankService {
220
233
  });
221
234
  }
222
235
  else {
223
- response = await axios_1.default.get(`${this.config.WELCOMEBANK_URL}:${this.config.WELCOMEBANK_PORT}/api/linkaccount?acc=${account}&br=${branch}&accType=${accountType}&mobile=${mobile}`, {
236
+ response = await axios_1.default.get(`${this.config.WELCOMEBANK_URL}:${this.config.WELCOMEBANK_PORT}/api/linkaccount?acc=${account}&br=${branch}&accType=${accountType}&mobile=${formattedMobile}`, {
224
237
  headers: headers,
225
238
  httpsAgent
226
239
  });
227
240
  }
228
- let responseData = response.data;
229
- this.logger.log({ responseData: response }, 'Welcome Bank Link Account Successful');
241
+ this.logger.log({ responseData: response.data }, 'Welcome Bank Link Account Successful');
230
242
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
231
- const encryptedResponsePayload = responseData.data;
243
+ const encryptedResponsePayload = response.data.data;
232
244
  if (!encryptedResponsePayload) {
233
245
  throw new Error("Encrypted response expected but not found");
234
246
  }
235
- let decryptedResponse;
236
247
  try {
237
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
248
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
238
249
  }
239
250
  catch (error) {
240
251
  this.logger.warn("Decryption with current OTP failed, trying with previous OTP");
252
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
241
253
  }
242
- if (!decryptedResponse) {
243
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
244
- }
245
- return {
246
- success: true,
247
- data: decryptedResponse,
248
- };
249
254
  }
250
255
  else {
251
- return {
252
- success: true,
253
- ...responseData,
254
- };
256
+ responseData = response.data;
255
257
  }
256
258
  }
257
259
  catch (error) {
260
+ if (error.response.data.message === "Mobile number is not registered in the account.") {
261
+ throw new common_1.HttpException({
262
+ statusCode: common_1.HttpStatus.BAD_REQUEST,
263
+ code: 400020307,
264
+ message: 'Mobile number is not registered in the account.',
265
+ data: { accountDto }
266
+ }, common_1.HttpStatus.BAD_REQUEST);
267
+ }
258
268
  axios_error_helper_1.AxiosErrorHelper.handleAxiosError(error);
259
269
  }
270
+ if (responseData.data.status === "99997") {
271
+ throw new common_1.HttpException({
272
+ statusCode: common_1.HttpStatus.BAD_REQUEST,
273
+ code: 400020303,
274
+ message: 'Account not found',
275
+ data: { ...accountDto }
276
+ }, common_1.HttpStatus.BAD_REQUEST);
277
+ }
278
+ if (responseData.data.status === "00001") {
279
+ throw new common_1.HttpException({
280
+ statusCode: common_1.HttpStatus.BAD_REQUEST,
281
+ code: 400020305,
282
+ message: 'Account type is not supported.',
283
+ data: { ...accountDto }
284
+ }, common_1.HttpStatus.BAD_REQUEST);
285
+ }
286
+ if (responseData.data.status === "00007") {
287
+ throw new common_1.HttpException({
288
+ statusCode: common_1.HttpStatus.BAD_REQUEST,
289
+ code: 400020307,
290
+ message: 'Mobile number is not registered in the account.',
291
+ data: { ...accountDto }
292
+ }, common_1.HttpStatus.BAD_REQUEST);
293
+ }
294
+ return {
295
+ success: true,
296
+ ...responseData,
297
+ };
260
298
  }
261
299
  async validateOtp(validateOtp) {
262
300
  const { token, account, branch, accountType, otp } = validateOtp;
@@ -272,7 +310,7 @@ let WelcomeBankService = class WelcomeBankService {
272
310
  throw new common_1.HttpException({
273
311
  statusCode: common_1.HttpStatus.BAD_REQUEST,
274
312
  code: 400020404,
275
- message: 'Bank account number should not be empty.',
313
+ message: 'Account number is required.',
276
314
  data: { validateOtp }
277
315
  }, common_1.HttpStatus.BAD_REQUEST);
278
316
  }
@@ -280,7 +318,7 @@ let WelcomeBankService = class WelcomeBankService {
280
318
  throw new common_1.HttpException({
281
319
  statusCode: common_1.HttpStatus.BAD_REQUEST,
282
320
  code: 400020406,
283
- message: 'Bank account type should not be empty.',
321
+ message: 'Account type is required.',
284
322
  data: { validateOtp }
285
323
  }, common_1.HttpStatus.BAD_REQUEST);
286
324
  }
@@ -288,7 +326,7 @@ let WelcomeBankService = class WelcomeBankService {
288
326
  throw new common_1.HttpException({
289
327
  statusCode: common_1.HttpStatus.BAD_REQUEST,
290
328
  code: 400020408,
291
- message: 'Mobile Number should not be empty.',
329
+ message: 'OTP is required.',
292
330
  data: { validateOtp }
293
331
  }, common_1.HttpStatus.BAD_REQUEST);
294
332
  }
@@ -299,6 +337,7 @@ let WelcomeBankService = class WelcomeBankService {
299
337
  const totpPrevious = this.generateTOTP(timeInSeconds - 30);
300
338
  this.logger.log(`TOTP GENERATED FOR WELCOME BANK VALIDATE OTP: ${totp}, For Time stamp: ${isoTimestamp}`);
301
339
  this.logger.log(`TOTP GENERATED FOR PREVIOUS TIME: ${totpPrevious}`);
340
+ let responseData;
302
341
  try {
303
342
  const headers = {
304
343
  'Authorization': `Bearer ${token}`,
@@ -322,38 +361,55 @@ let WelcomeBankService = class WelcomeBankService {
322
361
  headers: headers,
323
362
  httpsAgent
324
363
  });
325
- let responseData = response.data;
326
- this.logger.log({ responseData: response }, 'Welcome Bank Validate OTP Successful');
364
+ this.logger.log({ responseData: response.data }, 'Welcome Bank Validate OTP Successful');
327
365
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
328
- const encryptedResponsePayload = responseData.data;
366
+ const encryptedResponsePayload = response.data.data;
329
367
  if (!encryptedResponsePayload) {
330
368
  throw new Error("Encrypted response expected but not found");
331
369
  }
332
- let decryptedResponse;
333
370
  try {
334
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
371
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
335
372
  }
336
373
  catch (error) {
337
374
  this.logger.warn("Decryption with current OTP failed, trying with previous OTP");
375
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
338
376
  }
339
- if (!decryptedResponse) {
340
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
341
- }
342
- return {
343
- success: true,
344
- data: decryptedResponse,
345
- };
346
377
  }
347
378
  else {
348
- return {
349
- success: true,
350
- ...responseData,
351
- };
379
+ responseData = response.data;
352
380
  }
353
381
  }
354
382
  catch (error) {
355
383
  axios_error_helper_1.AxiosErrorHelper.handleAxiosError(error);
356
384
  }
385
+ if (responseData.data.status === "99997") {
386
+ throw new common_1.HttpException({
387
+ statusCode: common_1.HttpStatus.BAD_REQUEST,
388
+ code: 400020403,
389
+ message: 'Account number is required.',
390
+ data: { ...validateOtp }
391
+ }, common_1.HttpStatus.BAD_REQUEST);
392
+ }
393
+ if (responseData.data.status === "00001") {
394
+ throw new common_1.HttpException({
395
+ statusCode: common_1.HttpStatus.BAD_REQUEST,
396
+ code: 400020405,
397
+ message: 'Account type is not supported.',
398
+ data: { ...validateOtp }
399
+ }, common_1.HttpStatus.BAD_REQUEST);
400
+ }
401
+ if (responseData.data.status === "00005") {
402
+ throw new common_1.HttpException({
403
+ statusCode: common_1.HttpStatus.BAD_REQUEST,
404
+ code: 400020407,
405
+ message: 'Invalid or expired OTP.',
406
+ data: { ...validateOtp }
407
+ }, common_1.HttpStatus.BAD_REQUEST);
408
+ }
409
+ return {
410
+ success: true,
411
+ ...responseData,
412
+ };
357
413
  }
358
414
  async processBalanceTransaction(fetchBalanceDto) {
359
415
  const { token, permissionKey, account, branch, accountType } = fetchBalanceDto;
@@ -367,17 +423,17 @@ let WelcomeBankService = class WelcomeBankService {
367
423
  }
368
424
  if (!permissionKey) {
369
425
  throw new common_1.HttpException({
370
- statusCode: common_1.HttpStatus.UNAUTHORIZED,
426
+ statusCode: common_1.HttpStatus.FORBIDDEN,
371
427
  code: 403020504,
372
- message: 'Bank permission key should not be empty.',
428
+ message: 'Permission key is required.',
373
429
  data: { fetchBalanceDto }
374
- }, common_1.HttpStatus.UNAUTHORIZED);
430
+ }, common_1.HttpStatus.FORBIDDEN);
375
431
  }
376
432
  if (!account) {
377
433
  throw new common_1.HttpException({
378
434
  statusCode: common_1.HttpStatus.BAD_REQUEST,
379
435
  code: 400020506,
380
- message: 'Bank account number should not be empty.',
436
+ message: 'Account number is required.',
381
437
  data: { fetchBalanceDto }
382
438
  }, common_1.HttpStatus.BAD_REQUEST);
383
439
  }
@@ -385,7 +441,7 @@ let WelcomeBankService = class WelcomeBankService {
385
441
  throw new common_1.HttpException({
386
442
  statusCode: common_1.HttpStatus.BAD_REQUEST,
387
443
  code: 400020508,
388
- message: 'Bank account type should not be empty.',
444
+ message: 'Account type is required.',
389
445
  data: { fetchBalanceDto }
390
446
  }, common_1.HttpStatus.BAD_REQUEST);
391
447
  }
@@ -396,6 +452,7 @@ let WelcomeBankService = class WelcomeBankService {
396
452
  const totpPrevious = this.generateTOTP(timeInSeconds - 30);
397
453
  this.logger.log(`TOTP GENERATED FOR WELCOME BANK BALANCE INQUIRY: ${totp}, For Time stamp: ${isoTimestamp}`);
398
454
  this.logger.log(`TOTP GENERATED FOR PREVIOUS TIME: ${totpPrevious}`);
455
+ let responseData;
399
456
  try {
400
457
  const headers = {
401
458
  'Authorization': `Bearer ${token}`,
@@ -419,38 +476,55 @@ let WelcomeBankService = class WelcomeBankService {
419
476
  headers: headers,
420
477
  httpsAgent
421
478
  });
422
- let responseData = response.data;
423
- this.logger.log({ responseData: response }, 'Welcome Bank Balance Inquiry Successful');
479
+ this.logger.log({ responseData: response.data }, 'Welcome Bank Balance Inquiry Successful');
424
480
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
425
- const encryptedResponsePayload = responseData.data;
481
+ const encryptedResponsePayload = response.data.data;
426
482
  if (!encryptedResponsePayload) {
427
483
  throw new Error("Encrypted response expected but not found");
428
484
  }
429
- let decryptedResponse;
430
485
  try {
431
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
486
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
432
487
  }
433
488
  catch (error) {
434
489
  this.logger.warn("Decryption with current OTP failed, trying with previous OTP");
490
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
435
491
  }
436
- if (!decryptedResponse) {
437
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
438
- }
439
- return {
440
- success: true,
441
- data: decryptedResponse,
442
- };
443
492
  }
444
493
  else {
445
- return {
446
- success: true,
447
- ...responseData,
448
- };
494
+ responseData = response.data;
449
495
  }
450
496
  }
451
497
  catch (error) {
452
498
  axios_error_helper_1.AxiosErrorHelper.handleAxiosError(error);
453
499
  }
500
+ if (responseData.data.status === "99999") {
501
+ throw new common_1.HttpException({
502
+ statusCode: common_1.HttpStatus.FORBIDDEN,
503
+ code: 403020503,
504
+ message: 'Invalid permission key.',
505
+ data: { ...fetchBalanceDto }
506
+ }, common_1.HttpStatus.FORBIDDEN);
507
+ }
508
+ if (responseData.data.status === "99997") {
509
+ throw new common_1.HttpException({
510
+ statusCode: common_1.HttpStatus.BAD_REQUEST,
511
+ code: 400020505,
512
+ message: 'Account not found.',
513
+ data: { ...fetchBalanceDto }
514
+ }, common_1.HttpStatus.BAD_REQUEST);
515
+ }
516
+ if (responseData.data.status === "00001") {
517
+ throw new common_1.HttpException({
518
+ statusCode: common_1.HttpStatus.BAD_REQUEST,
519
+ code: 400020507,
520
+ message: 'Account type is not supported.',
521
+ data: { ...fetchBalanceDto }
522
+ }, common_1.HttpStatus.BAD_REQUEST);
523
+ }
524
+ return {
525
+ success: true,
526
+ ...responseData,
527
+ };
454
528
  }
455
529
  async accountCashIn(accountTransferDto) {
456
530
  const { token, permissionKey, sourceAccount, sourceBranch, sourceAccountType, destinationAccount, destinationBranch, destinationAccountType, amount } = accountTransferDto;
@@ -466,7 +540,7 @@ let WelcomeBankService = class WelcomeBankService {
466
540
  throw new common_1.HttpException({
467
541
  statusCode: common_1.HttpStatus.FORBIDDEN,
468
542
  code: 403020604,
469
- message: 'Bank permission key should not be empty.',
543
+ message: 'Permission key is required.',
470
544
  data: { accountTransferDto }
471
545
  }, common_1.HttpStatus.FORBIDDEN);
472
546
  }
@@ -474,7 +548,7 @@ let WelcomeBankService = class WelcomeBankService {
474
548
  throw new common_1.HttpException({
475
549
  statusCode: common_1.HttpStatus.BAD_REQUEST,
476
550
  code: 400020606,
477
- message: 'Bank source account number should not be empty.',
551
+ message: 'Source account number is required.',
478
552
  data: { accountTransferDto }
479
553
  }, common_1.HttpStatus.BAD_REQUEST);
480
554
  }
@@ -482,7 +556,7 @@ let WelcomeBankService = class WelcomeBankService {
482
556
  throw new common_1.HttpException({
483
557
  statusCode: common_1.HttpStatus.BAD_REQUEST,
484
558
  code: 400020608,
485
- message: 'Bank source account type should not be empty.',
559
+ message: 'Source account type is required.',
486
560
  data: { accountTransferDto }
487
561
  }, common_1.HttpStatus.BAD_REQUEST);
488
562
  }
@@ -490,7 +564,7 @@ let WelcomeBankService = class WelcomeBankService {
490
564
  throw new common_1.HttpException({
491
565
  statusCode: common_1.HttpStatus.BAD_REQUEST,
492
566
  code: 400020610,
493
- message: 'Bank destination account number should not be empty.',
567
+ message: 'Destination account number is required.',
494
568
  data: { accountTransferDto }
495
569
  }, common_1.HttpStatus.BAD_REQUEST);
496
570
  }
@@ -498,7 +572,7 @@ let WelcomeBankService = class WelcomeBankService {
498
572
  throw new common_1.HttpException({
499
573
  statusCode: common_1.HttpStatus.BAD_REQUEST,
500
574
  code: 400020612,
501
- message: 'Bank destination account type should not be empty.',
575
+ message: 'Destination account type is required.',
502
576
  data: { accountTransferDto }
503
577
  }, common_1.HttpStatus.BAD_REQUEST);
504
578
  }
@@ -506,7 +580,7 @@ let WelcomeBankService = class WelcomeBankService {
506
580
  throw new common_1.HttpException({
507
581
  statusCode: common_1.HttpStatus.BAD_REQUEST,
508
582
  code: 400020613,
509
- message: 'Amount should not be empty.',
583
+ message: 'Transaction amount is required.',
510
584
  data: { accountTransferDto }
511
585
  }, common_1.HttpStatus.BAD_REQUEST);
512
586
  }
@@ -517,6 +591,7 @@ let WelcomeBankService = class WelcomeBankService {
517
591
  const totpPrevious = this.generateTOTP(timeInSeconds - 30);
518
592
  this.logger.log(`TOTP GENERATED FOR WELCOME BANK CASH IN: ${totp}, For Time stamp: ${isoTimestamp}`);
519
593
  this.logger.log(`TOTP GENERATED FOR PREVIOUS TIME: ${totpPrevious}`);
594
+ let responseData;
520
595
  try {
521
596
  const headers = {
522
597
  'Authorization': `Bearer ${token}`,
@@ -544,38 +619,63 @@ let WelcomeBankService = class WelcomeBankService {
544
619
  headers: headers,
545
620
  httpsAgent
546
621
  });
547
- let responseData = response.data;
548
- this.logger.log({ responseData: response }, 'Welcome Bank Cash In Successful');
622
+ this.logger.log({ responseData: response.data }, 'Welcome Bank Cash In Successful');
549
623
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
550
- const encryptedResponsePayload = responseData.data;
624
+ const encryptedResponsePayload = response.data.data;
551
625
  if (!encryptedResponsePayload) {
552
626
  throw new Error("Encrypted response expected but not found");
553
627
  }
554
- let decryptedResponse;
555
628
  try {
556
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
629
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
557
630
  }
558
631
  catch (error) {
559
632
  this.logger.warn("Decryption with current OTP failed, trying with previous OTP");
633
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
560
634
  }
561
- if (!decryptedResponse) {
562
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
563
- }
564
- return {
565
- success: true,
566
- data: decryptedResponse,
567
- };
568
635
  }
569
636
  else {
570
- return {
571
- success: true,
572
- ...responseData,
573
- };
637
+ responseData = response.data;
574
638
  }
575
639
  }
576
640
  catch (error) {
577
641
  axios_error_helper_1.AxiosErrorHelper.handleAxiosError(error);
578
642
  }
643
+ if (responseData.data.status === "99999") {
644
+ throw new common_1.HttpException({
645
+ statusCode: common_1.HttpStatus.FORBIDDEN,
646
+ code: 403020603,
647
+ message: 'Invalid permission key.',
648
+ data: { ...accountTransferDto }
649
+ }, common_1.HttpStatus.FORBIDDEN);
650
+ }
651
+ if (responseData.data.status === "99997") {
652
+ throw new common_1.HttpException({
653
+ statusCode: common_1.HttpStatus.BAD_REQUEST,
654
+ code: 400020605,
655
+ message: 'Account not found.',
656
+ data: { ...accountTransferDto }
657
+ }, common_1.HttpStatus.BAD_REQUEST);
658
+ }
659
+ if (responseData.data.status === "00001") {
660
+ throw new common_1.HttpException({
661
+ statusCode: common_1.HttpStatus.BAD_REQUEST,
662
+ code: 400020607,
663
+ message: 'Account type is not supported.',
664
+ data: { ...accountTransferDto }
665
+ }, common_1.HttpStatus.BAD_REQUEST);
666
+ }
667
+ if (responseData.data.status === "00004") {
668
+ throw new common_1.HttpException({
669
+ statusCode: common_1.HttpStatus.UNPROCESSABLE_ENTITY,
670
+ code: 422020614,
671
+ message: 'Invalid transaction amount value.',
672
+ data: { ...accountTransferDto }
673
+ }, common_1.HttpStatus.UNPROCESSABLE_ENTITY);
674
+ }
675
+ return {
676
+ success: true,
677
+ ...responseData,
678
+ };
579
679
  }
580
680
  async accountDeposit(accountTransferDto) {
581
681
  const { token, permissionKey, sourceAccount, sourceBranch, sourceAccountType, destinationAccount, destinationBranch, destinationAccountType, amount } = accountTransferDto;
@@ -591,7 +691,7 @@ let WelcomeBankService = class WelcomeBankService {
591
691
  throw new common_1.HttpException({
592
692
  statusCode: common_1.HttpStatus.FORBIDDEN,
593
693
  code: 403020704,
594
- message: 'Bank permission key should not be empty.',
694
+ message: 'Permission key is required.',
595
695
  data: { accountTransferDto }
596
696
  }, common_1.HttpStatus.FORBIDDEN);
597
697
  }
@@ -599,7 +699,7 @@ let WelcomeBankService = class WelcomeBankService {
599
699
  throw new common_1.HttpException({
600
700
  statusCode: common_1.HttpStatus.BAD_REQUEST,
601
701
  code: 400020706,
602
- message: 'Bank source account number should not be empty.',
702
+ message: 'Source account number is required',
603
703
  data: { accountTransferDto }
604
704
  }, common_1.HttpStatus.BAD_REQUEST);
605
705
  }
@@ -607,7 +707,7 @@ let WelcomeBankService = class WelcomeBankService {
607
707
  throw new common_1.HttpException({
608
708
  statusCode: common_1.HttpStatus.BAD_REQUEST,
609
709
  code: 400020708,
610
- message: 'Bank source account type should not be empty.',
710
+ message: 'Source account type is required.',
611
711
  data: { accountTransferDto }
612
712
  }, common_1.HttpStatus.BAD_REQUEST);
613
713
  }
@@ -615,7 +715,7 @@ let WelcomeBankService = class WelcomeBankService {
615
715
  throw new common_1.HttpException({
616
716
  statusCode: common_1.HttpStatus.BAD_REQUEST,
617
717
  code: 400020710,
618
- message: 'Bank destination account number should not be empty.',
718
+ message: 'Destination account number is required',
619
719
  data: { accountTransferDto }
620
720
  }, common_1.HttpStatus.BAD_REQUEST);
621
721
  }
@@ -631,7 +731,7 @@ let WelcomeBankService = class WelcomeBankService {
631
731
  throw new common_1.HttpException({
632
732
  statusCode: common_1.HttpStatus.BAD_REQUEST,
633
733
  code: 400020713,
634
- message: 'Amount should not be empty.',
734
+ message: 'Transaction amount is required.',
635
735
  data: { accountTransferDto }
636
736
  }, common_1.HttpStatus.BAD_REQUEST);
637
737
  }
@@ -642,6 +742,7 @@ let WelcomeBankService = class WelcomeBankService {
642
742
  const totpPrevious = this.generateTOTP(timeInSeconds - 30);
643
743
  this.logger.log(`TOTP GENERATED FOR WELCOME BANK DEPOSIT: ${totp}, For Time stamp: ${isoTimestamp}`);
644
744
  this.logger.log(`TOTP GENERATED FOR PREVIOUS TIME: ${totpPrevious}`);
745
+ let responseData;
645
746
  try {
646
747
  const headers = {
647
748
  'Authorization': `Bearer ${token}`,
@@ -669,41 +770,68 @@ let WelcomeBankService = class WelcomeBankService {
669
770
  headers: headers,
670
771
  httpsAgent
671
772
  });
672
- let responseData = response.data;
673
773
  this.logger.log({ responseData: response.data }, 'Welcom Bank Deposit Successful');
674
774
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
675
- const encryptedResponsePayload = responseData.data;
775
+ const encryptedResponsePayload = response.data.data;
676
776
  if (!encryptedResponsePayload) {
677
777
  throw new Error("Encrypted response expected but not found");
678
778
  }
679
- let decryptedResponse;
680
779
  try {
681
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
780
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
682
781
  }
683
782
  catch (error) {
684
783
  this.logger.warn("Decryption with current OTP failed, trying with previous OTP");
784
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
685
785
  }
686
- if (!decryptedResponse) {
687
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
688
- }
689
- return {
690
- success: true,
691
- data: decryptedResponse,
692
- };
693
786
  }
694
787
  else {
695
- return {
696
- success: true,
697
- ...responseData,
698
- };
788
+ responseData = response.data;
699
789
  }
700
790
  }
701
791
  catch (error) {
702
792
  axios_error_helper_1.AxiosErrorHelper.handleAxiosError(error);
703
793
  }
794
+ if (responseData.data.status === "99999") {
795
+ throw new common_1.HttpException({
796
+ statusCode: common_1.HttpStatus.FORBIDDEN,
797
+ code: 403020703,
798
+ message: 'Invalid permission key.',
799
+ data: { ...accountTransferDto }
800
+ }, common_1.HttpStatus.FORBIDDEN);
801
+ }
802
+ if (responseData.data.status === "99997") {
803
+ throw new common_1.HttpException({
804
+ statusCode: common_1.HttpStatus.BAD_REQUEST,
805
+ code: 400020709,
806
+ message: 'Account not found.',
807
+ data: { ...accountTransferDto }
808
+ }, common_1.HttpStatus.BAD_REQUEST);
809
+ }
810
+ if (responseData.data.status === "00001") {
811
+ throw new common_1.HttpException({
812
+ statusCode: common_1.HttpStatus.BAD_REQUEST,
813
+ code: 400020711,
814
+ message: 'Account type is not supported.',
815
+ data: { ...accountTransferDto }
816
+ }, common_1.HttpStatus.BAD_REQUEST);
817
+ }
818
+ if (responseData.data.status === "00004") {
819
+ throw new common_1.HttpException({
820
+ statusCode: common_1.HttpStatus.UNPROCESSABLE_ENTITY,
821
+ code: 422020714,
822
+ message: 'Invalid transaction amount value.',
823
+ data: { ...accountTransferDto }
824
+ }, common_1.HttpStatus.UNPROCESSABLE_ENTITY);
825
+ }
826
+ return {
827
+ success: true,
828
+ ...responseData,
829
+ };
704
830
  }
705
831
  async getTransactionHistory(transactionHistoryDto) {
706
832
  const { token, permissionKey, account, branch, accountType, dateFrom, dateTo, page } = transactionHistoryDto;
833
+ const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
834
+ const reformattedTransactions = {};
707
835
  if (!token) {
708
836
  throw new common_1.HttpException({
709
837
  statusCode: common_1.HttpStatus.UNAUTHORIZED,
@@ -716,7 +844,7 @@ let WelcomeBankService = class WelcomeBankService {
716
844
  throw new common_1.HttpException({
717
845
  statusCode: common_1.HttpStatus.FORBIDDEN,
718
846
  code: 403020804,
719
- message: 'Bank permission key should not be empty.',
847
+ message: 'Permission key is required.',
720
848
  data: { transactionHistoryDto }
721
849
  }, common_1.HttpStatus.FORBIDDEN);
722
850
  }
@@ -724,7 +852,7 @@ let WelcomeBankService = class WelcomeBankService {
724
852
  throw new common_1.HttpException({
725
853
  statusCode: common_1.HttpStatus.BAD_REQUEST,
726
854
  code: 400020806,
727
- message: 'Bank account number should not be empty.',
855
+ message: 'Account number is required',
728
856
  data: { transactionHistoryDto }
729
857
  }, common_1.HttpStatus.BAD_REQUEST);
730
858
  }
@@ -732,7 +860,7 @@ let WelcomeBankService = class WelcomeBankService {
732
860
  throw new common_1.HttpException({
733
861
  statusCode: common_1.HttpStatus.BAD_REQUEST,
734
862
  code: 400020808,
735
- message: 'Bank account type should not be empty.',
863
+ message: 'Account type is required.',
736
864
  data: { transactionHistoryDto }
737
865
  }, common_1.HttpStatus.BAD_REQUEST);
738
866
  }
@@ -740,25 +868,42 @@ let WelcomeBankService = class WelcomeBankService {
740
868
  throw new common_1.HttpException({
741
869
  statusCode: common_1.HttpStatus.BAD_REQUEST,
742
870
  code: 400020810,
743
- message: 'Date From should not be empty.',
871
+ message: 'Starting date is required.',
744
872
  data: { transactionHistoryDto }
745
873
  }, common_1.HttpStatus.BAD_REQUEST);
746
874
  }
875
+ if (!dateRegex.test(dateFrom)) {
876
+ throw new common_1.HttpException({
877
+ statusCode: common_1.HttpStatus.UNPROCESSABLE_ENTITY,
878
+ code: 422020809,
879
+ message: 'Invalid starting date format. Format should be in YYYY-MM-DD.',
880
+ data: { ...transactionHistoryDto }
881
+ }, common_1.HttpStatus.UNPROCESSABLE_ENTITY);
882
+ }
747
883
  if (!dateTo) {
748
884
  throw new common_1.HttpException({
749
885
  statusCode: common_1.HttpStatus.BAD_REQUEST,
750
886
  code: 400020812,
751
- message: 'Date From should not be empty.',
887
+ message: 'Ending date is required.',
752
888
  data: { transactionHistoryDto }
753
889
  }, common_1.HttpStatus.BAD_REQUEST);
754
890
  }
891
+ if (!dateRegex.test(dateTo)) {
892
+ throw new common_1.HttpException({
893
+ statusCode: common_1.HttpStatus.UNPROCESSABLE_ENTITY,
894
+ code: 422020811,
895
+ message: 'Invalid starting date format. Format should be in YYYY-MM-DD.',
896
+ data: { ...transactionHistoryDto }
897
+ }, common_1.HttpStatus.UNPROCESSABLE_ENTITY);
898
+ }
755
899
  this.logger.log("Welcome Bank transaction history");
756
900
  const isoTimestamp = new Date().toISOString();
757
901
  const timeInSeconds = Math.floor(Date.parse(isoTimestamp) / 1000);
758
902
  const totp = this.generateTOTP(timeInSeconds);
759
903
  const totpPrevious = this.generateTOTP(timeInSeconds - 30);
760
- this.logger.log(`TOTP GENERATED FOR WELCOME BANK VALIDATE OTP: ${totp}, For Time stamp: ${isoTimestamp}`);
904
+ this.logger.log(`TOTP GENERATED FOR WELCOME BANK TRANSACTION HISTORY: ${totp}, For Time stamp: ${isoTimestamp}`);
761
905
  this.logger.log(`TOTP GENERATED FOR PREVIOUS TIME: ${totpPrevious}`);
906
+ let responseData;
762
907
  try {
763
908
  const headers = {
764
909
  'Authorization': `Bearer ${token}`,
@@ -785,38 +930,77 @@ let WelcomeBankService = class WelcomeBankService {
785
930
  headers: headers,
786
931
  httpsAgent
787
932
  });
788
- let responseData = response.data;
789
933
  this.logger.log({ responseData: response.data }, 'Welcome Bank Transaction History Successful');
790
934
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
791
- const encryptedResponsePayload = responseData.data;
935
+ const encryptedResponsePayload = response.data.data;
792
936
  if (!encryptedResponsePayload) {
793
937
  throw new Error("Encrypted response expected but not found");
794
938
  }
795
- let decryptedResponse;
796
939
  try {
797
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
940
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
798
941
  }
799
942
  catch (error) {
800
943
  this.logger.warn("Decryption with current OTP failed, trying with previous OTP");
944
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
801
945
  }
802
- if (!decryptedResponse) {
803
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
804
- }
805
- return {
806
- success: true,
807
- data: decryptedResponse,
808
- };
946
+ this.logger.log(`Decrypted Response Log: ${JSON.stringify(responseData)}`);
947
+ this.logger.log(`Decrypted.data.transactions Response Log: ${JSON.stringify(responseData.data.transaction)}`);
948
+ responseData.data.transaction.forEach((txn, index) => {
949
+ const key = `${index + 1}`;
950
+ reformattedTransactions[key] = {
951
+ dateTime: txn.dateTime,
952
+ amount: txn.amount,
953
+ type: txn.type,
954
+ description: txn.description,
955
+ transactionReference: txn.tranReference
956
+ };
957
+ });
809
958
  }
810
959
  else {
811
- return {
812
- success: true,
813
- ...responseData,
814
- };
960
+ responseData = response.data;
815
961
  }
816
962
  }
817
963
  catch (error) {
818
964
  axios_error_helper_1.AxiosErrorHelper.handleAxiosError(error);
819
965
  }
966
+ if (responseData.data.status === "99999") {
967
+ throw new common_1.HttpException({
968
+ statusCode: common_1.HttpStatus.FORBIDDEN,
969
+ code: 403020803,
970
+ message: 'Invalid permission key.',
971
+ data: { ...transactionHistoryDto }
972
+ }, common_1.HttpStatus.FORBIDDEN);
973
+ }
974
+ if (responseData.data.status === "99997") {
975
+ throw new common_1.HttpException({
976
+ statusCode: common_1.HttpStatus.BAD_REQUEST,
977
+ code: 400020805,
978
+ message: 'Account not found.',
979
+ data: { ...transactionHistoryDto }
980
+ }, common_1.HttpStatus.BAD_REQUEST);
981
+ }
982
+ if (responseData.data.status === "00001") {
983
+ throw new common_1.HttpException({
984
+ statusCode: common_1.HttpStatus.BAD_REQUEST,
985
+ code: 400020807,
986
+ message: 'Account type is not supported.',
987
+ data: { ...transactionHistoryDto }
988
+ }, common_1.HttpStatus.BAD_REQUEST);
989
+ }
990
+ if (responseData.data.status === "XXXXX") {
991
+ throw new common_1.HttpException({
992
+ statusCode: common_1.HttpStatus.UNPROCESSABLE_ENTITY,
993
+ code: 422020813,
994
+ message: 'Invalid page number format.',
995
+ data: { ...transactionHistoryDto }
996
+ }, common_1.HttpStatus.UNPROCESSABLE_ENTITY);
997
+ }
998
+ return {
999
+ success: true,
1000
+ message: responseData.data.responseMessage,
1001
+ timestamp: responseData.timestamp,
1002
+ transactions: reformattedTransactions,
1003
+ };
820
1004
  }
821
1005
  async findAccountDetailsRaw(token, userid) {
822
1006
  return "Sorry Service Currently Unavaible";