@teamdigipay/dgepay-customer-transaction-package 0.0.25 → 0.0.27

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.
@@ -11,177 +11,118 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const axios_1 = require("axios");
13
13
  const utils_1 = require("../utils/utils");
14
- const constants_1 = require("../utils/constants");
15
14
  const APIResponses_1 = require("./APIResponses");
16
15
  const DatadogTxn_1 = require("../utils/DatadogTxn");
17
- const netinfo_1 = require("@react-native-community/netinfo");
18
- const Strings_1 = require("../utils/Strings");
19
- const react_native_1 = require("react-native");
16
+ // import NetInfo, { NetInfoState } from "@react-native-community/netinfo";
20
17
  const CommonConfig_1 = require("../utils/CommonConfig");
21
18
  const index_1 = require("../index");
22
19
  const commonConfig = (0, CommonConfig_1.getCommonConfig)();
23
20
  exports.default = (apiConfig, apiPayload, onSuccess, onFailure) => __awaiter(void 0, void 0, void 0, function* () {
24
21
  var _a, _b, _c, _d;
25
- const isConnected = yield netinfo_1.default.fetch();
26
- console.log('Internet connection', isConnected);
27
- if (!isConnected.isConnected) {
28
- onFailure({
29
- errorMessage: Strings_1.default.PACKAGE_INTERNET_CONNECTION_ERROR_TEXT,
30
- errorCode: constants_1.ERROR_CODE.INTERNET_NOT_AVAILABLE,
31
- success: false
32
- });
33
- console.log('Please, Check your Internet Connection..!!!!!!!!!!!!!!!');
22
+ // const isConnected: NetInfoState = await NetInfo.fetch()
23
+ // console.log('Internet connection', isConnected);
24
+ // if (!isConnected.isConnected) {
25
+ // onFailure({
26
+ // errorMessage: Strings.PACKAGE_INTERNET_CONNECTION_ERROR_TEXT,
27
+ // errorCode: ERROR_CODE.INTERNET_NOT_AVAILABLE,
28
+ // success: false
29
+ // })
30
+ // console.log('Please, Check your Internet Connection..!!!!!!!!!!!!!!!')
31
+ // }
32
+ // else{
33
+ const method = apiConfig.method || "get";
34
+ const companyId = apiConfig.companyId;
35
+ const userOriginalToken = (apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.userOriginalToken) == false ? false : true;
36
+ const token = typeof (apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.token) === "string"
37
+ ? apiConfig.token
38
+ : (_a = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.token) === null || _a === void 0 ? void 0 : _a.token;
39
+ const secret_key = (_b = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.token) === null || _b === void 0 ? void 0 : _b.secret_key;
40
+ const Language = (_c = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.token) === null || _c === void 0 ? void 0 : _c.language;
41
+ const requestId = (0, utils_1.generateUUID)(32);
42
+ const data = apiPayload.data;
43
+ const langugaeCode = apiConfig.languageCode;
44
+ let params = apiPayload.params || {};
45
+ let newParam = data ? data : params;
46
+ let newPayload = Object.assign({ company_id: companyId, request_id: requestId }, newParam);
47
+ (0, utils_1.consoleHelper)('newPayload txn--------------------------------', newPayload);
48
+ let digitalSignature = yield (0, utils_1.createDigitalSignature)(newPayload, secret_key || '');
49
+ console.log("secret_key in Txn Packages ===== >", secret_key, "---- Api_end_point=======>", apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.endPoint);
50
+ console.log("digitalSignature in Txn Packages ===== > ", digitalSignature);
51
+ const endPoint = `${apiConfig.baseURL + apiConfig.endPoint}`;
52
+ let headers = {
53
+ CompanyID: companyId,
54
+ RequestID: requestId,
55
+ signature: digitalSignature,
56
+ Language: langugaeCode
57
+ };
58
+ if (!userOriginalToken) {
59
+ headers["Authorization"] = `Basic ${token}`;
34
60
  }
35
61
  else {
36
- const method = apiConfig.method || "get";
37
- const companyId = apiConfig.companyId;
38
- const token = (_a = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.token) === null || _a === void 0 ? void 0 : _a.token;
39
- const secret_key = (_b = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.token) === null || _b === void 0 ? void 0 : _b.secret_key;
40
- const Language = (_c = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.token) === null || _c === void 0 ? void 0 : _c.language;
41
- const requestId = (0, utils_1.generateUUID)(32);
42
- const data = apiPayload.data;
43
- const langugaeCode = apiConfig.languageCode;
44
- let params = apiPayload.params || {};
45
- let newParam = data ? data : params;
46
- let newPayload = Object.assign({ company_id: companyId, request_id: requestId }, newParam);
47
- (0, utils_1.consoleHelper)('newPayload txn--------------------------------', newPayload);
48
- let digitalSignature = yield (0, utils_1.createDigitalSignature)(newPayload, secret_key || '');
49
- console.log("secret_key in Txn Packages ===== >", secret_key, "---- Api_end_point=======>", apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.endPoint);
50
- console.log("digitalSignature in Txn Packages ===== > ", digitalSignature);
51
- const endPoint = `${apiConfig.baseURL + apiConfig.endPoint}`;
52
- let headers = {
53
- CompanyID: companyId,
54
- RequestID: requestId,
55
- signature: digitalSignature,
56
- Language: langugaeCode
57
- };
58
- if (token) {
59
- headers['Authorization'] = `Token ${token}`;
60
- }
61
- if (apiConfig.headers) {
62
- headers = Object.assign(Object.assign({}, headers), apiConfig.headers);
63
- // if (apiPayload.headersFlutterWave) {
64
- // headers = { ...apiPayload.headersFlutterWave }
65
- // }
66
- }
67
- if ((_d = apiPayload === null || apiPayload === void 0 ? void 0 : apiPayload.data) === null || _d === void 0 ? void 0 : _d._parts) {
68
- headers = Object.assign(Object.assign({}, headers), { "Content-Type": "multipart/form-data" });
69
- }
70
- else if (apiConfig.ContentType === "text/plain") {
71
- headers = Object.assign(Object.assign({}, headers), { "Content-Type": "text/plain" });
72
- }
73
- let config = {
74
- baseURL: endPoint,
75
- timeout: apiConfig.timeout || 6000000000,
76
- headers: headers,
77
- };
78
- console.log("\n_____________payload_____________", apiPayload);
79
- (0, utils_1.consoleHelper)('\n___________params__________________', params);
80
- (0, utils_1.consoleHelper)('\n___________config__________________', config);
81
- (0, utils_1.consoleHelper)('\n___________endPoint__________________', endPoint);
82
- (0, utils_1.consoleHelper)('\n___________method__________________', method);
83
- let request;
84
- switch (method) {
85
- case "post":
86
- request = axios_1.default.post(endPoint, data, config);
87
- break;
88
- case "get":
89
- config = Object.assign(Object.assign({}, config), { params });
90
- request = axios_1.default.get(endPoint, config);
91
- break;
92
- case "delete":
93
- config = Object.assign(Object.assign({}, config), { params });
94
- request = axios_1.default.delete(endPoint, config);
95
- break;
96
- case "put":
97
- request = axios_1.default.put(endPoint, data, config);
98
- break;
99
- case "patch":
100
- request = axios_1.default.patch(endPoint, data, config);
101
- break;
102
- }
103
- yield request
104
- .then((response) => __awaiter(void 0, void 0, void 0, function* () {
105
- (0, utils_1.consoleHelper)('\n___________success__________________', {
106
- response: response === null || response === void 0 ? void 0 : response.data,
107
- status: response === null || response === void 0 ? void 0 : response.status,
108
- config: response === null || response === void 0 ? void 0 : response.config
109
- });
110
- if ((0, utils_1.isNotNull)(response)) {
111
- const status = response.status;
112
- switch (status) {
113
- case (200):
114
- const responseData = response.data;
115
- commonConfig.setItem(commonConfig.SESSION_EXPIRE_VALUE, JSON.stringify(false));
116
- if (response.data.success) {
117
- let successMessage = undefined;
118
- if (response && responseData.data.message) {
119
- successMessage = (0, APIResponses_1.getBackendResponseMessage)(response.data.data.message);
120
- }
121
- DatadogTxn_1.default.info("CUSTOMER TXN API CALL SUCCESS", {
122
- config: {
123
- headers: response.config.headers,
124
- baseURL: response.config.baseURL,
125
- params: response.config.params
126
- },
127
- response: response === null || response === void 0 ? void 0 : response.data,
128
- user_id: commonConfig.getItem(commonConfig.USER_ID),
129
- apiEndPoint: apiConfig.endPoint,
130
- method: method,
131
- RequestID: requestId,
132
- status: status,
133
- params: params,
134
- api_status: status
135
- });
136
- onSuccess({ data: responseData.data, message: successMessage, success: true });
137
- }
138
- else {
139
- const error = response.data.message ||
140
- (response.data.error && response.data.error[0]);
141
- DatadogTxn_1.default.error("CUSTOMER TXN API CALL FAIL", {
142
- config: {
143
- headers: response.config.headers,
144
- baseURL: response.config.baseURL,
145
- params: response.config.params
146
- },
147
- response: response === null || response === void 0 ? void 0 : response.data,
148
- user_id: commonConfig.getItem(commonConfig.USER_ID),
149
- apiEndPoint: apiConfig.endPoint,
150
- method: method,
151
- RequestID: requestId,
152
- status: status,
153
- params: params,
154
- api_status: status
155
- });
156
- onFailure({
157
- errorMessage: (0, APIResponses_1.getBackendResponseMessage)(error),
158
- errorCode: response.data.error_code,
159
- success: false
160
- });
62
+ headers["Authorization"] = `Token ${token}`;
63
+ }
64
+ if (apiConfig.headers) {
65
+ headers = Object.assign(Object.assign({}, headers), apiConfig.headers);
66
+ // if (apiPayload.headersFlutterWave) {
67
+ // headers = { ...apiPayload.headersFlutterWave }
68
+ // }
69
+ }
70
+ if ((_d = apiPayload === null || apiPayload === void 0 ? void 0 : apiPayload.data) === null || _d === void 0 ? void 0 : _d._parts) {
71
+ headers = Object.assign(Object.assign({}, headers), { "Content-Type": "multipart/form-data" });
72
+ }
73
+ else if (apiConfig.ContentType === "text/plain") {
74
+ headers = Object.assign(Object.assign({}, headers), { "Content-Type": "text/plain" });
75
+ }
76
+ let config = {
77
+ baseURL: endPoint,
78
+ timeout: apiConfig.timeout || 6000000000,
79
+ headers: headers,
80
+ };
81
+ console.log("\n_____________payload_____________", apiPayload);
82
+ (0, utils_1.consoleHelper)('\n___________params__________________', params);
83
+ (0, utils_1.consoleHelper)('\n___________config__________________', config);
84
+ (0, utils_1.consoleHelper)('\n___________endPoint__________________', endPoint);
85
+ (0, utils_1.consoleHelper)('\n___________method__________________', method);
86
+ let request;
87
+ switch (method) {
88
+ case "post":
89
+ request = axios_1.default.post(endPoint, data, config);
90
+ break;
91
+ case "get":
92
+ config = Object.assign(Object.assign({}, config), { params });
93
+ request = axios_1.default.get(endPoint, config);
94
+ break;
95
+ case "delete":
96
+ config = Object.assign(Object.assign({}, config), { params });
97
+ request = axios_1.default.delete(endPoint, config);
98
+ break;
99
+ case "put":
100
+ request = axios_1.default.put(endPoint, data, config);
101
+ break;
102
+ case "patch":
103
+ request = axios_1.default.patch(endPoint, data, config);
104
+ break;
105
+ }
106
+ yield request
107
+ .then((response) => __awaiter(void 0, void 0, void 0, function* () {
108
+ var _e, _f, _g;
109
+ (0, utils_1.consoleHelper)('\n___________success__________________', {
110
+ response: response === null || response === void 0 ? void 0 : response.data,
111
+ status: response === null || response === void 0 ? void 0 : response.status,
112
+ config: response === null || response === void 0 ? void 0 : response.config
113
+ });
114
+ if ((0, utils_1.isNotNull)(response)) {
115
+ const status = response.status;
116
+ switch (status) {
117
+ case (200):
118
+ const responseData = response.data;
119
+ commonConfig.setItem(commonConfig.SESSION_EXPIRE_VALUE, JSON.stringify(false));
120
+ if (response.data.success) {
121
+ let successMessage = undefined;
122
+ if (response && responseData.data.message) {
123
+ successMessage = (0, APIResponses_1.getBackendResponseMessage)(response.data.data.message);
161
124
  }
162
- break;
163
- case 401:
164
- onFailure({
165
- errorMessage: "",
166
- errorCode: 401,
167
- success: false
168
- });
169
- yield commonConfig.cleanSession();
170
- commonConfig.resetNavigation(index_1.txnNavigationConstants.LOGIN);
171
- commonConfig.showDangerToast(commonConfig.message);
172
- break;
173
- case (502 || 500 || 503 || 404 || 403):
174
- onFailure({
175
- errorMessage: "",
176
- errorCode: "",
177
- success: false
178
- });
179
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
180
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
181
- ]);
182
- break;
183
- default:
184
- DatadogTxn_1.default.error("CUSTOMER TXN API CALL FAIL", {
125
+ DatadogTxn_1.default.info("CUSTOMER TXN API CALL SUCCESS", {
185
126
  config: {
186
127
  headers: response.config.headers,
187
128
  baseURL: response.config.baseURL,
@@ -196,266 +137,276 @@ exports.default = (apiConfig, apiPayload, onSuccess, onFailure) => __awaiter(voi
196
137
  params: params,
197
138
  api_status: status
198
139
  });
199
- onFailure({
200
- errorMessage: "",
201
- errorCode: "",
202
- success: false
203
- });
204
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
205
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
206
- ]);
207
- }
208
- }
209
- else {
210
- DatadogTxn_1.default.error("CUSTOMER TXN API CALL FAIL", {
211
- config: {
212
- headers: response.config.headers,
213
- baseURL: response.config.baseURL,
214
- params: response.config.params
215
- },
216
- response: response === null || response === void 0 ? void 0 : response.data,
217
- user_id: commonConfig.getItem(commonConfig.USER_ID),
218
- apiEndPoint: apiConfig.endPoint,
219
- method: method,
220
- RequestID: requestId,
221
- status: status,
222
- params: params,
223
- api_status: response === null || response === void 0 ? void 0 : response.status
224
- });
225
- onFailure({
226
- errorMessage: "",
227
- errorCode: "",
228
- success: false
229
- });
230
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
231
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
232
- ]);
233
- }
234
- }))
235
- .catch((error) => __awaiter(void 0, void 0, void 0, function* () {
236
- var _e;
237
- DatadogTxn_1.default.error(`${error}`, {
238
- user_id: commonConfig.getItem(commonConfig.USER_ID),
239
- apiEndPoint: apiConfig.endPoint,
240
- method: method,
241
- config: { config },
242
- params: params,
243
- RequestID: requestId,
244
- api_status: `${error}`
245
- });
246
- (0, utils_1.consoleHelper)('\n___________error__________________', error);
247
- if (error) {
248
- (0, utils_1.consoleHelper)('\n___________error__________________', error === null || error === void 0 ? void 0 : error.response);
249
- if (error === null || error === void 0 ? void 0 : error.response) {
250
- (0, utils_1.consoleHelper)('\n___________error__________________', (_e = error === null || error === void 0 ? void 0 : error.response) === null || _e === void 0 ? void 0 : _e.status);
251
- if (commonConfig.getItem(commonConfig.SESSION_EXPIRE_VALUE) === JSON.stringify(false)) {
252
- switch (error.response.status) {
253
- case 401:
254
- onFailure({
255
- errorMessage: "",
256
- errorCode: 401,
257
- success: false
258
- });
259
- yield commonConfig.cleanSession();
260
- commonConfig.resetNavigation(index_1.txnNavigationConstants.LOGIN);
261
- commonConfig.showDangerToast(commonConfig.message);
262
- break;
263
- case 502:
264
- onFailure({
265
- errorMessage: "",
266
- errorCode: 0,
267
- success: false
268
- });
269
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
270
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
271
- ]);
272
- break;
273
- case 500:
274
- onFailure({
275
- errorMessage: "",
276
- errorCode: 0,
277
- success: false
278
- });
279
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
280
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
281
- ]);
282
- break;
283
- case 503:
284
- onFailure({
285
- errorMessage: "",
286
- errorCode: 0,
287
- success: false
288
- });
289
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
290
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
291
- ]);
292
- break;
293
- case 404:
294
- onFailure({
295
- errorMessage: "",
296
- errorCode: 0,
297
- success: false
298
- });
299
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
300
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
301
- ]);
302
- break;
303
- case 403:
304
- onFailure({
305
- errorMessage: "",
306
- errorCode: 0,
307
- success: false
308
- });
309
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
310
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
311
- ]);
312
- break;
313
- case 504:
314
- onFailure({
315
- errorMessage: "",
316
- errorCode: 0,
317
- success: false
318
- });
319
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
320
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
321
- ]);
322
- break;
323
- default:
324
- DatadogTxn_1.default.error("MERCHANT TXN API CALL FAIL(Error)", {
325
- error: error,
326
- config: { config },
327
- user_id: commonConfig.getItem(commonConfig.USER_ID),
328
- apiEndPoint: apiConfig.endPoint,
329
- method: method,
330
- RequestID: requestId,
331
- status: status,
332
- params: params,
333
- });
334
- onFailure({
335
- errorMessage: "",
336
- errorCode: "",
337
- success: false
338
- });
339
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
340
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
341
- ]);
342
- break;
343
- }
140
+ onSuccess({ data: responseData.data, message: successMessage, success: true });
344
141
  }
345
142
  else {
346
- switch (error.response.status) {
347
- case 502:
348
- onFailure({
349
- errorMessage: "",
350
- errorCode: 0,
351
- success: false
352
- });
353
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
354
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
355
- ]);
356
- break;
357
- case 500:
358
- onFailure({
359
- errorMessage: "",
360
- errorCode: 0,
361
- success: false
362
- });
363
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
364
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
365
- ]);
366
- break;
367
- case 503:
368
- onFailure({
369
- errorMessage: "",
370
- errorCode: 0,
371
- success: false
372
- });
373
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
374
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
375
- ]);
376
- break;
377
- case 404:
378
- onFailure({
379
- errorMessage: "",
380
- errorCode: 0,
381
- success: false
382
- });
383
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
384
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
385
- ]);
386
- break;
387
- case 403:
388
- onFailure({
389
- errorMessage: "",
390
- errorCode: 0,
391
- success: false
392
- });
393
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
394
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
395
- ]);
396
- break;
397
- case 504:
398
- onFailure({
399
- errorMessage: "",
400
- errorCode: 0,
401
- success: false
402
- });
403
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
404
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
405
- ]);
406
- break;
407
- default:
408
- DatadogTxn_1.default.error("MERCHANT TXN API CALL FAIL(Error)", {
409
- error: error,
410
- config: { config },
411
- user_id: commonConfig.getItem(commonConfig.USER_ID),
412
- apiEndPoint: apiConfig.endPoint,
413
- method: method,
414
- RequestID: requestId,
415
- status: status,
416
- params: params,
417
- });
418
- onFailure({
419
- errorMessage: "",
420
- errorCode: "",
421
- success: false
422
- });
423
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
424
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
425
- ]);
426
- break;
427
- }
428
- }
429
- }
430
- else if (error.message) {
431
- if ((error === null || error === void 0 ? void 0 : error.message) === "Network Error") {
143
+ const error = response.data.message ||
144
+ (response.data.error && response.data.error[0]);
145
+ DatadogTxn_1.default.error("CUSTOMER TXN API CALL FAIL", {
146
+ config: {
147
+ headers: response.config.headers,
148
+ baseURL: response.config.baseURL,
149
+ params: response.config.params
150
+ },
151
+ response: response === null || response === void 0 ? void 0 : response.data,
152
+ user_id: commonConfig.getItem(commonConfig.USER_ID),
153
+ apiEndPoint: apiConfig.endPoint,
154
+ method: method,
155
+ RequestID: requestId,
156
+ status: status,
157
+ params: params,
158
+ api_status: status
159
+ });
432
160
  onFailure({
433
- errorMessage: "",
434
- errorCode: "",
161
+ errorMessage: (0, APIResponses_1.getBackendResponseMessage)(error),
162
+ errorCode: response.data.error_code,
435
163
  success: false
436
164
  });
437
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
438
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
439
- ]);
440
- return;
441
165
  }
442
- DatadogTxn_1.default.error("CUSTOMER TXN API CALL FAIL(Error)", {
443
- error: error,
444
- config: { config },
166
+ break;
167
+ case 401:
168
+ onFailure({
169
+ errorMessage: "",
170
+ errorCode: 401,
171
+ success: false
172
+ });
173
+ yield commonConfig.cleanSession();
174
+ commonConfig.resetNavigation(index_1.txnNavigationConstants.LOGIN);
175
+ commonConfig.showDangerToast(commonConfig.message);
176
+ break;
177
+ case (502 || 500 || 503 || 404 || 403):
178
+ onFailure({
179
+ errorMessage: "",
180
+ errorCode: "",
181
+ success: false
182
+ });
183
+ (_e = commonConfig.callBack) === null || _e === void 0 ? void 0 : _e.call(commonConfig, 'system_under_maintenance');
184
+ break;
185
+ default:
186
+ DatadogTxn_1.default.error("CUSTOMER TXN API CALL FAIL", {
187
+ config: {
188
+ headers: response.config.headers,
189
+ baseURL: response.config.baseURL,
190
+ params: response.config.params
191
+ },
192
+ response: response === null || response === void 0 ? void 0 : response.data,
445
193
  user_id: commonConfig.getItem(commonConfig.USER_ID),
446
194
  apiEndPoint: apiConfig.endPoint,
447
195
  method: method,
448
196
  RequestID: requestId,
449
197
  status: status,
450
198
  params: params,
199
+ api_status: status
451
200
  });
452
201
  onFailure({
453
- errorMessage: "CUSTOMER_APP_SOMETHING_WENT_WRONG",
454
- errorCode: 0,
202
+ errorMessage: "",
203
+ errorCode: "",
204
+ success: false
455
205
  });
206
+ (_f = commonConfig.callBack) === null || _f === void 0 ? void 0 : _f.call(commonConfig, 'system_under_maintenance');
207
+ }
208
+ }
209
+ else {
210
+ DatadogTxn_1.default.error("CUSTOMER TXN API CALL FAIL", {
211
+ config: {
212
+ headers: response.config.headers,
213
+ baseURL: response.config.baseURL,
214
+ params: response.config.params
215
+ },
216
+ response: response === null || response === void 0 ? void 0 : response.data,
217
+ user_id: commonConfig.getItem(commonConfig.USER_ID),
218
+ apiEndPoint: apiConfig.endPoint,
219
+ method: method,
220
+ RequestID: requestId,
221
+ status: status,
222
+ params: params,
223
+ api_status: response === null || response === void 0 ? void 0 : response.status
224
+ });
225
+ onFailure({
226
+ errorMessage: "",
227
+ errorCode: "",
228
+ success: false
229
+ });
230
+ (_g = commonConfig.callBack) === null || _g === void 0 ? void 0 : _g.call(commonConfig, 'system_under_maintenance');
231
+ }
232
+ }))
233
+ .catch((error) => __awaiter(void 0, void 0, void 0, function* () {
234
+ var _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
235
+ DatadogTxn_1.default.error(`${error}`, {
236
+ user_id: commonConfig.getItem(commonConfig.USER_ID),
237
+ apiEndPoint: apiConfig.endPoint,
238
+ method: method,
239
+ config: { config },
240
+ params: params,
241
+ RequestID: requestId,
242
+ api_status: `${error}`
243
+ });
244
+ (0, utils_1.consoleHelper)('\n___________error__________________', error);
245
+ if (error) {
246
+ (0, utils_1.consoleHelper)('\n___________error__________________', error === null || error === void 0 ? void 0 : error.response);
247
+ if (error === null || error === void 0 ? void 0 : error.response) {
248
+ (0, utils_1.consoleHelper)('\n___________error__________________', (_h = error === null || error === void 0 ? void 0 : error.response) === null || _h === void 0 ? void 0 : _h.status);
249
+ if (commonConfig.getItem(commonConfig.SESSION_EXPIRE_VALUE) === JSON.stringify(false)) {
250
+ switch (error.response.status) {
251
+ case 401:
252
+ onFailure({
253
+ errorMessage: "",
254
+ errorCode: 401,
255
+ success: false
256
+ });
257
+ yield commonConfig.cleanSession();
258
+ commonConfig.resetNavigation(index_1.txnNavigationConstants.LOGIN);
259
+ commonConfig.showDangerToast(commonConfig.message);
260
+ break;
261
+ case 502:
262
+ onFailure({
263
+ errorMessage: "",
264
+ errorCode: 0,
265
+ success: false
266
+ });
267
+ (_j = commonConfig.callBack) === null || _j === void 0 ? void 0 : _j.call(commonConfig, 'system_under_maintenance');
268
+ break;
269
+ case 500:
270
+ onFailure({
271
+ errorMessage: "",
272
+ errorCode: 0,
273
+ success: false
274
+ });
275
+ (_k = commonConfig.callBack) === null || _k === void 0 ? void 0 : _k.call(commonConfig, 'system_under_maintenance');
276
+ break;
277
+ case 503:
278
+ onFailure({
279
+ errorMessage: "",
280
+ errorCode: 0,
281
+ success: false
282
+ });
283
+ (_l = commonConfig.callBack) === null || _l === void 0 ? void 0 : _l.call(commonConfig, 'system_under_maintenance');
284
+ break;
285
+ case 404:
286
+ onFailure({
287
+ errorMessage: "",
288
+ errorCode: 0,
289
+ success: false
290
+ });
291
+ (_m = commonConfig.callBack) === null || _m === void 0 ? void 0 : _m.call(commonConfig, 'system_under_maintenance');
292
+ break;
293
+ case 403:
294
+ onFailure({
295
+ errorMessage: "",
296
+ errorCode: 0,
297
+ success: false
298
+ });
299
+ (_o = commonConfig.callBack) === null || _o === void 0 ? void 0 : _o.call(commonConfig, 'system_under_maintenance');
300
+ break;
301
+ case 504:
302
+ onFailure({
303
+ errorMessage: "",
304
+ errorCode: 0,
305
+ success: false
306
+ });
307
+ (_p = commonConfig.callBack) === null || _p === void 0 ? void 0 : _p.call(commonConfig, 'system_under_maintenance');
308
+ break;
309
+ default:
310
+ DatadogTxn_1.default.error("MERCHANT TXN API CALL FAIL(Error)", {
311
+ error: error,
312
+ config: { config },
313
+ user_id: commonConfig.getItem(commonConfig.USER_ID),
314
+ apiEndPoint: apiConfig.endPoint,
315
+ method: method,
316
+ RequestID: requestId,
317
+ status: status,
318
+ params: params,
319
+ });
320
+ onFailure({
321
+ errorMessage: "",
322
+ errorCode: "",
323
+ success: false
324
+ });
325
+ (_q = commonConfig.callBack) === null || _q === void 0 ? void 0 : _q.call(commonConfig, 'system_under_maintenance');
326
+ break;
327
+ }
328
+ }
329
+ else {
330
+ switch (error.response.status) {
331
+ case 502:
332
+ onFailure({
333
+ errorMessage: "",
334
+ errorCode: 0,
335
+ success: false
336
+ });
337
+ (_r = commonConfig.callBack) === null || _r === void 0 ? void 0 : _r.call(commonConfig, 'system_under_maintenance');
338
+ break;
339
+ case 500:
340
+ onFailure({
341
+ errorMessage: "",
342
+ errorCode: 0,
343
+ success: false
344
+ });
345
+ (_s = commonConfig.callBack) === null || _s === void 0 ? void 0 : _s.call(commonConfig, 'system_under_maintenance');
346
+ break;
347
+ case 503:
348
+ onFailure({
349
+ errorMessage: "",
350
+ errorCode: 0,
351
+ success: false
352
+ });
353
+ (_t = commonConfig.callBack) === null || _t === void 0 ? void 0 : _t.call(commonConfig, 'system_under_maintenance');
354
+ break;
355
+ case 404:
356
+ onFailure({
357
+ errorMessage: "",
358
+ errorCode: 0,
359
+ success: false
360
+ });
361
+ (_u = commonConfig.callBack) === null || _u === void 0 ? void 0 : _u.call(commonConfig, 'system_under_maintenance');
362
+ break;
363
+ case 403:
364
+ onFailure({
365
+ errorMessage: "",
366
+ errorCode: 0,
367
+ success: false
368
+ });
369
+ (_v = commonConfig.callBack) === null || _v === void 0 ? void 0 : _v.call(commonConfig, 'system_under_maintenance');
370
+ break;
371
+ case 504:
372
+ onFailure({
373
+ errorMessage: "",
374
+ errorCode: 0,
375
+ success: false
376
+ });
377
+ (_w = commonConfig.callBack) === null || _w === void 0 ? void 0 : _w.call(commonConfig, 'system_under_maintenance');
378
+ break;
379
+ default:
380
+ DatadogTxn_1.default.error("MERCHANT TXN API CALL FAIL(Error)", {
381
+ error: error,
382
+ config: { config },
383
+ user_id: commonConfig.getItem(commonConfig.USER_ID),
384
+ apiEndPoint: apiConfig.endPoint,
385
+ method: method,
386
+ RequestID: requestId,
387
+ status: status,
388
+ params: params,
389
+ });
390
+ onFailure({
391
+ errorMessage: "",
392
+ errorCode: "",
393
+ success: false
394
+ });
395
+ (_x = commonConfig.callBack) === null || _x === void 0 ? void 0 : _x.call(commonConfig, 'system_under_maintenance');
396
+ break;
397
+ }
456
398
  }
457
399
  }
458
- else {
400
+ else if (error.message) {
401
+ if ((error === null || error === void 0 ? void 0 : error.message) === "Network Error") {
402
+ onFailure({
403
+ errorMessage: "",
404
+ errorCode: "",
405
+ success: false
406
+ });
407
+ (_y = commonConfig.callBack) === null || _y === void 0 ? void 0 : _y.call(commonConfig, 'no_internet_connection');
408
+ return;
409
+ }
459
410
  DatadogTxn_1.default.error("CUSTOMER TXN API CALL FAIL(Error)", {
460
411
  error: error,
461
412
  config: { config },
@@ -471,6 +422,23 @@ exports.default = (apiConfig, apiPayload, onSuccess, onFailure) => __awaiter(voi
471
422
  errorCode: 0,
472
423
  });
473
424
  }
474
- }));
475
- }
425
+ }
426
+ else {
427
+ DatadogTxn_1.default.error("CUSTOMER TXN API CALL FAIL(Error)", {
428
+ error: error,
429
+ config: { config },
430
+ user_id: commonConfig.getItem(commonConfig.USER_ID),
431
+ apiEndPoint: apiConfig.endPoint,
432
+ method: method,
433
+ RequestID: requestId,
434
+ status: status,
435
+ params: params,
436
+ });
437
+ onFailure({
438
+ errorMessage: "CUSTOMER_APP_SOMETHING_WENT_WRONG",
439
+ errorCode: 0,
440
+ });
441
+ }
442
+ }));
443
+ // }
476
444
  });