@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.
Files changed (203) hide show
  1. package/.prettierrc +4 -0
  2. package/Dockerfile +26 -0
  3. package/README.md +109 -0
  4. package/dist/app.module.d.ts +3 -0
  5. package/dist/app.module.d.ts.map +1 -0
  6. package/dist/app.module.js +44 -0
  7. package/dist/app.module.js.map +1 -0
  8. package/dist/auth/apikey.guard.d.ts +9 -0
  9. package/dist/auth/apikey.guard.d.ts.map +1 -0
  10. package/dist/auth/apikey.guard.js +86 -0
  11. package/dist/auth/apikey.guard.js.map +1 -0
  12. package/dist/auth/auth.controller.d.ts +10 -0
  13. package/dist/auth/auth.controller.d.ts.map +1 -0
  14. package/dist/auth/auth.controller.js +65 -0
  15. package/dist/auth/auth.controller.js.map +1 -0
  16. package/dist/auth/auth.interface.d.ts +8 -0
  17. package/dist/auth/auth.interface.d.ts.map +1 -0
  18. package/dist/auth/auth.interface.js +3 -0
  19. package/dist/auth/auth.interface.js.map +1 -0
  20. package/dist/auth/auth.module.d.ts +6 -0
  21. package/dist/auth/auth.module.d.ts.map +1 -0
  22. package/dist/auth/auth.module.js +81 -0
  23. package/dist/auth/auth.module.js.map +1 -0
  24. package/dist/auth/constant.d.ts +2 -0
  25. package/dist/auth/constant.d.ts.map +1 -0
  26. package/dist/auth/constant.js +5 -0
  27. package/dist/auth/constant.js.map +1 -0
  28. package/dist/auth/jwt-constant.d.ts +8 -0
  29. package/dist/auth/jwt-constant.d.ts.map +1 -0
  30. package/dist/auth/jwt-constant.js +60 -0
  31. package/dist/auth/jwt-constant.js.map +1 -0
  32. package/dist/auth/jwt-guard.d.ts +5 -0
  33. package/dist/auth/jwt-guard.d.ts.map +1 -0
  34. package/dist/auth/jwt-guard.js +18 -0
  35. package/dist/auth/jwt-guard.js.map +1 -0
  36. package/dist/auth/jwt-strategy.d.ts +16 -0
  37. package/dist/auth/jwt-strategy.d.ts.map +1 -0
  38. package/dist/auth/jwt-strategy.js +59 -0
  39. package/dist/auth/jwt-strategy.js.map +1 -0
  40. package/dist/auth/services/auth.service.d.ts +14 -0
  41. package/dist/auth/services/auth.service.d.ts.map +1 -0
  42. package/dist/auth/services/auth.service.js +56 -0
  43. package/dist/auth/services/auth.service.js.map +1 -0
  44. package/dist/auth/services/encryption.service.d.ts +11 -0
  45. package/dist/auth/services/encryption.service.d.ts.map +1 -0
  46. package/dist/auth/services/encryption.service.js +49 -0
  47. package/dist/auth/services/encryption.service.js.map +1 -0
  48. package/dist/auth.config.d.ts +29 -0
  49. package/dist/auth.config.d.ts.map +1 -0
  50. package/dist/auth.config.js +71 -0
  51. package/dist/auth.config.js.map +1 -0
  52. package/dist/banking/banking.controller.d.ts +18 -0
  53. package/dist/banking/banking.controller.d.ts.map +1 -0
  54. package/dist/banking/banking.controller.js +146 -0
  55. package/dist/banking/banking.controller.js.map +1 -0
  56. package/dist/banking/banking.module.d.ts +6 -0
  57. package/dist/banking/banking.module.d.ts.map +1 -0
  58. package/dist/banking/banking.module.js +90 -0
  59. package/dist/banking/banking.module.js.map +1 -0
  60. package/dist/banking/dto/account-transfer.dto.d.ts +17 -0
  61. package/dist/banking/dto/account-transfer.dto.d.ts.map +1 -0
  62. package/dist/banking/dto/account-transfer.dto.js +101 -0
  63. package/dist/banking/dto/account-transfer.dto.js.map +1 -0
  64. package/dist/banking/dto/account.dto.d.ts +19 -0
  65. package/dist/banking/dto/account.dto.d.ts.map +1 -0
  66. package/dist/banking/dto/account.dto.js +104 -0
  67. package/dist/banking/dto/account.dto.js.map +1 -0
  68. package/dist/banking/dto/fetch-bank-balance.dto.d.ts +12 -0
  69. package/dist/banking/dto/fetch-bank-balance.dto.d.ts.map +1 -0
  70. package/dist/banking/dto/fetch-bank-balance.dto.js +71 -0
  71. package/dist/banking/dto/fetch-bank-balance.dto.js.map +1 -0
  72. package/dist/banking/dto/transaction-history.dto.d.ts +15 -0
  73. package/dist/banking/dto/transaction-history.dto.d.ts.map +1 -0
  74. package/dist/banking/dto/transaction-history.dto.js +89 -0
  75. package/dist/banking/dto/transaction-history.dto.js.map +1 -0
  76. package/dist/banking/factory/bank-strategy.factory.d.ts +9 -0
  77. package/dist/banking/factory/bank-strategy.factory.d.ts.map +1 -0
  78. package/dist/banking/factory/bank-strategy.factory.js +48 -0
  79. package/dist/banking/factory/bank-strategy.factory.js.map +1 -0
  80. package/dist/banking/interfaces/bank-config.interface.d.ts +22 -0
  81. package/dist/banking/interfaces/bank-config.interface.d.ts.map +1 -0
  82. package/dist/banking/interfaces/bank-config.interface.js +3 -0
  83. package/dist/banking/interfaces/bank-config.interface.js.map +1 -0
  84. package/dist/banking/interfaces/bank-service.interface.d.ts +19 -0
  85. package/dist/banking/interfaces/bank-service.interface.d.ts.map +1 -0
  86. package/dist/banking/interfaces/bank-service.interface.js +3 -0
  87. package/dist/banking/interfaces/bank-service.interface.js.map +1 -0
  88. package/dist/banking/services/ASPAC.service.d.ts +25 -0
  89. package/dist/banking/services/ASPAC.service.d.ts.map +1 -0
  90. package/dist/banking/services/ASPAC.service.js +498 -0
  91. package/dist/banking/services/ASPAC.service.js.map +1 -0
  92. package/dist/banking/services/BankGateway.service.d.ts +18 -0
  93. package/dist/banking/services/BankGateway.service.d.ts.map +1 -0
  94. package/dist/banking/services/BankGateway.service.js +71 -0
  95. package/dist/banking/services/BankGateway.service.js.map +1 -0
  96. package/dist/banking/services/MBWIN.service.d.ts +25 -0
  97. package/dist/banking/services/MBWIN.service.d.ts.map +1 -0
  98. package/dist/banking/services/MBWIN.service.js +655 -0
  99. package/dist/banking/services/MBWIN.service.js.map +1 -0
  100. package/dist/banking/services/WelcomeBank.service.d.ts +29 -0
  101. package/dist/banking/services/WelcomeBank.service.d.ts.map +1 -0
  102. package/dist/banking/services/WelcomeBank.service.js +840 -0
  103. package/dist/banking/services/WelcomeBank.service.js.map +1 -0
  104. package/dist/banking/services/sms.service.d.ts +10 -0
  105. package/dist/banking/services/sms.service.d.ts.map +1 -0
  106. package/dist/banking/services/sms.service.js +97 -0
  107. package/dist/banking/services/sms.service.js.map +1 -0
  108. package/dist/banking/tokens/bank-service.tokens.d.ts +5 -0
  109. package/dist/banking/tokens/bank-service.tokens.d.ts.map +1 -0
  110. package/dist/banking/tokens/bank-service.tokens.js +8 -0
  111. package/dist/banking/tokens/bank-service.tokens.js.map +1 -0
  112. package/dist/banking/types.d.ts +10 -0
  113. package/dist/banking/types.d.ts.map +1 -0
  114. package/dist/banking/types.js +3 -0
  115. package/dist/banking/types.js.map +1 -0
  116. package/dist/decorators/response_message.decorator.d.ts +2 -0
  117. package/dist/decorators/response_message.decorator.d.ts.map +1 -0
  118. package/dist/decorators/response_message.decorator.js +7 -0
  119. package/dist/decorators/response_message.decorator.js.map +1 -0
  120. package/dist/helpers/axios-error.helper.d.ts +6 -0
  121. package/dist/helpers/axios-error.helper.d.ts.map +1 -0
  122. package/dist/helpers/axios-error.helper.js +78 -0
  123. package/dist/helpers/axios-error.helper.js.map +1 -0
  124. package/dist/helpers/response-format.helper.d.ts +4 -0
  125. package/dist/helpers/response-format.helper.d.ts.map +1 -0
  126. package/dist/helpers/response-format.helper.js +15 -0
  127. package/dist/helpers/response-format.helper.js.map +1 -0
  128. package/dist/index.d.ts +10 -0
  129. package/dist/index.d.ts.map +1 -0
  130. package/dist/index.js +26 -0
  131. package/dist/index.js.map +1 -0
  132. package/dist/interceptors/response.interceptor.d.ts +16 -0
  133. package/dist/interceptors/response.interceptor.d.ts.map +1 -0
  134. package/dist/interceptors/response.interceptor.js +80 -0
  135. package/dist/interceptors/response.interceptor.js.map +1 -0
  136. package/dist/logger/logger-interceptor.d.ts +14 -0
  137. package/dist/logger/logger-interceptor.d.ts.map +1 -0
  138. package/dist/logger/logger-interceptor.js +60 -0
  139. package/dist/logger/logger-interceptor.js.map +1 -0
  140. package/dist/logger/logger-option.d.ts +6 -0
  141. package/dist/logger/logger-option.d.ts.map +1 -0
  142. package/dist/logger/logger-option.js +103 -0
  143. package/dist/logger/logger-option.js.map +1 -0
  144. package/dist/logger/logger.config.d.ts +3 -0
  145. package/dist/logger/logger.config.d.ts.map +1 -0
  146. package/dist/logger/logger.config.js +31 -0
  147. package/dist/logger/logger.config.js.map +1 -0
  148. package/dist/logger/logger.module.d.ts +3 -0
  149. package/dist/logger/logger.module.d.ts.map +1 -0
  150. package/dist/logger/logger.module.js +76 -0
  151. package/dist/logger/logger.module.js.map +1 -0
  152. package/dist/main.d.ts +2 -0
  153. package/dist/main.d.ts.map +1 -0
  154. package/dist/main.js +13 -0
  155. package/dist/main.js.map +1 -0
  156. package/dist/tsconfig.build.tsbuildinfo +1 -0
  157. package/docker-compose.yml +14 -0
  158. package/ecosystem.config.js +35 -0
  159. package/eslint.config.mjs +34 -0
  160. package/nest-cli.json +8 -0
  161. package/package.json +102 -0
  162. package/src/app.module.ts +33 -0
  163. package/src/auth/apikey.guard.ts +42 -0
  164. package/src/auth/auth.controller.ts +41 -0
  165. package/src/auth/auth.interface.ts +7 -0
  166. package/src/auth/auth.module.ts +125 -0
  167. package/src/auth/constant.ts +1 -0
  168. package/src/auth/jwt-constant.ts +31 -0
  169. package/src/auth/jwt-guard.ts +5 -0
  170. package/src/auth/jwt-strategy.ts +43 -0
  171. package/src/auth/services/auth.service.ts +33 -0
  172. package/src/auth/services/encryption.service.ts +35 -0
  173. package/src/auth.config.ts +42 -0
  174. package/src/banking/banking.controller.ts +142 -0
  175. package/src/banking/banking.module.ts +142 -0
  176. package/src/banking/dto/account-transfer.dto.ts +66 -0
  177. package/src/banking/dto/account.dto.ts +70 -0
  178. package/src/banking/dto/fetch-bank-balance.dto.ts +46 -0
  179. package/src/banking/dto/transaction-history.dto.ts +58 -0
  180. package/src/banking/factory/bank-strategy.factory.ts +25 -0
  181. package/src/banking/interfaces/bank-config.interface.ts +25 -0
  182. package/src/banking/interfaces/bank-service.interface.ts +164 -0
  183. package/src/banking/services/ASPAC.service.ts +574 -0
  184. package/src/banking/services/BankGateway.service.ts +64 -0
  185. package/src/banking/services/MBWIN.service.ts +779 -0
  186. package/src/banking/services/WelcomeBank.service.ts +990 -0
  187. package/src/banking/services/sms.service.ts +50 -0
  188. package/src/banking/tokens/bank-service.tokens.ts +4 -0
  189. package/src/banking/types.ts +10 -0
  190. package/src/decorators/response_message.decorator.ts +4 -0
  191. package/src/helpers/axios-error.helper.ts +63 -0
  192. package/src/helpers/response-format.helper.ts +15 -0
  193. package/src/index.ts +15 -0
  194. package/src/interceptors/response.interceptor.ts +53 -0
  195. package/src/logger/logger-interceptor.ts +55 -0
  196. package/src/logger/logger-option.ts +119 -0
  197. package/src/logger/logger.config.ts +31 -0
  198. package/src/logger/logger.module.ts +31 -0
  199. package/src/main.ts +10 -0
  200. package/src/types/pino-daily-rotate-file.d.ts +31 -0
  201. package/tsconfig.build.json +11 -0
  202. package/tsconfig.build.tsbuildinfo +1 -0
  203. package/tsconfig.json +22 -0
@@ -0,0 +1,779 @@
1
+ import { Inject, Injectable, HttpStatus, HttpException } from '@nestjs/common';
2
+ import { BankService } from '../interfaces/bank-service.interface';
3
+ import axios from 'axios';
4
+ import { AxiosErrorHelper } from '../../helpers/axios-error.helper';
5
+ import { BankingConfig } from '../interfaces/bank-config.interface';
6
+ import { BANKING_CONFIG } from '../tokens/bank-service.tokens';
7
+ import * as https from 'https';
8
+ import { Logger } from 'nestjs-pino';
9
+ import { AccountDto, ValidateOtp } from '../dto/account.dto';
10
+ import { TransactionHistoryDto } from '../dto/transaction-history.dto'
11
+ import { AccountTransferDto } from '../dto/account-transfer.dto'
12
+ import { FetchBankBalanceDto } from '../dto/fetch-bank-balance.dto';
13
+
14
+ @Injectable()
15
+ export class MBWINService implements BankService {
16
+
17
+ constructor(
18
+ @Inject(BANKING_CONFIG)
19
+ private readonly config: BankingConfig,
20
+ private readonly logger: Logger
21
+ ) {
22
+ }
23
+
24
+ async generateToken(): Promise<any> {
25
+
26
+ this.logger.log("Generating MBWINToken");
27
+
28
+ try {
29
+ const headers = {
30
+ 'Content-Type': 'application/json',
31
+ 'X-API-KEY': `${this.config.MBWIN_API_KEY}`,
32
+ };
33
+
34
+ const httpsAgent = new https.Agent({
35
+ rejectUnauthorized: false,
36
+ });
37
+
38
+ const response = await axios.get(
39
+ `${this.config.MBWIN_URL}:${this.config.MBWIN_PORT}/api/token`,
40
+ {
41
+ headers: headers,
42
+ httpsAgent,
43
+ }
44
+ );
45
+
46
+ this.logger.log({ responseData: response }, 'MBWIN Token generated successfully');
47
+
48
+ return {
49
+ success: true,
50
+ ...response.data,
51
+ };
52
+
53
+ } catch (error) {
54
+ AxiosErrorHelper.handleAxiosError(error);
55
+ }
56
+ }
57
+
58
+ async refreshToken(refreshToken: string): Promise<any> {
59
+
60
+ this.logger.log("MBWIN refresh token");
61
+
62
+ return "Sorry service is currently unavaible"
63
+
64
+ /* try {
65
+ const headers = {
66
+ 'Content-Type': 'application/json',
67
+ 'X-API-KEY': `${this.config.ASPAC_API_KEY}`,
68
+ 'X-API-VERSION': `${this.config.ASPAC_VERSION_KEY}`
69
+ };
70
+
71
+ const payload = {
72
+ "refreshtoken": refreshToken
73
+ }
74
+ const httpsAgent = new https.Agent({
75
+ rejectUnauthorized: false,
76
+ });
77
+
78
+ const response = await axios.post(
79
+ `${this.config.ASPAC_URL}/api/v1/token/refresh`,
80
+ payload,
81
+ {
82
+ headers: headers,
83
+ httpsAgent,
84
+ }
85
+ );
86
+
87
+ this.logger.log({ responseData: response }, 'MBWIN Refresh Token Successful');
88
+
89
+ return {
90
+ success: true,
91
+ ...response.data,
92
+ };
93
+
94
+ } catch (error) {
95
+ AxiosErrorHelper.handleAxiosError(error);
96
+ } */
97
+ }
98
+
99
+ async linkAccount(accountDto: AccountDto) {
100
+
101
+ const { token, account, accountType, mobile, branch, fullName, birthDate } = accountDto;
102
+
103
+ if (!token) {
104
+ throw new HttpException({
105
+ statusCode: HttpStatus.UNAUTHORIZED,
106
+ code: 4000, //TBD
107
+ message: 'Bank token should not be empty.',
108
+ data: { accountDto }
109
+ }, HttpStatus.UNAUTHORIZED);
110
+ }
111
+
112
+ if (!account) {
113
+ throw new HttpException({
114
+ statusCode: HttpStatus.BAD_REQUEST,
115
+ code: 4000, //TBD
116
+ message: 'Bank account number should not be empty.',
117
+ data: { accountDto }
118
+ }, HttpStatus.BAD_REQUEST);
119
+ }
120
+
121
+ if (!branch) {
122
+ throw new HttpException({
123
+ statusCode: HttpStatus.BAD_REQUEST,
124
+ code: 4000, //TBD
125
+ message: 'Bank branch should not be empty.',
126
+ data: { accountDto }
127
+ }, HttpStatus.BAD_REQUEST);
128
+ }
129
+
130
+ if (!accountType) {
131
+ throw new HttpException({
132
+ statusCode: HttpStatus.BAD_REQUEST,
133
+ code: 4000, //TBD
134
+ message: 'Bank account type should not be empty.',
135
+ data: { accountDto }
136
+ }, HttpStatus.BAD_REQUEST);
137
+ }
138
+
139
+ if (!mobile) {
140
+ throw new HttpException({
141
+ statusCode: HttpStatus.BAD_REQUEST,
142
+ code: 4000, //TBD
143
+ message: 'Mobile Number should not be empty.',
144
+ data: { accountDto }
145
+ }, HttpStatus.BAD_REQUEST);
146
+ }
147
+
148
+ if (!fullName) {
149
+ throw new HttpException({
150
+ statusCode: HttpStatus.BAD_REQUEST,
151
+ code: 4000, //TBD
152
+ message: 'Full name should not be empty.',
153
+ data: { accountDto }
154
+ }, HttpStatus.BAD_REQUEST);
155
+ }
156
+
157
+ if (!birthDate) {
158
+ throw new HttpException({
159
+ statusCode: HttpStatus.BAD_REQUEST,
160
+ code: 4000, //TBD
161
+ message: 'Birth date should not be empty.',
162
+ data: { accountDto }
163
+ }, HttpStatus.BAD_REQUEST);
164
+ }
165
+
166
+ this.logger.log("MBWIN Link Account");
167
+
168
+ try {
169
+ const headers = {
170
+ 'Authorization': `Bearer ${token}`,
171
+ 'Content-Type': 'application/json',
172
+ };
173
+
174
+ const httpsAgent = new https.Agent({
175
+ rejectUnauthorized: false,
176
+ });
177
+
178
+ const payload = {
179
+ "acc": account,
180
+ "br": branch,
181
+ "appType": accountType,
182
+ "displayName": fullName,
183
+ "birthDate": birthDate,
184
+ "mobile1": mobile
185
+ }
186
+
187
+ console.log(payload);
188
+
189
+ const response = await axios.post(
190
+ `${this.config.MBWIN_URL}:${this.config.MBWIN_PORT}/api/account/link`,
191
+ payload,
192
+ {
193
+ headers: headers,
194
+ httpsAgent
195
+ }
196
+ );
197
+
198
+
199
+ this.logger.log({ responseData: response }, 'MBWIN Link Account Successful');
200
+
201
+ return {
202
+ success: true,
203
+ ...response.data,
204
+ }
205
+ }
206
+ catch (error) {
207
+ AxiosErrorHelper.handleAxiosError(error);
208
+ }
209
+ }
210
+
211
+ async validateOtp(validateOtp: ValidateOtp): Promise<any> {
212
+
213
+ const { token, account, otp } = validateOtp;
214
+
215
+ if (!token) {
216
+ throw new HttpException({
217
+ statusCode: HttpStatus.UNAUTHORIZED,
218
+ code: 4000, //TBD
219
+ message: 'Bank token should not be empty.',
220
+ data: { validateOtp }
221
+ }, HttpStatus.UNAUTHORIZED);
222
+ }
223
+
224
+ if (!account) {
225
+ throw new HttpException({
226
+ statusCode: HttpStatus.BAD_REQUEST,
227
+ code: 4000, //TBD
228
+ message: 'Bank account number should not be empty.',
229
+ data: { validateOtp }
230
+ }, HttpStatus.BAD_REQUEST);
231
+ }
232
+
233
+ if (!otp) {
234
+ throw new HttpException({
235
+ statusCode: HttpStatus.BAD_REQUEST,
236
+ code: 4000, //TBD
237
+ message: 'Mobile Number should not be empty.',
238
+ data: { validateOtp }
239
+ }, HttpStatus.BAD_REQUEST);
240
+ }
241
+
242
+ this.logger.log("MBWIN Validate OTP");
243
+
244
+ try {
245
+ const headers = {
246
+ 'Authorization': `Bearer ${token}`,
247
+ 'Content-Type': 'application/json',
248
+ };
249
+
250
+ const payload = {
251
+ "acc": account,
252
+ "otp": otp
253
+ }
254
+
255
+ const httpsAgent = new https.Agent({
256
+ rejectUnauthorized: false,
257
+ });
258
+
259
+ const response = await axios.post(
260
+ `${this.config.MBWIN_URL}:${this.config.MBWIN_PORT}/api/account/validate`,
261
+ payload,
262
+ {
263
+ headers: headers,
264
+ httpsAgent
265
+ }
266
+ );
267
+
268
+ this.logger.log({ responseData: response }, 'MBWIN Validate OTP Successful');
269
+
270
+ return {
271
+ success: true,
272
+ ...response.data,
273
+ }
274
+ }
275
+ catch (error) {
276
+ AxiosErrorHelper.handleAxiosError(error);
277
+ }
278
+ }
279
+
280
+ async processBalanceTransaction(fetchBalanceDto: FetchBankBalanceDto): Promise<any> {
281
+
282
+ const { token, account, branch, accountType, fullName, birthDate, mobile } = fetchBalanceDto;
283
+
284
+ if (!token) {
285
+ throw new HttpException({
286
+ statusCode: HttpStatus.UNAUTHORIZED,
287
+ code: 4000, //TBD
288
+ message: 'Bank token should not be empty.',
289
+ data: { fetchBalanceDto }
290
+ }, HttpStatus.UNAUTHORIZED);
291
+ }
292
+
293
+ if (!account) {
294
+ throw new HttpException({
295
+ statusCode: HttpStatus.BAD_REQUEST,
296
+ code: 4000, //TBD
297
+ message: 'Bank account number should not be empty.',
298
+ data: { fetchBalanceDto }
299
+ }, HttpStatus.BAD_REQUEST);
300
+ }
301
+
302
+ if (!branch) {
303
+ throw new HttpException({
304
+ statusCode: HttpStatus.BAD_REQUEST,
305
+ code: 4000, //TBD
306
+ message: 'Bank branch should not be empty.',
307
+ data: { fetchBalanceDto }
308
+ }, HttpStatus.BAD_REQUEST);
309
+ }
310
+
311
+ if (!accountType) {
312
+ throw new HttpException({
313
+ statusCode: HttpStatus.BAD_REQUEST,
314
+ code: 4000, //TBD
315
+ message: 'Bank account type should not be empty.',
316
+ data: { fetchBalanceDto }
317
+ }, HttpStatus.BAD_REQUEST);
318
+ }
319
+
320
+ if (!fullName) {
321
+ throw new HttpException({
322
+ statusCode: HttpStatus.BAD_REQUEST,
323
+ code: 4000, //TBD
324
+ message: 'Full name should not be empty.',
325
+ data: { fetchBalanceDto }
326
+ }, HttpStatus.BAD_REQUEST);
327
+ }
328
+
329
+ if (!birthDate) {
330
+ throw new HttpException({
331
+ statusCode: HttpStatus.BAD_REQUEST,
332
+ code: 4000, //TBD
333
+ message: 'Birth Date should not be empty.',
334
+ data: { fetchBalanceDto }
335
+ }, HttpStatus.BAD_REQUEST);
336
+ }
337
+
338
+ if (!mobile) {
339
+ throw new HttpException({
340
+ statusCode: HttpStatus.BAD_REQUEST,
341
+ code: 4000, //TBD
342
+ message: 'Mobile number should not be empty.',
343
+ data: { fetchBalanceDto }
344
+ }, HttpStatus.BAD_REQUEST);
345
+ }
346
+
347
+ this.logger.log("MBWIN Balance Inquiry");
348
+
349
+ try {
350
+ const headers = {
351
+ 'Authorization': `Bearer ${token}`,
352
+ 'Content-Type': 'application/json',
353
+ };
354
+
355
+ const payload = {
356
+ "acc": account,
357
+ "br": branch,
358
+ "appType": accountType,
359
+ "displayName": fullName,
360
+ "birthDate": birthDate,
361
+ "mobile1": mobile
362
+ }
363
+
364
+ const httpsAgent = new https.Agent({
365
+ rejectUnauthorized: false,
366
+ });
367
+
368
+ const response = await axios.post(
369
+ `${this.config.MBWIN_URL}:${this.config.MBWIN_PORT}/api/mbwin/balance-inquiry`,
370
+ payload,
371
+ {
372
+ headers: headers,
373
+ httpsAgent
374
+ }
375
+ );
376
+
377
+ this.logger.log({ responseData: response }, 'MBWIN Balance Inquiry Successful');
378
+
379
+ return {
380
+ success: true,
381
+ ...response.data,
382
+ }
383
+ }
384
+ catch (error) {
385
+ AxiosErrorHelper.handleAxiosError(error);
386
+ }
387
+ }
388
+
389
+ async accountCashIn(accountTransferDto: AccountTransferDto): Promise<any> {
390
+
391
+ const { token, sourceAccount, amount, birthDate, sourceBranch, fullName, sourceAccountType, mobile} = accountTransferDto;
392
+
393
+ if (!token) {
394
+ throw new HttpException({
395
+ statusCode: HttpStatus.UNAUTHORIZED,
396
+ code: 4000, //TBD
397
+ message: 'Bank token should not be empty.',
398
+ data: { accountTransferDto }
399
+ }, HttpStatus.UNAUTHORIZED);
400
+ }
401
+
402
+ if (!sourceAccount) {
403
+ throw new HttpException({
404
+ statusCode: HttpStatus.BAD_REQUEST,
405
+ code: 4000, //TBD
406
+ message: 'Bank source account number should not be empty.',
407
+ data: { accountTransferDto }
408
+ }, HttpStatus.BAD_REQUEST);
409
+ }
410
+
411
+ if (!sourceBranch) {
412
+ throw new HttpException({
413
+ statusCode: HttpStatus.BAD_REQUEST,
414
+ code: 4000, //TBD
415
+ message: 'Bank source branch should not be empty.',
416
+ data: { accountTransferDto }
417
+ }, HttpStatus.BAD_REQUEST);
418
+ }
419
+
420
+ if (!sourceAccountType) {
421
+ throw new HttpException({
422
+ statusCode: HttpStatus.BAD_REQUEST,
423
+ code: 4000, //TBD
424
+ message: 'Bank source account type should not be empty.',
425
+ data: { accountTransferDto }
426
+ }, HttpStatus.BAD_REQUEST);
427
+ }
428
+
429
+ if (!amount) {
430
+ throw new HttpException({
431
+ statusCode: HttpStatus.BAD_REQUEST,
432
+ code: 4000, //TBD
433
+ message: 'Amount should not be empty.',
434
+ data: { accountTransferDto }
435
+ }, HttpStatus.BAD_REQUEST);
436
+ }
437
+
438
+ if (!fullName) {
439
+ throw new HttpException({
440
+ statusCode: HttpStatus.BAD_REQUEST,
441
+ code: 4000, //TBD
442
+ message: 'Full name should not be empty.',
443
+ data: { accountTransferDto }
444
+ }, HttpStatus.BAD_REQUEST);
445
+ }
446
+
447
+ if (!birthDate) {
448
+ throw new HttpException({
449
+ statusCode: HttpStatus.BAD_REQUEST,
450
+ code: 4000, //TBD
451
+ message: 'Birth Date should not be empty.',
452
+ data: { accountTransferDto }
453
+ }, HttpStatus.BAD_REQUEST);
454
+ }
455
+
456
+ if (!mobile) {
457
+ throw new HttpException({
458
+ statusCode: HttpStatus.BAD_REQUEST,
459
+ code: 4000, //TBD
460
+ message: 'Mobile number should not be empty.',
461
+ data: { accountTransferDto }
462
+ }, HttpStatus.BAD_REQUEST);
463
+ }
464
+
465
+ this.logger.log("MBWIN cash in");
466
+
467
+ try {
468
+ const headers = {
469
+ 'Authorization': `Bearer ${token}`,
470
+ 'Content-Type': 'application/json',
471
+ };
472
+
473
+ const payload = {
474
+ "trnAmt": amount,
475
+ "accountValidation": {
476
+ "acc": sourceAccount,
477
+ "br": sourceBranch,
478
+ "appType": sourceAccountType,
479
+ "displayName": fullName,
480
+ "birthDate": birthDate,
481
+ "mobile1": mobile
482
+ }
483
+ }
484
+
485
+ const httpsAgent = new https.Agent({
486
+ rejectUnauthorized: false,
487
+ });
488
+
489
+ const response = await axios.post(
490
+ `${this.config.MBWIN_URL}:${this.config.MBWIN_PORT}/api/mbwin/account-transfer`,
491
+ payload,
492
+ {
493
+ headers: headers,
494
+ httpsAgent
495
+ }
496
+ );
497
+
498
+ this.logger.log({ responseData: response }, 'MBWIN Cash In Successful');
499
+
500
+ return {
501
+ success: true,
502
+ ...response.data,
503
+ }
504
+ }
505
+ catch (error) {
506
+ AxiosErrorHelper.handleAxiosError(error);
507
+ }
508
+ }
509
+
510
+ async accountDeposit(accountTransferDto: AccountTransferDto): Promise<any> {
511
+
512
+ const { token, destinationAccount, amount, birthDate, destinationBranch, fullName, destinationAccountType, mobile} = accountTransferDto;
513
+
514
+ if (!token) {
515
+ throw new HttpException({
516
+ statusCode: HttpStatus.UNAUTHORIZED,
517
+ code: 4000, //TBD
518
+ message: 'Bank token should not be empty.',
519
+ data: { accountTransferDto }
520
+ }, HttpStatus.UNAUTHORIZED);
521
+ }
522
+
523
+ if (!destinationAccount) {
524
+ throw new HttpException({
525
+ statusCode: HttpStatus.BAD_REQUEST,
526
+ code: 4000, //TBD
527
+ message: 'Bank destination account number should not be empty.',
528
+ data: { accountTransferDto }
529
+ }, HttpStatus.BAD_REQUEST);
530
+ }
531
+
532
+ if (!destinationBranch) {
533
+ throw new HttpException({
534
+ statusCode: HttpStatus.BAD_REQUEST,
535
+ code: 4000, //TBD
536
+ message: 'Bank destination branch should not be empty.',
537
+ data: { accountTransferDto }
538
+ }, HttpStatus.BAD_REQUEST);
539
+ }
540
+
541
+ if (!destinationAccountType) {
542
+ throw new HttpException({
543
+ statusCode: HttpStatus.BAD_REQUEST,
544
+ code: 4000, //TBD
545
+ message: 'Bank destination account type should not be empty.',
546
+ data: { accountTransferDto }
547
+ }, HttpStatus.BAD_REQUEST);
548
+ }
549
+
550
+ if (!amount) {
551
+ throw new HttpException({
552
+ statusCode: HttpStatus.BAD_REQUEST,
553
+ code: 4000, //TBD
554
+ message: 'Amount should not be empty.',
555
+ data: { accountTransferDto }
556
+ }, HttpStatus.BAD_REQUEST);
557
+ }
558
+
559
+ if (!fullName) {
560
+ throw new HttpException({
561
+ statusCode: HttpStatus.BAD_REQUEST,
562
+ code: 4000, //TBD
563
+ message: 'Full name should not be empty.',
564
+ data: { accountTransferDto }
565
+ }, HttpStatus.BAD_REQUEST);
566
+ }
567
+
568
+ if (!birthDate) {
569
+ throw new HttpException({
570
+ statusCode: HttpStatus.BAD_REQUEST,
571
+ code: 4000, //TBD
572
+ message: 'Birth Date should not be empty.',
573
+ data: { accountTransferDto }
574
+ }, HttpStatus.BAD_REQUEST);
575
+ }
576
+
577
+ if (!mobile) {
578
+ throw new HttpException({
579
+ statusCode: HttpStatus.BAD_REQUEST,
580
+ code: 4000, //TBD
581
+ message: 'Mobile number should not be empty.',
582
+ data: { accountTransferDto }
583
+ }, HttpStatus.BAD_REQUEST);
584
+ }
585
+
586
+ this.logger.log("MBWIN deposit");
587
+
588
+ try {
589
+ const headers = {
590
+ 'Authorization': `Bearer ${token}`,
591
+ 'Content-Type': 'application/json',
592
+ };
593
+
594
+ const payload = {
595
+ "trnAmt": amount,
596
+ "accountValidation": {
597
+ "acc": "0",
598
+ "accTo": destinationAccount,
599
+ "br": destinationBranch,
600
+ "appType": destinationAccountType,
601
+ "displayName": fullName,
602
+ "birthDate": birthDate,
603
+ "mobile1": mobile
604
+ }
605
+ }
606
+
607
+ const httpsAgent = new https.Agent({
608
+ rejectUnauthorized: false,
609
+ });
610
+
611
+ const response = await axios.post(
612
+ `${this.config.MBWIN_URL}:${this.config.MBWIN_PORT}/api/mbwin/account-transfer`,
613
+ payload,
614
+ {
615
+ headers: headers,
616
+ httpsAgent
617
+ }
618
+ );
619
+
620
+ this.logger.log({ responseData: response.data }, 'Welcom Bank Deposit Successful');
621
+
622
+ return {
623
+ success: true,
624
+ ...response.data,
625
+ }
626
+ }
627
+ catch (error) {
628
+ AxiosErrorHelper.handleAxiosError(error);
629
+ }
630
+ }
631
+
632
+ async getTransactionHistory(transactionHistoryDto: TransactionHistoryDto) {
633
+
634
+ const { token, account, dateFrom, dateTo, page, branch, accountType, fullName, birthDate, mobile } = transactionHistoryDto;
635
+
636
+ if (!token) {
637
+ throw new HttpException({
638
+ statusCode: HttpStatus.UNAUTHORIZED,
639
+ code: 4000, //TBD
640
+ message: 'Bank token should not be empty.',
641
+ data: { transactionHistoryDto }
642
+ }, HttpStatus.UNAUTHORIZED);
643
+ }
644
+
645
+ if (!account) {
646
+ throw new HttpException({
647
+ statusCode: HttpStatus.BAD_REQUEST,
648
+ code: 4000, //TBD
649
+ message: 'Bank account number should not be empty.',
650
+ data: { transactionHistoryDto }
651
+ }, HttpStatus.BAD_REQUEST);
652
+ }
653
+
654
+ if (!branch) {
655
+ throw new HttpException({
656
+ statusCode: HttpStatus.BAD_REQUEST,
657
+ code: 4000, //TBD
658
+ message: 'Bank branch should not be empty.',
659
+ data: { transactionHistoryDto }
660
+ }, HttpStatus.BAD_REQUEST);
661
+ }
662
+
663
+ if (!accountType) {
664
+ throw new HttpException({
665
+ statusCode: HttpStatus.BAD_REQUEST,
666
+ code: 4000, //TBD
667
+ message: 'Bank account type should not be empty.',
668
+ data: { transactionHistoryDto }
669
+ }, HttpStatus.BAD_REQUEST);
670
+ }
671
+
672
+ if (!dateFrom) {
673
+ throw new HttpException({
674
+ statusCode: HttpStatus.BAD_REQUEST,
675
+ code: 4000, //TBD
676
+ message: 'Date From should not be empty.',
677
+ data: { transactionHistoryDto }
678
+ }, HttpStatus.BAD_REQUEST);
679
+ }
680
+
681
+ if (!dateTo) {
682
+ throw new HttpException({
683
+ statusCode: HttpStatus.BAD_REQUEST,
684
+ code: 4000, //TBD
685
+ message: 'Date From should not be empty.',
686
+ data: { transactionHistoryDto }
687
+ }, HttpStatus.BAD_REQUEST);
688
+ }
689
+
690
+ if (!fullName) {
691
+ throw new HttpException({
692
+ statusCode: HttpStatus.BAD_REQUEST,
693
+ code: 4000, //TBD
694
+ message: 'Full name should not be empty.',
695
+ data: { transactionHistoryDto }
696
+ }, HttpStatus.BAD_REQUEST);
697
+ }
698
+
699
+ if (!birthDate) {
700
+ throw new HttpException({
701
+ statusCode: HttpStatus.BAD_REQUEST,
702
+ code: 4000, //TBD
703
+ message: 'Birth Date should not be empty.',
704
+ data: { transactionHistoryDto }
705
+ }, HttpStatus.BAD_REQUEST);
706
+ }
707
+
708
+ if (!mobile) {
709
+ throw new HttpException({
710
+ statusCode: HttpStatus.BAD_REQUEST,
711
+ code: 4000, //TBD
712
+ message: 'Mobile number should not be empty.',
713
+ data: { transactionHistoryDto }
714
+ }, HttpStatus.BAD_REQUEST);
715
+ }
716
+
717
+ this.logger.log("MBWIN transaction history");
718
+
719
+ try {
720
+ const headers = {
721
+ 'Authorization': `Bearer ${token}`,
722
+ 'Content-Type': 'application/json',
723
+ };
724
+
725
+ const payload = {
726
+ "dateFrom": dateFrom,
727
+ "dateTo": dateTo,
728
+ "seqRef": page,
729
+ "accountValidation": {
730
+ "acc": account,
731
+ "br": branch,
732
+ "appType": accountType,
733
+ "displayName": fullName,
734
+ "birthDate": birthDate,
735
+ "mobile1": mobile
736
+ }
737
+ }
738
+
739
+ const httpsAgent = new https.Agent({
740
+ rejectUnauthorized: false,
741
+ });
742
+
743
+ const response = await axios.post(
744
+ `${this.config.MBWIN_URL}:${this.config.MBWIN_PORT}/api/mbwin/history`,
745
+ payload,
746
+ {
747
+ headers: headers,
748
+ httpsAgent
749
+ }
750
+ );
751
+
752
+ this.logger.log({ responseData: response.data }, 'MBWIN Transaction History Successful');
753
+
754
+ return {
755
+ success: true,
756
+ ...response.data,
757
+ }
758
+ }
759
+ catch (error) {
760
+ AxiosErrorHelper.handleAxiosError(error);
761
+ }
762
+ }
763
+
764
+ async findAccountDetailsRaw(token: string, userid: number) {
765
+ return "Sorry Service Currently Unavaible";
766
+ }
767
+
768
+ async accountTransfer(token: string, useridFrom: string, useridTo: string, amount: number) {
769
+ return "Sorry Service Currently Unavaible";
770
+ }
771
+
772
+ generateOtp(mobile: string, acc: string, bankid: string): string {
773
+ return "Sorry Service Currently Unavaible";
774
+ }
775
+
776
+ generateRandomOtp(length: number): string {
777
+ return "Sorry Service Currently Unavaible";
778
+ }
779
+ }