@traxionpay/cbsmiddleware 0.0.1
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/.prettierrc +4 -0
- package/Dockerfile +26 -0
- package/README.md +109 -0
- package/dist/app.module.d.ts +3 -0
- package/dist/app.module.d.ts.map +1 -0
- package/dist/app.module.js +44 -0
- package/dist/app.module.js.map +1 -0
- package/dist/auth/apikey.guard.d.ts +9 -0
- package/dist/auth/apikey.guard.d.ts.map +1 -0
- package/dist/auth/apikey.guard.js +86 -0
- package/dist/auth/apikey.guard.js.map +1 -0
- package/dist/auth/auth.controller.d.ts +10 -0
- package/dist/auth/auth.controller.d.ts.map +1 -0
- package/dist/auth/auth.controller.js +65 -0
- package/dist/auth/auth.controller.js.map +1 -0
- package/dist/auth/auth.interface.d.ts +8 -0
- package/dist/auth/auth.interface.d.ts.map +1 -0
- package/dist/auth/auth.interface.js +3 -0
- package/dist/auth/auth.interface.js.map +1 -0
- package/dist/auth/auth.module.d.ts +6 -0
- package/dist/auth/auth.module.d.ts.map +1 -0
- package/dist/auth/auth.module.js +81 -0
- package/dist/auth/auth.module.js.map +1 -0
- package/dist/auth/constant.d.ts +2 -0
- package/dist/auth/constant.d.ts.map +1 -0
- package/dist/auth/constant.js +5 -0
- package/dist/auth/constant.js.map +1 -0
- package/dist/auth/jwt-constant.d.ts +8 -0
- package/dist/auth/jwt-constant.d.ts.map +1 -0
- package/dist/auth/jwt-constant.js +60 -0
- package/dist/auth/jwt-constant.js.map +1 -0
- package/dist/auth/jwt-guard.d.ts +5 -0
- package/dist/auth/jwt-guard.d.ts.map +1 -0
- package/dist/auth/jwt-guard.js +18 -0
- package/dist/auth/jwt-guard.js.map +1 -0
- package/dist/auth/jwt-strategy.d.ts +16 -0
- package/dist/auth/jwt-strategy.d.ts.map +1 -0
- package/dist/auth/jwt-strategy.js +59 -0
- package/dist/auth/jwt-strategy.js.map +1 -0
- package/dist/auth/services/auth.service.d.ts +14 -0
- package/dist/auth/services/auth.service.d.ts.map +1 -0
- package/dist/auth/services/auth.service.js +56 -0
- package/dist/auth/services/auth.service.js.map +1 -0
- package/dist/auth/services/encryption.service.d.ts +11 -0
- package/dist/auth/services/encryption.service.d.ts.map +1 -0
- package/dist/auth/services/encryption.service.js +49 -0
- package/dist/auth/services/encryption.service.js.map +1 -0
- package/dist/auth.config.d.ts +29 -0
- package/dist/auth.config.d.ts.map +1 -0
- package/dist/auth.config.js +71 -0
- package/dist/auth.config.js.map +1 -0
- package/dist/banking/banking.controller.d.ts +18 -0
- package/dist/banking/banking.controller.d.ts.map +1 -0
- package/dist/banking/banking.controller.js +146 -0
- package/dist/banking/banking.controller.js.map +1 -0
- package/dist/banking/banking.module.d.ts +6 -0
- package/dist/banking/banking.module.d.ts.map +1 -0
- package/dist/banking/banking.module.js +90 -0
- package/dist/banking/banking.module.js.map +1 -0
- package/dist/banking/dto/account-transfer.dto.d.ts +17 -0
- package/dist/banking/dto/account-transfer.dto.d.ts.map +1 -0
- package/dist/banking/dto/account-transfer.dto.js +101 -0
- package/dist/banking/dto/account-transfer.dto.js.map +1 -0
- package/dist/banking/dto/account.dto.d.ts +19 -0
- package/dist/banking/dto/account.dto.d.ts.map +1 -0
- package/dist/banking/dto/account.dto.js +104 -0
- package/dist/banking/dto/account.dto.js.map +1 -0
- package/dist/banking/dto/fetch-bank-balance.dto.d.ts +12 -0
- package/dist/banking/dto/fetch-bank-balance.dto.d.ts.map +1 -0
- package/dist/banking/dto/fetch-bank-balance.dto.js +71 -0
- package/dist/banking/dto/fetch-bank-balance.dto.js.map +1 -0
- package/dist/banking/dto/transaction-history.dto.d.ts +15 -0
- package/dist/banking/dto/transaction-history.dto.d.ts.map +1 -0
- package/dist/banking/dto/transaction-history.dto.js +89 -0
- package/dist/banking/dto/transaction-history.dto.js.map +1 -0
- package/dist/banking/factory/bank-strategy.factory.d.ts +9 -0
- package/dist/banking/factory/bank-strategy.factory.d.ts.map +1 -0
- package/dist/banking/factory/bank-strategy.factory.js +48 -0
- package/dist/banking/factory/bank-strategy.factory.js.map +1 -0
- package/dist/banking/interfaces/bank-config.interface.d.ts +22 -0
- package/dist/banking/interfaces/bank-config.interface.d.ts.map +1 -0
- package/dist/banking/interfaces/bank-config.interface.js +3 -0
- package/dist/banking/interfaces/bank-config.interface.js.map +1 -0
- package/dist/banking/interfaces/bank-service.interface.d.ts +19 -0
- package/dist/banking/interfaces/bank-service.interface.d.ts.map +1 -0
- package/dist/banking/interfaces/bank-service.interface.js +3 -0
- package/dist/banking/interfaces/bank-service.interface.js.map +1 -0
- package/dist/banking/services/ASPAC.service.d.ts +25 -0
- package/dist/banking/services/ASPAC.service.d.ts.map +1 -0
- package/dist/banking/services/ASPAC.service.js +498 -0
- package/dist/banking/services/ASPAC.service.js.map +1 -0
- package/dist/banking/services/BankGateway.service.d.ts +18 -0
- package/dist/banking/services/BankGateway.service.d.ts.map +1 -0
- package/dist/banking/services/BankGateway.service.js +71 -0
- package/dist/banking/services/BankGateway.service.js.map +1 -0
- package/dist/banking/services/MBWIN.service.d.ts +25 -0
- package/dist/banking/services/MBWIN.service.d.ts.map +1 -0
- package/dist/banking/services/MBWIN.service.js +655 -0
- package/dist/banking/services/MBWIN.service.js.map +1 -0
- package/dist/banking/services/WelcomeBank.service.d.ts +29 -0
- package/dist/banking/services/WelcomeBank.service.d.ts.map +1 -0
- package/dist/banking/services/WelcomeBank.service.js +840 -0
- package/dist/banking/services/WelcomeBank.service.js.map +1 -0
- package/dist/banking/services/sms.service.d.ts +10 -0
- package/dist/banking/services/sms.service.d.ts.map +1 -0
- package/dist/banking/services/sms.service.js +97 -0
- package/dist/banking/services/sms.service.js.map +1 -0
- package/dist/banking/tokens/bank-service.tokens.d.ts +5 -0
- package/dist/banking/tokens/bank-service.tokens.d.ts.map +1 -0
- package/dist/banking/tokens/bank-service.tokens.js +8 -0
- package/dist/banking/tokens/bank-service.tokens.js.map +1 -0
- package/dist/banking/types.d.ts +10 -0
- package/dist/banking/types.d.ts.map +1 -0
- package/dist/banking/types.js +3 -0
- package/dist/banking/types.js.map +1 -0
- package/dist/decorators/response_message.decorator.d.ts +2 -0
- package/dist/decorators/response_message.decorator.d.ts.map +1 -0
- package/dist/decorators/response_message.decorator.js +7 -0
- package/dist/decorators/response_message.decorator.js.map +1 -0
- package/dist/helpers/axios-error.helper.d.ts +6 -0
- package/dist/helpers/axios-error.helper.d.ts.map +1 -0
- package/dist/helpers/axios-error.helper.js +78 -0
- package/dist/helpers/axios-error.helper.js.map +1 -0
- package/dist/helpers/response-format.helper.d.ts +4 -0
- package/dist/helpers/response-format.helper.d.ts.map +1 -0
- package/dist/helpers/response-format.helper.js +15 -0
- package/dist/helpers/response-format.helper.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/interceptors/response.interceptor.d.ts +16 -0
- package/dist/interceptors/response.interceptor.d.ts.map +1 -0
- package/dist/interceptors/response.interceptor.js +80 -0
- package/dist/interceptors/response.interceptor.js.map +1 -0
- package/dist/logger/logger-interceptor.d.ts +14 -0
- package/dist/logger/logger-interceptor.d.ts.map +1 -0
- package/dist/logger/logger-interceptor.js +60 -0
- package/dist/logger/logger-interceptor.js.map +1 -0
- package/dist/logger/logger-option.d.ts +6 -0
- package/dist/logger/logger-option.d.ts.map +1 -0
- package/dist/logger/logger-option.js +103 -0
- package/dist/logger/logger-option.js.map +1 -0
- package/dist/logger/logger.config.d.ts +3 -0
- package/dist/logger/logger.config.d.ts.map +1 -0
- package/dist/logger/logger.config.js +31 -0
- package/dist/logger/logger.config.js.map +1 -0
- package/dist/logger/logger.module.d.ts +3 -0
- package/dist/logger/logger.module.d.ts.map +1 -0
- package/dist/logger/logger.module.js +76 -0
- package/dist/logger/logger.module.js.map +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +13 -0
- package/dist/main.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/docker-compose.yml +14 -0
- package/ecosystem.config.js +35 -0
- package/eslint.config.mjs +34 -0
- package/nest-cli.json +8 -0
- package/package.json +102 -0
- package/src/app.module.ts +33 -0
- package/src/auth/apikey.guard.ts +42 -0
- package/src/auth/auth.controller.ts +41 -0
- package/src/auth/auth.interface.ts +7 -0
- package/src/auth/auth.module.ts +125 -0
- package/src/auth/constant.ts +1 -0
- package/src/auth/jwt-constant.ts +31 -0
- package/src/auth/jwt-guard.ts +5 -0
- package/src/auth/jwt-strategy.ts +43 -0
- package/src/auth/services/auth.service.ts +33 -0
- package/src/auth/services/encryption.service.ts +35 -0
- package/src/auth.config.ts +42 -0
- package/src/banking/banking.controller.ts +142 -0
- package/src/banking/banking.module.ts +142 -0
- package/src/banking/dto/account-transfer.dto.ts +66 -0
- package/src/banking/dto/account.dto.ts +70 -0
- package/src/banking/dto/fetch-bank-balance.dto.ts +46 -0
- package/src/banking/dto/transaction-history.dto.ts +58 -0
- package/src/banking/factory/bank-strategy.factory.ts +25 -0
- package/src/banking/interfaces/bank-config.interface.ts +25 -0
- package/src/banking/interfaces/bank-service.interface.ts +164 -0
- package/src/banking/services/ASPAC.service.ts +574 -0
- package/src/banking/services/BankGateway.service.ts +64 -0
- package/src/banking/services/MBWIN.service.ts +779 -0
- package/src/banking/services/WelcomeBank.service.ts +990 -0
- package/src/banking/services/sms.service.ts +50 -0
- package/src/banking/tokens/bank-service.tokens.ts +4 -0
- package/src/banking/types.ts +10 -0
- package/src/decorators/response_message.decorator.ts +4 -0
- package/src/helpers/axios-error.helper.ts +63 -0
- package/src/helpers/response-format.helper.ts +15 -0
- package/src/index.ts +15 -0
- package/src/interceptors/response.interceptor.ts +53 -0
- package/src/logger/logger-interceptor.ts +55 -0
- package/src/logger/logger-option.ts +119 -0
- package/src/logger/logger.config.ts +31 -0
- package/src/logger/logger.module.ts +31 -0
- package/src/main.ts +10 -0
- package/src/types/pino-daily-rotate-file.d.ts +31 -0
- package/tsconfig.build.json +11 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,840 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
45
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
46
|
+
};
|
|
47
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
48
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
|
+
};
|
|
50
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
+
exports.WelcomeBankService = void 0;
|
|
52
|
+
const common_1 = require("@nestjs/common");
|
|
53
|
+
const axios_1 = __importDefault(require("axios"));
|
|
54
|
+
const axios_error_helper_1 = require("../../helpers/axios-error.helper");
|
|
55
|
+
const bank_service_tokens_1 = require("../tokens/bank-service.tokens");
|
|
56
|
+
const https = __importStar(require("https"));
|
|
57
|
+
const speakeasy = __importStar(require("speakeasy"));
|
|
58
|
+
const CryptoJS = __importStar(require("crypto-js"));
|
|
59
|
+
const nestjs_pino_1 = require("nestjs-pino");
|
|
60
|
+
let WelcomeBankService = class WelcomeBankService {
|
|
61
|
+
config;
|
|
62
|
+
logger;
|
|
63
|
+
secretKey = '5HZ3HAX4MVCGFH3EWYP3U62QRDR6R3TD';
|
|
64
|
+
constructor(config, logger) {
|
|
65
|
+
this.config = config;
|
|
66
|
+
this.logger = logger;
|
|
67
|
+
}
|
|
68
|
+
generateTOTP(serverTimestamp) {
|
|
69
|
+
const timeInSeconds = typeof serverTimestamp === 'string'
|
|
70
|
+
? Math.floor(Date.parse(serverTimestamp) / 1000)
|
|
71
|
+
: serverTimestamp;
|
|
72
|
+
return speakeasy.totp({
|
|
73
|
+
secret: this.secretKey,
|
|
74
|
+
encoding: 'base32',
|
|
75
|
+
step: 30,
|
|
76
|
+
algorithm: 'sha1',
|
|
77
|
+
digits: 6,
|
|
78
|
+
time: timeInSeconds,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
encryptPayloadWithOTP(payload, otp) {
|
|
82
|
+
const stringified = JSON.stringify(payload);
|
|
83
|
+
const encrypted = CryptoJS.AES.encrypt(stringified, otp).toString();
|
|
84
|
+
return encrypted;
|
|
85
|
+
}
|
|
86
|
+
decryptPayloadWithOTP(encryptedPayload, otp) {
|
|
87
|
+
const decrypted = CryptoJS.AES.decrypt(encryptedPayload, otp);
|
|
88
|
+
const plaintext = decrypted.toString(CryptoJS.enc.Utf8);
|
|
89
|
+
try {
|
|
90
|
+
return JSON.parse(plaintext);
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
this.logger.error("Failed to JSON.parse decrypted payload", err);
|
|
94
|
+
throw new Error("Decryption or JSON parsing failed");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async generateToken() {
|
|
98
|
+
this.logger.log("Generating WelcomeBank Token");
|
|
99
|
+
try {
|
|
100
|
+
const headers = {
|
|
101
|
+
'Content-Type': 'application/json',
|
|
102
|
+
'X-API-KEY': `${this.config.WELCOMEBANK_API_KEY}`,
|
|
103
|
+
'X-API-VERSION': `${this.config.WELCOMEBANK_VERSION_KEY}`
|
|
104
|
+
};
|
|
105
|
+
const httpsAgent = new https.Agent({
|
|
106
|
+
rejectUnauthorized: false,
|
|
107
|
+
});
|
|
108
|
+
const response = await axios_1.default.get(`${this.config.WELCOMEBANK_URL}:${this.config.WELCOMEBANK_PORT}/api/token/generate`, {
|
|
109
|
+
headers: headers,
|
|
110
|
+
httpsAgent,
|
|
111
|
+
});
|
|
112
|
+
this.logger.log({ responseData: response }, 'Welcome Bank Token generated successfully');
|
|
113
|
+
return {
|
|
114
|
+
success: true,
|
|
115
|
+
...response.data,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
axios_error_helper_1.AxiosErrorHelper.handleAxiosError(error);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async refreshToken(refreshToken) {
|
|
123
|
+
if (!refreshToken) {
|
|
124
|
+
throw new common_1.HttpException({
|
|
125
|
+
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
126
|
+
code: 400020206,
|
|
127
|
+
message: 'Bank token should not be empty.',
|
|
128
|
+
data: { refreshToken }
|
|
129
|
+
}, common_1.HttpStatus.BAD_REQUEST);
|
|
130
|
+
}
|
|
131
|
+
this.logger.log("Welcome Bank refresh token");
|
|
132
|
+
try {
|
|
133
|
+
const headers = {
|
|
134
|
+
'Content-Type': 'application/json',
|
|
135
|
+
};
|
|
136
|
+
const payload = {
|
|
137
|
+
"refreshToken": refreshToken
|
|
138
|
+
};
|
|
139
|
+
const httpsAgent = new https.Agent({
|
|
140
|
+
rejectUnauthorized: false,
|
|
141
|
+
});
|
|
142
|
+
const response = await axios_1.default.post(`${this.config.WELCOMEBANK_URL}:${this.config.WELCOMEBANK_PORT}/api/token/refresh`, payload, {
|
|
143
|
+
headers: headers,
|
|
144
|
+
httpsAgent,
|
|
145
|
+
});
|
|
146
|
+
this.logger.log({ responseData: response }, 'Welcome Bank Refresh Token Successful');
|
|
147
|
+
return {
|
|
148
|
+
success: true,
|
|
149
|
+
...response.data,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
axios_error_helper_1.AxiosErrorHelper.handleAxiosError(error);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
async linkAccount(accountDto) {
|
|
157
|
+
const { token, account, branch, accountType, mobile } = accountDto;
|
|
158
|
+
if (!token) {
|
|
159
|
+
throw new common_1.HttpException({
|
|
160
|
+
statusCode: common_1.HttpStatus.UNAUTHORIZED,
|
|
161
|
+
code: 401020302,
|
|
162
|
+
message: 'Bank token should not be empty.',
|
|
163
|
+
data: { accountDto }
|
|
164
|
+
}, common_1.HttpStatus.UNAUTHORIZED);
|
|
165
|
+
}
|
|
166
|
+
if (!account) {
|
|
167
|
+
throw new common_1.HttpException({
|
|
168
|
+
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
169
|
+
code: 400020304,
|
|
170
|
+
message: 'Bank account number should not be empty.',
|
|
171
|
+
data: { accountDto }
|
|
172
|
+
}, common_1.HttpStatus.BAD_REQUEST);
|
|
173
|
+
}
|
|
174
|
+
if (!accountType) {
|
|
175
|
+
throw new common_1.HttpException({
|
|
176
|
+
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
177
|
+
code: 4400020306,
|
|
178
|
+
message: 'Bank account type should not be empty.',
|
|
179
|
+
data: { accountDto }
|
|
180
|
+
}, common_1.HttpStatus.BAD_REQUEST);
|
|
181
|
+
}
|
|
182
|
+
if (!mobile) {
|
|
183
|
+
throw new common_1.HttpException({
|
|
184
|
+
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
185
|
+
code: 4000203009,
|
|
186
|
+
message: 'Mobile Number should not be empty.',
|
|
187
|
+
data: { accountDto }
|
|
188
|
+
}, common_1.HttpStatus.BAD_REQUEST);
|
|
189
|
+
}
|
|
190
|
+
this.logger.log("Welcome Bank Link Account");
|
|
191
|
+
const isoTimestamp = new Date().toISOString();
|
|
192
|
+
const timeInSeconds = Math.floor(Date.parse(isoTimestamp) / 1000);
|
|
193
|
+
const totp = this.generateTOTP(timeInSeconds);
|
|
194
|
+
const totpPrevious = this.generateTOTP(timeInSeconds - 30);
|
|
195
|
+
this.logger.log(`TOTP GENERATED FOR WELCOMEBANK LINK ACCOUNT: ${totp}, For Time stamp: ${isoTimestamp}`);
|
|
196
|
+
this.logger.log(`TOTP GENERATED FOR PREVIOUS TIME: ${totpPrevious}`);
|
|
197
|
+
try {
|
|
198
|
+
const headers = {
|
|
199
|
+
'Authorization': `Bearer ${token}`,
|
|
200
|
+
'Content-Type': 'application/json',
|
|
201
|
+
'X-SERVER-TIMESTAMP': `${isoTimestamp}`
|
|
202
|
+
};
|
|
203
|
+
const httpsAgent = new https.Agent({
|
|
204
|
+
rejectUnauthorized: false,
|
|
205
|
+
});
|
|
206
|
+
let response;
|
|
207
|
+
if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
|
|
208
|
+
let payload;
|
|
209
|
+
payload = {
|
|
210
|
+
"acc": account,
|
|
211
|
+
"br": branch,
|
|
212
|
+
"accType": accountType,
|
|
213
|
+
"mobile": mobile
|
|
214
|
+
};
|
|
215
|
+
payload = this.encryptPayloadWithOTP(payload, totp);
|
|
216
|
+
const encodedPayload = encodeURIComponent(payload);
|
|
217
|
+
response = await axios_1.default.get(`${this.config.WELCOMEBANK_URL}:${this.config.WELCOMEBANK_PORT}/api/linkaccount?data=${encodedPayload}`, {
|
|
218
|
+
headers: headers,
|
|
219
|
+
httpsAgent
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
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}`, {
|
|
224
|
+
headers: headers,
|
|
225
|
+
httpsAgent
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
let responseData = response.data;
|
|
229
|
+
this.logger.log({ responseData: response }, 'Welcome Bank Link Account Successful');
|
|
230
|
+
if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
|
|
231
|
+
const encryptedResponsePayload = responseData.data;
|
|
232
|
+
if (!encryptedResponsePayload) {
|
|
233
|
+
throw new Error("Encrypted response expected but not found");
|
|
234
|
+
}
|
|
235
|
+
let decryptedResponse;
|
|
236
|
+
try {
|
|
237
|
+
decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
this.logger.warn("Decryption with current OTP failed, trying with previous OTP");
|
|
241
|
+
}
|
|
242
|
+
if (!decryptedResponse) {
|
|
243
|
+
decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
success: true,
|
|
247
|
+
data: decryptedResponse,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
return {
|
|
252
|
+
success: true,
|
|
253
|
+
...responseData,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
catch (error) {
|
|
258
|
+
axios_error_helper_1.AxiosErrorHelper.handleAxiosError(error);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
async validateOtp(validateOtp) {
|
|
262
|
+
const { token, account, branch, accountType, otp } = validateOtp;
|
|
263
|
+
if (!token) {
|
|
264
|
+
throw new common_1.HttpException({
|
|
265
|
+
statusCode: common_1.HttpStatus.UNAUTHORIZED,
|
|
266
|
+
code: 401020402,
|
|
267
|
+
message: 'Bank token should not be empty.',
|
|
268
|
+
data: { validateOtp }
|
|
269
|
+
}, common_1.HttpStatus.UNAUTHORIZED);
|
|
270
|
+
}
|
|
271
|
+
if (!account) {
|
|
272
|
+
throw new common_1.HttpException({
|
|
273
|
+
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
274
|
+
code: 400020404,
|
|
275
|
+
message: 'Bank account number should not be empty.',
|
|
276
|
+
data: { validateOtp }
|
|
277
|
+
}, common_1.HttpStatus.BAD_REQUEST);
|
|
278
|
+
}
|
|
279
|
+
if (!accountType) {
|
|
280
|
+
throw new common_1.HttpException({
|
|
281
|
+
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
282
|
+
code: 400020406,
|
|
283
|
+
message: 'Bank account type should not be empty.',
|
|
284
|
+
data: { validateOtp }
|
|
285
|
+
}, common_1.HttpStatus.BAD_REQUEST);
|
|
286
|
+
}
|
|
287
|
+
if (!otp) {
|
|
288
|
+
throw new common_1.HttpException({
|
|
289
|
+
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
290
|
+
code: 400020408,
|
|
291
|
+
message: 'Mobile Number should not be empty.',
|
|
292
|
+
data: { validateOtp }
|
|
293
|
+
}, common_1.HttpStatus.BAD_REQUEST);
|
|
294
|
+
}
|
|
295
|
+
this.logger.log("Welcome Bank Validate OTP");
|
|
296
|
+
const isoTimestamp = new Date().toISOString();
|
|
297
|
+
const timeInSeconds = Math.floor(Date.parse(isoTimestamp) / 1000);
|
|
298
|
+
const totp = this.generateTOTP(timeInSeconds);
|
|
299
|
+
const totpPrevious = this.generateTOTP(timeInSeconds - 30);
|
|
300
|
+
this.logger.log(`TOTP GENERATED FOR WELCOME BANK VALIDATE OTP: ${totp}, For Time stamp: ${isoTimestamp}`);
|
|
301
|
+
this.logger.log(`TOTP GENERATED FOR PREVIOUS TIME: ${totpPrevious}`);
|
|
302
|
+
try {
|
|
303
|
+
const headers = {
|
|
304
|
+
'Authorization': `Bearer ${token}`,
|
|
305
|
+
'Content-Type': 'application/json',
|
|
306
|
+
'X-SERVER-TIMESTAMP': `${isoTimestamp}`
|
|
307
|
+
};
|
|
308
|
+
let payload;
|
|
309
|
+
payload = {
|
|
310
|
+
"acc": account,
|
|
311
|
+
"br": branch,
|
|
312
|
+
"accType": accountType,
|
|
313
|
+
"otp": otp
|
|
314
|
+
};
|
|
315
|
+
if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
|
|
316
|
+
payload = { data: this.encryptPayloadWithOTP(payload, totp) };
|
|
317
|
+
}
|
|
318
|
+
const httpsAgent = new https.Agent({
|
|
319
|
+
rejectUnauthorized: false,
|
|
320
|
+
});
|
|
321
|
+
const response = await axios_1.default.post(`${this.config.WELCOMEBANK_URL}:${this.config.WELCOMEBANK_PORT}/api/validateotp`, payload, {
|
|
322
|
+
headers: headers,
|
|
323
|
+
httpsAgent
|
|
324
|
+
});
|
|
325
|
+
let responseData = response.data;
|
|
326
|
+
this.logger.log({ responseData: response }, 'Welcome Bank Validate OTP Successful');
|
|
327
|
+
if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
|
|
328
|
+
const encryptedResponsePayload = responseData.data;
|
|
329
|
+
if (!encryptedResponsePayload) {
|
|
330
|
+
throw new Error("Encrypted response expected but not found");
|
|
331
|
+
}
|
|
332
|
+
let decryptedResponse;
|
|
333
|
+
try {
|
|
334
|
+
decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
|
|
335
|
+
}
|
|
336
|
+
catch (error) {
|
|
337
|
+
this.logger.warn("Decryption with current OTP failed, trying with previous OTP");
|
|
338
|
+
}
|
|
339
|
+
if (!decryptedResponse) {
|
|
340
|
+
decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
|
|
341
|
+
}
|
|
342
|
+
return {
|
|
343
|
+
success: true,
|
|
344
|
+
data: decryptedResponse,
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
return {
|
|
349
|
+
success: true,
|
|
350
|
+
...responseData,
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
catch (error) {
|
|
355
|
+
axios_error_helper_1.AxiosErrorHelper.handleAxiosError(error);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
async processBalanceTransaction(fetchBalanceDto) {
|
|
359
|
+
const { token, permissionKey, account, branch, accountType } = fetchBalanceDto;
|
|
360
|
+
if (!token) {
|
|
361
|
+
throw new common_1.HttpException({
|
|
362
|
+
statusCode: common_1.HttpStatus.UNAUTHORIZED,
|
|
363
|
+
code: 401020502,
|
|
364
|
+
message: 'Bank token should not be empty.',
|
|
365
|
+
data: { fetchBalanceDto }
|
|
366
|
+
}, common_1.HttpStatus.UNAUTHORIZED);
|
|
367
|
+
}
|
|
368
|
+
if (!permissionKey) {
|
|
369
|
+
throw new common_1.HttpException({
|
|
370
|
+
statusCode: common_1.HttpStatus.UNAUTHORIZED,
|
|
371
|
+
code: 403020504,
|
|
372
|
+
message: 'Bank permission key should not be empty.',
|
|
373
|
+
data: { fetchBalanceDto }
|
|
374
|
+
}, common_1.HttpStatus.UNAUTHORIZED);
|
|
375
|
+
}
|
|
376
|
+
if (!account) {
|
|
377
|
+
throw new common_1.HttpException({
|
|
378
|
+
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
379
|
+
code: 400020506,
|
|
380
|
+
message: 'Bank account number should not be empty.',
|
|
381
|
+
data: { fetchBalanceDto }
|
|
382
|
+
}, common_1.HttpStatus.BAD_REQUEST);
|
|
383
|
+
}
|
|
384
|
+
if (!accountType) {
|
|
385
|
+
throw new common_1.HttpException({
|
|
386
|
+
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
387
|
+
code: 400020508,
|
|
388
|
+
message: 'Bank account type should not be empty.',
|
|
389
|
+
data: { fetchBalanceDto }
|
|
390
|
+
}, common_1.HttpStatus.BAD_REQUEST);
|
|
391
|
+
}
|
|
392
|
+
this.logger.log("Welcome Bank Balance Inquiry");
|
|
393
|
+
const isoTimestamp = new Date().toISOString();
|
|
394
|
+
const timeInSeconds = Math.floor(Date.parse(isoTimestamp) / 1000);
|
|
395
|
+
const totp = this.generateTOTP(timeInSeconds);
|
|
396
|
+
const totpPrevious = this.generateTOTP(timeInSeconds - 30);
|
|
397
|
+
this.logger.log(`TOTP GENERATED FOR WELCOME BANK BALANCE INQUIRY: ${totp}, For Time stamp: ${isoTimestamp}`);
|
|
398
|
+
this.logger.log(`TOTP GENERATED FOR PREVIOUS TIME: ${totpPrevious}`);
|
|
399
|
+
try {
|
|
400
|
+
const headers = {
|
|
401
|
+
'Authorization': `Bearer ${token}`,
|
|
402
|
+
'Content-Type': 'application/json',
|
|
403
|
+
'X-SERVER-TIMESTAMP': `${new Date().toISOString()}`
|
|
404
|
+
};
|
|
405
|
+
let payload;
|
|
406
|
+
payload = {
|
|
407
|
+
"acc": account,
|
|
408
|
+
"br": branch,
|
|
409
|
+
"accType": accountType,
|
|
410
|
+
"permissionKey": permissionKey,
|
|
411
|
+
};
|
|
412
|
+
if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
|
|
413
|
+
payload = { data: this.encryptPayloadWithOTP(payload, totp) };
|
|
414
|
+
}
|
|
415
|
+
const httpsAgent = new https.Agent({
|
|
416
|
+
rejectUnauthorized: false,
|
|
417
|
+
});
|
|
418
|
+
const response = await axios_1.default.post(`${this.config.WELCOMEBANK_URL}:${this.config.WELCOMEBANK_PORT}/api/balanceinquiry`, payload, {
|
|
419
|
+
headers: headers,
|
|
420
|
+
httpsAgent
|
|
421
|
+
});
|
|
422
|
+
let responseData = response.data;
|
|
423
|
+
this.logger.log({ responseData: response }, 'Welcome Bank Balance Inquiry Successful');
|
|
424
|
+
if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
|
|
425
|
+
const encryptedResponsePayload = responseData.data;
|
|
426
|
+
if (!encryptedResponsePayload) {
|
|
427
|
+
throw new Error("Encrypted response expected but not found");
|
|
428
|
+
}
|
|
429
|
+
let decryptedResponse;
|
|
430
|
+
try {
|
|
431
|
+
decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
|
|
432
|
+
}
|
|
433
|
+
catch (error) {
|
|
434
|
+
this.logger.warn("Decryption with current OTP failed, trying with previous OTP");
|
|
435
|
+
}
|
|
436
|
+
if (!decryptedResponse) {
|
|
437
|
+
decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
|
|
438
|
+
}
|
|
439
|
+
return {
|
|
440
|
+
success: true,
|
|
441
|
+
data: decryptedResponse,
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
return {
|
|
446
|
+
success: true,
|
|
447
|
+
...responseData,
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
catch (error) {
|
|
452
|
+
axios_error_helper_1.AxiosErrorHelper.handleAxiosError(error);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
async accountCashIn(accountTransferDto) {
|
|
456
|
+
const { token, permissionKey, sourceAccount, sourceBranch, sourceAccountType, destinationAccount, destinationBranch, destinationAccountType, amount } = accountTransferDto;
|
|
457
|
+
if (!token) {
|
|
458
|
+
throw new common_1.HttpException({
|
|
459
|
+
statusCode: common_1.HttpStatus.UNAUTHORIZED,
|
|
460
|
+
code: 401020602,
|
|
461
|
+
message: 'Bank token should not be empty.',
|
|
462
|
+
data: { accountTransferDto }
|
|
463
|
+
}, common_1.HttpStatus.UNAUTHORIZED);
|
|
464
|
+
}
|
|
465
|
+
if (!permissionKey) {
|
|
466
|
+
throw new common_1.HttpException({
|
|
467
|
+
statusCode: common_1.HttpStatus.FORBIDDEN,
|
|
468
|
+
code: 403020604,
|
|
469
|
+
message: 'Bank permission key should not be empty.',
|
|
470
|
+
data: { accountTransferDto }
|
|
471
|
+
}, common_1.HttpStatus.FORBIDDEN);
|
|
472
|
+
}
|
|
473
|
+
if (!sourceAccount) {
|
|
474
|
+
throw new common_1.HttpException({
|
|
475
|
+
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
476
|
+
code: 400020606,
|
|
477
|
+
message: 'Bank source account number should not be empty.',
|
|
478
|
+
data: { accountTransferDto }
|
|
479
|
+
}, common_1.HttpStatus.BAD_REQUEST);
|
|
480
|
+
}
|
|
481
|
+
if (!sourceAccountType) {
|
|
482
|
+
throw new common_1.HttpException({
|
|
483
|
+
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
484
|
+
code: 400020608,
|
|
485
|
+
message: 'Bank source account type should not be empty.',
|
|
486
|
+
data: { accountTransferDto }
|
|
487
|
+
}, common_1.HttpStatus.BAD_REQUEST);
|
|
488
|
+
}
|
|
489
|
+
if (!destinationAccount) {
|
|
490
|
+
throw new common_1.HttpException({
|
|
491
|
+
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
492
|
+
code: 400020610,
|
|
493
|
+
message: 'Bank destination account number should not be empty.',
|
|
494
|
+
data: { accountTransferDto }
|
|
495
|
+
}, common_1.HttpStatus.BAD_REQUEST);
|
|
496
|
+
}
|
|
497
|
+
if (!destinationAccountType) {
|
|
498
|
+
throw new common_1.HttpException({
|
|
499
|
+
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
500
|
+
code: 400020612,
|
|
501
|
+
message: 'Bank destination account type should not be empty.',
|
|
502
|
+
data: { accountTransferDto }
|
|
503
|
+
}, common_1.HttpStatus.BAD_REQUEST);
|
|
504
|
+
}
|
|
505
|
+
if (!amount) {
|
|
506
|
+
throw new common_1.HttpException({
|
|
507
|
+
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
508
|
+
code: 400020613,
|
|
509
|
+
message: 'Amount should not be empty.',
|
|
510
|
+
data: { accountTransferDto }
|
|
511
|
+
}, common_1.HttpStatus.BAD_REQUEST);
|
|
512
|
+
}
|
|
513
|
+
this.logger.log("Welcome Bank cash in");
|
|
514
|
+
const isoTimestamp = new Date().toISOString();
|
|
515
|
+
const timeInSeconds = Math.floor(Date.parse(isoTimestamp) / 1000);
|
|
516
|
+
const totp = this.generateTOTP(timeInSeconds);
|
|
517
|
+
const totpPrevious = this.generateTOTP(timeInSeconds - 30);
|
|
518
|
+
this.logger.log(`TOTP GENERATED FOR WELCOME BANK CASH IN: ${totp}, For Time stamp: ${isoTimestamp}`);
|
|
519
|
+
this.logger.log(`TOTP GENERATED FOR PREVIOUS TIME: ${totpPrevious}`);
|
|
520
|
+
try {
|
|
521
|
+
const headers = {
|
|
522
|
+
'Authorization': `Bearer ${token}`,
|
|
523
|
+
'Content-Type': 'application/json',
|
|
524
|
+
'X-SERVER-TIMESTAMP': `${new Date().toISOString()}`
|
|
525
|
+
};
|
|
526
|
+
let payload;
|
|
527
|
+
payload = {
|
|
528
|
+
"permissionKey": permissionKey,
|
|
529
|
+
"sourceAcc": sourceAccount,
|
|
530
|
+
"sourceBr": sourceBranch,
|
|
531
|
+
"sourceAccType": sourceAccountType,
|
|
532
|
+
"destAcc": destinationAccount,
|
|
533
|
+
"destBr": destinationBranch,
|
|
534
|
+
"destAccType": destinationAccountType,
|
|
535
|
+
"trnAmt": amount
|
|
536
|
+
};
|
|
537
|
+
if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
|
|
538
|
+
payload = { data: this.encryptPayloadWithOTP(payload, totp) };
|
|
539
|
+
}
|
|
540
|
+
const httpsAgent = new https.Agent({
|
|
541
|
+
rejectUnauthorized: false,
|
|
542
|
+
});
|
|
543
|
+
const response = await axios_1.default.post(`${this.config.WELCOMEBANK_URL}:${this.config.WELCOMEBANK_PORT}/api/cashin`, payload, {
|
|
544
|
+
headers: headers,
|
|
545
|
+
httpsAgent
|
|
546
|
+
});
|
|
547
|
+
let responseData = response.data;
|
|
548
|
+
this.logger.log({ responseData: response }, 'Welcome Bank Cash In Successful');
|
|
549
|
+
if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
|
|
550
|
+
const encryptedResponsePayload = responseData.data;
|
|
551
|
+
if (!encryptedResponsePayload) {
|
|
552
|
+
throw new Error("Encrypted response expected but not found");
|
|
553
|
+
}
|
|
554
|
+
let decryptedResponse;
|
|
555
|
+
try {
|
|
556
|
+
decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
|
|
557
|
+
}
|
|
558
|
+
catch (error) {
|
|
559
|
+
this.logger.warn("Decryption with current OTP failed, trying with previous OTP");
|
|
560
|
+
}
|
|
561
|
+
if (!decryptedResponse) {
|
|
562
|
+
decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
|
|
563
|
+
}
|
|
564
|
+
return {
|
|
565
|
+
success: true,
|
|
566
|
+
data: decryptedResponse,
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
else {
|
|
570
|
+
return {
|
|
571
|
+
success: true,
|
|
572
|
+
...responseData,
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
catch (error) {
|
|
577
|
+
axios_error_helper_1.AxiosErrorHelper.handleAxiosError(error);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
async accountDeposit(accountTransferDto) {
|
|
581
|
+
const { token, permissionKey, sourceAccount, sourceBranch, sourceAccountType, destinationAccount, destinationBranch, destinationAccountType, amount } = accountTransferDto;
|
|
582
|
+
if (!token) {
|
|
583
|
+
throw new common_1.HttpException({
|
|
584
|
+
statusCode: common_1.HttpStatus.UNAUTHORIZED,
|
|
585
|
+
code: 401020702,
|
|
586
|
+
message: 'Bank token should not be empty.',
|
|
587
|
+
data: { accountTransferDto }
|
|
588
|
+
}, common_1.HttpStatus.UNAUTHORIZED);
|
|
589
|
+
}
|
|
590
|
+
if (!permissionKey) {
|
|
591
|
+
throw new common_1.HttpException({
|
|
592
|
+
statusCode: common_1.HttpStatus.FORBIDDEN,
|
|
593
|
+
code: 403020704,
|
|
594
|
+
message: 'Bank permission key should not be empty.',
|
|
595
|
+
data: { accountTransferDto }
|
|
596
|
+
}, common_1.HttpStatus.FORBIDDEN);
|
|
597
|
+
}
|
|
598
|
+
if (!sourceAccount) {
|
|
599
|
+
throw new common_1.HttpException({
|
|
600
|
+
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
601
|
+
code: 400020706,
|
|
602
|
+
message: 'Bank source account number should not be empty.',
|
|
603
|
+
data: { accountTransferDto }
|
|
604
|
+
}, common_1.HttpStatus.BAD_REQUEST);
|
|
605
|
+
}
|
|
606
|
+
if (!sourceAccountType) {
|
|
607
|
+
throw new common_1.HttpException({
|
|
608
|
+
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
609
|
+
code: 400020708,
|
|
610
|
+
message: 'Bank source account type should not be empty.',
|
|
611
|
+
data: { accountTransferDto }
|
|
612
|
+
}, common_1.HttpStatus.BAD_REQUEST);
|
|
613
|
+
}
|
|
614
|
+
if (!destinationAccount) {
|
|
615
|
+
throw new common_1.HttpException({
|
|
616
|
+
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
617
|
+
code: 400020710,
|
|
618
|
+
message: 'Bank destination account number should not be empty.',
|
|
619
|
+
data: { accountTransferDto }
|
|
620
|
+
}, common_1.HttpStatus.BAD_REQUEST);
|
|
621
|
+
}
|
|
622
|
+
if (!destinationAccountType) {
|
|
623
|
+
throw new common_1.HttpException({
|
|
624
|
+
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
625
|
+
code: 400020712,
|
|
626
|
+
message: 'Bank destination account type should not be empty.',
|
|
627
|
+
data: { accountTransferDto }
|
|
628
|
+
}, common_1.HttpStatus.BAD_REQUEST);
|
|
629
|
+
}
|
|
630
|
+
if (!amount) {
|
|
631
|
+
throw new common_1.HttpException({
|
|
632
|
+
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
633
|
+
code: 400020713,
|
|
634
|
+
message: 'Amount should not be empty.',
|
|
635
|
+
data: { accountTransferDto }
|
|
636
|
+
}, common_1.HttpStatus.BAD_REQUEST);
|
|
637
|
+
}
|
|
638
|
+
this.logger.log("Welcome Bank deposit");
|
|
639
|
+
const isoTimestamp = new Date().toISOString();
|
|
640
|
+
const timeInSeconds = Math.floor(Date.parse(isoTimestamp) / 1000);
|
|
641
|
+
const totp = this.generateTOTP(timeInSeconds);
|
|
642
|
+
const totpPrevious = this.generateTOTP(timeInSeconds - 30);
|
|
643
|
+
this.logger.log(`TOTP GENERATED FOR WELCOME BANK DEPOSIT: ${totp}, For Time stamp: ${isoTimestamp}`);
|
|
644
|
+
this.logger.log(`TOTP GENERATED FOR PREVIOUS TIME: ${totpPrevious}`);
|
|
645
|
+
try {
|
|
646
|
+
const headers = {
|
|
647
|
+
'Authorization': `Bearer ${token}`,
|
|
648
|
+
'Content-Type': 'application/json',
|
|
649
|
+
'X-SERVER-TIMESTAMP': `${new Date().toISOString()}`
|
|
650
|
+
};
|
|
651
|
+
let payload;
|
|
652
|
+
payload = {
|
|
653
|
+
"permissionKey": permissionKey,
|
|
654
|
+
"sourceAcc": sourceAccount,
|
|
655
|
+
"sourceBr": sourceBranch,
|
|
656
|
+
"sourceAccType": sourceAccountType,
|
|
657
|
+
"destAcc": destinationAccount,
|
|
658
|
+
"destBr": destinationBranch,
|
|
659
|
+
"destAccType": destinationAccountType,
|
|
660
|
+
"trnAmt": amount
|
|
661
|
+
};
|
|
662
|
+
if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
|
|
663
|
+
payload = { data: this.encryptPayloadWithOTP(payload, totp) };
|
|
664
|
+
}
|
|
665
|
+
const httpsAgent = new https.Agent({
|
|
666
|
+
rejectUnauthorized: false,
|
|
667
|
+
});
|
|
668
|
+
const response = await axios_1.default.post(`${this.config.WELCOMEBANK_URL}:${this.config.WELCOMEBANK_PORT}/api/customerdeposit`, payload, {
|
|
669
|
+
headers: headers,
|
|
670
|
+
httpsAgent
|
|
671
|
+
});
|
|
672
|
+
let responseData = response.data;
|
|
673
|
+
this.logger.log({ responseData: response.data }, 'Welcom Bank Deposit Successful');
|
|
674
|
+
if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
|
|
675
|
+
const encryptedResponsePayload = responseData.data;
|
|
676
|
+
if (!encryptedResponsePayload) {
|
|
677
|
+
throw new Error("Encrypted response expected but not found");
|
|
678
|
+
}
|
|
679
|
+
let decryptedResponse;
|
|
680
|
+
try {
|
|
681
|
+
decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
|
|
682
|
+
}
|
|
683
|
+
catch (error) {
|
|
684
|
+
this.logger.warn("Decryption with current OTP failed, trying with previous OTP");
|
|
685
|
+
}
|
|
686
|
+
if (!decryptedResponse) {
|
|
687
|
+
decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
|
|
688
|
+
}
|
|
689
|
+
return {
|
|
690
|
+
success: true,
|
|
691
|
+
data: decryptedResponse,
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
else {
|
|
695
|
+
return {
|
|
696
|
+
success: true,
|
|
697
|
+
...responseData,
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
catch (error) {
|
|
702
|
+
axios_error_helper_1.AxiosErrorHelper.handleAxiosError(error);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
async getTransactionHistory(transactionHistoryDto) {
|
|
706
|
+
const { token, permissionKey, account, branch, accountType, dateFrom, dateTo, page } = transactionHistoryDto;
|
|
707
|
+
if (!token) {
|
|
708
|
+
throw new common_1.HttpException({
|
|
709
|
+
statusCode: common_1.HttpStatus.UNAUTHORIZED,
|
|
710
|
+
code: 401020802,
|
|
711
|
+
message: 'Bank token should not be empty.',
|
|
712
|
+
data: { transactionHistoryDto }
|
|
713
|
+
}, common_1.HttpStatus.UNAUTHORIZED);
|
|
714
|
+
}
|
|
715
|
+
if (!permissionKey) {
|
|
716
|
+
throw new common_1.HttpException({
|
|
717
|
+
statusCode: common_1.HttpStatus.FORBIDDEN,
|
|
718
|
+
code: 403020804,
|
|
719
|
+
message: 'Bank permission key should not be empty.',
|
|
720
|
+
data: { transactionHistoryDto }
|
|
721
|
+
}, common_1.HttpStatus.FORBIDDEN);
|
|
722
|
+
}
|
|
723
|
+
if (!account) {
|
|
724
|
+
throw new common_1.HttpException({
|
|
725
|
+
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
726
|
+
code: 400020806,
|
|
727
|
+
message: 'Bank account number should not be empty.',
|
|
728
|
+
data: { transactionHistoryDto }
|
|
729
|
+
}, common_1.HttpStatus.BAD_REQUEST);
|
|
730
|
+
}
|
|
731
|
+
if (!accountType) {
|
|
732
|
+
throw new common_1.HttpException({
|
|
733
|
+
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
734
|
+
code: 400020808,
|
|
735
|
+
message: 'Bank account type should not be empty.',
|
|
736
|
+
data: { transactionHistoryDto }
|
|
737
|
+
}, common_1.HttpStatus.BAD_REQUEST);
|
|
738
|
+
}
|
|
739
|
+
if (!dateFrom) {
|
|
740
|
+
throw new common_1.HttpException({
|
|
741
|
+
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
742
|
+
code: 400020810,
|
|
743
|
+
message: 'Date From should not be empty.',
|
|
744
|
+
data: { transactionHistoryDto }
|
|
745
|
+
}, common_1.HttpStatus.BAD_REQUEST);
|
|
746
|
+
}
|
|
747
|
+
if (!dateTo) {
|
|
748
|
+
throw new common_1.HttpException({
|
|
749
|
+
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
750
|
+
code: 400020812,
|
|
751
|
+
message: 'Date From should not be empty.',
|
|
752
|
+
data: { transactionHistoryDto }
|
|
753
|
+
}, common_1.HttpStatus.BAD_REQUEST);
|
|
754
|
+
}
|
|
755
|
+
this.logger.log("Welcome Bank transaction history");
|
|
756
|
+
const isoTimestamp = new Date().toISOString();
|
|
757
|
+
const timeInSeconds = Math.floor(Date.parse(isoTimestamp) / 1000);
|
|
758
|
+
const totp = this.generateTOTP(timeInSeconds);
|
|
759
|
+
const totpPrevious = this.generateTOTP(timeInSeconds - 30);
|
|
760
|
+
this.logger.log(`TOTP GENERATED FOR WELCOME BANK VALIDATE OTP: ${totp}, For Time stamp: ${isoTimestamp}`);
|
|
761
|
+
this.logger.log(`TOTP GENERATED FOR PREVIOUS TIME: ${totpPrevious}`);
|
|
762
|
+
try {
|
|
763
|
+
const headers = {
|
|
764
|
+
'Authorization': `Bearer ${token}`,
|
|
765
|
+
'Content-Type': 'application/json',
|
|
766
|
+
'X-SERVER-TIMESTAMP': `${new Date().toISOString()}`
|
|
767
|
+
};
|
|
768
|
+
let payload;
|
|
769
|
+
payload = {
|
|
770
|
+
"acc": account,
|
|
771
|
+
"br": branch,
|
|
772
|
+
"accType": accountType,
|
|
773
|
+
"permissionKey": permissionKey,
|
|
774
|
+
"dateFrom": dateFrom,
|
|
775
|
+
"dateTo": dateTo,
|
|
776
|
+
"pageNo": page
|
|
777
|
+
};
|
|
778
|
+
if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
|
|
779
|
+
payload = { data: this.encryptPayloadWithOTP(payload, totp) };
|
|
780
|
+
}
|
|
781
|
+
const httpsAgent = new https.Agent({
|
|
782
|
+
rejectUnauthorized: false,
|
|
783
|
+
});
|
|
784
|
+
const response = await axios_1.default.post(`${this.config.WELCOMEBANK_URL}:${this.config.WELCOMEBANK_PORT}/api/transhistory`, payload, {
|
|
785
|
+
headers: headers,
|
|
786
|
+
httpsAgent
|
|
787
|
+
});
|
|
788
|
+
let responseData = response.data;
|
|
789
|
+
this.logger.log({ responseData: response.data }, 'Welcome Bank Transaction History Successful');
|
|
790
|
+
if (String(this.config.WELCOMBANK_ENABLEENCRYPTION).toLowerCase() === 'true') {
|
|
791
|
+
const encryptedResponsePayload = responseData.data;
|
|
792
|
+
if (!encryptedResponsePayload) {
|
|
793
|
+
throw new Error("Encrypted response expected but not found");
|
|
794
|
+
}
|
|
795
|
+
let decryptedResponse;
|
|
796
|
+
try {
|
|
797
|
+
decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totp);
|
|
798
|
+
}
|
|
799
|
+
catch (error) {
|
|
800
|
+
this.logger.warn("Decryption with current OTP failed, trying with previous OTP");
|
|
801
|
+
}
|
|
802
|
+
if (!decryptedResponse) {
|
|
803
|
+
decryptedResponse = this.decryptPayloadWithOTP(encryptedResponsePayload, totpPrevious);
|
|
804
|
+
}
|
|
805
|
+
return {
|
|
806
|
+
success: true,
|
|
807
|
+
data: decryptedResponse,
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
else {
|
|
811
|
+
return {
|
|
812
|
+
success: true,
|
|
813
|
+
...responseData,
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
catch (error) {
|
|
818
|
+
axios_error_helper_1.AxiosErrorHelper.handleAxiosError(error);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
async findAccountDetailsRaw(token, userid) {
|
|
822
|
+
return "Sorry Service Currently Unavaible";
|
|
823
|
+
}
|
|
824
|
+
async accountTransfer(token, useridFrom, useridTo, amount) {
|
|
825
|
+
return "Sorry Service Currently Unavaible";
|
|
826
|
+
}
|
|
827
|
+
generateOtp(mobile, acc, bankid) {
|
|
828
|
+
return "Sorry Service Currently Unavaible";
|
|
829
|
+
}
|
|
830
|
+
generateRandomOtp(length) {
|
|
831
|
+
return "Sorry Service Currently Unavaible";
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
exports.WelcomeBankService = WelcomeBankService;
|
|
835
|
+
exports.WelcomeBankService = WelcomeBankService = __decorate([
|
|
836
|
+
(0, common_1.Injectable)(),
|
|
837
|
+
__param(0, (0, common_1.Inject)(bank_service_tokens_1.BANKING_CONFIG)),
|
|
838
|
+
__metadata("design:paramtypes", [Object, nestjs_pino_1.Logger])
|
|
839
|
+
], WelcomeBankService);
|
|
840
|
+
//# sourceMappingURL=WelcomeBank.service.js.map
|