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