@traxionpay/cbsmiddleware 0.0.1 → 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.
@@ -100,8 +100,8 @@ export class WelcomeBankService implements BankService {
100
100
  if (!refreshToken) {
101
101
  throw new HttpException({
102
102
  statusCode: HttpStatus.BAD_REQUEST,
103
- code: 400020206,
104
- message: 'Bank token should not be empty.',
103
+ code: 400020205,
104
+ message: 'Refresh token is required.',
105
105
  data: { refreshToken }
106
106
  }, HttpStatus.BAD_REQUEST);
107
107
  }
@@ -132,6 +132,15 @@ export class WelcomeBankService implements BankService {
132
132
 
133
133
  this.logger.log({ responseData: response }, 'Welcome Bank Refresh Token Successful');
134
134
 
135
+ if (response.data.message === "Unable to Process this request. Please check your payload.") {
136
+ throw new HttpException({
137
+ statusCode: HttpStatus.BAD_REQUEST,
138
+ code: 400020206,
139
+ message: 'Invalid refresh token.',
140
+ data: { refreshToken }
141
+ }, HttpStatus.BAD_REQUEST);
142
+ }
143
+
135
144
  return {
136
145
  success: true,
137
146
  ...response.data,
@@ -159,7 +168,7 @@ export class WelcomeBankService implements BankService {
159
168
  throw new HttpException({
160
169
  statusCode: HttpStatus.BAD_REQUEST,
161
170
  code: 400020304,
162
- message: 'Bank account number should not be empty.',
171
+ message: 'Account number is required.',
163
172
  data: { accountDto }
164
173
  }, HttpStatus.BAD_REQUEST);
165
174
  }
@@ -167,8 +176,8 @@ export class WelcomeBankService implements BankService {
167
176
  if (!accountType) {
168
177
  throw new HttpException({
169
178
  statusCode: HttpStatus.BAD_REQUEST,
170
- code: 4400020306,
171
- message: 'Bank account type should not be empty.',
179
+ code: 400020306,
180
+ message: 'Account type is required.',
172
181
  data: { accountDto }
173
182
  }, HttpStatus.BAD_REQUEST);
174
183
  }
@@ -177,7 +186,7 @@ export class WelcomeBankService implements BankService {
177
186
  throw new HttpException({
178
187
  statusCode: HttpStatus.BAD_REQUEST,
179
188
  code: 4000203009,
180
- message: 'Mobile Number should not be empty.',
189
+ message: 'Mobile number is required.',
181
190
  data: { accountDto }
182
191
  }, HttpStatus.BAD_REQUEST);
183
192
  }
@@ -192,6 +201,8 @@ export class WelcomeBankService implements BankService {
192
201
  this.logger.log(`TOTP GENERATED FOR WELCOMEBANK LINK ACCOUNT: ${totp}, For Time stamp: ${isoTimestamp}`);
193
202
  this.logger.log(`TOTP GENERATED FOR PREVIOUS TIME: ${totpPrevious}`);
194
203
 
204
+ let responseData;
205
+
195
206
  try {
196
207
  const headers = {
197
208
  'Authorization': `Bearer ${token}`,
@@ -205,13 +216,18 @@ export class WelcomeBankService implements BankService {
205
216
 
206
217
  let response;
207
218
 
219
+ let formattedMobile = mobile;
220
+ if (mobile.startsWith("63") && mobile.length > 2) {
221
+ formattedMobile = "0" + mobile.slice(2);
222
+ }
223
+
208
224
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
209
225
  let payload;
210
226
  payload = {
211
227
  "acc": account,
212
228
  "br": branch,
213
229
  "accType": accountType,
214
- "mobile": mobile
230
+ "mobile": formattedMobile
215
231
  }
216
232
  payload = this.encryptPayloadWithOTP(payload, totp);
217
233
  const encodedPayload = encodeURIComponent(payload);
@@ -227,52 +243,80 @@ export class WelcomeBankService implements BankService {
227
243
 
228
244
  else {
229
245
  response = await axios.get(
230
- `${this.config.WELCOMEBANK_URL}:${this.config.WELCOMEBANK_PORT}/api/linkaccount?acc=${account}&br=${branch}&accType=${accountType}&mobile=${mobile}`,
246
+ `${this.config.WELCOMEBANK_URL}:${this.config.WELCOMEBANK_PORT}/api/linkaccount?acc=${account}&br=${branch}&accType=${accountType}&mobile=${formattedMobile}`,
231
247
  {
232
248
  headers: headers,
233
249
  httpsAgent
234
250
  }
235
251
  );
236
252
  }
237
- let responseData = response.data;
238
253
 
239
- this.logger.log({ responseData: response }, 'Welcome Bank Link Account Successful');
254
+ this.logger.log({ responseData: response.data }, 'Welcome Bank Link Account Successful');
240
255
 
241
256
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
242
257
 
243
- const encryptedResponsePayload = responseData.data;
258
+ const encryptedResponsePayload = response.data.data;
244
259
 
245
260
  if (!encryptedResponsePayload) {
246
261
  throw new Error("Encrypted response expected but not found");
247
262
  }
248
263
 
249
- let decryptedResponse;
250
264
  try {
251
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
265
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
252
266
  } catch (error) {
253
267
  this.logger.warn("Decryption with current OTP failed, trying with previous OTP");
268
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
254
269
  }
270
+ }
271
+ else {
272
+ responseData = response.data;
273
+ }
274
+ }
275
+ catch (error) {
255
276
 
256
- if (!decryptedResponse) {
257
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
258
- }
277
+ if (error.response.data.message === "Mobile number is not registered in the account.") {
278
+ throw new HttpException({
279
+ statusCode: HttpStatus.BAD_REQUEST,
280
+ code: 400020307,
281
+ message: 'Mobile number is not registered in the account.',
282
+ data: { accountDto }
283
+ }, HttpStatus.BAD_REQUEST);
284
+ }
259
285
 
260
- return {
261
- success: true,
262
- data: decryptedResponse,
263
- };
286
+ AxiosErrorHelper.handleAxiosError(error);
287
+ }
264
288
 
265
- } else {
289
+ if (responseData.data.status === "99997") {
290
+ throw new HttpException({
291
+ statusCode: HttpStatus.BAD_REQUEST,
292
+ code: 400020303,
293
+ message: 'Account not found',
294
+ data: { ...accountDto }
295
+ }, HttpStatus.BAD_REQUEST);
296
+ }
266
297
 
267
- return {
268
- success: true,
269
- ...responseData,
270
- };
271
- }
298
+ if (responseData.data.status === "00001") {
299
+ throw new HttpException({
300
+ statusCode: HttpStatus.BAD_REQUEST,
301
+ code: 400020305,
302
+ message: 'Account type is not supported.',
303
+ data: { ...accountDto }
304
+ }, HttpStatus.BAD_REQUEST);
272
305
  }
273
- catch (error) {
274
- AxiosErrorHelper.handleAxiosError(error);
306
+
307
+ if (responseData.data.status === "00007") {
308
+ throw new HttpException({
309
+ statusCode: HttpStatus.BAD_REQUEST,
310
+ code: 400020307,
311
+ message: 'Mobile number is not registered in the account.',
312
+ data: { ...accountDto }
313
+ }, HttpStatus.BAD_REQUEST);
275
314
  }
315
+
316
+ return {
317
+ success: true,
318
+ ...responseData,
319
+ };
276
320
  }
277
321
 
278
322
 
@@ -293,7 +337,7 @@ export class WelcomeBankService implements BankService {
293
337
  throw new HttpException({
294
338
  statusCode: HttpStatus.BAD_REQUEST,
295
339
  code: 400020404,
296
- message: 'Bank account number should not be empty.',
340
+ message: 'Account number is required.',
297
341
  data: { validateOtp }
298
342
  }, HttpStatus.BAD_REQUEST);
299
343
  }
@@ -302,7 +346,7 @@ export class WelcomeBankService implements BankService {
302
346
  throw new HttpException({
303
347
  statusCode: HttpStatus.BAD_REQUEST,
304
348
  code: 400020406,
305
- message: 'Bank account type should not be empty.',
349
+ message: 'Account type is required.',
306
350
  data: { validateOtp }
307
351
  }, HttpStatus.BAD_REQUEST);
308
352
  }
@@ -311,7 +355,7 @@ export class WelcomeBankService implements BankService {
311
355
  throw new HttpException({
312
356
  statusCode: HttpStatus.BAD_REQUEST,
313
357
  code: 400020408,
314
- message: 'Mobile Number should not be empty.',
358
+ message: 'OTP is required.',
315
359
  data: { validateOtp }
316
360
  }, HttpStatus.BAD_REQUEST);
317
361
  }
@@ -326,6 +370,8 @@ export class WelcomeBankService implements BankService {
326
370
  this.logger.log(`TOTP GENERATED FOR WELCOME BANK VALIDATE OTP: ${totp}, For Time stamp: ${isoTimestamp}`);
327
371
  this.logger.log(`TOTP GENERATED FOR PREVIOUS TIME: ${totpPrevious}`);
328
372
 
373
+ let responseData;
374
+
329
375
  try {
330
376
  const headers = {
331
377
  'Authorization': `Bearer ${token}`,
@@ -343,7 +389,7 @@ export class WelcomeBankService implements BankService {
343
389
  }
344
390
 
345
391
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
346
- payload = {data: this.encryptPayloadWithOTP(payload, totp)};
392
+ payload = { data: this.encryptPayloadWithOTP(payload, totp) };
347
393
  }
348
394
 
349
395
  const httpsAgent = new https.Agent({
@@ -359,44 +405,61 @@ export class WelcomeBankService implements BankService {
359
405
  }
360
406
  );
361
407
 
362
- let responseData = response.data;
363
- this.logger.log({ responseData: response }, 'Welcome Bank Validate OTP Successful');
408
+ this.logger.log({ responseData: response.data }, 'Welcome Bank Validate OTP Successful');
364
409
 
365
410
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
366
411
 
367
- const encryptedResponsePayload = responseData.data;
412
+ const encryptedResponsePayload = response.data.data;
368
413
 
369
414
  if (!encryptedResponsePayload) {
370
415
  throw new Error("Encrypted response expected but not found");
371
416
  }
372
417
 
373
- let decryptedResponse;
374
418
  try {
375
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
419
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
376
420
  } catch (error) {
377
421
  this.logger.warn("Decryption with current OTP failed, trying with previous OTP");
422
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
378
423
  }
379
-
380
- if (!decryptedResponse) {
381
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
382
- }
383
-
384
- return {
385
- success: true,
386
- data: decryptedResponse,
387
- };
388
-
389
- } else {
390
-
391
- return {
392
- success: true,
393
- ...responseData,
394
- };
424
+ }
425
+ else {
426
+ responseData = response.data;
395
427
  }
396
428
  }
397
429
  catch (error) {
398
430
  AxiosErrorHelper.handleAxiosError(error);
399
431
  }
432
+ if (responseData.data.status === "99997") {
433
+ throw new HttpException({
434
+ statusCode: HttpStatus.BAD_REQUEST,
435
+ code: 400020403,
436
+ message: 'Account number is required.',
437
+ data: { ...validateOtp }
438
+ }, HttpStatus.BAD_REQUEST);
439
+ }
440
+
441
+ if (responseData.data.status === "00001") {
442
+ throw new HttpException({
443
+ statusCode: HttpStatus.BAD_REQUEST,
444
+ code: 400020405,
445
+ message: 'Account type is not supported.',
446
+ data: { ...validateOtp }
447
+ }, HttpStatus.BAD_REQUEST);
448
+ }
449
+
450
+ if (responseData.data.status === "00005") {
451
+ throw new HttpException({
452
+ statusCode: HttpStatus.BAD_REQUEST,
453
+ code: 400020407,
454
+ message: 'Invalid or expired OTP.',
455
+ data: { ...validateOtp }
456
+ }, HttpStatus.BAD_REQUEST);
457
+ }
458
+
459
+ return {
460
+ success: true,
461
+ ...responseData,
462
+ };
400
463
  }
401
464
 
402
465
  async processBalanceTransaction(fetchBalanceDto: FetchBankBalanceDto): Promise<any> {
@@ -414,18 +477,18 @@ export class WelcomeBankService implements BankService {
414
477
 
415
478
  if (!permissionKey) {
416
479
  throw new HttpException({
417
- statusCode: HttpStatus.UNAUTHORIZED,
480
+ statusCode: HttpStatus.FORBIDDEN,
418
481
  code: 403020504,
419
- message: 'Bank permission key should not be empty.',
482
+ message: 'Permission key is required.',
420
483
  data: { fetchBalanceDto }
421
- }, HttpStatus.UNAUTHORIZED);
484
+ }, HttpStatus.FORBIDDEN);
422
485
  }
423
486
 
424
487
  if (!account) {
425
488
  throw new HttpException({
426
489
  statusCode: HttpStatus.BAD_REQUEST,
427
490
  code: 400020506,
428
- message: 'Bank account number should not be empty.',
491
+ message: 'Account number is required.',
429
492
  data: { fetchBalanceDto }
430
493
  }, HttpStatus.BAD_REQUEST);
431
494
  }
@@ -434,7 +497,7 @@ export class WelcomeBankService implements BankService {
434
497
  throw new HttpException({
435
498
  statusCode: HttpStatus.BAD_REQUEST,
436
499
  code: 400020508,
437
- message: 'Bank account type should not be empty.',
500
+ message: 'Account type is required.',
438
501
  data: { fetchBalanceDto }
439
502
  }, HttpStatus.BAD_REQUEST);
440
503
  }
@@ -445,9 +508,12 @@ export class WelcomeBankService implements BankService {
445
508
  const timeInSeconds = Math.floor(Date.parse(isoTimestamp) / 1000);
446
509
  const totp = this.generateTOTP(timeInSeconds);
447
510
  const totpPrevious = this.generateTOTP(timeInSeconds - 30);
511
+
448
512
  this.logger.log(`TOTP GENERATED FOR WELCOME BANK BALANCE INQUIRY: ${totp}, For Time stamp: ${isoTimestamp}`);
449
513
  this.logger.log(`TOTP GENERATED FOR PREVIOUS TIME: ${totpPrevious}`);
450
514
 
515
+ let responseData;
516
+
451
517
  try {
452
518
  const headers = {
453
519
  'Authorization': `Bearer ${token}`,
@@ -465,7 +531,7 @@ export class WelcomeBankService implements BankService {
465
531
  }
466
532
 
467
533
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
468
- payload = {data: this.encryptPayloadWithOTP(payload, totp)};
534
+ payload = { data: this.encryptPayloadWithOTP(payload, totp) };
469
535
  }
470
536
 
471
537
  const httpsAgent = new https.Agent({
@@ -481,44 +547,62 @@ export class WelcomeBankService implements BankService {
481
547
  }
482
548
  );
483
549
 
484
- let responseData = response.data;
485
-
486
- this.logger.log({ responseData: response }, 'Welcome Bank Balance Inquiry Successful');
550
+ this.logger.log({ responseData: response.data }, 'Welcome Bank Balance Inquiry Successful');
487
551
 
488
552
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
489
553
 
490
- const encryptedResponsePayload = responseData.data;
554
+ const encryptedResponsePayload = response.data.data;
491
555
 
492
556
  if (!encryptedResponsePayload) {
493
557
  throw new Error("Encrypted response expected but not found");
494
558
  }
495
559
 
496
- let decryptedResponse;
497
560
  try {
498
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
561
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
499
562
  } catch (error) {
500
563
  this.logger.warn("Decryption with current OTP failed, trying with previous OTP");
564
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
501
565
  }
502
-
503
- if (!decryptedResponse) {
504
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
505
- }
506
- return {
507
- success: true,
508
- data: decryptedResponse,
509
- };
510
-
511
- } else {
512
-
513
- return {
514
- success: true,
515
- ...responseData,
516
- };
566
+ }
567
+ else {
568
+ responseData = response.data;
517
569
  }
518
570
  }
519
571
  catch (error) {
520
572
  AxiosErrorHelper.handleAxiosError(error);
521
573
  }
574
+ if (responseData.data.status === "99999") {
575
+ throw new HttpException({
576
+ statusCode: HttpStatus.FORBIDDEN,
577
+ code: 403020503,
578
+ message: 'Invalid permission key.',
579
+ data: { ...fetchBalanceDto }
580
+ }, HttpStatus.FORBIDDEN);
581
+ }
582
+
583
+ if (responseData.data.status === "99997") {
584
+ throw new HttpException({
585
+ statusCode: HttpStatus.BAD_REQUEST,
586
+ code: 400020505,
587
+ message: 'Account not found.',
588
+ data: { ...fetchBalanceDto }
589
+ }, HttpStatus.BAD_REQUEST);
590
+ }
591
+
592
+ if (responseData.data.status === "00001") {
593
+ throw new HttpException({
594
+ statusCode: HttpStatus.BAD_REQUEST,
595
+ code: 400020507,
596
+ message: 'Account type is not supported.',
597
+ data: { ...fetchBalanceDto }
598
+ }, HttpStatus.BAD_REQUEST);
599
+ }
600
+
601
+ return {
602
+ success: true,
603
+ ...responseData,
604
+ };
605
+
522
606
  }
523
607
 
524
608
  async accountCashIn(accountTransferDto: AccountTransferDto): Promise<any> {
@@ -538,7 +622,7 @@ export class WelcomeBankService implements BankService {
538
622
  throw new HttpException({
539
623
  statusCode: HttpStatus.FORBIDDEN,
540
624
  code: 403020604,
541
- message: 'Bank permission key should not be empty.',
625
+ message: 'Permission key is required.',
542
626
  data: { accountTransferDto }
543
627
  }, HttpStatus.FORBIDDEN);
544
628
  }
@@ -547,7 +631,7 @@ export class WelcomeBankService implements BankService {
547
631
  throw new HttpException({
548
632
  statusCode: HttpStatus.BAD_REQUEST,
549
633
  code: 400020606,
550
- message: 'Bank source account number should not be empty.',
634
+ message: 'Source account number is required.',
551
635
  data: { accountTransferDto }
552
636
  }, HttpStatus.BAD_REQUEST);
553
637
  }
@@ -556,7 +640,7 @@ export class WelcomeBankService implements BankService {
556
640
  throw new HttpException({
557
641
  statusCode: HttpStatus.BAD_REQUEST,
558
642
  code: 400020608,
559
- message: 'Bank source account type should not be empty.',
643
+ message: 'Source account type is required.',
560
644
  data: { accountTransferDto }
561
645
  }, HttpStatus.BAD_REQUEST);
562
646
  }
@@ -565,7 +649,7 @@ export class WelcomeBankService implements BankService {
565
649
  throw new HttpException({
566
650
  statusCode: HttpStatus.BAD_REQUEST,
567
651
  code: 400020610,
568
- message: 'Bank destination account number should not be empty.',
652
+ message: 'Destination account number is required.',
569
653
  data: { accountTransferDto }
570
654
  }, HttpStatus.BAD_REQUEST);
571
655
  }
@@ -574,7 +658,7 @@ export class WelcomeBankService implements BankService {
574
658
  throw new HttpException({
575
659
  statusCode: HttpStatus.BAD_REQUEST,
576
660
  code: 400020612,
577
- message: 'Bank destination account type should not be empty.',
661
+ message: 'Destination account type is required.',
578
662
  data: { accountTransferDto }
579
663
  }, HttpStatus.BAD_REQUEST);
580
664
  }
@@ -583,7 +667,7 @@ export class WelcomeBankService implements BankService {
583
667
  throw new HttpException({
584
668
  statusCode: HttpStatus.BAD_REQUEST,
585
669
  code: 400020613,
586
- message: 'Amount should not be empty.',
670
+ message: 'Transaction amount is required.',
587
671
  data: { accountTransferDto }
588
672
  }, HttpStatus.BAD_REQUEST);
589
673
  }
@@ -598,6 +682,8 @@ export class WelcomeBankService implements BankService {
598
682
  this.logger.log(`TOTP GENERATED FOR WELCOME BANK CASH IN: ${totp}, For Time stamp: ${isoTimestamp}`);
599
683
  this.logger.log(`TOTP GENERATED FOR PREVIOUS TIME: ${totpPrevious}`);
600
684
 
685
+ let responseData;
686
+
601
687
  try {
602
688
  const headers = {
603
689
  'Authorization': `Bearer ${token}`,
@@ -619,7 +705,7 @@ export class WelcomeBankService implements BankService {
619
705
  }
620
706
 
621
707
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
622
- payload = {data: this.encryptPayloadWithOTP(payload, totp)};
708
+ payload = { data: this.encryptPayloadWithOTP(payload, totp) };
623
709
  }
624
710
 
625
711
  const httpsAgent = new https.Agent({
@@ -635,44 +721,70 @@ export class WelcomeBankService implements BankService {
635
721
  }
636
722
  );
637
723
 
638
- let responseData = response.data;
639
- this.logger.log({ responseData: response }, 'Welcome Bank Cash In Successful');
724
+ this.logger.log({ responseData: response.data }, 'Welcome Bank Cash In Successful');
640
725
 
641
726
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
642
727
 
643
- const encryptedResponsePayload = responseData.data;
728
+ const encryptedResponsePayload = response.data.data;
644
729
 
645
730
  if (!encryptedResponsePayload) {
646
731
  throw new Error("Encrypted response expected but not found");
647
732
  }
648
733
 
649
- let decryptedResponse;
650
734
  try {
651
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
735
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
652
736
  } catch (error) {
653
737
  this.logger.warn("Decryption with current OTP failed, trying with previous OTP");
738
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
654
739
  }
655
-
656
- if (!decryptedResponse) {
657
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
658
- }
659
-
660
- return {
661
- success: true,
662
- data: decryptedResponse,
663
- };
664
-
665
- } else {
666
-
667
- return {
668
- success: true,
669
- ...responseData,
670
- };
740
+ }
741
+ else {
742
+ responseData = response.data;
671
743
  }
672
744
  }
673
745
  catch (error) {
674
746
  AxiosErrorHelper.handleAxiosError(error);
675
747
  }
748
+ if (responseData.data.status === "99999") {
749
+ throw new HttpException({
750
+ statusCode: HttpStatus.FORBIDDEN,
751
+ code: 403020603,
752
+ message: 'Invalid permission key.',
753
+ data: { ...accountTransferDto }
754
+ }, HttpStatus.FORBIDDEN);
755
+ }
756
+
757
+ if (responseData.data.status === "99997") {
758
+ throw new HttpException({
759
+ statusCode: HttpStatus.BAD_REQUEST,
760
+ code: 400020605,
761
+ message: 'Account not found.',
762
+ data: { ...accountTransferDto }
763
+ }, HttpStatus.BAD_REQUEST);
764
+ }
765
+
766
+ if (responseData.data.status === "00001") {
767
+ throw new HttpException({
768
+ statusCode: HttpStatus.BAD_REQUEST,
769
+ code: 400020607,
770
+ message: 'Account type is not supported.',
771
+ data: { ...accountTransferDto }
772
+ }, HttpStatus.BAD_REQUEST);
773
+ }
774
+
775
+ if (responseData.data.status === "00004") {
776
+ throw new HttpException({
777
+ statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
778
+ code: 422020614,
779
+ message: 'Invalid transaction amount value.',
780
+ data: { ...accountTransferDto }
781
+ }, HttpStatus.UNPROCESSABLE_ENTITY);
782
+ }
783
+
784
+ return {
785
+ success: true,
786
+ ...responseData,
787
+ };
676
788
  }
677
789
 
678
790
  async accountDeposit(accountTransferDto: AccountTransferDto): Promise<any> {
@@ -692,7 +804,7 @@ export class WelcomeBankService implements BankService {
692
804
  throw new HttpException({
693
805
  statusCode: HttpStatus.FORBIDDEN,
694
806
  code: 403020704,
695
- message: 'Bank permission key should not be empty.',
807
+ message: 'Permission key is required.',
696
808
  data: { accountTransferDto }
697
809
  }, HttpStatus.FORBIDDEN);
698
810
  }
@@ -701,7 +813,7 @@ export class WelcomeBankService implements BankService {
701
813
  throw new HttpException({
702
814
  statusCode: HttpStatus.BAD_REQUEST,
703
815
  code: 400020706,
704
- message: 'Bank source account number should not be empty.',
816
+ message: 'Source account number is required',
705
817
  data: { accountTransferDto }
706
818
  }, HttpStatus.BAD_REQUEST);
707
819
  }
@@ -710,7 +822,7 @@ export class WelcomeBankService implements BankService {
710
822
  throw new HttpException({
711
823
  statusCode: HttpStatus.BAD_REQUEST,
712
824
  code: 400020708,
713
- message: 'Bank source account type should not be empty.',
825
+ message: 'Source account type is required.',
714
826
  data: { accountTransferDto }
715
827
  }, HttpStatus.BAD_REQUEST);
716
828
  }
@@ -719,7 +831,7 @@ export class WelcomeBankService implements BankService {
719
831
  throw new HttpException({
720
832
  statusCode: HttpStatus.BAD_REQUEST,
721
833
  code: 400020710,
722
- message: 'Bank destination account number should not be empty.',
834
+ message: 'Destination account number is required',
723
835
  data: { accountTransferDto }
724
836
  }, HttpStatus.BAD_REQUEST);
725
837
  }
@@ -737,7 +849,7 @@ export class WelcomeBankService implements BankService {
737
849
  throw new HttpException({
738
850
  statusCode: HttpStatus.BAD_REQUEST,
739
851
  code: 400020713,
740
- message: 'Amount should not be empty.',
852
+ message: 'Transaction amount is required.',
741
853
  data: { accountTransferDto }
742
854
  }, HttpStatus.BAD_REQUEST);
743
855
  }
@@ -752,6 +864,8 @@ export class WelcomeBankService implements BankService {
752
864
  this.logger.log(`TOTP GENERATED FOR WELCOME BANK DEPOSIT: ${totp}, For Time stamp: ${isoTimestamp}`);
753
865
  this.logger.log(`TOTP GENERATED FOR PREVIOUS TIME: ${totpPrevious}`);
754
866
 
867
+ let responseData;
868
+
755
869
  try {
756
870
  const headers = {
757
871
  'Authorization': `Bearer ${token}`,
@@ -759,8 +873,8 @@ export class WelcomeBankService implements BankService {
759
873
  'X-SERVER-TIMESTAMP': `${new Date().toISOString()}`
760
874
  };
761
875
 
762
-
763
876
  let payload;
877
+
764
878
  payload = {
765
879
  "permissionKey": permissionKey,
766
880
  "sourceAcc": sourceAccount,
@@ -774,7 +888,7 @@ export class WelcomeBankService implements BankService {
774
888
 
775
889
 
776
890
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
777
- payload = {data: this.encryptPayloadWithOTP(payload, totp)};
891
+ payload = { data: this.encryptPayloadWithOTP(payload, totp) };
778
892
  }
779
893
 
780
894
  const httpsAgent = new https.Agent({
@@ -790,49 +904,95 @@ export class WelcomeBankService implements BankService {
790
904
  }
791
905
  );
792
906
 
793
- let responseData = response.data;
794
907
  this.logger.log({ responseData: response.data }, 'Welcom Bank Deposit Successful');
795
908
 
796
909
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
797
910
 
798
- const encryptedResponsePayload = responseData.data;
911
+ const encryptedResponsePayload = response.data.data;
799
912
 
800
913
  if (!encryptedResponsePayload) {
801
914
  throw new Error("Encrypted response expected but not found");
802
915
  }
803
916
 
804
- let decryptedResponse;
805
917
  try {
806
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
918
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
807
919
  } catch (error) {
808
920
  this.logger.warn("Decryption with current OTP failed, trying with previous OTP");
921
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
809
922
  }
810
923
 
811
- if (!decryptedResponse) {
812
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
813
- }
814
-
815
- return {
816
- success: true,
817
- data: decryptedResponse,
818
- };
819
-
820
- } else {
821
-
822
- return {
823
- success: true,
824
- ...responseData,
825
- };
924
+ }
925
+ else {
926
+ responseData = response.data;
826
927
  }
827
928
  }
828
929
  catch (error) {
829
930
  AxiosErrorHelper.handleAxiosError(error);
830
931
  }
932
+ if (responseData.data.status === "99999") {
933
+ throw new HttpException({
934
+ statusCode: HttpStatus.FORBIDDEN,
935
+ code: 403020703,
936
+ message: 'Invalid permission key.',
937
+ data: { ...accountTransferDto }
938
+ }, HttpStatus.FORBIDDEN);
939
+ }
940
+
941
+ if (responseData.data.status === "99997") {
942
+ throw new HttpException({
943
+ statusCode: HttpStatus.BAD_REQUEST,
944
+ code: 400020709,
945
+ message: 'Account not found.',
946
+ data: { ...accountTransferDto }
947
+ }, HttpStatus.BAD_REQUEST);
948
+ }
949
+
950
+ if (responseData.data.status === "00001") {
951
+ throw new HttpException({
952
+ statusCode: HttpStatus.BAD_REQUEST,
953
+ code: 400020711,
954
+ message: 'Account type is not supported.',
955
+ data: { ...accountTransferDto }
956
+ }, HttpStatus.BAD_REQUEST);
957
+ }
958
+
959
+ if (responseData.data.status === "00004") {
960
+ throw new HttpException({
961
+ statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
962
+ code: 422020714,
963
+ message: 'Invalid transaction amount value.',
964
+ data: { ...accountTransferDto }
965
+ }, HttpStatus.UNPROCESSABLE_ENTITY);
966
+ }
967
+
968
+ return {
969
+ success: true,
970
+ ...responseData,
971
+ };
972
+
831
973
  }
832
974
 
833
- async getTransactionHistory(transactionHistoryDto: TransactionHistoryDto) {
975
+ async getTransactionHistory(transactionHistoryDto: TransactionHistoryDto):
976
+ Promise<{
977
+ success: boolean;
978
+ message: any;
979
+ timestamp: any;
980
+ transactions: any;
981
+ }> {
834
982
 
835
983
  const { token, permissionKey, account, branch, accountType, dateFrom, dateTo, page } = transactionHistoryDto;
984
+ const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
985
+
986
+ interface ReformattedTransaction {
987
+ dateTime: string;
988
+ amount: number;
989
+ type: string;
990
+ description: string;
991
+ transactionReference: string;
992
+ }
993
+
994
+ const reformattedTransactions: Record<string, ReformattedTransaction> = {};
995
+
836
996
 
837
997
  if (!token) {
838
998
  throw new HttpException({
@@ -847,7 +1007,7 @@ export class WelcomeBankService implements BankService {
847
1007
  throw new HttpException({
848
1008
  statusCode: HttpStatus.FORBIDDEN,
849
1009
  code: 403020804,
850
- message: 'Bank permission key should not be empty.',
1010
+ message: 'Permission key is required.',
851
1011
  data: { transactionHistoryDto }
852
1012
  }, HttpStatus.FORBIDDEN);
853
1013
  }
@@ -856,7 +1016,7 @@ export class WelcomeBankService implements BankService {
856
1016
  throw new HttpException({
857
1017
  statusCode: HttpStatus.BAD_REQUEST,
858
1018
  code: 400020806,
859
- message: 'Bank account number should not be empty.',
1019
+ message: 'Account number is required',
860
1020
  data: { transactionHistoryDto }
861
1021
  }, HttpStatus.BAD_REQUEST);
862
1022
  }
@@ -865,7 +1025,7 @@ export class WelcomeBankService implements BankService {
865
1025
  throw new HttpException({
866
1026
  statusCode: HttpStatus.BAD_REQUEST,
867
1027
  code: 400020808,
868
- message: 'Bank account type should not be empty.',
1028
+ message: 'Account type is required.',
869
1029
  data: { transactionHistoryDto }
870
1030
  }, HttpStatus.BAD_REQUEST);
871
1031
  }
@@ -874,20 +1034,38 @@ export class WelcomeBankService implements BankService {
874
1034
  throw new HttpException({
875
1035
  statusCode: HttpStatus.BAD_REQUEST,
876
1036
  code: 400020810,
877
- message: 'Date From should not be empty.',
1037
+ message: 'Starting date is required.',
878
1038
  data: { transactionHistoryDto }
879
1039
  }, HttpStatus.BAD_REQUEST);
880
1040
  }
881
1041
 
1042
+ if (!dateRegex.test(dateFrom)) {
1043
+ throw new HttpException({
1044
+ statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
1045
+ code: 422020809,
1046
+ message: 'Invalid starting date format. Format should be in YYYY-MM-DD.',
1047
+ data: { ...transactionHistoryDto }
1048
+ }, HttpStatus.UNPROCESSABLE_ENTITY);
1049
+ }
1050
+
882
1051
  if (!dateTo) {
883
1052
  throw new HttpException({
884
1053
  statusCode: HttpStatus.BAD_REQUEST,
885
1054
  code: 400020812,
886
- message: 'Date From should not be empty.',
1055
+ message: 'Ending date is required.',
887
1056
  data: { transactionHistoryDto }
888
1057
  }, HttpStatus.BAD_REQUEST);
889
1058
  }
890
1059
 
1060
+ if (!dateRegex.test(dateTo)) {
1061
+ throw new HttpException({
1062
+ statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
1063
+ code: 422020811,
1064
+ message: 'Invalid starting date format. Format should be in YYYY-MM-DD.',
1065
+ data: { ...transactionHistoryDto }
1066
+ }, HttpStatus.UNPROCESSABLE_ENTITY);
1067
+ }
1068
+
891
1069
  this.logger.log("Welcome Bank transaction history");
892
1070
 
893
1071
  const isoTimestamp = new Date().toISOString();
@@ -895,9 +1073,11 @@ export class WelcomeBankService implements BankService {
895
1073
  const totp = this.generateTOTP(timeInSeconds);
896
1074
  const totpPrevious = this.generateTOTP(timeInSeconds - 30);
897
1075
 
898
- this.logger.log(`TOTP GENERATED FOR WELCOME BANK VALIDATE OTP: ${totp}, For Time stamp: ${isoTimestamp}`);
1076
+ this.logger.log(`TOTP GENERATED FOR WELCOME BANK TRANSACTION HISTORY: ${totp}, For Time stamp: ${isoTimestamp}`);
899
1077
  this.logger.log(`TOTP GENERATED FOR PREVIOUS TIME: ${totpPrevious}`);
900
1078
 
1079
+ let responseData;
1080
+
901
1081
  try {
902
1082
  const headers = {
903
1083
  'Authorization': `Bearer ${token}`,
@@ -917,7 +1097,7 @@ export class WelcomeBankService implements BankService {
917
1097
  }
918
1098
 
919
1099
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
920
- payload = {data: this.encryptPayloadWithOTP(payload, totp)};
1100
+ payload = { data: this.encryptPayloadWithOTP(payload, totp) };
921
1101
  }
922
1102
 
923
1103
  const httpsAgent = new https.Agent({
@@ -932,44 +1112,93 @@ export class WelcomeBankService implements BankService {
932
1112
  httpsAgent
933
1113
  }
934
1114
  );
935
- let responseData = response.data;
1115
+
1116
+
936
1117
  this.logger.log({ responseData: response.data }, 'Welcome Bank Transaction History Successful');
937
1118
 
938
1119
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
939
1120
 
940
- const encryptedResponsePayload = responseData.data;
1121
+ const encryptedResponsePayload = response.data.data;
941
1122
 
942
1123
  if (!encryptedResponsePayload) {
943
1124
  throw new Error("Encrypted response expected but not found");
944
1125
  }
945
1126
 
946
- let decryptedResponse;
947
1127
  try {
948
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
1128
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
949
1129
  } catch (error) {
950
1130
  this.logger.warn("Decryption with current OTP failed, trying with previous OTP");
1131
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
951
1132
  }
952
1133
 
953
- if (!decryptedResponse) {
954
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
955
- }
956
-
957
- return {
958
- success: true,
959
- data: decryptedResponse,
960
- };
961
-
962
- } else {
1134
+ this.logger.log(`Decrypted Response Log: ${JSON.stringify(responseData)}`);
1135
+ this.logger.log(`Decrypted.data.transactions Response Log: ${JSON.stringify(responseData.data.transaction)}`);
1136
+
1137
+ responseData.data.transaction.forEach((txn, index) => {
1138
+ const key = `${index + 1}`;
1139
+
1140
+ reformattedTransactions[key] = {
1141
+ dateTime: txn.dateTime,
1142
+ amount: txn.amount,
1143
+ type: txn.type,
1144
+ description: txn.description,
1145
+ transactionReference: txn.tranReference
1146
+ };
1147
+ });
963
1148
 
964
- return {
965
- success: true,
966
- ...responseData,
967
- };
968
1149
  }
1150
+ else {
1151
+ responseData = response.data;
1152
+ }
1153
+
969
1154
  }
970
1155
  catch (error) {
971
1156
  AxiosErrorHelper.handleAxiosError(error);
972
1157
  }
1158
+
1159
+ if (responseData.data.status === "99999") {
1160
+ throw new HttpException({
1161
+ statusCode: HttpStatus.FORBIDDEN,
1162
+ code: 403020803,
1163
+ message: 'Invalid permission key.',
1164
+ data: { ...transactionHistoryDto }
1165
+ }, HttpStatus.FORBIDDEN);
1166
+ }
1167
+
1168
+ if (responseData.data.status === "99997") {
1169
+ throw new HttpException({
1170
+ statusCode: HttpStatus.BAD_REQUEST,
1171
+ code: 400020805,
1172
+ message: 'Account not found.',
1173
+ data: { ...transactionHistoryDto }
1174
+ }, HttpStatus.BAD_REQUEST);
1175
+ }
1176
+
1177
+ if (responseData.data.status === "00001") {
1178
+ throw new HttpException({
1179
+ statusCode: HttpStatus.BAD_REQUEST,
1180
+ code: 400020807,
1181
+ message: 'Account type is not supported.',
1182
+ data: { ...transactionHistoryDto }
1183
+ }, HttpStatus.BAD_REQUEST);
1184
+ }
1185
+
1186
+ if (responseData.data.status === "XXXXX") {
1187
+ throw new HttpException({
1188
+ statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
1189
+ code: 422020813,
1190
+ message: 'Invalid page number format.',
1191
+ data: { ...transactionHistoryDto }
1192
+ }, HttpStatus.UNPROCESSABLE_ENTITY);
1193
+ }
1194
+
1195
+ return {
1196
+ success: true,
1197
+ message: responseData.data.responseMessage,
1198
+ timestamp: responseData.timestamp,
1199
+ transactions: reformattedTransactions,
1200
+ }
1201
+
973
1202
  }
974
1203
 
975
1204
  async findAccountDetailsRaw(token: string, userid: number) {