@traxionpay/cbsmiddleware 0.0.11 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@traxionpay/cbsmiddleware",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "description": "This is a cbs middlware for RB Banks",
5
5
  "author": "Archer",
6
6
  "private": false,
@@ -10,6 +10,7 @@ import { AccountDto, ValidateOtp } from '../dto/account.dto';
10
10
  import { TransactionHistoryDto } from '../dto/transaction-history.dto'
11
11
  import { AccountTransferDto } from '../dto/account-transfer.dto'
12
12
  import { FetchBankBalanceDto } from '../dto/fetch-bank-balance.dto';
13
+ import { formatTo09 } from 'src/helpers/utils';
13
14
 
14
15
  @Injectable()
15
16
  export class MBWINService implements BankService {
@@ -99,6 +100,7 @@ export class MBWINService implements BankService {
99
100
  async linkAccount(accountDto: AccountDto) {
100
101
 
101
102
  const { token, account, accountType, mobile, branch, fullName, birthDate } = accountDto;
103
+ const mobileFormatted = mobile? formatTo09(mobile) : '';
102
104
 
103
105
  if (!token) {
104
106
  throw new HttpException({
@@ -136,7 +138,7 @@ export class MBWINService implements BankService {
136
138
  }, HttpStatus.BAD_REQUEST);
137
139
  }
138
140
 
139
- if (!mobile) {
141
+ if (!mobileFormatted) {
140
142
  throw new HttpException({
141
143
  statusCode: HttpStatus.BAD_REQUEST,
142
144
  code: 4000303009,
@@ -181,7 +183,7 @@ export class MBWINService implements BankService {
181
183
  "appType": accountType,
182
184
  "displayName": fullName,
183
185
  "birthDate": birthDate,
184
- "mobile1": mobile
186
+ "mobile1": mobileFormatted
185
187
  }
186
188
 
187
189
  this.logger.log({ payload: payload }, 'MBWIN Link Request');
@@ -303,7 +305,7 @@ export class MBWINService implements BankService {
303
305
  async processBalanceTransaction(fetchBalanceDto: FetchBankBalanceDto): Promise<any> {
304
306
 
305
307
  const { token, account, branch, accountType, fullName, birthDate, mobile, permissionKey } = fetchBalanceDto;
306
-
308
+ const mobileFormatted = mobile? formatTo09(mobile) : '';
307
309
  if (!token) {
308
310
  throw new HttpException({
309
311
  statusCode: HttpStatus.UNAUTHORIZED,
@@ -358,7 +360,7 @@ export class MBWINService implements BankService {
358
360
  }, HttpStatus.BAD_REQUEST);
359
361
  }
360
362
 
361
- if (!mobile) {
363
+ if (!mobileFormatted) {
362
364
  throw new HttpException({
363
365
  statusCode: HttpStatus.BAD_REQUEST,
364
366
  code: 4000, //TBD
@@ -382,7 +384,7 @@ export class MBWINService implements BankService {
382
384
  "appType": accountType,
383
385
  "displayName": fullName,
384
386
  "birthDate": birthDate,
385
- "mobile1": mobile
387
+ "mobile1": mobileFormatted
386
388
  }
387
389
 
388
390
  const httpsAgent = new https.Agent({
@@ -427,6 +429,7 @@ export class MBWINService implements BankService {
427
429
  async accountCashIn(accountTransferDto: AccountTransferDto): Promise<any> {
428
430
 
429
431
  const { token, sourceAccount, amount, birthDate, sourceBranch, fullName, sourceAccountType, mobile} = accountTransferDto;
432
+ const mobileFormatted = mobile? formatTo09(mobile) : '';
430
433
 
431
434
  if (!token) {
432
435
  throw new HttpException({
@@ -491,7 +494,7 @@ export class MBWINService implements BankService {
491
494
  }, HttpStatus.BAD_REQUEST);
492
495
  }
493
496
 
494
- if (!mobile) {
497
+ if (!mobileFormatted) {
495
498
  throw new HttpException({
496
499
  statusCode: HttpStatus.BAD_REQUEST,
497
500
  code: 4000, //TBD
@@ -514,7 +517,7 @@ export class MBWINService implements BankService {
514
517
  "appType": sourceAccountType,
515
518
  "displayName": fullName,
516
519
  "birthDate": birthDate,
517
- "mobile1": mobile
520
+ "mobile1": mobileFormatted
518
521
  }
519
522
  }
520
523
 
@@ -560,6 +563,7 @@ export class MBWINService implements BankService {
560
563
  async accountDeposit(accountTransferDto: AccountTransferDto): Promise<any> {
561
564
 
562
565
  const { token, destinationAccount, amount, birthDate, destinationBranch, fullName, destinationAccountType, mobile} = accountTransferDto;
566
+ const mobileFormatted = mobile? formatTo09(mobile) : '';
563
567
 
564
568
  if (!token) {
565
569
  throw new HttpException({
@@ -624,7 +628,7 @@ export class MBWINService implements BankService {
624
628
  }, HttpStatus.BAD_REQUEST);
625
629
  }
626
630
 
627
- if (!mobile) {
631
+ if (!mobileFormatted) {
628
632
  throw new HttpException({
629
633
  statusCode: HttpStatus.BAD_REQUEST,
630
634
  code: 4000, //TBD
@@ -648,7 +652,7 @@ export class MBWINService implements BankService {
648
652
  "appType": destinationAccountType,
649
653
  "displayName": fullName,
650
654
  "birthDate": birthDate,
651
- "mobile1": mobile
655
+ "mobile1": mobileFormatted
652
656
  }
653
657
  }
654
658
 
@@ -694,6 +698,7 @@ export class MBWINService implements BankService {
694
698
  async getTransactionHistory(transactionHistoryDto: TransactionHistoryDto) {
695
699
 
696
700
  const { token, account, dateFrom, dateTo, page, branch, accountType, fullName, birthDate, mobile, permissionKey } = transactionHistoryDto;
701
+ const mobileFormatted = mobile? formatTo09(mobile) : '';
697
702
 
698
703
  if (!token) {
699
704
  throw new HttpException({
@@ -767,7 +772,7 @@ export class MBWINService implements BankService {
767
772
  }, HttpStatus.BAD_REQUEST);
768
773
  }
769
774
 
770
- if (!mobile) {
775
+ if (!mobileFormatted) {
771
776
  throw new HttpException({
772
777
  statusCode: HttpStatus.BAD_REQUEST,
773
778
  code: 4000, //TBD
@@ -793,7 +798,7 @@ export class MBWINService implements BankService {
793
798
  "appType": accountType,
794
799
  "displayName": fullName,
795
800
  "birthDate": birthDate,
796
- "mobile1": mobile
801
+ "mobile1": mobileFormatted
797
802
  }
798
803
  }
799
804
 
@@ -286,6 +286,15 @@ export class WelcomeBankService implements BankService {
286
286
  AxiosErrorHelper.handleAxiosError(error);
287
287
  }
288
288
 
289
+ if (responseData.data.status === "99994") {
290
+ throw new HttpException({
291
+ statusCode: HttpStatus.BAD_REQUEST,
292
+ code: 400020309,
293
+ message: 'The customer\'s account is a corporate account / joint account',
294
+ data: { ...accountDto }
295
+ }, HttpStatus.BAD_REQUEST);
296
+ }
297
+
289
298
  if (responseData.data.status === "99997") {
290
299
  throw new HttpException({
291
300
  statusCode: HttpStatus.BAD_REQUEST,
@@ -431,6 +440,16 @@ export class WelcomeBankService implements BankService {
431
440
  catch (error) {
432
441
  AxiosErrorHelper.handleAxiosError(error);
433
442
  }
443
+
444
+ if (responseData.data.status === "99994") {
445
+ throw new HttpException({
446
+ statusCode: HttpStatus.BAD_REQUEST,
447
+ code: 400020309,
448
+ message: 'The customer\'s account is a corporate account / joint account',
449
+ data: { ...validateOtp }
450
+ }, HttpStatus.BAD_REQUEST);
451
+ }
452
+
434
453
  if (responseData.data.status === "99997") {
435
454
  throw new HttpException({
436
455
  statusCode: HttpStatus.BAD_REQUEST,
@@ -444,7 +463,7 @@ export class WelcomeBankService implements BankService {
444
463
  throw new HttpException({
445
464
  statusCode: HttpStatus.BAD_REQUEST,
446
465
  code: 400020405,
447
- message: 'Account type is not supported.',
466
+ message: '00001 Account type is not supported.',
448
467
  data: { ...validateOtp }
449
468
  }, HttpStatus.BAD_REQUEST);
450
469
  }
@@ -0,0 +1,24 @@
1
+ export function formatTo09(input:string) {
2
+ if (!input) return null;
3
+
4
+ // Remove all non-digits
5
+ let num = input.replace(/\D/g, '');
6
+
7
+ // Remove country code if present
8
+ if (num.startsWith('63')) {
9
+ num = num.slice(2);
10
+ }
11
+
12
+ // Remove leading zero if duplicated
13
+ if (num.startsWith('0')) {
14
+ num = num.slice(1);
15
+ }
16
+
17
+ // At this point should be: 9XXXXXXXXX
18
+ if (!/^9\d{9}$/.test(num)) {
19
+ return null; // invalid PH mobile
20
+ }
21
+
22
+ return '0' + num; // force 09XXXXXXXXX
23
+ }
24
+