@teamdigipay/dgepay-customer-transaction-package 0.0.26 → 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,179 +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
- apiPayload: apiPayload
136
- });
137
- onSuccess({ data: responseData.data, message: successMessage, success: true });
138
- }
139
- else {
140
- const error = response.data.message ||
141
- (response.data.error && response.data.error[0]);
142
- DatadogTxn_1.default.error("CUSTOMER TXN API CALL FAIL", {
143
- config: {
144
- headers: response.config.headers,
145
- baseURL: response.config.baseURL,
146
- params: response.config.params
147
- },
148
- response: response === null || response === void 0 ? void 0 : response.data,
149
- user_id: commonConfig.getItem(commonConfig.USER_ID),
150
- apiEndPoint: apiConfig.endPoint,
151
- method: method,
152
- RequestID: requestId,
153
- status: status,
154
- params: params,
155
- api_status: status,
156
- apiPayload: apiPayload
157
- });
158
- onFailure({
159
- errorMessage: (0, APIResponses_1.getBackendResponseMessage)(error),
160
- errorCode: response.data.error_code,
161
- success: false
162
- });
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);
163
124
  }
164
- break;
165
- case 401:
166
- onFailure({
167
- errorMessage: "",
168
- errorCode: 401,
169
- success: false
170
- });
171
- yield commonConfig.cleanSession();
172
- commonConfig.resetNavigation(index_1.txnNavigationConstants.LOGIN);
173
- commonConfig.showDangerToast(commonConfig.message);
174
- break;
175
- case (502 || 500 || 503 || 404 || 403):
176
- onFailure({
177
- errorMessage: "",
178
- errorCode: "",
179
- success: false
180
- });
181
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
182
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
183
- ]);
184
- break;
185
- default:
186
- DatadogTxn_1.default.error("CUSTOMER TXN API CALL FAIL", {
125
+ DatadogTxn_1.default.info("CUSTOMER TXN API CALL SUCCESS", {
187
126
  config: {
188
127
  headers: response.config.headers,
189
128
  baseURL: response.config.baseURL,
@@ -196,274 +135,278 @@ exports.default = (apiConfig, apiPayload, onSuccess, onFailure) => __awaiter(voi
196
135
  RequestID: requestId,
197
136
  status: status,
198
137
  params: params,
199
- api_status: status,
200
- apiPayload: apiPayload
138
+ api_status: status
201
139
  });
202
- onFailure({
203
- errorMessage: "",
204
- errorCode: "",
205
- success: false
206
- });
207
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
208
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
209
- ]);
210
- }
211
- }
212
- else {
213
- DatadogTxn_1.default.error("CUSTOMER TXN API CALL FAIL", {
214
- config: {
215
- headers: response.config.headers,
216
- baseURL: response.config.baseURL,
217
- params: response.config.params
218
- },
219
- response: response === null || response === void 0 ? void 0 : response.data,
220
- user_id: commonConfig.getItem(commonConfig.USER_ID),
221
- apiEndPoint: apiConfig.endPoint,
222
- method: method,
223
- RequestID: requestId,
224
- status: status,
225
- params: params,
226
- api_status: response === null || response === void 0 ? void 0 : response.status,
227
- apiPayload: apiPayload
228
- });
229
- onFailure({
230
- errorMessage: "",
231
- errorCode: "",
232
- success: false
233
- });
234
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
235
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
236
- ]);
237
- }
238
- }))
239
- .catch((error) => __awaiter(void 0, void 0, void 0, function* () {
240
- var _e;
241
- DatadogTxn_1.default.error(`${error}`, {
242
- user_id: commonConfig.getItem(commonConfig.USER_ID),
243
- apiEndPoint: apiConfig.endPoint,
244
- method: method,
245
- config: { config },
246
- params: params,
247
- RequestID: requestId,
248
- api_status: `${error}`,
249
- apiPayload: apiPayload
250
- });
251
- (0, utils_1.consoleHelper)('\n___________error__________________', error);
252
- if (error) {
253
- (0, utils_1.consoleHelper)('\n___________error__________________', error === null || error === void 0 ? void 0 : error.response);
254
- if (error === null || error === void 0 ? void 0 : error.response) {
255
- (0, utils_1.consoleHelper)('\n___________error__________________', (_e = error === null || error === void 0 ? void 0 : error.response) === null || _e === void 0 ? void 0 : _e.status);
256
- if (commonConfig.getItem(commonConfig.SESSION_EXPIRE_VALUE) === JSON.stringify(false)) {
257
- switch (error.response.status) {
258
- case 401:
259
- onFailure({
260
- errorMessage: "",
261
- errorCode: 401,
262
- success: false
263
- });
264
- yield commonConfig.cleanSession();
265
- commonConfig.resetNavigation(index_1.txnNavigationConstants.LOGIN);
266
- commonConfig.showDangerToast(commonConfig.message);
267
- break;
268
- case 502:
269
- onFailure({
270
- errorMessage: "",
271
- errorCode: 0,
272
- success: false
273
- });
274
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
275
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
276
- ]);
277
- break;
278
- case 500:
279
- onFailure({
280
- errorMessage: "",
281
- errorCode: 0,
282
- success: false
283
- });
284
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
285
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
286
- ]);
287
- break;
288
- case 503:
289
- onFailure({
290
- errorMessage: "",
291
- errorCode: 0,
292
- success: false
293
- });
294
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
295
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
296
- ]);
297
- break;
298
- case 404:
299
- onFailure({
300
- errorMessage: "",
301
- errorCode: 0,
302
- success: false
303
- });
304
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
305
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
306
- ]);
307
- break;
308
- case 403:
309
- onFailure({
310
- errorMessage: "",
311
- errorCode: 0,
312
- success: false
313
- });
314
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
315
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
316
- ]);
317
- break;
318
- case 504:
319
- onFailure({
320
- errorMessage: "",
321
- errorCode: 0,
322
- success: false
323
- });
324
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
325
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
326
- ]);
327
- break;
328
- default:
329
- DatadogTxn_1.default.error("MERCHANT TXN API CALL FAIL(Error)", {
330
- error: error,
331
- config: { config },
332
- user_id: commonConfig.getItem(commonConfig.USER_ID),
333
- apiEndPoint: apiConfig.endPoint,
334
- method: method,
335
- RequestID: requestId,
336
- status: status,
337
- params: params,
338
- apiPayload: apiPayload
339
- });
340
- onFailure({
341
- errorMessage: "",
342
- errorCode: "",
343
- success: false
344
- });
345
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
346
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
347
- ]);
348
- break;
349
- }
140
+ onSuccess({ data: responseData.data, message: successMessage, success: true });
350
141
  }
351
142
  else {
352
- switch (error.response.status) {
353
- case 502:
354
- onFailure({
355
- errorMessage: "",
356
- errorCode: 0,
357
- success: false
358
- });
359
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
360
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
361
- ]);
362
- break;
363
- case 500:
364
- onFailure({
365
- errorMessage: "",
366
- errorCode: 0,
367
- success: false
368
- });
369
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
370
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
371
- ]);
372
- break;
373
- case 503:
374
- onFailure({
375
- errorMessage: "",
376
- errorCode: 0,
377
- success: false
378
- });
379
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
380
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
381
- ]);
382
- break;
383
- case 404:
384
- onFailure({
385
- errorMessage: "",
386
- errorCode: 0,
387
- success: false
388
- });
389
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
390
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
391
- ]);
392
- break;
393
- case 403:
394
- onFailure({
395
- errorMessage: "",
396
- errorCode: 0,
397
- success: false
398
- });
399
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
400
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
401
- ]);
402
- break;
403
- case 504:
404
- onFailure({
405
- errorMessage: "",
406
- errorCode: 0,
407
- success: false
408
- });
409
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
410
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
411
- ]);
412
- break;
413
- default:
414
- DatadogTxn_1.default.error("MERCHANT TXN API CALL FAIL(Error)", {
415
- error: error,
416
- config: { config },
417
- user_id: commonConfig.getItem(commonConfig.USER_ID),
418
- apiEndPoint: apiConfig.endPoint,
419
- method: method,
420
- RequestID: requestId,
421
- status: status,
422
- params: params,
423
- apiPayload: apiPayload
424
- });
425
- onFailure({
426
- errorMessage: "",
427
- errorCode: "",
428
- success: false
429
- });
430
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
431
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
432
- ]);
433
- break;
434
- }
435
- }
436
- }
437
- else if (error.message) {
438
- 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
+ });
439
160
  onFailure({
440
- errorMessage: "",
441
- errorCode: "",
161
+ errorMessage: (0, APIResponses_1.getBackendResponseMessage)(error),
162
+ errorCode: response.data.error_code,
442
163
  success: false
443
164
  });
444
- react_native_1.Alert.alert(langugaeCode && langugaeCode == "bn" ? "রক্ষণাবেক্ষণ অধীনে সিস্টেম" : "System Under Maintenance", '', [
445
- { text: langugaeCode && langugaeCode == "bn" ? "ঠিক আছে" : 'OK', },
446
- ]);
447
- return;
448
165
  }
449
- DatadogTxn_1.default.error("CUSTOMER TXN API CALL FAIL(Error)", {
450
- error: error,
451
- 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,
452
193
  user_id: commonConfig.getItem(commonConfig.USER_ID),
453
194
  apiEndPoint: apiConfig.endPoint,
454
195
  method: method,
455
196
  RequestID: requestId,
456
197
  status: status,
457
198
  params: params,
458
- apiPayload: apiPayload
199
+ api_status: status
459
200
  });
460
201
  onFailure({
461
- errorMessage: "CUSTOMER_APP_SOMETHING_WENT_WRONG",
462
- errorCode: 0,
202
+ errorMessage: "",
203
+ errorCode: "",
204
+ success: false
463
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
+ }
464
398
  }
465
399
  }
466
- 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
+ }
467
410
  DatadogTxn_1.default.error("CUSTOMER TXN API CALL FAIL(Error)", {
468
411
  error: error,
469
412
  config: { config },
@@ -473,13 +416,29 @@ exports.default = (apiConfig, apiPayload, onSuccess, onFailure) => __awaiter(voi
473
416
  RequestID: requestId,
474
417
  status: status,
475
418
  params: params,
476
- apiPayload: apiPayload
477
419
  });
478
420
  onFailure({
479
421
  errorMessage: "CUSTOMER_APP_SOMETHING_WENT_WRONG",
480
422
  errorCode: 0,
481
423
  });
482
424
  }
483
- }));
484
- }
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
+ // }
485
444
  });