@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,574 @@
|
|
|
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
|
+
@Injectable()
|
|
14
|
+
export class ASPACService implements BankService {
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
@Inject(BANKING_CONFIG)
|
|
18
|
+
private readonly config: BankingConfig,
|
|
19
|
+
private readonly logger: Logger
|
|
20
|
+
) {
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async generateToken(): Promise<any> {
|
|
24
|
+
|
|
25
|
+
this.logger.log("Generating WelcomeBank Token");
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
const headers = {
|
|
29
|
+
'Content-Type': 'application/json',
|
|
30
|
+
'X-API-KEY': `${this.config.ASPAC_API_KEY}`,
|
|
31
|
+
'X-API-VERSION': `${this.config.ASPAC_VERSION_KEY}`
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const httpsAgent = new https.Agent({
|
|
35
|
+
rejectUnauthorized: false,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const response = await axios.get(
|
|
39
|
+
`${this.config.ASPAC_URL}/api/v1/token/generate`,
|
|
40
|
+
{
|
|
41
|
+
headers: headers,
|
|
42
|
+
httpsAgent,
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
this.logger.log({ responseData: response }, 'Welcome Bank 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
|
+
if (!refreshToken) {
|
|
61
|
+
throw new HttpException({
|
|
62
|
+
statusCode: HttpStatus.BAD_REQUEST,
|
|
63
|
+
code: 4000, //TBD
|
|
64
|
+
message: 'Bank token should not be empty.',
|
|
65
|
+
data: { refreshToken }
|
|
66
|
+
}, HttpStatus.BAD_REQUEST);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
this.logger.log("Welcome Bank refresh token");
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
const headers = {
|
|
73
|
+
'Content-Type': 'application/json',
|
|
74
|
+
'X-API-KEY': `${this.config.ASPAC_API_KEY}`,
|
|
75
|
+
'X-API-VERSION': `${this.config.ASPAC_VERSION_KEY}`
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const payload = {
|
|
79
|
+
"refreshtoken": refreshToken
|
|
80
|
+
}
|
|
81
|
+
const httpsAgent = new https.Agent({
|
|
82
|
+
rejectUnauthorized: false,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const response = await axios.post(
|
|
86
|
+
`${this.config.ASPAC_URL}/api/v1/token/refresh`,
|
|
87
|
+
payload,
|
|
88
|
+
{
|
|
89
|
+
headers: headers,
|
|
90
|
+
httpsAgent,
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
this.logger.log({ responseData: response }, 'Welcome Bank Refresh Token Successful');
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
success: true,
|
|
98
|
+
...response.data,
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
} catch (error) {
|
|
102
|
+
AxiosErrorHelper.handleAxiosError(error);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async linkAccount(accountDto: AccountDto) {
|
|
107
|
+
|
|
108
|
+
const { token, account, accountType, mobile } = accountDto;
|
|
109
|
+
|
|
110
|
+
if (!token) {
|
|
111
|
+
throw new HttpException({
|
|
112
|
+
statusCode: HttpStatus.UNAUTHORIZED,
|
|
113
|
+
code: 4000, //TBD
|
|
114
|
+
message: 'Bank token should not be empty.',
|
|
115
|
+
data: { accountDto }
|
|
116
|
+
}, HttpStatus.UNAUTHORIZED);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (!account) {
|
|
120
|
+
throw new HttpException({
|
|
121
|
+
statusCode: HttpStatus.BAD_REQUEST,
|
|
122
|
+
code: 4000, //TBD
|
|
123
|
+
message: 'Bank account number should not be empty.',
|
|
124
|
+
data: { accountDto }
|
|
125
|
+
}, HttpStatus.BAD_REQUEST);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (!accountType) {
|
|
129
|
+
throw new HttpException({
|
|
130
|
+
statusCode: HttpStatus.BAD_REQUEST,
|
|
131
|
+
code: 4000, //TBD
|
|
132
|
+
message: 'Bank account type should not be empty.',
|
|
133
|
+
data: { accountDto }
|
|
134
|
+
}, HttpStatus.BAD_REQUEST);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (!mobile) {
|
|
138
|
+
throw new HttpException({
|
|
139
|
+
statusCode: HttpStatus.BAD_REQUEST,
|
|
140
|
+
code: 4000, //TBD
|
|
141
|
+
message: 'Mobile Number should not be empty.',
|
|
142
|
+
data: { accountDto }
|
|
143
|
+
}, HttpStatus.BAD_REQUEST);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
this.logger.log("Welcome Bank Link Account");
|
|
147
|
+
|
|
148
|
+
try {
|
|
149
|
+
const headers = {
|
|
150
|
+
'Authorization': `Bearer ${token}`,
|
|
151
|
+
'Content-Type': 'application/json',
|
|
152
|
+
'X-API-KEY': `${this.config.ASPAC_API_KEY}`,
|
|
153
|
+
'X-API-VERSION': `${this.config.ASPAC_VERSION_KEY}`
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const httpsAgent = new https.Agent({
|
|
157
|
+
rejectUnauthorized: false,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const response = await axios.get(
|
|
161
|
+
`${this.config.ASPAC_URL}/api/v1/linkaccount?acc=${account}&accType=${accountType}&mobile=${mobile}`,
|
|
162
|
+
{
|
|
163
|
+
headers: headers,
|
|
164
|
+
httpsAgent
|
|
165
|
+
}
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
this.logger.log({ responseData: response }, 'Welcome Bank Link Account Successful');
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
success: true,
|
|
172
|
+
...response.data,
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
AxiosErrorHelper.handleAxiosError(error);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async validateOtp(validateOtp: ValidateOtp): Promise<any> {
|
|
181
|
+
|
|
182
|
+
const { token, account, otp } = validateOtp;
|
|
183
|
+
|
|
184
|
+
if (!token) {
|
|
185
|
+
throw new HttpException({
|
|
186
|
+
statusCode: HttpStatus.UNAUTHORIZED,
|
|
187
|
+
code: 4000, //TBD
|
|
188
|
+
message: 'Bank token should not be empty.',
|
|
189
|
+
data: { validateOtp }
|
|
190
|
+
}, HttpStatus.UNAUTHORIZED);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (!account) {
|
|
194
|
+
throw new HttpException({
|
|
195
|
+
statusCode: HttpStatus.BAD_REQUEST,
|
|
196
|
+
code: 4000, //TBD
|
|
197
|
+
message: 'Bank account number should not be empty.',
|
|
198
|
+
data: { validateOtp }
|
|
199
|
+
}, HttpStatus.BAD_REQUEST);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (!otp) {
|
|
203
|
+
throw new HttpException({
|
|
204
|
+
statusCode: HttpStatus.BAD_REQUEST,
|
|
205
|
+
code: 4000, //TBD
|
|
206
|
+
message: 'Bank account number should not be empty.',
|
|
207
|
+
data: { validateOtp }
|
|
208
|
+
}, HttpStatus.BAD_REQUEST);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
this.logger.log("Welcome Bank Validate OTP");
|
|
213
|
+
|
|
214
|
+
try {
|
|
215
|
+
const headers = {
|
|
216
|
+
'Authorization': `Bearer ${token}`,
|
|
217
|
+
'Content-Type': 'application/json',
|
|
218
|
+
'X-API-KEY': `${this.config.ASPAC_API_KEY}`,
|
|
219
|
+
'X-API-VERSION': `${this.config.ASPAC_VERSION_KEY}`
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const payload = {
|
|
223
|
+
"acc": account,
|
|
224
|
+
"otp": otp
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const httpsAgent = new https.Agent({
|
|
228
|
+
rejectUnauthorized: false,
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
const response = await axios.post(
|
|
232
|
+
`${this.config.ASPAC_URL}/api/v1/validateotp`,
|
|
233
|
+
payload,
|
|
234
|
+
{
|
|
235
|
+
headers: headers,
|
|
236
|
+
httpsAgent
|
|
237
|
+
}
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
this.logger.log({ responseData: response }, 'Welcome Bank Validate OTP Successful');
|
|
241
|
+
|
|
242
|
+
return {
|
|
243
|
+
success: true,
|
|
244
|
+
...response.data,
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
}
|
|
248
|
+
catch (error) {
|
|
249
|
+
AxiosErrorHelper.handleAxiosError(error);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async processBalanceTransaction(fetchBalanceDto: FetchBankBalanceDto): Promise<any> {
|
|
254
|
+
|
|
255
|
+
const { token, account } = fetchBalanceDto;
|
|
256
|
+
|
|
257
|
+
if (!token) {
|
|
258
|
+
throw new HttpException({
|
|
259
|
+
statusCode: HttpStatus.UNAUTHORIZED,
|
|
260
|
+
code: 4000, //TBD
|
|
261
|
+
message: 'Bank token should not be empty.',
|
|
262
|
+
data: { fetchBalanceDto }
|
|
263
|
+
}, HttpStatus.UNAUTHORIZED);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (!account) {
|
|
267
|
+
throw new HttpException({
|
|
268
|
+
statusCode: HttpStatus.BAD_REQUEST,
|
|
269
|
+
code: 4000, //TBD
|
|
270
|
+
message: 'Bank account number should not be empty.',
|
|
271
|
+
data: { fetchBalanceDto }
|
|
272
|
+
}, HttpStatus.BAD_REQUEST);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
this.logger.log("Welcome Bank Balance Inquiry");
|
|
276
|
+
|
|
277
|
+
try {
|
|
278
|
+
const headers = {
|
|
279
|
+
'Authorization': `Bearer ${token}`,
|
|
280
|
+
'Content-Type': 'application/json',
|
|
281
|
+
'X-API-KEY': `${this.config.ASPAC_API_KEY}`,
|
|
282
|
+
'X-API-VERSION': `${this.config.ASPAC_VERSION_KEY}`
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
const payload = {
|
|
286
|
+
"acc": account,
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const httpsAgent = new https.Agent({
|
|
290
|
+
rejectUnauthorized: false,
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
const response = await axios.post(
|
|
294
|
+
`${this.config.ASPAC_URL}/api/v1/balanceinquiry`,
|
|
295
|
+
payload,
|
|
296
|
+
{
|
|
297
|
+
headers: headers,
|
|
298
|
+
httpsAgent
|
|
299
|
+
}
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
this.logger.log({ responseData: response }, 'Welcome Bank Balance Inquiry Successful');
|
|
303
|
+
|
|
304
|
+
return {
|
|
305
|
+
success: true,
|
|
306
|
+
...response.data,
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
catch (error) {
|
|
310
|
+
AxiosErrorHelper.handleAxiosError(error);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
async accountCashIn(accountTransferDto: AccountTransferDto): Promise<any> {
|
|
315
|
+
|
|
316
|
+
const { token, sourceAccount, amount, particulars } = accountTransferDto;
|
|
317
|
+
|
|
318
|
+
if (!token) {
|
|
319
|
+
throw new HttpException({
|
|
320
|
+
statusCode: HttpStatus.UNAUTHORIZED,
|
|
321
|
+
code: 4000, //TBD
|
|
322
|
+
message: 'Bank token should not be empty.',
|
|
323
|
+
data: { accountTransferDto }
|
|
324
|
+
}, HttpStatus.UNAUTHORIZED);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (!sourceAccount) {
|
|
328
|
+
throw new HttpException({
|
|
329
|
+
statusCode: HttpStatus.BAD_REQUEST,
|
|
330
|
+
code: 4000, //TBD
|
|
331
|
+
message: 'Bank source account number should not be empty.',
|
|
332
|
+
data: { accountTransferDto }
|
|
333
|
+
}, HttpStatus.BAD_REQUEST);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (!amount) {
|
|
337
|
+
throw new HttpException({
|
|
338
|
+
statusCode: HttpStatus.BAD_REQUEST,
|
|
339
|
+
code: 4000, //TBD
|
|
340
|
+
message: 'Amount should not be empty.',
|
|
341
|
+
data: { accountTransferDto }
|
|
342
|
+
}, HttpStatus.BAD_REQUEST);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (!particulars) {
|
|
346
|
+
throw new HttpException({
|
|
347
|
+
statusCode: HttpStatus.BAD_REQUEST,
|
|
348
|
+
code: 4000, //TBD
|
|
349
|
+
message: 'Particulars should not be empty.',
|
|
350
|
+
data: { accountTransferDto }
|
|
351
|
+
}, HttpStatus.BAD_REQUEST);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
this.logger.log("Welcome Bank cash in");
|
|
355
|
+
|
|
356
|
+
try {
|
|
357
|
+
const headers = {
|
|
358
|
+
'Authorization': `Bearer ${token}`,
|
|
359
|
+
'Content-Type': 'application/json',
|
|
360
|
+
'X-API-KEY': `${this.config.ASPAC_API_KEY}`,
|
|
361
|
+
'X-API-VERSION': `${this.config.ASPAC_VERSION_KEY}`
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
const payload = {
|
|
365
|
+
"acc": sourceAccount,
|
|
366
|
+
"amount": String(amount),
|
|
367
|
+
"particulars": particulars
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const httpsAgent = new https.Agent({
|
|
371
|
+
rejectUnauthorized: false,
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
const response = await axios.post(
|
|
375
|
+
`${this.config.ASPAC_URL}/api/v1/cashin`,
|
|
376
|
+
payload,
|
|
377
|
+
{
|
|
378
|
+
headers: headers,
|
|
379
|
+
httpsAgent
|
|
380
|
+
}
|
|
381
|
+
);
|
|
382
|
+
|
|
383
|
+
this.logger.log({ responseData: response }, 'Welcome Bank Cash In Successful');
|
|
384
|
+
|
|
385
|
+
return {
|
|
386
|
+
success: true,
|
|
387
|
+
...response.data,
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
catch (error) {
|
|
391
|
+
AxiosErrorHelper.handleAxiosError(error);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
async accountDeposit(accountTransferDto: AccountTransferDto): Promise<any> {
|
|
396
|
+
|
|
397
|
+
const { token, destinationAccount, amount, particulars } = accountTransferDto;
|
|
398
|
+
|
|
399
|
+
if (!token) {
|
|
400
|
+
throw new HttpException({
|
|
401
|
+
statusCode: HttpStatus.UNAUTHORIZED,
|
|
402
|
+
code: 4000, //TBD
|
|
403
|
+
message: 'Bank token should not be empty.',
|
|
404
|
+
data: { accountTransferDto }
|
|
405
|
+
}, HttpStatus.UNAUTHORIZED);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (!destinationAccount) {
|
|
409
|
+
throw new HttpException({
|
|
410
|
+
statusCode: HttpStatus.BAD_REQUEST,
|
|
411
|
+
code: 4000, //TBD
|
|
412
|
+
message: 'Bank destination account number should not be empty.',
|
|
413
|
+
data: { accountTransferDto }
|
|
414
|
+
}, HttpStatus.BAD_REQUEST);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
if (!amount) {
|
|
418
|
+
throw new HttpException({
|
|
419
|
+
statusCode: HttpStatus.BAD_REQUEST,
|
|
420
|
+
code: 4000, //TBD
|
|
421
|
+
message: 'amount should not be empty.',
|
|
422
|
+
data: { accountTransferDto }
|
|
423
|
+
}, HttpStatus.BAD_REQUEST);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
if (!particulars) {
|
|
427
|
+
throw new HttpException({
|
|
428
|
+
statusCode: HttpStatus.BAD_REQUEST,
|
|
429
|
+
code: 4000, //TBD
|
|
430
|
+
message: 'Particulars should not be empty.',
|
|
431
|
+
data: { accountTransferDto }
|
|
432
|
+
}, HttpStatus.BAD_REQUEST);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
this.logger.log("Welcome Bank deposit");
|
|
436
|
+
|
|
437
|
+
try {
|
|
438
|
+
const headers = {
|
|
439
|
+
'Authorization': `Bearer ${token}`,
|
|
440
|
+
'Content-Type': 'application/json',
|
|
441
|
+
'X-API-KEY': `${this.config.ASPAC_API_KEY}`,
|
|
442
|
+
'X-API-VERSION': `${this.config.ASPAC_VERSION_KEY}`
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
const payload = {
|
|
446
|
+
"acc": destinationAccount,
|
|
447
|
+
"amount": String(amount),
|
|
448
|
+
"particulars": particulars
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
const httpsAgent = new https.Agent({
|
|
452
|
+
rejectUnauthorized: false,
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
const response = await axios.post(
|
|
456
|
+
`${this.config.ASPAC_URL}/api/v1/customerdeposit`,
|
|
457
|
+
payload,
|
|
458
|
+
{
|
|
459
|
+
headers: headers,
|
|
460
|
+
httpsAgent
|
|
461
|
+
}
|
|
462
|
+
);
|
|
463
|
+
|
|
464
|
+
this.logger.log({ responseData: response.data }, 'Welcom Bank Deposit Successful');
|
|
465
|
+
|
|
466
|
+
return {
|
|
467
|
+
success: true,
|
|
468
|
+
...response.data,
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
catch (error) {
|
|
472
|
+
AxiosErrorHelper.handleAxiosError(error);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
async getTransactionHistory(transactionHistoryDto: TransactionHistoryDto) {
|
|
477
|
+
|
|
478
|
+
const { token, account, dateFrom, dateTo, page } = transactionHistoryDto;
|
|
479
|
+
|
|
480
|
+
if (!token) {
|
|
481
|
+
throw new HttpException({
|
|
482
|
+
statusCode: HttpStatus.UNAUTHORIZED,
|
|
483
|
+
code: 4000, //TBD
|
|
484
|
+
message: 'Bank token should not be empty.',
|
|
485
|
+
data: { transactionHistoryDto }
|
|
486
|
+
}, HttpStatus.UNAUTHORIZED);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
if (!account) {
|
|
490
|
+
throw new HttpException({
|
|
491
|
+
statusCode: HttpStatus.BAD_REQUEST,
|
|
492
|
+
code: 4000, //TBD
|
|
493
|
+
message: 'Bank account number should not be empty.',
|
|
494
|
+
data: { transactionHistoryDto }
|
|
495
|
+
}, HttpStatus.BAD_REQUEST);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
if (!dateFrom) {
|
|
499
|
+
throw new HttpException({
|
|
500
|
+
statusCode: HttpStatus.BAD_REQUEST,
|
|
501
|
+
code: 4000, //TBD
|
|
502
|
+
message: 'Date From should not be empty.',
|
|
503
|
+
data: { transactionHistoryDto }
|
|
504
|
+
}, HttpStatus.BAD_REQUEST);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
if (!dateTo) {
|
|
508
|
+
throw new HttpException({
|
|
509
|
+
statusCode: HttpStatus.BAD_REQUEST,
|
|
510
|
+
code: 4000, //TBD
|
|
511
|
+
message: 'Date From should not be empty.',
|
|
512
|
+
data: { transactionHistoryDto }
|
|
513
|
+
}, HttpStatus.BAD_REQUEST);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
this.logger.log("Welcome Bank transaction history");
|
|
518
|
+
|
|
519
|
+
try {
|
|
520
|
+
const headers = {
|
|
521
|
+
'Authorization': `Bearer ${token}`,
|
|
522
|
+
'Content-Type': 'application/json',
|
|
523
|
+
'X-API-KEY': `${this.config.ASPAC_API_KEY}`,
|
|
524
|
+
'X-API-VERSION': `${this.config.ASPAC_VERSION_KEY}`
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
const payload = {
|
|
528
|
+
"acc": account,
|
|
529
|
+
"dateFrom": dateFrom,
|
|
530
|
+
"dateTo": dateTo,
|
|
531
|
+
"pageNo": page
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
const httpsAgent = new https.Agent({
|
|
535
|
+
rejectUnauthorized: false,
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
const response = await axios.post(
|
|
539
|
+
`${this.config.ASPAC_URL}/api/v1/transhistory`,
|
|
540
|
+
payload,
|
|
541
|
+
{
|
|
542
|
+
headers: headers,
|
|
543
|
+
httpsAgent
|
|
544
|
+
}
|
|
545
|
+
);
|
|
546
|
+
|
|
547
|
+
this.logger.log({ responseData: response.data }, 'Welcome Bank Transaction History Successful');
|
|
548
|
+
|
|
549
|
+
return {
|
|
550
|
+
success: true,
|
|
551
|
+
...response.data,
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
catch (error) {
|
|
555
|
+
AxiosErrorHelper.handleAxiosError(error);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
async findAccountDetailsRaw(token: string, userid: number) {
|
|
560
|
+
return "Sorry Service Currently Unavaible";
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
async accountTransfer(token: string, useridFrom: string, useridTo: string, amount: number) {
|
|
564
|
+
return "Sorry Service Currently Unavaible";
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
generateOtp(mobile: string, acc: string, bankid: string): string {
|
|
568
|
+
return "Sorry Service Currently Unavaible";
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
generateRandomOtp(length: number): string {
|
|
572
|
+
return "Sorry Service Currently Unavaible";
|
|
573
|
+
}
|
|
574
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { BankStrategyFactory } from '../factory/bank-strategy.factory';
|
|
3
|
+
import { FetchBankBalanceDto } from '../dto/fetch-bank-balance.dto';
|
|
4
|
+
import { AccountDto, ValidateOtp } from '../dto/account.dto';
|
|
5
|
+
import { TransactionHistoryDto } from '../dto/transaction-history.dto';
|
|
6
|
+
import { AccountTransferDto } from '../dto/account-transfer.dto';
|
|
7
|
+
|
|
8
|
+
@Injectable()
|
|
9
|
+
export class BankingGatewayService {
|
|
10
|
+
constructor(private readonly factory: BankStrategyFactory) {}
|
|
11
|
+
|
|
12
|
+
async getAccessToken(bankId: string): Promise<any> {
|
|
13
|
+
const service = this.factory.getBankService(bankId);
|
|
14
|
+
const token = await service.generateToken();
|
|
15
|
+
return token;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async getRefreshToken(bankId: string, refreshToken: string): Promise<any> {
|
|
19
|
+
const service = this.factory.getBankService(bankId);
|
|
20
|
+
return await service.refreshToken(refreshToken);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async linkAccount(accountDto: AccountDto): Promise<any> {
|
|
24
|
+
const { bankId } = accountDto;
|
|
25
|
+
const service = this.factory.getBankService(bankId);
|
|
26
|
+
const response = await service.linkAccount(accountDto);
|
|
27
|
+
return response;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async validateOtp(validateOtp: ValidateOtp): Promise<any> {
|
|
31
|
+
const { bankId } = validateOtp;
|
|
32
|
+
const service = this.factory.getBankService(bankId);
|
|
33
|
+
const response = service.validateOtp(validateOtp);
|
|
34
|
+
return response;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async fetchBankBalance(fetchBankBalanceDto: FetchBankBalanceDto): Promise<any> {
|
|
38
|
+
const { bankId } = fetchBankBalanceDto;
|
|
39
|
+
const service = this.factory.getBankService(bankId);
|
|
40
|
+
const balance = await service.processBalanceTransaction(fetchBankBalanceDto);
|
|
41
|
+
return balance;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async accountCashIn(accountTransferDto: AccountTransferDto): Promise<any> {
|
|
45
|
+
const { bankId } = accountTransferDto;
|
|
46
|
+
const service = this.factory.getBankService(bankId);
|
|
47
|
+
const response = await service.accountCashIn(accountTransferDto);
|
|
48
|
+
return response;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async accountDeposit(accountTransferDto: AccountTransferDto): Promise<any> {
|
|
52
|
+
const { bankId } = accountTransferDto;
|
|
53
|
+
const service = this.factory.getBankService(bankId);
|
|
54
|
+
const response = await service.accountDeposit(accountTransferDto);
|
|
55
|
+
return response;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async getTransactionHistory(transactionHistoryDto: TransactionHistoryDto): Promise<any> {
|
|
59
|
+
const { bankId } = transactionHistoryDto;
|
|
60
|
+
const service = this.factory.getBankService(bankId);
|
|
61
|
+
const response = await service.getTransactionHistory(transactionHistoryDto);
|
|
62
|
+
return response;
|
|
63
|
+
}
|
|
64
|
+
}
|