@xsolla/payment-client-core 0.0.5 → 0.0.7
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/esm2020/lib/core/exceptions-handling/elk/additional-info.interface.mjs +2 -0
- package/esm2020/lib/core/exceptions-handling/elk/elk-logger.service.mjs +120 -0
- package/esm2020/lib/core/exceptions-handling/elk/error-without-meta-fields.interface.mjs +2 -0
- package/esm2020/lib/core/exceptions-handling/elk/log-message.interface.mjs +2 -0
- package/esm2020/lib/core/exceptions-handling/errors/elk-error-types.enum.mjs +13 -0
- package/esm2020/lib/core/exceptions-handling/errors/tagged-error.class.mjs +16 -0
- package/esm2020/lib/core/exceptions-handling/errors/ws-error.class.mjs +10 -0
- package/esm2020/lib/core/payment/actions/action-type-command.map.mjs +2 -1
- package/esm2020/lib/core/payment/actions/check-status/check-status.action.class.mjs +16 -0
- package/esm2020/lib/core/payment/actions/check-status/check-status.action.token.mjs +11 -0
- package/esm2020/lib/core/payment/actions/check-status/check-status.action.type.mjs +1 -1
- package/esm2020/lib/core/payment/actions/next-action.interface.mjs +1 -1
- package/esm2020/lib/core/payment/actions/next-action.service.mjs +9 -1
- package/esm2020/lib/core/payment/actions/next-actions.mjs +8 -2
- package/esm2020/lib/core/payment/actions/status-updated/status-updated.action.class.mjs +13 -0
- package/esm2020/lib/core/payment/actions/status-updated/status-updated.action.token.mjs +11 -0
- package/esm2020/lib/core/payment/actions/status-updated/status-updated.action.type.mjs +2 -0
- package/esm2020/lib/core/payment/payment.interface.mjs +1 -1
- package/esm2020/lib/core/payment/payment.service.mjs +13 -7
- package/esm2020/lib/core/payment/status/check-status/check-status.service.mjs +56 -0
- package/esm2020/lib/core/payment/status/check-status/request/check-status-request.class.mjs +16 -0
- package/esm2020/lib/core/payment/status/check-status/request/check-status-request.token.mjs +8 -0
- package/esm2020/lib/core/payment/status/check-status/response/check-status-response.class.mjs +9 -0
- package/esm2020/lib/core/payment/status/check-status/response/check-status-response.token.mjs +8 -0
- package/esm2020/lib/core/payment/status/listen-status/listen-status.service.mjs +112 -0
- package/esm2020/lib/core/payment/status/status-groups.mjs +7 -0
- package/esm2020/lib/core/payment/status/status-params.interface.mjs +2 -0
- package/esm2020/lib/core/payment/status/status-request/request/status-request.class.mjs +22 -0
- package/esm2020/lib/core/payment/status/status-request/request/status-request.token.mjs +8 -0
- package/esm2020/lib/core/payment/status/status-request/response/status-response.class.mjs +96 -0
- package/esm2020/lib/core/payment/status/status-request/response/status-response.token.mjs +8 -0
- package/esm2020/lib/core/payment/status/status-request/status-request-params.interface.mjs +2 -0
- package/esm2020/lib/core/payment/status/status-request/status-request.service.mjs +68 -0
- package/esm2020/lib/core/payment/status/status-settings.interface.mjs +2 -0
- package/esm2020/lib/core/payment/status/status-updated.interface.mjs +2 -0
- package/esm2020/lib/core/payment/status/status.interface.mjs +1 -1
- package/esm2020/lib/core/payment/status/status.service.mjs +38 -0
- package/esm2020/lib/core/payment/status/websocket-status/websocket-status.enum.mjs +6 -0
- package/esm2020/lib/core/payment/status/websocket-status/websocket-status.service.mjs +76 -0
- package/esm2020/lib/core/payment/xps-api-part.abstract.mjs +19 -0
- package/esm2020/lib/core/properties.type.mjs +2 -0
- package/esm2020/lib/core/web-socket/centrifugo-web-socket.service.mjs +200 -0
- package/esm2020/lib/core/web-socket/nchan-web-socket.service.mjs +116 -0
- package/esm2020/lib/core/web-socket/web-socket-client-type.enum.mjs +6 -0
- package/esm2020/lib/core/web-socket/web-socket.factory.mjs +28 -0
- package/esm2020/lib/core/web-socket/web-socket.interface.mjs +2 -0
- package/esm2020/lib/core-library.module.mjs +13 -1
- package/esm2020/lib/core-library.service.mjs +8 -5
- package/fesm2015/xsolla-payment-client-core.mjs +1117 -13
- package/fesm2015/xsolla-payment-client-core.mjs.map +1 -1
- package/fesm2020/xsolla-payment-client-core.mjs +1079 -13
- package/fesm2020/xsolla-payment-client-core.mjs.map +1 -1
- package/lib/core/exceptions-handling/elk/additional-info.interface.d.ts +19 -0
- package/lib/core/exceptions-handling/elk/elk-logger.service.d.ts +27 -0
- package/lib/core/exceptions-handling/elk/error-without-meta-fields.interface.d.ts +8 -0
- package/lib/core/exceptions-handling/elk/log-message.interface.d.ts +8 -0
- package/lib/core/exceptions-handling/errors/elk-error-types.enum.d.ts +11 -0
- package/lib/core/exceptions-handling/errors/tagged-error.class.d.ts +10 -0
- package/lib/core/exceptions-handling/errors/ws-error.class.d.ts +5 -0
- package/lib/core/payment/actions/check-status/check-status.action.class.d.ts +8 -0
- package/lib/core/payment/actions/check-status/check-status.action.token.d.ts +4 -0
- package/lib/core/payment/actions/check-status/check-status.action.type.d.ts +9 -9
- package/lib/core/payment/actions/next-action.interface.d.ts +2 -1
- package/lib/core/payment/actions/next-action.service.d.ts +4 -0
- package/lib/core/payment/actions/status-updated/status-updated.action.class.d.ts +8 -0
- package/lib/core/payment/actions/status-updated/status-updated.action.token.d.ts +4 -0
- package/lib/core/payment/actions/status-updated/status-updated.action.type.d.ts +11 -0
- package/lib/core/payment/payment.interface.d.ts +6 -3
- package/lib/core/payment/payment.service.d.ts +6 -2
- package/lib/core/payment/status/check-status/check-status.service.d.ts +20 -0
- package/lib/core/payment/status/check-status/request/check-status-request.class.d.ts +8 -0
- package/lib/core/payment/status/check-status/request/check-status-request.token.d.ts +6 -0
- package/lib/core/payment/status/check-status/response/check-status-response.class.d.ts +8 -0
- package/lib/core/payment/status/check-status/response/check-status-response.token.d.ts +7 -0
- package/lib/core/payment/status/listen-status/listen-status.service.d.ts +28 -0
- package/lib/core/payment/status/status-groups.d.ts +5 -0
- package/lib/core/payment/status/status-params.interface.d.ts +9 -0
- package/lib/core/payment/status/status-request/request/status-request.class.d.ts +17 -0
- package/lib/core/payment/status/status-request/request/status-request.token.d.ts +6 -0
- package/lib/core/payment/status/status-request/response/status-response.class.d.ts +14 -0
- package/lib/core/payment/status/status-request/response/status-response.token.d.ts +7 -0
- package/lib/core/payment/status/status-request/status-request-params.interface.d.ts +10 -0
- package/lib/core/payment/status/status-request/status-request.service.d.ts +21 -0
- package/lib/core/payment/status/status-settings.interface.d.ts +13 -0
- package/lib/core/payment/status/status-updated.interface.d.ts +6 -0
- package/lib/core/payment/status/status.interface.d.ts +0 -1
- package/lib/core/payment/status/status.service.d.ts +16 -0
- package/lib/core/payment/status/websocket-status/websocket-status.enum.d.ts +4 -0
- package/lib/core/payment/status/websocket-status/websocket-status.service.d.ts +24 -0
- package/lib/core/payment/xps-api-part.abstract.d.ts +8 -0
- package/lib/core/properties.type.d.ts +3 -0
- package/lib/core/web-socket/centrifugo-web-socket.service.d.ts +41 -0
- package/lib/core/web-socket/nchan-web-socket.service.d.ts +30 -0
- package/lib/core/web-socket/web-socket-client-type.enum.d.ts +4 -0
- package/lib/core/web-socket/web-socket.factory.d.ts +13 -0
- package/lib/core/web-socket/web-socket.interface.d.ts +9 -0
- package/lib/core-library.service.d.ts +3 -1
- package/package.json +12 -4
- package/xsolla-payment-client-core-0.0.7.tgz +0 -0
- package/xsolla-payment-client-core-0.0.5.tgz +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { __awaiter } from 'tslib';
|
|
2
2
|
import * as i0 from '@angular/core';
|
|
3
|
-
import { InjectionToken, Injectable, Inject, NgModule } from '@angular/core';
|
|
4
|
-
import { firstValueFrom, lastValueFrom, map, throwError } from 'rxjs';
|
|
3
|
+
import { InjectionToken, Injectable, Inject, isDevMode, NgModule } from '@angular/core';
|
|
4
|
+
import { firstValueFrom, lastValueFrom, map, BehaviorSubject, Subject, filter as filter$1, takeUntil, skip, throwError } from 'rxjs';
|
|
5
5
|
import * as i1 from '@angular/common/http';
|
|
6
6
|
import { HttpParams, HttpHeaders, HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
|
|
7
7
|
import { UntypedFormGroup, Validators, UntypedFormControl, ReactiveFormsModule } from '@angular/forms';
|
|
8
|
-
import { catchError } from 'rxjs/operators';
|
|
8
|
+
import { filter, map as map$1, catchError } from 'rxjs/operators';
|
|
9
9
|
import * as i1$1 from '@angular/router';
|
|
10
10
|
|
|
11
11
|
class AppError extends Error {
|
|
@@ -1323,6 +1323,1016 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
|
|
|
1323
1323
|
type: Injectable
|
|
1324
1324
|
}], ctorParameters: function () { return [{ type: ControlConfigService }]; } });
|
|
1325
1325
|
|
|
1326
|
+
class StatusUpdatedAction {
|
|
1327
|
+
constructor(statusResponse) {
|
|
1328
|
+
this.type = 'status_updated';
|
|
1329
|
+
this.data = {
|
|
1330
|
+
statusState: statusResponse.status.statusState,
|
|
1331
|
+
invoice: statusResponse.status.invoice,
|
|
1332
|
+
isSuccess: statusResponse.status.isSuccess,
|
|
1333
|
+
isCanceled: statusResponse.status.isCanceled,
|
|
1334
|
+
group: statusResponse.status.group,
|
|
1335
|
+
};
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
class XpsApiPart {
|
|
1340
|
+
constructor() {
|
|
1341
|
+
this.response = new BehaviorSubject(null);
|
|
1342
|
+
}
|
|
1343
|
+
get response$() {
|
|
1344
|
+
return this.response
|
|
1345
|
+
.asObservable()
|
|
1346
|
+
.pipe(filter((response) => response !== null));
|
|
1347
|
+
}
|
|
1348
|
+
emitResponse(response) {
|
|
1349
|
+
this.response.next(response);
|
|
1350
|
+
}
|
|
1351
|
+
get currentValue() {
|
|
1352
|
+
return this.response.getValue();
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
1357
|
+
class StatusRequest extends XpsApiPartRequest {
|
|
1358
|
+
constructor(parameters) {
|
|
1359
|
+
super();
|
|
1360
|
+
this.xps_fix_command = 'status';
|
|
1361
|
+
if (parameters.token === null) {
|
|
1362
|
+
throw new TokenError();
|
|
1363
|
+
}
|
|
1364
|
+
this.access_token = parameters.token;
|
|
1365
|
+
this.xps_fix_invoice = parameters.invoice;
|
|
1366
|
+
this.xps_fix_pid = parameters.pid;
|
|
1367
|
+
this.xps_signature = parameters.signature;
|
|
1368
|
+
this.xps_fix_testProject = parameters.testProject;
|
|
1369
|
+
this.xps_fix_testPs = parameters.testPs;
|
|
1370
|
+
this.xps_fix_testXsolla = parameters.testXsolla;
|
|
1371
|
+
this.xps_fix_userReturnStatus = parameters.userReturnStatus;
|
|
1372
|
+
this.xps_locale = parameters.locale;
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
const statusRequestFactoryToken = new InjectionToken('StatusRequest');
|
|
1377
|
+
const statusRequestFactoryProvider = {
|
|
1378
|
+
provide: statusRequestFactoryToken,
|
|
1379
|
+
useValue: (...args) => new StatusRequest(...args),
|
|
1380
|
+
};
|
|
1381
|
+
|
|
1382
|
+
var StatusGroups;
|
|
1383
|
+
(function (StatusGroups) {
|
|
1384
|
+
StatusGroups["troubled"] = "troubled";
|
|
1385
|
+
StatusGroups["done"] = "done";
|
|
1386
|
+
StatusGroups["invoice"] = "invoice";
|
|
1387
|
+
})(StatusGroups || (StatusGroups = {}));
|
|
1388
|
+
|
|
1389
|
+
var StatusEnum;
|
|
1390
|
+
(function (StatusEnum) {
|
|
1391
|
+
StatusEnum["created"] = "created";
|
|
1392
|
+
StatusEnum["awaiting"] = "awaiting";
|
|
1393
|
+
StatusEnum["processing"] = "processing";
|
|
1394
|
+
StatusEnum["authorized"] = "authorized";
|
|
1395
|
+
StatusEnum["held"] = "held";
|
|
1396
|
+
StatusEnum["done"] = "done";
|
|
1397
|
+
StatusEnum["error"] = "error";
|
|
1398
|
+
StatusEnum["canceled"] = "canceled";
|
|
1399
|
+
})(StatusEnum || (StatusEnum = {}));
|
|
1400
|
+
|
|
1401
|
+
class StatusResponse {
|
|
1402
|
+
constructor(parameters) {
|
|
1403
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1404
|
+
if ((_a = parameters.errors) === null || _a === void 0 ? void 0 : _a[0]) {
|
|
1405
|
+
this.error = {
|
|
1406
|
+
code: parameters.errors[0].code.toString(),
|
|
1407
|
+
message: parameters.errors[0].message,
|
|
1408
|
+
};
|
|
1409
|
+
}
|
|
1410
|
+
if (!parameters.status) {
|
|
1411
|
+
throw new TerminalError((_c = (_b = this.error) === null || _b === void 0 ? void 0 : _b.message) !== null && _c !== void 0 ? _c : '', (_e = (_d = this.error) === null || _d === void 0 ? void 0 : _d.code.toString()) !== null && _e !== void 0 ? _e : '');
|
|
1412
|
+
}
|
|
1413
|
+
this.status = {
|
|
1414
|
+
statusState: parameters.status.statusData.stateText,
|
|
1415
|
+
email: parameters.status.statusData.email,
|
|
1416
|
+
webSocketUrl: parameters.status.statusData.webSocketChannelUrl,
|
|
1417
|
+
webSocketChannelName: parameters.status.statusData.webSocketChannelName,
|
|
1418
|
+
webSocketClientType: parameters.status.statusData.webSocketClientType,
|
|
1419
|
+
financeInfo: parameters.status.text.info,
|
|
1420
|
+
discount: parameters.status.text.info.discount
|
|
1421
|
+
? Math.abs(Number.parseFloat((_g = (_f = parameters.status.text.info.discount) === null || _f === void 0 ? void 0 : _f.value) !== null && _g !== void 0 ? _g : ''))
|
|
1422
|
+
: null,
|
|
1423
|
+
isCancelUser: parameters.status.isCancelUser,
|
|
1424
|
+
postMessageStatus: parameters.status.isCancelUser
|
|
1425
|
+
? StatusGroups.troubled
|
|
1426
|
+
: parameters.status.group,
|
|
1427
|
+
virtualCurrencyAmount: parameters.status.statusData.out,
|
|
1428
|
+
backUrlSettings: {
|
|
1429
|
+
backUrl: parameters.status.text.backurl,
|
|
1430
|
+
backUrlAction: parameters.status.text.backurl_action,
|
|
1431
|
+
backUrlCaption: parameters.status.text.backurl_caption,
|
|
1432
|
+
returnRegion: parameters.status.return_region,
|
|
1433
|
+
},
|
|
1434
|
+
additionalBackButton: this.getAdditionalBackButton(parameters.status),
|
|
1435
|
+
group: parameters.status.group,
|
|
1436
|
+
needToCheck: parameters.status.needToCheck,
|
|
1437
|
+
autoRedirect: parameters.status.autoredirect,
|
|
1438
|
+
statusMessage: parameters.status.text.state,
|
|
1439
|
+
userId: parameters.status.statusData.v1,
|
|
1440
|
+
invoice: parameters.status.statusData.invoice,
|
|
1441
|
+
pid: parameters.status.statusData.pid,
|
|
1442
|
+
projectAmount: this.getProjectAmount(parameters.status),
|
|
1443
|
+
titleClass: parameters.status.title_class,
|
|
1444
|
+
paymentCountryIso: parameters.status.statusData.payment_country_iso,
|
|
1445
|
+
order: parameters.status.text.order,
|
|
1446
|
+
};
|
|
1447
|
+
if (parameters.form) {
|
|
1448
|
+
this.status.userReturnStatus = this.getUserReturnStatus(parameters.form);
|
|
1449
|
+
}
|
|
1450
|
+
if (this.status.statusState === StatusEnum.done ||
|
|
1451
|
+
this.status.statusState === StatusEnum.authorized) {
|
|
1452
|
+
this.status.isSuccess = true;
|
|
1453
|
+
}
|
|
1454
|
+
if (this.status.statusState === StatusEnum.canceled ||
|
|
1455
|
+
this.status.isCancelUser) {
|
|
1456
|
+
this.status.isCanceled = true;
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
getUserReturnStatus(form) {
|
|
1460
|
+
var _a;
|
|
1461
|
+
const value = (_a = form['fix_userReturnStatus']) === null || _a === void 0 ? void 0 : _a.value;
|
|
1462
|
+
if (value === 'undefined')
|
|
1463
|
+
return undefined;
|
|
1464
|
+
return value;
|
|
1465
|
+
}
|
|
1466
|
+
getProjectAmount(status) {
|
|
1467
|
+
if (!status.statusData.projectAmount) {
|
|
1468
|
+
return;
|
|
1469
|
+
}
|
|
1470
|
+
const [amount, currency] = status.statusData.projectAmount.split(' ');
|
|
1471
|
+
return {
|
|
1472
|
+
amount,
|
|
1473
|
+
currency,
|
|
1474
|
+
};
|
|
1475
|
+
}
|
|
1476
|
+
getAdditionalBackButton(status) {
|
|
1477
|
+
var _a, _b, _c, _d;
|
|
1478
|
+
if (!status.text.is_additional_back_url_enabled) {
|
|
1479
|
+
return {
|
|
1480
|
+
link: '',
|
|
1481
|
+
action: '',
|
|
1482
|
+
label: '',
|
|
1483
|
+
region: '',
|
|
1484
|
+
isEnabled: false,
|
|
1485
|
+
};
|
|
1486
|
+
}
|
|
1487
|
+
return {
|
|
1488
|
+
link: (_a = status.text.additional_back_url_link) !== null && _a !== void 0 ? _a : '',
|
|
1489
|
+
action: (_b = status.text.additional_back_url_action) !== null && _b !== void 0 ? _b : '',
|
|
1490
|
+
label: (_c = status.text.additional_back_url_label) !== null && _c !== void 0 ? _c : '',
|
|
1491
|
+
region: (_d = status.additional_button_return_region) !== null && _d !== void 0 ? _d : '',
|
|
1492
|
+
isEnabled: status.text.is_additional_back_url_enabled,
|
|
1493
|
+
};
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
const statusResponseFactoryToken = new InjectionToken('StatusResponse');
|
|
1498
|
+
const statusResponseFactoryProvider = {
|
|
1499
|
+
provide: statusResponseFactoryToken,
|
|
1500
|
+
useValue: (...args) => new StatusResponse(...args),
|
|
1501
|
+
};
|
|
1502
|
+
|
|
1503
|
+
class StatusRequestService extends XpsApiPart {
|
|
1504
|
+
constructor(secureApiClient, settingsService, requestFactory, responseFactory) {
|
|
1505
|
+
super();
|
|
1506
|
+
this.secureApiClient = secureApiClient;
|
|
1507
|
+
this.settingsService = settingsService;
|
|
1508
|
+
this.requestFactory = requestFactory;
|
|
1509
|
+
this.responseFactory = responseFactory;
|
|
1510
|
+
this.apiRoute = 'directpayment';
|
|
1511
|
+
}
|
|
1512
|
+
setRequestParams(params) {
|
|
1513
|
+
this.requestParams = {
|
|
1514
|
+
locale: params.locale,
|
|
1515
|
+
testProject: params.testProject,
|
|
1516
|
+
testPs: params.testPs,
|
|
1517
|
+
testXsolla: params.testXsolla,
|
|
1518
|
+
userReturnStatus: params.userReturnStatus,
|
|
1519
|
+
invoice: params.invoice,
|
|
1520
|
+
pid: params.pid,
|
|
1521
|
+
signature: params.signature,
|
|
1522
|
+
};
|
|
1523
|
+
}
|
|
1524
|
+
request() {
|
|
1525
|
+
const requestParams = this.requestFactory(Object.assign({ token: this.settingsService.token }, this.requestParams));
|
|
1526
|
+
lastValueFrom(this.secureApiClient.post(this.apiRoute, new URLSearchParams(requestParams), {
|
|
1527
|
+
headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'),
|
|
1528
|
+
responseType: 'json',
|
|
1529
|
+
}))
|
|
1530
|
+
.then((response) => {
|
|
1531
|
+
const statusResponse = this.responseFactory({
|
|
1532
|
+
status: response.status,
|
|
1533
|
+
errors: response.errors,
|
|
1534
|
+
form: response.form,
|
|
1535
|
+
});
|
|
1536
|
+
this.emitResponse(statusResponse);
|
|
1537
|
+
})
|
|
1538
|
+
.catch((e) => {
|
|
1539
|
+
throw new TerminalError(e.message, e.code);
|
|
1540
|
+
});
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
StatusRequestService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusRequestService, deps: [{ token: SecureApiClient }, { token: SettingsService }, { token: statusRequestFactoryToken }, { token: statusResponseFactoryToken }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1544
|
+
StatusRequestService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusRequestService, providedIn: 'root' });
|
|
1545
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusRequestService, decorators: [{
|
|
1546
|
+
type: Injectable,
|
|
1547
|
+
args: [{
|
|
1548
|
+
providedIn: 'root',
|
|
1549
|
+
}]
|
|
1550
|
+
}], ctorParameters: function () {
|
|
1551
|
+
return [{ type: SecureApiClient }, { type: SettingsService }, { type: undefined, decorators: [{
|
|
1552
|
+
type: Inject,
|
|
1553
|
+
args: [statusRequestFactoryToken]
|
|
1554
|
+
}] }, { type: undefined, decorators: [{
|
|
1555
|
+
type: Inject,
|
|
1556
|
+
args: [statusResponseFactoryToken]
|
|
1557
|
+
}] }];
|
|
1558
|
+
} });
|
|
1559
|
+
|
|
1560
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
1561
|
+
class CheckStatusRequest extends XpsApiPartRequest {
|
|
1562
|
+
constructor(token, invoice) {
|
|
1563
|
+
super();
|
|
1564
|
+
this.xps_fix_command = 'status';
|
|
1565
|
+
this.section = 'getstatus';
|
|
1566
|
+
if (token === null) {
|
|
1567
|
+
throw new TokenError();
|
|
1568
|
+
}
|
|
1569
|
+
this.access_token = token;
|
|
1570
|
+
this.invoice = invoice;
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
const checkStatusRequestFactoryToken = new InjectionToken('CheckStatusRequest');
|
|
1575
|
+
const checkStatusRequestFactoryProvider = {
|
|
1576
|
+
provide: checkStatusRequestFactoryToken,
|
|
1577
|
+
useValue: (...args) => new CheckStatusRequest(...args),
|
|
1578
|
+
};
|
|
1579
|
+
|
|
1580
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
1581
|
+
class CheckStatusResponse {
|
|
1582
|
+
constructor(parameters) {
|
|
1583
|
+
this.status = parameters.status;
|
|
1584
|
+
this.final = parameters.final;
|
|
1585
|
+
this.isPaymentAccountAttached = parameters.isPaymentAccountAttached;
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
const checkStatusResponseFactoryToken = new InjectionToken('CheckStatusResponse');
|
|
1590
|
+
const checkStatusResponseFactoryProvider = {
|
|
1591
|
+
provide: checkStatusResponseFactoryToken,
|
|
1592
|
+
useValue: (...args) => new CheckStatusResponse(...args),
|
|
1593
|
+
};
|
|
1594
|
+
|
|
1595
|
+
class CheckStatusService extends XpsApiPart {
|
|
1596
|
+
constructor(secureApiClient, settingsService, requestFactory, responseFactory) {
|
|
1597
|
+
super();
|
|
1598
|
+
this.secureApiClient = secureApiClient;
|
|
1599
|
+
this.settingsService = settingsService;
|
|
1600
|
+
this.requestFactory = requestFactory;
|
|
1601
|
+
this.responseFactory = responseFactory;
|
|
1602
|
+
this.apiRoute = 'directpayment';
|
|
1603
|
+
}
|
|
1604
|
+
setRequestParams(invoice) {
|
|
1605
|
+
this.invoice = invoice;
|
|
1606
|
+
}
|
|
1607
|
+
request() {
|
|
1608
|
+
const requestParams = this.requestFactory(this.settingsService.token, this.invoice);
|
|
1609
|
+
lastValueFrom(this.secureApiClient.post(this.apiRoute, new URLSearchParams(Object.assign({}, requestParams)), {
|
|
1610
|
+
headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'),
|
|
1611
|
+
responseType: 'json',
|
|
1612
|
+
}))
|
|
1613
|
+
.then((response) => {
|
|
1614
|
+
const checkStatusResponse = this.responseFactory({
|
|
1615
|
+
status: response.status,
|
|
1616
|
+
final: response.final,
|
|
1617
|
+
isPaymentAccountAttached: response.is_payment_account_attached,
|
|
1618
|
+
});
|
|
1619
|
+
this.emitResponse(checkStatusResponse);
|
|
1620
|
+
})
|
|
1621
|
+
.catch((error) => {
|
|
1622
|
+
throw new ResponseError(error.message);
|
|
1623
|
+
});
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
CheckStatusService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckStatusService, deps: [{ token: SecureApiClient }, { token: SettingsService }, { token: checkStatusRequestFactoryToken }, { token: checkStatusResponseFactoryToken }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1627
|
+
CheckStatusService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckStatusService, providedIn: 'root' });
|
|
1628
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckStatusService, decorators: [{
|
|
1629
|
+
type: Injectable,
|
|
1630
|
+
args: [{
|
|
1631
|
+
providedIn: 'root',
|
|
1632
|
+
}]
|
|
1633
|
+
}], ctorParameters: function () {
|
|
1634
|
+
return [{ type: SecureApiClient }, { type: SettingsService }, { type: undefined, decorators: [{
|
|
1635
|
+
type: Inject,
|
|
1636
|
+
args: [checkStatusRequestFactoryToken]
|
|
1637
|
+
}] }, { type: undefined, decorators: [{
|
|
1638
|
+
type: Inject,
|
|
1639
|
+
args: [checkStatusResponseFactoryToken]
|
|
1640
|
+
}] }];
|
|
1641
|
+
} });
|
|
1642
|
+
|
|
1643
|
+
var WebSocketStatus;
|
|
1644
|
+
(function (WebSocketStatus) {
|
|
1645
|
+
WebSocketStatus["statusChanged"] = "status_changed";
|
|
1646
|
+
WebSocketStatus["troubledStatus"] = "troubled_status";
|
|
1647
|
+
})(WebSocketStatus || (WebSocketStatus = {}));
|
|
1648
|
+
|
|
1649
|
+
var WebSocketClientType;
|
|
1650
|
+
(function (WebSocketClientType) {
|
|
1651
|
+
WebSocketClientType["nchan"] = "nchan";
|
|
1652
|
+
WebSocketClientType["centrifugo"] = "centrifugo";
|
|
1653
|
+
})(WebSocketClientType || (WebSocketClientType = {}));
|
|
1654
|
+
|
|
1655
|
+
class NchanWebSocketService {
|
|
1656
|
+
constructor() {
|
|
1657
|
+
this.type = WebSocketClientType.nchan;
|
|
1658
|
+
this.reconnectionTimerId = null;
|
|
1659
|
+
this.incomingMessages$ = new Subject();
|
|
1660
|
+
this.successfulReconnectionEventsProxy$ = new Subject();
|
|
1661
|
+
}
|
|
1662
|
+
open() {
|
|
1663
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1664
|
+
if (this.openPromise && !this.isClosed()) {
|
|
1665
|
+
return this.openPromise;
|
|
1666
|
+
}
|
|
1667
|
+
this.openPromise = this.createConnection()
|
|
1668
|
+
.catch(() => __awaiter(this, void 0, void 0, function* () {
|
|
1669
|
+
return this.waitWhileNotReconnect();
|
|
1670
|
+
}))
|
|
1671
|
+
.then(() => {
|
|
1672
|
+
this.connection.onclose = () => __awaiter(this, void 0, void 0, function* () { return this.open(); });
|
|
1673
|
+
});
|
|
1674
|
+
return this.openPromise;
|
|
1675
|
+
});
|
|
1676
|
+
}
|
|
1677
|
+
close() {
|
|
1678
|
+
this.clearReconnectionTimer();
|
|
1679
|
+
if (this.isClosed()) {
|
|
1680
|
+
return;
|
|
1681
|
+
}
|
|
1682
|
+
this.connection.onclose = null;
|
|
1683
|
+
this.connection.close();
|
|
1684
|
+
}
|
|
1685
|
+
get messages$() {
|
|
1686
|
+
return this.incomingMessages$
|
|
1687
|
+
.asObservable()
|
|
1688
|
+
.pipe(map$1((event) => event.data));
|
|
1689
|
+
}
|
|
1690
|
+
subscribeOnSuccessfulReconnection(next) {
|
|
1691
|
+
return this.successfulReconnectionEventsProxy$
|
|
1692
|
+
.asObservable()
|
|
1693
|
+
.subscribe(next);
|
|
1694
|
+
}
|
|
1695
|
+
isClosed() {
|
|
1696
|
+
if (!this.connection) {
|
|
1697
|
+
return true;
|
|
1698
|
+
}
|
|
1699
|
+
return [this.connection.CLOSED, this.connection.CLOSING].includes(this.connection.readyState);
|
|
1700
|
+
}
|
|
1701
|
+
clearReconnectionTimer() {
|
|
1702
|
+
if (this.reconnectionTimerId) {
|
|
1703
|
+
clearTimeout(this.reconnectionTimerId);
|
|
1704
|
+
this.reconnectionTimerId = null;
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
setFirstReconnectionTimeout() {
|
|
1708
|
+
const min = NchanWebSocketService.timeoutsMs.reconnection -
|
|
1709
|
+
NchanWebSocketService.timeoutsMs.reconnectionMaxDeviation;
|
|
1710
|
+
const max = NchanWebSocketService.timeoutsMs.reconnection +
|
|
1711
|
+
NchanWebSocketService.timeoutsMs.reconnectionMaxDeviation;
|
|
1712
|
+
this.reconnectionTimeoutMs =
|
|
1713
|
+
Math.floor(Math.random() * (max - min + 1)) + min;
|
|
1714
|
+
}
|
|
1715
|
+
incrementReconnectionTimeout() {
|
|
1716
|
+
this.reconnectionTimeoutMs =
|
|
1717
|
+
this.reconnectionTimeoutMs *
|
|
1718
|
+
NchanWebSocketService.reconnectionTimeoutIncrementFactor;
|
|
1719
|
+
}
|
|
1720
|
+
createConnection() {
|
|
1721
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1722
|
+
this.connection = new WebSocket(this.url);
|
|
1723
|
+
this.connection.onmessage = this.incomingMessages$.next.bind(this.incomingMessages$);
|
|
1724
|
+
return new Promise((resolve, reject) => {
|
|
1725
|
+
this.connection.onopen = () => {
|
|
1726
|
+
clearTimeout(this.openConnectionTimerId);
|
|
1727
|
+
resolve();
|
|
1728
|
+
};
|
|
1729
|
+
this.connection.onclose = () => {
|
|
1730
|
+
reject();
|
|
1731
|
+
};
|
|
1732
|
+
});
|
|
1733
|
+
});
|
|
1734
|
+
}
|
|
1735
|
+
reconnect() {
|
|
1736
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1737
|
+
this.clearReconnectionTimer();
|
|
1738
|
+
return new Promise((resolve) => {
|
|
1739
|
+
this.reconnectionTimerId = setTimeout(() => {
|
|
1740
|
+
this.createConnection()
|
|
1741
|
+
.then(() => resolve(true))
|
|
1742
|
+
.catch(() => resolve(false));
|
|
1743
|
+
this.incrementReconnectionTimeout();
|
|
1744
|
+
}, this.reconnectionTimeoutMs);
|
|
1745
|
+
});
|
|
1746
|
+
});
|
|
1747
|
+
}
|
|
1748
|
+
waitWhileNotReconnect() {
|
|
1749
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1750
|
+
this.clearReconnectionTimer();
|
|
1751
|
+
this.setFirstReconnectionTimeout();
|
|
1752
|
+
let isConnected = false;
|
|
1753
|
+
while (!isConnected) {
|
|
1754
|
+
isConnected = yield this.reconnect();
|
|
1755
|
+
}
|
|
1756
|
+
this.successfulReconnectionEventsProxy$.next();
|
|
1757
|
+
});
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
NchanWebSocketService.reconnectionTimeoutIncrementFactor = 2;
|
|
1761
|
+
NchanWebSocketService.timeoutsMs = {
|
|
1762
|
+
reconnection: 1500,
|
|
1763
|
+
reconnectionMaxDeviation: 1500,
|
|
1764
|
+
};
|
|
1765
|
+
NchanWebSocketService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: NchanWebSocketService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1766
|
+
NchanWebSocketService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: NchanWebSocketService, providedIn: 'root' });
|
|
1767
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: NchanWebSocketService, decorators: [{
|
|
1768
|
+
type: Injectable,
|
|
1769
|
+
args: [{
|
|
1770
|
+
providedIn: 'root',
|
|
1771
|
+
}]
|
|
1772
|
+
}] });
|
|
1773
|
+
|
|
1774
|
+
var ErrorTags;
|
|
1775
|
+
(function (ErrorTags) {
|
|
1776
|
+
ErrorTags["APP"] = "appError";
|
|
1777
|
+
ErrorTags["HTTP"] = "httpError";
|
|
1778
|
+
ErrorTags["JS"] = "jsError";
|
|
1779
|
+
ErrorTags["WS"] = "webSocket";
|
|
1780
|
+
ErrorTags["ENCRYPT"] = "encrypt";
|
|
1781
|
+
ErrorTags["APPLEPAY"] = "applepay";
|
|
1782
|
+
ErrorTags["HEADLESS_UI"] = "headlessUi";
|
|
1783
|
+
ErrorTags["GOOGLEPAY"] = "googlepay";
|
|
1784
|
+
ErrorTags["PAYTM"] = "paytm";
|
|
1785
|
+
})(ErrorTags || (ErrorTags = {}));
|
|
1786
|
+
|
|
1787
|
+
class TaggedError extends Error {
|
|
1788
|
+
constructor(message, tags) {
|
|
1789
|
+
super(message);
|
|
1790
|
+
this.tags = [];
|
|
1791
|
+
this.parentTag = ErrorTags.HEADLESS_UI;
|
|
1792
|
+
this.tags = this.childTag
|
|
1793
|
+
? [this.parentTag, this.childTag]
|
|
1794
|
+
: [this.parentTag];
|
|
1795
|
+
if (tags) {
|
|
1796
|
+
const newTags = tags.filter((t, i, arr) => !this.tags.includes(t) && arr.indexOf(t) == i);
|
|
1797
|
+
this.tags = [...this.tags, ...newTags];
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
|
|
1802
|
+
class WsError extends TaggedError {
|
|
1803
|
+
constructor(message, channelName, tags) {
|
|
1804
|
+
tags = tags ? [...tags, ErrorTags.WS] : [ErrorTags.WS];
|
|
1805
|
+
const messageWithChannel = `${message}. ChannelName - ${channelName}`;
|
|
1806
|
+
super(messageWithChannel, tags);
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
class ElkLoggerService {
|
|
1811
|
+
constructor(window, settingsService, http, ngZone) {
|
|
1812
|
+
this.window = window;
|
|
1813
|
+
this.settingsService = settingsService;
|
|
1814
|
+
this.http = http;
|
|
1815
|
+
this.ngZone = ngZone;
|
|
1816
|
+
this.vendors = new RegExp('node_modules\\/(@angular|zone).*.js$');
|
|
1817
|
+
this.stackTrace = this.loadStackTrace();
|
|
1818
|
+
}
|
|
1819
|
+
handleError(error) {
|
|
1820
|
+
this.ngZone.runOutsideAngular(() => {
|
|
1821
|
+
if (isDevMode()) {
|
|
1822
|
+
console.error(error);
|
|
1823
|
+
return;
|
|
1824
|
+
}
|
|
1825
|
+
this.parseError(error).catch(console.log);
|
|
1826
|
+
});
|
|
1827
|
+
}
|
|
1828
|
+
log(message, tags, extra) {
|
|
1829
|
+
const logTags = [ErrorTags.HEADLESS_UI, ...tags];
|
|
1830
|
+
if (isDevMode()) {
|
|
1831
|
+
console.log(message, tags);
|
|
1832
|
+
return;
|
|
1833
|
+
}
|
|
1834
|
+
const logMessage = {
|
|
1835
|
+
additionalInfo: this.getAdditionalInfo(),
|
|
1836
|
+
extra,
|
|
1837
|
+
message,
|
|
1838
|
+
};
|
|
1839
|
+
this.sendLog(logMessage, logTags);
|
|
1840
|
+
}
|
|
1841
|
+
parseError(error) {
|
|
1842
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1843
|
+
const errorObj = error instanceof TaggedError
|
|
1844
|
+
? error
|
|
1845
|
+
: new TaggedError(error.message || error.toString());
|
|
1846
|
+
errorObj.trace = yield this.getErrorTrace(errorObj);
|
|
1847
|
+
errorObj.additionalInfo = this.getAdditionalInfo();
|
|
1848
|
+
const { tags } = errorObj;
|
|
1849
|
+
const cleanError = this.removeErrorMetaFields(errorObj);
|
|
1850
|
+
this.sendLog(cleanError, tags);
|
|
1851
|
+
return errorObj;
|
|
1852
|
+
});
|
|
1853
|
+
}
|
|
1854
|
+
loadStackTrace() {
|
|
1855
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1856
|
+
const library = yield import('stacktrace-js');
|
|
1857
|
+
return library.default;
|
|
1858
|
+
});
|
|
1859
|
+
}
|
|
1860
|
+
getErrorTrace(error) {
|
|
1861
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1862
|
+
const stackTrace = yield this.stackTrace;
|
|
1863
|
+
const stackFramesArr = yield stackTrace.fromError(error);
|
|
1864
|
+
const filteredFramesArr = stackFramesArr.filter(({ fileName }) => fileName && !this.vendors.test(fileName));
|
|
1865
|
+
return filteredFramesArr
|
|
1866
|
+
.map((stackFrame) => stackFrame.toString())
|
|
1867
|
+
.join('\n');
|
|
1868
|
+
});
|
|
1869
|
+
}
|
|
1870
|
+
getAdditionalInfo() {
|
|
1871
|
+
const extractUrlHost = (url) => url.replace(/^https?:\/\/([^/?#]+).*$/i, '$1');
|
|
1872
|
+
return {
|
|
1873
|
+
location: {
|
|
1874
|
+
url: this.window.location.href,
|
|
1875
|
+
},
|
|
1876
|
+
project: {
|
|
1877
|
+
id: this.settingsService.project.id,
|
|
1878
|
+
},
|
|
1879
|
+
referrer: {
|
|
1880
|
+
url: this.window.document.referrer,
|
|
1881
|
+
},
|
|
1882
|
+
viewport: {
|
|
1883
|
+
width: this.window.document.documentElement.clientWidth,
|
|
1884
|
+
height: this.window.document.documentElement.clientHeight,
|
|
1885
|
+
},
|
|
1886
|
+
cdn_address: this.settingsService.settings.cdnUrl
|
|
1887
|
+
? extractUrlHost(this.settingsService.settings.cdnUrl)
|
|
1888
|
+
: 'none',
|
|
1889
|
+
country: this.settingsService.user.country.value,
|
|
1890
|
+
local: this.settingsService.user.country.localized_name,
|
|
1891
|
+
};
|
|
1892
|
+
}
|
|
1893
|
+
removeErrorMetaFields(error) {
|
|
1894
|
+
const metaPropList = [
|
|
1895
|
+
'parentTag',
|
|
1896
|
+
'childTag',
|
|
1897
|
+
'RESTRICTED_KEYS_REGEXP',
|
|
1898
|
+
'tags',
|
|
1899
|
+
];
|
|
1900
|
+
Object.keys(error).forEach((key) => {
|
|
1901
|
+
if (metaPropList.includes(key))
|
|
1902
|
+
delete error[key];
|
|
1903
|
+
});
|
|
1904
|
+
// implementing own 'message' property from prototype
|
|
1905
|
+
return Object.assign(Object.assign({}, error), { message: error.message });
|
|
1906
|
+
}
|
|
1907
|
+
sendLog(message, tags) {
|
|
1908
|
+
const url = `https://logs-01.xsolla.com/tag/${tags.join(',')}`;
|
|
1909
|
+
firstValueFrom(this.http.post(url, message, {
|
|
1910
|
+
headers: new HttpHeaders().set('Content-Type', 'text/plain'),
|
|
1911
|
+
responseType: 'text',
|
|
1912
|
+
})).catch((err) => console.error('Elk Logger: request error', err));
|
|
1913
|
+
}
|
|
1914
|
+
}
|
|
1915
|
+
ElkLoggerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ElkLoggerService, deps: [{ token: windowToken }, { token: SettingsService }, { token: i1.HttpClient }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1916
|
+
ElkLoggerService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ElkLoggerService, providedIn: 'root' });
|
|
1917
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ElkLoggerService, decorators: [{
|
|
1918
|
+
type: Injectable,
|
|
1919
|
+
args: [{
|
|
1920
|
+
providedIn: 'root',
|
|
1921
|
+
}]
|
|
1922
|
+
}], ctorParameters: function () {
|
|
1923
|
+
return [{ type: undefined, decorators: [{
|
|
1924
|
+
type: Inject,
|
|
1925
|
+
args: [windowToken]
|
|
1926
|
+
}] }, { type: SettingsService }, { type: i1.HttpClient }, { type: i0.NgZone }];
|
|
1927
|
+
} });
|
|
1928
|
+
|
|
1929
|
+
class CentrifugoWebSocketService {
|
|
1930
|
+
constructor(elkLoggerService) {
|
|
1931
|
+
this.elkLoggerService = elkLoggerService;
|
|
1932
|
+
this.type = WebSocketClientType.centrifugo;
|
|
1933
|
+
this.reconnectionTimerId = null;
|
|
1934
|
+
this.isConnectionOpen = false;
|
|
1935
|
+
this.isConnecting = false;
|
|
1936
|
+
this.incomingMessages$ = new Subject();
|
|
1937
|
+
this.successfulReconnectionEventsProxy$ = new Subject();
|
|
1938
|
+
}
|
|
1939
|
+
open(url, channel) {
|
|
1940
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1941
|
+
if (url === this.url && channel === this.channel) {
|
|
1942
|
+
return;
|
|
1943
|
+
}
|
|
1944
|
+
try {
|
|
1945
|
+
this.url = url;
|
|
1946
|
+
this.channel = channel;
|
|
1947
|
+
yield this.createConnection(url, channel);
|
|
1948
|
+
}
|
|
1949
|
+
catch (error) {
|
|
1950
|
+
// @ts-expect-error error is unknown
|
|
1951
|
+
const message = ((error === null || error === void 0 ? void 0 : error.message) || error);
|
|
1952
|
+
const unknownError = new WsError(`unknown websocket error: ${message}`, channel);
|
|
1953
|
+
this.elkLoggerService.handleError(unknownError);
|
|
1954
|
+
}
|
|
1955
|
+
});
|
|
1956
|
+
}
|
|
1957
|
+
close() {
|
|
1958
|
+
this.clearReconnectionTimer();
|
|
1959
|
+
if (!this.isConnectionOpen) {
|
|
1960
|
+
return;
|
|
1961
|
+
}
|
|
1962
|
+
this.connection.disconnect();
|
|
1963
|
+
}
|
|
1964
|
+
get messages$() {
|
|
1965
|
+
return (this.incomingMessages$
|
|
1966
|
+
.asObservable()
|
|
1967
|
+
// event don't respect type from argument, it's weird
|
|
1968
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
1969
|
+
.pipe(map$1((event) => event.data)));
|
|
1970
|
+
}
|
|
1971
|
+
subscribeOnSuccessfulReconnection(next) {
|
|
1972
|
+
return this.successfulReconnectionEventsProxy$
|
|
1973
|
+
.asObservable()
|
|
1974
|
+
.subscribe(next);
|
|
1975
|
+
}
|
|
1976
|
+
clearReconnectionTimer() {
|
|
1977
|
+
if (this.reconnectionTimerId) {
|
|
1978
|
+
clearTimeout(this.reconnectionTimerId);
|
|
1979
|
+
this.reconnectionTimerId = null;
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
setFirstReconnectionTimeout() {
|
|
1983
|
+
const min = CentrifugoWebSocketService.timeoutsMs.reconnection -
|
|
1984
|
+
CentrifugoWebSocketService.timeoutsMs.reconnectionMaxDeviation;
|
|
1985
|
+
const max = CentrifugoWebSocketService.timeoutsMs.reconnection +
|
|
1986
|
+
CentrifugoWebSocketService.timeoutsMs.reconnectionMaxDeviation;
|
|
1987
|
+
this.reconnectionTimeoutMs =
|
|
1988
|
+
Math.floor(Math.random() * (max - min + 1)) + min;
|
|
1989
|
+
}
|
|
1990
|
+
incrementReconnectionTimeout() {
|
|
1991
|
+
this.reconnectionTimeoutMs =
|
|
1992
|
+
this.reconnectionTimeoutMs *
|
|
1993
|
+
CentrifugoWebSocketService.reconnectionTimeoutIncrementFactor;
|
|
1994
|
+
}
|
|
1995
|
+
getCentrifugoClient() {
|
|
1996
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1997
|
+
return import('centrifuge').then((module) => module.Centrifuge);
|
|
1998
|
+
});
|
|
1999
|
+
}
|
|
2000
|
+
createConnection(url, channel) {
|
|
2001
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2002
|
+
if (this.isConnectionOpen || this.isConnecting) {
|
|
2003
|
+
return;
|
|
2004
|
+
}
|
|
2005
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
2006
|
+
const CentrifugeClient = yield this.getCentrifugoClient();
|
|
2007
|
+
const websocketUrl = url !== null && url !== void 0 ? url : this.url;
|
|
2008
|
+
const websocketChannel = channel !== null && channel !== void 0 ? channel : this.channel;
|
|
2009
|
+
this.connection = new CentrifugeClient(websocketUrl, {
|
|
2010
|
+
debug: true,
|
|
2011
|
+
maxReconnectDelay: 1500,
|
|
2012
|
+
maxServerPingDelay: 1000,
|
|
2013
|
+
});
|
|
2014
|
+
return new Promise((resolve, reject) => {
|
|
2015
|
+
this.connection
|
|
2016
|
+
.on('connecting', () => {
|
|
2017
|
+
this.isConnecting = true;
|
|
2018
|
+
})
|
|
2019
|
+
.on('connected', () => {
|
|
2020
|
+
this.onConnect();
|
|
2021
|
+
resolve();
|
|
2022
|
+
})
|
|
2023
|
+
.on('disconnected', (ctx) => {
|
|
2024
|
+
this.onDisconnect(ctx, websocketChannel);
|
|
2025
|
+
reject();
|
|
2026
|
+
})
|
|
2027
|
+
.on('error', (ctx) => {
|
|
2028
|
+
const message = `code ${ctx.error.code} - ${ctx.error.message}`;
|
|
2029
|
+
this.elkLoggerService.log(`connection error: ${message}`, [ErrorTags.WS], {
|
|
2030
|
+
channel: websocketChannel,
|
|
2031
|
+
});
|
|
2032
|
+
})
|
|
2033
|
+
.connect();
|
|
2034
|
+
this.subscription = this.connection.newSubscription(websocketChannel, this.getSubscriptionOptions(websocketChannel));
|
|
2035
|
+
this.subscription
|
|
2036
|
+
.on('subscribed', (ctx) => {
|
|
2037
|
+
this.subscriptionPosition = ctx.streamPosition;
|
|
2038
|
+
this.prevSubscribedChannel = websocketChannel;
|
|
2039
|
+
})
|
|
2040
|
+
.on('publication', (ctx) => {
|
|
2041
|
+
const message = ctx.data;
|
|
2042
|
+
this.elkLoggerService.log(`websocket message received: ${message}`, [ErrorTags.WS], {
|
|
2043
|
+
channel: websocketChannel,
|
|
2044
|
+
});
|
|
2045
|
+
this.incomingMessages$.next(ctx);
|
|
2046
|
+
})
|
|
2047
|
+
.on('error', (ctx) => {
|
|
2048
|
+
const message = `code ${ctx.error.code} - ${ctx.error.message}`;
|
|
2049
|
+
this.elkLoggerService.log(`subscription error: ${message}`, [ErrorTags.WS], {
|
|
2050
|
+
channel: websocketChannel,
|
|
2051
|
+
});
|
|
2052
|
+
})
|
|
2053
|
+
.subscribe();
|
|
2054
|
+
});
|
|
2055
|
+
});
|
|
2056
|
+
}
|
|
2057
|
+
onConnect() {
|
|
2058
|
+
clearTimeout(this.openConnectionTimerId);
|
|
2059
|
+
this.isConnecting = false;
|
|
2060
|
+
this.isConnectionOpen = true;
|
|
2061
|
+
}
|
|
2062
|
+
onDisconnect(ctx, websocketChannel) {
|
|
2063
|
+
this.isConnecting = false;
|
|
2064
|
+
this.isConnectionOpen = false;
|
|
2065
|
+
/* If connection error, cause any connection error isn't 0 */
|
|
2066
|
+
if (ctx.code !== 0) {
|
|
2067
|
+
const message = `code ${ctx.code} - ${ctx.reason}`;
|
|
2068
|
+
this.elkLoggerService.log(`disconnected error: ${message}`, [ErrorTags.WS], {
|
|
2069
|
+
channel: websocketChannel,
|
|
2070
|
+
});
|
|
2071
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
2072
|
+
yield this.waitWhileNotReconnect();
|
|
2073
|
+
}))();
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
reconnect() {
|
|
2077
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2078
|
+
this.clearReconnectionTimer();
|
|
2079
|
+
return new Promise((resolve) => {
|
|
2080
|
+
this.reconnectionTimerId = setTimeout(() => {
|
|
2081
|
+
this.createConnection()
|
|
2082
|
+
.then(() => resolve(true))
|
|
2083
|
+
.catch(() => resolve(false));
|
|
2084
|
+
this.incrementReconnectionTimeout();
|
|
2085
|
+
}, this.reconnectionTimeoutMs);
|
|
2086
|
+
});
|
|
2087
|
+
});
|
|
2088
|
+
}
|
|
2089
|
+
waitWhileNotReconnect() {
|
|
2090
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2091
|
+
this.clearReconnectionTimer();
|
|
2092
|
+
this.setFirstReconnectionTimeout();
|
|
2093
|
+
let isConnected = false;
|
|
2094
|
+
const beforeTimer = performance.now();
|
|
2095
|
+
while (!isConnected) {
|
|
2096
|
+
isConnected = yield this.reconnect();
|
|
2097
|
+
}
|
|
2098
|
+
const afterTimer = performance.now();
|
|
2099
|
+
const timerDuration = afterTimer - beforeTimer;
|
|
2100
|
+
this.elkLoggerService.log(`fallback to reconnection timer: duration ${timerDuration}ms`, [ErrorTags.WS], {
|
|
2101
|
+
channel: this.channel,
|
|
2102
|
+
});
|
|
2103
|
+
this.successfulReconnectionEventsProxy$.next();
|
|
2104
|
+
});
|
|
2105
|
+
}
|
|
2106
|
+
getSubscriptionOptions(websocketChannel) {
|
|
2107
|
+
const options = {
|
|
2108
|
+
recoverable: true,
|
|
2109
|
+
};
|
|
2110
|
+
if (websocketChannel === this.prevSubscribedChannel &&
|
|
2111
|
+
this.subscriptionPosition) {
|
|
2112
|
+
options.since = this.subscriptionPosition;
|
|
2113
|
+
}
|
|
2114
|
+
return options;
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
CentrifugoWebSocketService.reconnectionTimeoutIncrementFactor = 2;
|
|
2118
|
+
CentrifugoWebSocketService.timeoutsMs = {
|
|
2119
|
+
reconnection: 1000,
|
|
2120
|
+
reconnectionMaxDeviation: 1000,
|
|
2121
|
+
};
|
|
2122
|
+
CentrifugoWebSocketService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CentrifugoWebSocketService, deps: [{ token: ElkLoggerService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2123
|
+
CentrifugoWebSocketService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CentrifugoWebSocketService, providedIn: 'root' });
|
|
2124
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CentrifugoWebSocketService, decorators: [{
|
|
2125
|
+
type: Injectable,
|
|
2126
|
+
args: [{
|
|
2127
|
+
providedIn: 'root',
|
|
2128
|
+
}]
|
|
2129
|
+
}], ctorParameters: function () { return [{ type: ElkLoggerService }]; } });
|
|
2130
|
+
|
|
2131
|
+
// @todo: remove this factory and switch to centrifugo client after centrifugo issues resolved
|
|
2132
|
+
class WebSocketFactory {
|
|
2133
|
+
constructor(nchanWebSocket, centrifugoWebSocket) {
|
|
2134
|
+
this.nchanWebSocket = nchanWebSocket;
|
|
2135
|
+
this.centrifugoWebSocket = centrifugoWebSocket;
|
|
2136
|
+
}
|
|
2137
|
+
createWebSocketClient(url, clientType) {
|
|
2138
|
+
if (clientType === WebSocketClientType.centrifugo) {
|
|
2139
|
+
return this.centrifugoWebSocket;
|
|
2140
|
+
}
|
|
2141
|
+
this.nchanWebSocket.url = url;
|
|
2142
|
+
return this.nchanWebSocket;
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
WebSocketFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: WebSocketFactory, deps: [{ token: NchanWebSocketService }, { token: CentrifugoWebSocketService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2146
|
+
WebSocketFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: WebSocketFactory, providedIn: 'root' });
|
|
2147
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: WebSocketFactory, decorators: [{
|
|
2148
|
+
type: Injectable,
|
|
2149
|
+
args: [{
|
|
2150
|
+
providedIn: 'root',
|
|
2151
|
+
}]
|
|
2152
|
+
}], ctorParameters: function () { return [{ type: NchanWebSocketService }, { type: CentrifugoWebSocketService }]; } });
|
|
2153
|
+
|
|
2154
|
+
class WebsocketStatusService {
|
|
2155
|
+
get needCheckStatus$() {
|
|
2156
|
+
return this.needCheckStatusSubject.asObservable();
|
|
2157
|
+
}
|
|
2158
|
+
get statusChanged$() {
|
|
2159
|
+
return this.statusChangedSubject.asObservable();
|
|
2160
|
+
}
|
|
2161
|
+
constructor(webSocketFactory) {
|
|
2162
|
+
this.webSocketFactory = webSocketFactory;
|
|
2163
|
+
this.reinsuranceCheckStatus = {
|
|
2164
|
+
timeoutId: null,
|
|
2165
|
+
timeoutMs: 180000,
|
|
2166
|
+
};
|
|
2167
|
+
this.needCheckStatusSubject = new Subject();
|
|
2168
|
+
this.statusChangedSubject = new Subject();
|
|
2169
|
+
this.webSocketClient = null;
|
|
2170
|
+
}
|
|
2171
|
+
checkStatusWithWebSocket(webSocketUrl, webSocketChannelName, webSocketClientType) {
|
|
2172
|
+
var _a;
|
|
2173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2174
|
+
this.webSocketClient = this.webSocketFactory.createWebSocketClient(webSocketUrl, webSocketClientType);
|
|
2175
|
+
yield this.webSocketClient.open(webSocketUrl, webSocketChannelName);
|
|
2176
|
+
(_a = this.webSocketSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
2177
|
+
this.webSocketSubscription = this.webSocketClient.messages$.subscribe((message) => this.statusProcessing(message));
|
|
2178
|
+
this.webSocketReconnectionSubscription =
|
|
2179
|
+
this.webSocketClient.subscribeOnSuccessfulReconnection(() => {
|
|
2180
|
+
this.needCheckStatusSubject.next();
|
|
2181
|
+
});
|
|
2182
|
+
this.needCheckStatusSubject.next();
|
|
2183
|
+
this.startReinsuranceCheckTimeout();
|
|
2184
|
+
});
|
|
2185
|
+
}
|
|
2186
|
+
closeWebSocket() {
|
|
2187
|
+
var _a;
|
|
2188
|
+
this.removeSubscription();
|
|
2189
|
+
(_a = this.webSocketClient) === null || _a === void 0 ? void 0 : _a.close();
|
|
2190
|
+
this.clearReinsuranceCheckTimeout();
|
|
2191
|
+
}
|
|
2192
|
+
startReinsuranceCheckTimeout() {
|
|
2193
|
+
this.clearReinsuranceCheckTimeout();
|
|
2194
|
+
this.reinsuranceCheckStatus.timeoutId = setTimeout(() => {
|
|
2195
|
+
this.needCheckStatusSubject.next();
|
|
2196
|
+
}, this.reinsuranceCheckStatus.timeoutMs);
|
|
2197
|
+
}
|
|
2198
|
+
clearReinsuranceCheckTimeout() {
|
|
2199
|
+
if (this.reinsuranceCheckStatus.timeoutId) {
|
|
2200
|
+
clearTimeout(this.reinsuranceCheckStatus.timeoutId);
|
|
2201
|
+
this.reinsuranceCheckStatus.timeoutId = null;
|
|
2202
|
+
}
|
|
2203
|
+
}
|
|
2204
|
+
statusProcessing(message) {
|
|
2205
|
+
if (message === WebSocketStatus.statusChanged) {
|
|
2206
|
+
this.statusChangedSubject.next();
|
|
2207
|
+
this.closeWebSocket();
|
|
2208
|
+
this.clearReinsuranceCheckTimeout();
|
|
2209
|
+
}
|
|
2210
|
+
if (message === WebSocketStatus.troubledStatus) {
|
|
2211
|
+
this.clearReinsuranceCheckTimeout();
|
|
2212
|
+
this.closeWebSocket();
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
removeSubscription() {
|
|
2216
|
+
var _a, _b;
|
|
2217
|
+
(_a = this.webSocketSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
2218
|
+
(_b = this.webSocketReconnectionSubscription) === null || _b === void 0 ? void 0 : _b.unsubscribe();
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
WebsocketStatusService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: WebsocketStatusService, deps: [{ token: WebSocketFactory }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2222
|
+
WebsocketStatusService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: WebsocketStatusService, providedIn: 'root' });
|
|
2223
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: WebsocketStatusService, decorators: [{
|
|
2224
|
+
type: Injectable,
|
|
2225
|
+
args: [{
|
|
2226
|
+
providedIn: 'root',
|
|
2227
|
+
}]
|
|
2228
|
+
}], ctorParameters: function () { return [{ type: WebSocketFactory }]; } });
|
|
2229
|
+
|
|
2230
|
+
class ListenStatusService {
|
|
2231
|
+
get websocketOpened$() {
|
|
2232
|
+
return this.websocketOpenedSubject.asObservable();
|
|
2233
|
+
}
|
|
2234
|
+
get statusUpdated$() {
|
|
2235
|
+
return this.statusUpdatedSubject.asObservable();
|
|
2236
|
+
}
|
|
2237
|
+
constructor(statusService, checkStatusService, websocketStatusService) {
|
|
2238
|
+
this.statusService = statusService;
|
|
2239
|
+
this.checkStatusService = checkStatusService;
|
|
2240
|
+
this.websocketStatusService = websocketStatusService;
|
|
2241
|
+
this.isListening = false;
|
|
2242
|
+
this.websocketOpenedSubject = new Subject();
|
|
2243
|
+
this.statusUpdatedSubject = new Subject();
|
|
2244
|
+
this.statusDoneSubject = new Subject();
|
|
2245
|
+
this.destroy$ = new Subject();
|
|
2246
|
+
}
|
|
2247
|
+
listen(invoice) {
|
|
2248
|
+
if (this.isListening) {
|
|
2249
|
+
this.stopListening();
|
|
2250
|
+
}
|
|
2251
|
+
this.destroy$ = new Subject();
|
|
2252
|
+
this.isListening = true;
|
|
2253
|
+
this.subscribeStatusUpdate(invoice);
|
|
2254
|
+
this.subscribeCheckStatusUpdate();
|
|
2255
|
+
this.subscribeWebsocketEvent();
|
|
2256
|
+
this.checkStatusService.setRequestParams(invoice);
|
|
2257
|
+
return this.statusDoneSubject.asObservable();
|
|
2258
|
+
}
|
|
2259
|
+
stopListening() {
|
|
2260
|
+
this.isListening = false;
|
|
2261
|
+
this.websocketStatusService.closeWebSocket();
|
|
2262
|
+
this.destroy$.next();
|
|
2263
|
+
this.destroy$.complete();
|
|
2264
|
+
}
|
|
2265
|
+
subscribeStatusUpdate(invoice) {
|
|
2266
|
+
this.statusService.response$
|
|
2267
|
+
.pipe(filter$1((statusResponse) => {
|
|
2268
|
+
var _a;
|
|
2269
|
+
return ((_a = statusResponse === null || statusResponse === void 0 ? void 0 : statusResponse.status) === null || _a === void 0 ? void 0 : _a.invoice) === Number(invoice);
|
|
2270
|
+
}), takeUntil(this.destroy$))
|
|
2271
|
+
.subscribe((statusResponse) => {
|
|
2272
|
+
if (!(statusResponse === null || statusResponse === void 0 ? void 0 : statusResponse.status)) {
|
|
2273
|
+
return;
|
|
2274
|
+
}
|
|
2275
|
+
const statusSettings = {
|
|
2276
|
+
statusState: statusResponse.status.statusState,
|
|
2277
|
+
isCancelUser: statusResponse.status.isCancelUser,
|
|
2278
|
+
needWebSocket: statusResponse.status.needToCheck,
|
|
2279
|
+
backUrlSettings: statusResponse.status.backUrlSettings,
|
|
2280
|
+
autoRedirect: statusResponse.status.autoRedirect,
|
|
2281
|
+
webSocketUrl: statusResponse.status.webSocketUrl,
|
|
2282
|
+
webSocketChannelName: statusResponse.status.webSocketChannelName,
|
|
2283
|
+
webSocketClientType: statusResponse.status.webSocketClientType,
|
|
2284
|
+
};
|
|
2285
|
+
this.statusUpdatedSubject.next({
|
|
2286
|
+
statusResponse: statusResponse,
|
|
2287
|
+
statusSettings: statusSettings,
|
|
2288
|
+
});
|
|
2289
|
+
if (statusSettings.needWebSocket) {
|
|
2290
|
+
this.openWebsocket(statusSettings);
|
|
2291
|
+
return;
|
|
2292
|
+
}
|
|
2293
|
+
this.stopListening();
|
|
2294
|
+
this.statusDoneSubject.next(statusSettings);
|
|
2295
|
+
});
|
|
2296
|
+
}
|
|
2297
|
+
subscribeCheckStatusUpdate() {
|
|
2298
|
+
this.checkStatusService.response$
|
|
2299
|
+
.pipe(takeUntil(this.destroy$))
|
|
2300
|
+
.subscribe((checkStatusResponse) => {
|
|
2301
|
+
if (!(checkStatusResponse === null || checkStatusResponse === void 0 ? void 0 : checkStatusResponse.status))
|
|
2302
|
+
return;
|
|
2303
|
+
if (checkStatusResponse.status === StatusEnum.done) {
|
|
2304
|
+
this.statusService.request();
|
|
2305
|
+
this.websocketStatusService.closeWebSocket();
|
|
2306
|
+
return;
|
|
2307
|
+
}
|
|
2308
|
+
if (checkStatusResponse.final === false) {
|
|
2309
|
+
this.websocketStatusService.startReinsuranceCheckTimeout();
|
|
2310
|
+
return;
|
|
2311
|
+
}
|
|
2312
|
+
});
|
|
2313
|
+
}
|
|
2314
|
+
subscribeWebsocketEvent() {
|
|
2315
|
+
this.websocketStatusService.needCheckStatus$
|
|
2316
|
+
.pipe(takeUntil(this.destroy$))
|
|
2317
|
+
.subscribe(() => this.checkStatusService.request());
|
|
2318
|
+
this.websocketStatusService.statusChanged$
|
|
2319
|
+
.pipe(takeUntil(this.destroy$))
|
|
2320
|
+
.subscribe(() => this.statusService.request());
|
|
2321
|
+
}
|
|
2322
|
+
openWebsocket(statusSettings) {
|
|
2323
|
+
void this.websocketStatusService.checkStatusWithWebSocket(statusSettings.webSocketUrl, statusSettings.webSocketChannelName, statusSettings.webSocketClientType);
|
|
2324
|
+
this.websocketOpenedSubject.next(statusSettings);
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
ListenStatusService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ListenStatusService, deps: [{ token: StatusRequestService }, { token: CheckStatusService }, { token: WebsocketStatusService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2328
|
+
ListenStatusService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ListenStatusService, providedIn: 'root' });
|
|
2329
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ListenStatusService, decorators: [{
|
|
2330
|
+
type: Injectable,
|
|
2331
|
+
args: [{
|
|
2332
|
+
providedIn: 'root',
|
|
2333
|
+
}]
|
|
2334
|
+
}], ctorParameters: function () { return [{ type: StatusRequestService }, { type: CheckStatusService }, { type: WebsocketStatusService }]; } });
|
|
2335
|
+
|
|
1326
2336
|
class ShowFieldsAction {
|
|
1327
2337
|
constructor(submitResponse) {
|
|
1328
2338
|
this.type = 'show_fields';
|
|
@@ -1348,17 +2358,61 @@ const showFieldsActionFactoryProvider = {
|
|
|
1348
2358
|
},
|
|
1349
2359
|
};
|
|
1350
2360
|
|
|
2361
|
+
class CheckStatusAction {
|
|
2362
|
+
constructor(submitResponse) {
|
|
2363
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2364
|
+
this.type = 'check_status';
|
|
2365
|
+
const status = submitResponse.parameters.status;
|
|
2366
|
+
this.data = {
|
|
2367
|
+
invoice: status === null || status === void 0 ? void 0 : status.invoice,
|
|
2368
|
+
signature: (_a = submitResponse.parameters.form.signature) === null || _a === void 0 ? void 0 : _a.value,
|
|
2369
|
+
locale: (_b = submitResponse.parameters.form.locale) === null || _b === void 0 ? void 0 : _b.value,
|
|
2370
|
+
testPs: (_c = submitResponse.parameters.form.testPs) === null || _c === void 0 ? void 0 : _c.value,
|
|
2371
|
+
testXsolla: (_d = submitResponse.parameters.form.testXsolla) === null || _d === void 0 ? void 0 : _d.value,
|
|
2372
|
+
testProject: (_e = submitResponse.parameters.form.testProject) === null || _e === void 0 ? void 0 : _e.value,
|
|
2373
|
+
userReturnStatus: (_f = submitResponse.parameters.form.userReturnStatus) === null || _f === void 0 ? void 0 : _f.value,
|
|
2374
|
+
};
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
|
|
2378
|
+
const checkStatusActionFactoryToken = new InjectionToken('CheckStatusAction');
|
|
2379
|
+
const checkStatusActionFactoryProvider = {
|
|
2380
|
+
provide: checkStatusActionFactoryToken,
|
|
2381
|
+
useValue: {
|
|
2382
|
+
factory: (...args) => new CheckStatusAction(...args),
|
|
2383
|
+
type: 'check_status',
|
|
2384
|
+
},
|
|
2385
|
+
};
|
|
2386
|
+
|
|
2387
|
+
const statusUpdatedActionFactoryToken = new InjectionToken('StatusUpdatedAction');
|
|
2388
|
+
const statusUpdatedActionFactoryProvider = {
|
|
2389
|
+
provide: statusUpdatedActionFactoryToken,
|
|
2390
|
+
useValue: {
|
|
2391
|
+
factory: (...args) => new StatusUpdatedAction(...args),
|
|
2392
|
+
type: 'status_updated',
|
|
2393
|
+
},
|
|
2394
|
+
};
|
|
2395
|
+
|
|
1351
2396
|
const nextActionsToken = new InjectionToken('Action');
|
|
1352
|
-
const nextActions = [
|
|
2397
|
+
const nextActions = [
|
|
2398
|
+
showFieldsActionFactoryProvider,
|
|
2399
|
+
checkStatusActionFactoryProvider,
|
|
2400
|
+
statusUpdatedActionFactoryProvider,
|
|
2401
|
+
];
|
|
1353
2402
|
|
|
1354
2403
|
const actionTypeCommandMap = {
|
|
1355
2404
|
[XpsCommand.check]: 'show_fields',
|
|
2405
|
+
[XpsCommand.status]: 'check_status',
|
|
1356
2406
|
};
|
|
1357
2407
|
|
|
1358
2408
|
class NextActionService {
|
|
2409
|
+
get flowUpdates$() {
|
|
2410
|
+
return this.flowUpdatesSubject.asObservable();
|
|
2411
|
+
}
|
|
1359
2412
|
constructor(nextActionTokens, injector) {
|
|
1360
2413
|
this.nextActionTokens = nextActionTokens;
|
|
1361
2414
|
this.injector = injector;
|
|
2415
|
+
this.flowUpdatesSubject = new Subject();
|
|
1362
2416
|
this.nextActionsMap = new Map();
|
|
1363
2417
|
this.fillNextActionsMap();
|
|
1364
2418
|
}
|
|
@@ -1372,6 +2426,9 @@ class NextActionService {
|
|
|
1372
2426
|
}
|
|
1373
2427
|
throw new Error('Next action is undefined.');
|
|
1374
2428
|
}
|
|
2429
|
+
emitFlowUpdates(action) {
|
|
2430
|
+
this.flowUpdatesSubject.next(action);
|
|
2431
|
+
}
|
|
1375
2432
|
fillNextActionsMap() {
|
|
1376
2433
|
this.nextActionTokens.forEach((nextAction) => {
|
|
1377
2434
|
const item = this.injector.get(nextAction.provide);
|
|
@@ -1400,12 +2457,46 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
|
|
|
1400
2457
|
}] }, { type: i0.Injector }];
|
|
1401
2458
|
} });
|
|
1402
2459
|
|
|
2460
|
+
class StatusService {
|
|
2461
|
+
constructor(statusRequestService, listenStatusService, nextActionService) {
|
|
2462
|
+
this.statusRequestService = statusRequestService;
|
|
2463
|
+
this.listenStatusService = listenStatusService;
|
|
2464
|
+
this.nextActionService = nextActionService;
|
|
2465
|
+
}
|
|
2466
|
+
getStatus(params) {
|
|
2467
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2468
|
+
this.statusRequestService.setRequestParams(params);
|
|
2469
|
+
this.startWaitingStatusUpdates(params.invoice);
|
|
2470
|
+
this.statusRequestService.request();
|
|
2471
|
+
const statusResponse = yield firstValueFrom(this.listenStatusService.statusUpdated$);
|
|
2472
|
+
return statusResponse.statusResponse.status;
|
|
2473
|
+
});
|
|
2474
|
+
}
|
|
2475
|
+
startWaitingStatusUpdates(invoice) {
|
|
2476
|
+
this.listenStatusService.listen(invoice);
|
|
2477
|
+
this.listenStatusService.statusUpdated$
|
|
2478
|
+
.pipe(skip(1))
|
|
2479
|
+
.subscribe(({ statusResponse }) => {
|
|
2480
|
+
this.nextActionService.emitFlowUpdates(new StatusUpdatedAction(statusResponse));
|
|
2481
|
+
});
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
StatusService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusService, deps: [{ token: StatusRequestService }, { token: ListenStatusService }, { token: NextActionService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2485
|
+
StatusService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusService, providedIn: 'root' });
|
|
2486
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusService, decorators: [{
|
|
2487
|
+
type: Injectable,
|
|
2488
|
+
args: [{
|
|
2489
|
+
providedIn: 'root',
|
|
2490
|
+
}]
|
|
2491
|
+
}], ctorParameters: function () { return [{ type: StatusRequestService }, { type: ListenStatusService }, { type: NextActionService }]; } });
|
|
2492
|
+
|
|
1403
2493
|
class PaymentService {
|
|
1404
|
-
constructor(initializeService, submitService, syncService, formService, nextActionService) {
|
|
2494
|
+
constructor(initializeService, submitService, syncService, formService, statusService, nextActionService) {
|
|
1405
2495
|
this.initializeService = initializeService;
|
|
1406
2496
|
this.submitService = submitService;
|
|
1407
2497
|
this.syncService = syncService;
|
|
1408
2498
|
this.formService = formService;
|
|
2499
|
+
this.statusService = statusService;
|
|
1409
2500
|
this.nextActionService = nextActionService;
|
|
1410
2501
|
this.form = null;
|
|
1411
2502
|
this.data = null;
|
|
@@ -1413,6 +2504,7 @@ class PaymentService {
|
|
|
1413
2504
|
}
|
|
1414
2505
|
initialize(config) {
|
|
1415
2506
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2507
|
+
this.config = config;
|
|
1416
2508
|
this.data = yield this.initializeService.request(config);
|
|
1417
2509
|
this.fields = this.getFields();
|
|
1418
2510
|
this.form = this.formService.createForm(this.fields);
|
|
@@ -1441,8 +2533,10 @@ class PaymentService {
|
|
|
1441
2533
|
getFinanceDetails() {
|
|
1442
2534
|
throw new Error('Method not implemented.');
|
|
1443
2535
|
}
|
|
1444
|
-
getStatus() {
|
|
1445
|
-
|
|
2536
|
+
getStatus(params) {
|
|
2537
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2538
|
+
return this.statusService.getStatus(Object.assign(Object.assign({}, params), { pid: this.config.paymentMethodId }));
|
|
2539
|
+
});
|
|
1446
2540
|
}
|
|
1447
2541
|
changeFieldValue(name, value) {
|
|
1448
2542
|
var _a;
|
|
@@ -1450,14 +2544,14 @@ class PaymentService {
|
|
|
1450
2544
|
formControl === null || formControl === void 0 ? void 0 : formControl.setValue(value);
|
|
1451
2545
|
}
|
|
1452
2546
|
}
|
|
1453
|
-
PaymentService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PaymentService, deps: [{ token: InitializeService }, { token: SubmitService }, { token: SyncService }, { token: FormService }, { token: NextActionService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2547
|
+
PaymentService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PaymentService, deps: [{ token: InitializeService }, { token: SubmitService }, { token: SyncService }, { token: FormService }, { token: StatusService }, { token: NextActionService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1454
2548
|
PaymentService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PaymentService, providedIn: 'root' });
|
|
1455
2549
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PaymentService, decorators: [{
|
|
1456
2550
|
type: Injectable,
|
|
1457
2551
|
args: [{
|
|
1458
2552
|
providedIn: 'root',
|
|
1459
2553
|
}]
|
|
1460
|
-
}], ctorParameters: function () { return [{ type: InitializeService }, { type: SubmitService }, { type: SyncService }, { type: FormService }, { type: NextActionService }]; } });
|
|
2554
|
+
}], ctorParameters: function () { return [{ type: InitializeService }, { type: SubmitService }, { type: SyncService }, { type: FormService }, { type: StatusService }, { type: NextActionService }]; } });
|
|
1461
2555
|
|
|
1462
2556
|
class RefundPolicyService {
|
|
1463
2557
|
constructor(settingsService) {
|
|
@@ -1565,7 +2659,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
|
|
|
1565
2659
|
}], ctorParameters: function () { return [{ type: SettingsService }, { type: RefundPolicyService }, { type: SecureConnectionService }, { type: DisclaimerService }]; } });
|
|
1566
2660
|
|
|
1567
2661
|
class CoreLibraryService {
|
|
1568
|
-
constructor(settingsService, countryService, paymentMethodsService, savedMethodsService, userBalanceService, paymentService, deviceFingerPrintService, legalService) {
|
|
2662
|
+
constructor(settingsService, countryService, paymentMethodsService, savedMethodsService, userBalanceService, paymentService, deviceFingerPrintService, legalService, nextActionService) {
|
|
1569
2663
|
this.settingsService = settingsService;
|
|
1570
2664
|
this.countryService = countryService;
|
|
1571
2665
|
this.paymentMethodsService = paymentMethodsService;
|
|
@@ -1574,6 +2668,7 @@ class CoreLibraryService {
|
|
|
1574
2668
|
this.paymentService = paymentService;
|
|
1575
2669
|
this.deviceFingerPrintService = deviceFingerPrintService;
|
|
1576
2670
|
this.legalService = legalService;
|
|
2671
|
+
this.nextActionService = nextActionService;
|
|
1577
2672
|
this.paymentMethods = {
|
|
1578
2673
|
getList: () => __awaiter(this, void 0, void 0, function* () { return this.paymentMethodsService.getList(); }),
|
|
1579
2674
|
getQuickMethods: () => __awaiter(this, void 0, void 0, function* () { return this.paymentMethodsService.getQuickMethods(); }),
|
|
@@ -1599,21 +2694,22 @@ class CoreLibraryService {
|
|
|
1599
2694
|
validate: (field) => __awaiter(this, void 0, void 0, function* () { return this.paymentService.validate(field); }),
|
|
1600
2695
|
getFinanceDetails: () => this.paymentService.getFinanceDetails(),
|
|
1601
2696
|
runThreeDs: () => this.paymentService.runThreeDs(),
|
|
1602
|
-
getStatus: () => this.paymentService.getStatus(),
|
|
2697
|
+
getStatus: (params) => __awaiter(this, void 0, void 0, function* () { return this.paymentService.getStatus(params); }),
|
|
2698
|
+
flowUpdates$: this.nextActionService.flowUpdates$,
|
|
1603
2699
|
};
|
|
1604
2700
|
}
|
|
1605
2701
|
getLegalComponentConfig() {
|
|
1606
2702
|
return this.legalService.getLegalComponentConfig();
|
|
1607
2703
|
}
|
|
1608
2704
|
}
|
|
1609
|
-
CoreLibraryService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryService, deps: [{ token: SettingsService }, { token: CountryService }, { token: PaymentMethodsService }, { token: SavedMethodsService }, { token: UserBalanceService }, { token: PaymentService }, { token: DeviceFingerPrintService }, { token: LegalService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2705
|
+
CoreLibraryService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryService, deps: [{ token: SettingsService }, { token: CountryService }, { token: PaymentMethodsService }, { token: SavedMethodsService }, { token: UserBalanceService }, { token: PaymentService }, { token: DeviceFingerPrintService }, { token: LegalService }, { token: NextActionService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1610
2706
|
CoreLibraryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryService, providedIn: 'root' });
|
|
1611
2707
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryService, decorators: [{
|
|
1612
2708
|
type: Injectable,
|
|
1613
2709
|
args: [{
|
|
1614
2710
|
providedIn: 'root',
|
|
1615
2711
|
}]
|
|
1616
|
-
}], ctorParameters: function () { return [{ type: SettingsService }, { type: CountryService }, { type: PaymentMethodsService }, { type: SavedMethodsService }, { type: UserBalanceService }, { type: PaymentService }, { type: DeviceFingerPrintService }, { type: LegalService }]; } });
|
|
2712
|
+
}], ctorParameters: function () { return [{ type: SettingsService }, { type: CountryService }, { type: PaymentMethodsService }, { type: SavedMethodsService }, { type: UserBalanceService }, { type: PaymentService }, { type: DeviceFingerPrintService }, { type: LegalService }, { type: NextActionService }]; } });
|
|
1617
2713
|
|
|
1618
2714
|
class HttpError extends AppError {
|
|
1619
2715
|
constructor(error, req) {
|
|
@@ -1712,6 +2808,10 @@ CoreLibraryModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", versi
|
|
|
1712
2808
|
submitResponseFactoryProvider,
|
|
1713
2809
|
syncRequestFactoryProvider,
|
|
1714
2810
|
syncResponseFactoryProvider,
|
|
2811
|
+
statusRequestFactoryProvider,
|
|
2812
|
+
statusResponseFactoryProvider,
|
|
2813
|
+
checkStatusRequestFactoryProvider,
|
|
2814
|
+
checkStatusResponseFactoryProvider,
|
|
1715
2815
|
{
|
|
1716
2816
|
provide: nextActionsToken,
|
|
1717
2817
|
useValue: nextActions,
|
|
@@ -1737,6 +2837,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
|
|
|
1737
2837
|
submitResponseFactoryProvider,
|
|
1738
2838
|
syncRequestFactoryProvider,
|
|
1739
2839
|
syncResponseFactoryProvider,
|
|
2840
|
+
statusRequestFactoryProvider,
|
|
2841
|
+
statusResponseFactoryProvider,
|
|
2842
|
+
checkStatusRequestFactoryProvider,
|
|
2843
|
+
checkStatusResponseFactoryProvider,
|
|
1740
2844
|
{
|
|
1741
2845
|
provide: nextActionsToken,
|
|
1742
2846
|
useValue: nextActions,
|