@traxionpay/cbsmiddleware 0.0.2 → 0.0.4

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,82 @@ 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
+ this.logger.log(`Response Data WelcomeBank Link , ${responseData}`);
317
+
318
+ return {
319
+ success: true,
320
+ ...responseData,
321
+ };
276
322
  }
277
323
 
278
324
 
@@ -293,7 +339,7 @@ export class WelcomeBankService implements BankService {
293
339
  throw new HttpException({
294
340
  statusCode: HttpStatus.BAD_REQUEST,
295
341
  code: 400020404,
296
- message: 'Bank account number should not be empty.',
342
+ message: 'Account number is required.',
297
343
  data: { validateOtp }
298
344
  }, HttpStatus.BAD_REQUEST);
299
345
  }
@@ -302,7 +348,7 @@ export class WelcomeBankService implements BankService {
302
348
  throw new HttpException({
303
349
  statusCode: HttpStatus.BAD_REQUEST,
304
350
  code: 400020406,
305
- message: 'Bank account type should not be empty.',
351
+ message: 'Account type is required.',
306
352
  data: { validateOtp }
307
353
  }, HttpStatus.BAD_REQUEST);
308
354
  }
@@ -311,7 +357,7 @@ export class WelcomeBankService implements BankService {
311
357
  throw new HttpException({
312
358
  statusCode: HttpStatus.BAD_REQUEST,
313
359
  code: 400020408,
314
- message: 'Mobile Number should not be empty.',
360
+ message: 'OTP is required.',
315
361
  data: { validateOtp }
316
362
  }, HttpStatus.BAD_REQUEST);
317
363
  }
@@ -326,6 +372,8 @@ export class WelcomeBankService implements BankService {
326
372
  this.logger.log(`TOTP GENERATED FOR WELCOME BANK VALIDATE OTP: ${totp}, For Time stamp: ${isoTimestamp}`);
327
373
  this.logger.log(`TOTP GENERATED FOR PREVIOUS TIME: ${totpPrevious}`);
328
374
 
375
+ let responseData;
376
+
329
377
  try {
330
378
  const headers = {
331
379
  'Authorization': `Bearer ${token}`,
@@ -343,7 +391,7 @@ export class WelcomeBankService implements BankService {
343
391
  }
344
392
 
345
393
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
346
- payload = {data: this.encryptPayloadWithOTP(payload, totp)};
394
+ payload = { data: this.encryptPayloadWithOTP(payload, totp) };
347
395
  }
348
396
 
349
397
  const httpsAgent = new https.Agent({
@@ -359,44 +407,63 @@ export class WelcomeBankService implements BankService {
359
407
  }
360
408
  );
361
409
 
362
- let responseData = response.data;
363
- this.logger.log({ responseData: response }, 'Welcome Bank Validate OTP Successful');
410
+ this.logger.log({ responseData: response.data }, 'Welcome Bank Validate OTP Successful');
364
411
 
365
412
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
366
413
 
367
- const encryptedResponsePayload = responseData.data;
414
+ const encryptedResponsePayload = response.data.data;
368
415
 
369
416
  if (!encryptedResponsePayload) {
370
417
  throw new Error("Encrypted response expected but not found");
371
418
  }
372
419
 
373
- let decryptedResponse;
374
420
  try {
375
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
421
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
376
422
  } catch (error) {
377
423
  this.logger.warn("Decryption with current OTP failed, trying with previous OTP");
424
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
378
425
  }
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
- };
426
+ }
427
+ else {
428
+ responseData = response.data;
395
429
  }
396
430
  }
397
431
  catch (error) {
398
432
  AxiosErrorHelper.handleAxiosError(error);
399
433
  }
434
+ if (responseData.data.status === "99997") {
435
+ throw new HttpException({
436
+ statusCode: HttpStatus.BAD_REQUEST,
437
+ code: 400020403,
438
+ message: 'Account number is required.',
439
+ data: { ...validateOtp }
440
+ }, HttpStatus.BAD_REQUEST);
441
+ }
442
+
443
+ if (responseData.data.status === "00001") {
444
+ throw new HttpException({
445
+ statusCode: HttpStatus.BAD_REQUEST,
446
+ code: 400020405,
447
+ message: 'Account type is not supported.',
448
+ data: { ...validateOtp }
449
+ }, HttpStatus.BAD_REQUEST);
450
+ }
451
+
452
+ if (responseData.data.status === "00005") {
453
+ throw new HttpException({
454
+ statusCode: HttpStatus.BAD_REQUEST,
455
+ code: 400020407,
456
+ message: 'Invalid or expired OTP.',
457
+ data: { ...validateOtp }
458
+ }, HttpStatus.BAD_REQUEST);
459
+ }
460
+
461
+ this.logger.log(`Response Data WelcomeBank Validate , ${responseData}`);
462
+
463
+ return {
464
+ success: true,
465
+ ...responseData,
466
+ };
400
467
  }
401
468
 
402
469
  async processBalanceTransaction(fetchBalanceDto: FetchBankBalanceDto): Promise<any> {
@@ -414,18 +481,18 @@ export class WelcomeBankService implements BankService {
414
481
 
415
482
  if (!permissionKey) {
416
483
  throw new HttpException({
417
- statusCode: HttpStatus.UNAUTHORIZED,
484
+ statusCode: HttpStatus.FORBIDDEN,
418
485
  code: 403020504,
419
- message: 'Bank permission key should not be empty.',
486
+ message: 'Permission key is required.',
420
487
  data: { fetchBalanceDto }
421
- }, HttpStatus.UNAUTHORIZED);
488
+ }, HttpStatus.FORBIDDEN);
422
489
  }
423
490
 
424
491
  if (!account) {
425
492
  throw new HttpException({
426
493
  statusCode: HttpStatus.BAD_REQUEST,
427
494
  code: 400020506,
428
- message: 'Bank account number should not be empty.',
495
+ message: 'Account number is required.',
429
496
  data: { fetchBalanceDto }
430
497
  }, HttpStatus.BAD_REQUEST);
431
498
  }
@@ -434,7 +501,7 @@ export class WelcomeBankService implements BankService {
434
501
  throw new HttpException({
435
502
  statusCode: HttpStatus.BAD_REQUEST,
436
503
  code: 400020508,
437
- message: 'Bank account type should not be empty.',
504
+ message: 'Account type is required.',
438
505
  data: { fetchBalanceDto }
439
506
  }, HttpStatus.BAD_REQUEST);
440
507
  }
@@ -445,9 +512,12 @@ export class WelcomeBankService implements BankService {
445
512
  const timeInSeconds = Math.floor(Date.parse(isoTimestamp) / 1000);
446
513
  const totp = this.generateTOTP(timeInSeconds);
447
514
  const totpPrevious = this.generateTOTP(timeInSeconds - 30);
515
+
448
516
  this.logger.log(`TOTP GENERATED FOR WELCOME BANK BALANCE INQUIRY: ${totp}, For Time stamp: ${isoTimestamp}`);
449
517
  this.logger.log(`TOTP GENERATED FOR PREVIOUS TIME: ${totpPrevious}`);
450
518
 
519
+ let responseData;
520
+
451
521
  try {
452
522
  const headers = {
453
523
  'Authorization': `Bearer ${token}`,
@@ -465,7 +535,7 @@ export class WelcomeBankService implements BankService {
465
535
  }
466
536
 
467
537
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
468
- payload = {data: this.encryptPayloadWithOTP(payload, totp)};
538
+ payload = { data: this.encryptPayloadWithOTP(payload, totp) };
469
539
  }
470
540
 
471
541
  const httpsAgent = new https.Agent({
@@ -481,44 +551,64 @@ export class WelcomeBankService implements BankService {
481
551
  }
482
552
  );
483
553
 
484
- let responseData = response.data;
485
-
486
- this.logger.log({ responseData: response }, 'Welcome Bank Balance Inquiry Successful');
554
+ this.logger.log({ responseData: response.data }, 'Welcome Bank Balance Inquiry Successful');
487
555
 
488
556
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
489
557
 
490
- const encryptedResponsePayload = responseData.data;
558
+ const encryptedResponsePayload = response.data.data;
491
559
 
492
560
  if (!encryptedResponsePayload) {
493
561
  throw new Error("Encrypted response expected but not found");
494
562
  }
495
563
 
496
- let decryptedResponse;
497
564
  try {
498
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
565
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
499
566
  } catch (error) {
500
567
  this.logger.warn("Decryption with current OTP failed, trying with previous OTP");
568
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
501
569
  }
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
- };
570
+ }
571
+ else {
572
+ responseData = response.data;
517
573
  }
518
574
  }
519
575
  catch (error) {
520
576
  AxiosErrorHelper.handleAxiosError(error);
521
577
  }
578
+ if (responseData.data.status === "99999") {
579
+ throw new HttpException({
580
+ statusCode: HttpStatus.FORBIDDEN,
581
+ code: 403020503,
582
+ message: 'Invalid permission key.',
583
+ data: { ...fetchBalanceDto }
584
+ }, HttpStatus.FORBIDDEN);
585
+ }
586
+
587
+ if (responseData.data.status === "99997") {
588
+ throw new HttpException({
589
+ statusCode: HttpStatus.BAD_REQUEST,
590
+ code: 400020505,
591
+ message: 'Account not found.',
592
+ data: { ...fetchBalanceDto }
593
+ }, HttpStatus.BAD_REQUEST);
594
+ }
595
+
596
+ if (responseData.data.status === "00001") {
597
+ throw new HttpException({
598
+ statusCode: HttpStatus.BAD_REQUEST,
599
+ code: 400020507,
600
+ message: 'Account type is not supported.',
601
+ data: { ...fetchBalanceDto }
602
+ }, HttpStatus.BAD_REQUEST);
603
+ }
604
+
605
+ this.logger.log(`Response Data WelcomeBank Balance Inquiry , ${responseData}`);
606
+
607
+ return {
608
+ success: true,
609
+ ...responseData,
610
+ };
611
+
522
612
  }
523
613
 
524
614
  async accountCashIn(accountTransferDto: AccountTransferDto): Promise<any> {
@@ -538,7 +628,7 @@ export class WelcomeBankService implements BankService {
538
628
  throw new HttpException({
539
629
  statusCode: HttpStatus.FORBIDDEN,
540
630
  code: 403020604,
541
- message: 'Bank permission key should not be empty.',
631
+ message: 'Permission key is required.',
542
632
  data: { accountTransferDto }
543
633
  }, HttpStatus.FORBIDDEN);
544
634
  }
@@ -547,7 +637,7 @@ export class WelcomeBankService implements BankService {
547
637
  throw new HttpException({
548
638
  statusCode: HttpStatus.BAD_REQUEST,
549
639
  code: 400020606,
550
- message: 'Bank source account number should not be empty.',
640
+ message: 'Source account number is required.',
551
641
  data: { accountTransferDto }
552
642
  }, HttpStatus.BAD_REQUEST);
553
643
  }
@@ -556,7 +646,7 @@ export class WelcomeBankService implements BankService {
556
646
  throw new HttpException({
557
647
  statusCode: HttpStatus.BAD_REQUEST,
558
648
  code: 400020608,
559
- message: 'Bank source account type should not be empty.',
649
+ message: 'Source account type is required.',
560
650
  data: { accountTransferDto }
561
651
  }, HttpStatus.BAD_REQUEST);
562
652
  }
@@ -565,7 +655,7 @@ export class WelcomeBankService implements BankService {
565
655
  throw new HttpException({
566
656
  statusCode: HttpStatus.BAD_REQUEST,
567
657
  code: 400020610,
568
- message: 'Bank destination account number should not be empty.',
658
+ message: 'Destination account number is required.',
569
659
  data: { accountTransferDto }
570
660
  }, HttpStatus.BAD_REQUEST);
571
661
  }
@@ -574,7 +664,7 @@ export class WelcomeBankService implements BankService {
574
664
  throw new HttpException({
575
665
  statusCode: HttpStatus.BAD_REQUEST,
576
666
  code: 400020612,
577
- message: 'Bank destination account type should not be empty.',
667
+ message: 'Destination account type is required.',
578
668
  data: { accountTransferDto }
579
669
  }, HttpStatus.BAD_REQUEST);
580
670
  }
@@ -583,7 +673,7 @@ export class WelcomeBankService implements BankService {
583
673
  throw new HttpException({
584
674
  statusCode: HttpStatus.BAD_REQUEST,
585
675
  code: 400020613,
586
- message: 'Amount should not be empty.',
676
+ message: 'Transaction amount is required.',
587
677
  data: { accountTransferDto }
588
678
  }, HttpStatus.BAD_REQUEST);
589
679
  }
@@ -598,6 +688,8 @@ export class WelcomeBankService implements BankService {
598
688
  this.logger.log(`TOTP GENERATED FOR WELCOME BANK CASH IN: ${totp}, For Time stamp: ${isoTimestamp}`);
599
689
  this.logger.log(`TOTP GENERATED FOR PREVIOUS TIME: ${totpPrevious}`);
600
690
 
691
+ let responseData;
692
+
601
693
  try {
602
694
  const headers = {
603
695
  'Authorization': `Bearer ${token}`,
@@ -619,7 +711,7 @@ export class WelcomeBankService implements BankService {
619
711
  }
620
712
 
621
713
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
622
- payload = {data: this.encryptPayloadWithOTP(payload, totp)};
714
+ payload = { data: this.encryptPayloadWithOTP(payload, totp) };
623
715
  }
624
716
 
625
717
  const httpsAgent = new https.Agent({
@@ -635,44 +727,72 @@ export class WelcomeBankService implements BankService {
635
727
  }
636
728
  );
637
729
 
638
- let responseData = response.data;
639
- this.logger.log({ responseData: response }, 'Welcome Bank Cash In Successful');
730
+ this.logger.log({ responseData: response.data }, 'Welcome Bank Cash In Successful');
640
731
 
641
732
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
642
733
 
643
- const encryptedResponsePayload = responseData.data;
734
+ const encryptedResponsePayload = response.data.data;
644
735
 
645
736
  if (!encryptedResponsePayload) {
646
737
  throw new Error("Encrypted response expected but not found");
647
738
  }
648
739
 
649
- let decryptedResponse;
650
740
  try {
651
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
741
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
652
742
  } catch (error) {
653
743
  this.logger.warn("Decryption with current OTP failed, trying with previous OTP");
744
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
654
745
  }
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
- };
746
+ }
747
+ else {
748
+ responseData = response.data;
671
749
  }
672
750
  }
673
751
  catch (error) {
674
752
  AxiosErrorHelper.handleAxiosError(error);
675
753
  }
754
+ if (responseData.data.status === "99999") {
755
+ throw new HttpException({
756
+ statusCode: HttpStatus.FORBIDDEN,
757
+ code: 403020603,
758
+ message: 'Invalid permission key.',
759
+ data: { ...accountTransferDto }
760
+ }, HttpStatus.FORBIDDEN);
761
+ }
762
+
763
+ if (responseData.data.status === "99997") {
764
+ throw new HttpException({
765
+ statusCode: HttpStatus.BAD_REQUEST,
766
+ code: 400020605,
767
+ message: 'Account not found.',
768
+ data: { ...accountTransferDto }
769
+ }, HttpStatus.BAD_REQUEST);
770
+ }
771
+
772
+ if (responseData.data.status === "00001") {
773
+ throw new HttpException({
774
+ statusCode: HttpStatus.BAD_REQUEST,
775
+ code: 400020607,
776
+ message: 'Account type is not supported.',
777
+ data: { ...accountTransferDto }
778
+ }, HttpStatus.BAD_REQUEST);
779
+ }
780
+
781
+ if (responseData.data.status === "00004") {
782
+ throw new HttpException({
783
+ statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
784
+ code: 422020614,
785
+ message: 'Invalid transaction amount value.',
786
+ data: { ...accountTransferDto }
787
+ }, HttpStatus.UNPROCESSABLE_ENTITY);
788
+ }
789
+
790
+ this.logger.log(`Response Data WelcomeBank Cashin , ${responseData}`);
791
+
792
+ return {
793
+ success: true,
794
+ ...responseData,
795
+ };
676
796
  }
677
797
 
678
798
  async accountDeposit(accountTransferDto: AccountTransferDto): Promise<any> {
@@ -692,7 +812,7 @@ export class WelcomeBankService implements BankService {
692
812
  throw new HttpException({
693
813
  statusCode: HttpStatus.FORBIDDEN,
694
814
  code: 403020704,
695
- message: 'Bank permission key should not be empty.',
815
+ message: 'Permission key is required.',
696
816
  data: { accountTransferDto }
697
817
  }, HttpStatus.FORBIDDEN);
698
818
  }
@@ -701,7 +821,7 @@ export class WelcomeBankService implements BankService {
701
821
  throw new HttpException({
702
822
  statusCode: HttpStatus.BAD_REQUEST,
703
823
  code: 400020706,
704
- message: 'Bank source account number should not be empty.',
824
+ message: 'Source account number is required',
705
825
  data: { accountTransferDto }
706
826
  }, HttpStatus.BAD_REQUEST);
707
827
  }
@@ -710,7 +830,7 @@ export class WelcomeBankService implements BankService {
710
830
  throw new HttpException({
711
831
  statusCode: HttpStatus.BAD_REQUEST,
712
832
  code: 400020708,
713
- message: 'Bank source account type should not be empty.',
833
+ message: 'Source account type is required.',
714
834
  data: { accountTransferDto }
715
835
  }, HttpStatus.BAD_REQUEST);
716
836
  }
@@ -719,7 +839,7 @@ export class WelcomeBankService implements BankService {
719
839
  throw new HttpException({
720
840
  statusCode: HttpStatus.BAD_REQUEST,
721
841
  code: 400020710,
722
- message: 'Bank destination account number should not be empty.',
842
+ message: 'Destination account number is required',
723
843
  data: { accountTransferDto }
724
844
  }, HttpStatus.BAD_REQUEST);
725
845
  }
@@ -737,7 +857,7 @@ export class WelcomeBankService implements BankService {
737
857
  throw new HttpException({
738
858
  statusCode: HttpStatus.BAD_REQUEST,
739
859
  code: 400020713,
740
- message: 'Amount should not be empty.',
860
+ message: 'Transaction amount is required.',
741
861
  data: { accountTransferDto }
742
862
  }, HttpStatus.BAD_REQUEST);
743
863
  }
@@ -752,6 +872,8 @@ export class WelcomeBankService implements BankService {
752
872
  this.logger.log(`TOTP GENERATED FOR WELCOME BANK DEPOSIT: ${totp}, For Time stamp: ${isoTimestamp}`);
753
873
  this.logger.log(`TOTP GENERATED FOR PREVIOUS TIME: ${totpPrevious}`);
754
874
 
875
+ let responseData;
876
+
755
877
  try {
756
878
  const headers = {
757
879
  'Authorization': `Bearer ${token}`,
@@ -759,8 +881,8 @@ export class WelcomeBankService implements BankService {
759
881
  'X-SERVER-TIMESTAMP': `${new Date().toISOString()}`
760
882
  };
761
883
 
762
-
763
884
  let payload;
885
+
764
886
  payload = {
765
887
  "permissionKey": permissionKey,
766
888
  "sourceAcc": sourceAccount,
@@ -774,7 +896,7 @@ export class WelcomeBankService implements BankService {
774
896
 
775
897
 
776
898
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
777
- payload = {data: this.encryptPayloadWithOTP(payload, totp)};
899
+ payload = { data: this.encryptPayloadWithOTP(payload, totp) };
778
900
  }
779
901
 
780
902
  const httpsAgent = new https.Agent({
@@ -790,49 +912,97 @@ export class WelcomeBankService implements BankService {
790
912
  }
791
913
  );
792
914
 
793
- let responseData = response.data;
794
915
  this.logger.log({ responseData: response.data }, 'Welcom Bank Deposit Successful');
795
916
 
796
917
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
797
918
 
798
- const encryptedResponsePayload = responseData.data;
919
+ const encryptedResponsePayload = response.data.data;
799
920
 
800
921
  if (!encryptedResponsePayload) {
801
922
  throw new Error("Encrypted response expected but not found");
802
923
  }
803
924
 
804
- let decryptedResponse;
805
925
  try {
806
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
926
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
807
927
  } catch (error) {
808
928
  this.logger.warn("Decryption with current OTP failed, trying with previous OTP");
929
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
809
930
  }
810
931
 
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
- };
932
+ }
933
+ else {
934
+ responseData = response.data;
826
935
  }
827
936
  }
828
937
  catch (error) {
829
938
  AxiosErrorHelper.handleAxiosError(error);
830
939
  }
940
+ if (responseData.data.status === "99999") {
941
+ throw new HttpException({
942
+ statusCode: HttpStatus.FORBIDDEN,
943
+ code: 403020703,
944
+ message: 'Invalid permission key.',
945
+ data: { ...accountTransferDto }
946
+ }, HttpStatus.FORBIDDEN);
947
+ }
948
+
949
+ if (responseData.data.status === "99997") {
950
+ throw new HttpException({
951
+ statusCode: HttpStatus.BAD_REQUEST,
952
+ code: 400020709,
953
+ message: 'Account not found.',
954
+ data: { ...accountTransferDto }
955
+ }, HttpStatus.BAD_REQUEST);
956
+ }
957
+
958
+ if (responseData.data.status === "00001") {
959
+ throw new HttpException({
960
+ statusCode: HttpStatus.BAD_REQUEST,
961
+ code: 400020711,
962
+ message: 'Account type is not supported.',
963
+ data: { ...accountTransferDto }
964
+ }, HttpStatus.BAD_REQUEST);
965
+ }
966
+
967
+ if (responseData.data.status === "00004") {
968
+ throw new HttpException({
969
+ statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
970
+ code: 422020714,
971
+ message: 'Invalid transaction amount value.',
972
+ data: { ...accountTransferDto }
973
+ }, HttpStatus.UNPROCESSABLE_ENTITY);
974
+ }
975
+
976
+ this.logger.log(`Response Data WelcomeBank Deposit , ${responseData}`);
977
+
978
+ return {
979
+ success: true,
980
+ ...responseData,
981
+ };
982
+
831
983
  }
832
984
 
833
- async getTransactionHistory(transactionHistoryDto: TransactionHistoryDto) {
985
+ async getTransactionHistory(transactionHistoryDto: TransactionHistoryDto):
986
+ Promise<{
987
+ success: boolean;
988
+ message: any;
989
+ timestamp: any;
990
+ transactions: any;
991
+ }> {
834
992
 
835
993
  const { token, permissionKey, account, branch, accountType, dateFrom, dateTo, page } = transactionHistoryDto;
994
+ const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
995
+
996
+ interface ReformattedTransaction {
997
+ dateTime: string;
998
+ amount: number;
999
+ type: string;
1000
+ description: string;
1001
+ transactionReference: string;
1002
+ }
1003
+
1004
+ const reformattedTransactions: Record<string, ReformattedTransaction> = {};
1005
+
836
1006
 
837
1007
  if (!token) {
838
1008
  throw new HttpException({
@@ -847,7 +1017,7 @@ export class WelcomeBankService implements BankService {
847
1017
  throw new HttpException({
848
1018
  statusCode: HttpStatus.FORBIDDEN,
849
1019
  code: 403020804,
850
- message: 'Bank permission key should not be empty.',
1020
+ message: 'Permission key is required.',
851
1021
  data: { transactionHistoryDto }
852
1022
  }, HttpStatus.FORBIDDEN);
853
1023
  }
@@ -856,7 +1026,7 @@ export class WelcomeBankService implements BankService {
856
1026
  throw new HttpException({
857
1027
  statusCode: HttpStatus.BAD_REQUEST,
858
1028
  code: 400020806,
859
- message: 'Bank account number should not be empty.',
1029
+ message: 'Account number is required',
860
1030
  data: { transactionHistoryDto }
861
1031
  }, HttpStatus.BAD_REQUEST);
862
1032
  }
@@ -865,7 +1035,7 @@ export class WelcomeBankService implements BankService {
865
1035
  throw new HttpException({
866
1036
  statusCode: HttpStatus.BAD_REQUEST,
867
1037
  code: 400020808,
868
- message: 'Bank account type should not be empty.',
1038
+ message: 'Account type is required.',
869
1039
  data: { transactionHistoryDto }
870
1040
  }, HttpStatus.BAD_REQUEST);
871
1041
  }
@@ -874,20 +1044,38 @@ export class WelcomeBankService implements BankService {
874
1044
  throw new HttpException({
875
1045
  statusCode: HttpStatus.BAD_REQUEST,
876
1046
  code: 400020810,
877
- message: 'Date From should not be empty.',
1047
+ message: 'Starting date is required.',
878
1048
  data: { transactionHistoryDto }
879
1049
  }, HttpStatus.BAD_REQUEST);
880
1050
  }
881
1051
 
1052
+ if (!dateRegex.test(dateFrom)) {
1053
+ throw new HttpException({
1054
+ statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
1055
+ code: 422020809,
1056
+ message: 'Invalid starting date format. Format should be in YYYY-MM-DD.',
1057
+ data: { ...transactionHistoryDto }
1058
+ }, HttpStatus.UNPROCESSABLE_ENTITY);
1059
+ }
1060
+
882
1061
  if (!dateTo) {
883
1062
  throw new HttpException({
884
1063
  statusCode: HttpStatus.BAD_REQUEST,
885
1064
  code: 400020812,
886
- message: 'Date From should not be empty.',
1065
+ message: 'Ending date is required.',
887
1066
  data: { transactionHistoryDto }
888
1067
  }, HttpStatus.BAD_REQUEST);
889
1068
  }
890
1069
 
1070
+ if (!dateRegex.test(dateTo)) {
1071
+ throw new HttpException({
1072
+ statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
1073
+ code: 422020811,
1074
+ message: 'Invalid starting date format. Format should be in YYYY-MM-DD.',
1075
+ data: { ...transactionHistoryDto }
1076
+ }, HttpStatus.UNPROCESSABLE_ENTITY);
1077
+ }
1078
+
891
1079
  this.logger.log("Welcome Bank transaction history");
892
1080
 
893
1081
  const isoTimestamp = new Date().toISOString();
@@ -895,9 +1083,11 @@ export class WelcomeBankService implements BankService {
895
1083
  const totp = this.generateTOTP(timeInSeconds);
896
1084
  const totpPrevious = this.generateTOTP(timeInSeconds - 30);
897
1085
 
898
- this.logger.log(`TOTP GENERATED FOR WELCOME BANK VALIDATE OTP: ${totp}, For Time stamp: ${isoTimestamp}`);
1086
+ this.logger.log(`TOTP GENERATED FOR WELCOME BANK TRANSACTION HISTORY: ${totp}, For Time stamp: ${isoTimestamp}`);
899
1087
  this.logger.log(`TOTP GENERATED FOR PREVIOUS TIME: ${totpPrevious}`);
900
1088
 
1089
+ let responseData;
1090
+
901
1091
  try {
902
1092
  const headers = {
903
1093
  'Authorization': `Bearer ${token}`,
@@ -917,7 +1107,7 @@ export class WelcomeBankService implements BankService {
917
1107
  }
918
1108
 
919
1109
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
920
- payload = {data: this.encryptPayloadWithOTP(payload, totp)};
1110
+ payload = { data: this.encryptPayloadWithOTP(payload, totp) };
921
1111
  }
922
1112
 
923
1113
  const httpsAgent = new https.Agent({
@@ -932,44 +1122,95 @@ export class WelcomeBankService implements BankService {
932
1122
  httpsAgent
933
1123
  }
934
1124
  );
935
- let responseData = response.data;
1125
+
1126
+
936
1127
  this.logger.log({ responseData: response.data }, 'Welcome Bank Transaction History Successful');
937
1128
 
938
1129
  if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
939
1130
 
940
- const encryptedResponsePayload = responseData.data;
1131
+ const encryptedResponsePayload = response.data.data;
941
1132
 
942
1133
  if (!encryptedResponsePayload) {
943
1134
  throw new Error("Encrypted response expected but not found");
944
1135
  }
945
1136
 
946
- let decryptedResponse;
947
1137
  try {
948
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
1138
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
949
1139
  } catch (error) {
950
1140
  this.logger.warn("Decryption with current OTP failed, trying with previous OTP");
1141
+ responseData = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
951
1142
  }
952
1143
 
953
- if (!decryptedResponse) {
954
- decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
955
- }
1144
+ this.logger.log(`Decrypted Response Log: ${JSON.stringify(responseData)}`);
1145
+ this.logger.log(`Decrypted.data.transactions Response Log: ${JSON.stringify(responseData.data.transaction)}`);
956
1146
 
957
- return {
958
- success: true,
959
- data: decryptedResponse,
960
- };
1147
+ responseData.data.transaction.forEach((txn, index) => {
1148
+ const key = `${index + 1}`;
961
1149
 
962
- } else {
1150
+ reformattedTransactions[key] = {
1151
+ dateTime: txn.dateTime,
1152
+ amount: txn.amount,
1153
+ type: txn.type,
1154
+ description: txn.description,
1155
+ transactionReference: txn.tranReference
1156
+ };
1157
+ });
963
1158
 
964
- return {
965
- success: true,
966
- ...responseData,
967
- };
968
1159
  }
1160
+ else {
1161
+ responseData = response.data;
1162
+ }
1163
+
969
1164
  }
970
1165
  catch (error) {
971
1166
  AxiosErrorHelper.handleAxiosError(error);
972
1167
  }
1168
+
1169
+ if (responseData.data.status === "99999") {
1170
+ throw new HttpException({
1171
+ statusCode: HttpStatus.FORBIDDEN,
1172
+ code: 403020803,
1173
+ message: 'Invalid permission key.',
1174
+ data: { ...transactionHistoryDto }
1175
+ }, HttpStatus.FORBIDDEN);
1176
+ }
1177
+
1178
+ if (responseData.data.status === "99997") {
1179
+ throw new HttpException({
1180
+ statusCode: HttpStatus.BAD_REQUEST,
1181
+ code: 400020805,
1182
+ message: 'Account not found.',
1183
+ data: { ...transactionHistoryDto }
1184
+ }, HttpStatus.BAD_REQUEST);
1185
+ }
1186
+
1187
+ if (responseData.data.status === "00001") {
1188
+ throw new HttpException({
1189
+ statusCode: HttpStatus.BAD_REQUEST,
1190
+ code: 400020807,
1191
+ message: 'Account type is not supported.',
1192
+ data: { ...transactionHistoryDto }
1193
+ }, HttpStatus.BAD_REQUEST);
1194
+ }
1195
+
1196
+ if (responseData.data.status === "XXXXX") {
1197
+ throw new HttpException({
1198
+ statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
1199
+ code: 422020813,
1200
+ message: 'Invalid page number format.',
1201
+ data: { ...transactionHistoryDto }
1202
+ }, HttpStatus.UNPROCESSABLE_ENTITY);
1203
+ }
1204
+
1205
+ this.logger.log(`Response Data WelcomeBank History , ${responseData}`);
1206
+
1207
+ return {
1208
+ success: true,
1209
+ message: responseData.data.responseMessage,
1210
+ timestamp: responseData.timestamp,
1211
+ transactions: reformattedTransactions,
1212
+ }
1213
+
973
1214
  }
974
1215
 
975
1216
  async findAccountDetailsRaw(token: string, userid: number) {