@xsolla/payment-client-core 0.2.101 → 0.2.102

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.
@@ -1632,6 +1632,45 @@ const isGooglePaySettingsGuard = (settings) => {
1632
1632
  return settings.paymentMethodId === googlePayPid;
1633
1633
  };
1634
1634
 
1635
+ class HttpError extends AppError {
1636
+ constructor(error, req) {
1637
+ super(error.message);
1638
+ this.RESTRICTED_KEYS_REGEXP = new RegExp('.*(card_number|number|cvv|cvn|month|year|cardholdername|client_data|dfp|password).*', 'i');
1639
+ this.httpErrorData = {
1640
+ request: {
1641
+ url: req.url,
1642
+ method: req.method,
1643
+ headers: req.headers,
1644
+ },
1645
+ response: {
1646
+ status: error.status,
1647
+ headers: error.headers,
1648
+ },
1649
+ };
1650
+ if (req.body) {
1651
+ this.httpErrorData.request.data = this.cleanPersonalData(req.body);
1652
+ }
1653
+ if (error.statusText) {
1654
+ const errorData = error.error;
1655
+ this.httpErrorData.response.data = {
1656
+ statusText: error.statusText,
1657
+ errors: errorData?.errors ?? [],
1658
+ };
1659
+ }
1660
+ }
1661
+ getHttpErrorData() {
1662
+ return this.httpErrorData;
1663
+ }
1664
+ cleanPersonalData(data) {
1665
+ return Object.entries(data).reduce((acc, [key, val]) => {
1666
+ return {
1667
+ ...acc,
1668
+ [key]: this.RESTRICTED_KEYS_REGEXP.test(key) ? '***' : val,
1669
+ };
1670
+ }, {});
1671
+ }
1672
+ }
1673
+
1635
1674
  const initializeResponseFactoryToken = new InjectionToken('InitializeResponse');
1636
1675
  const initializeResponseFactoryProvider = {
1637
1676
  provide: initializeResponseFactoryToken,
@@ -2279,6 +2318,26 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
2279
2318
  type: Injectable
2280
2319
  }] });
2281
2320
 
2321
+ class ServerErrorActionCreator {
2322
+ constructor() {
2323
+ this.type = 'server_error';
2324
+ }
2325
+ getActionData(data) {
2326
+ return {
2327
+ type: this.type,
2328
+ data,
2329
+ };
2330
+ }
2331
+ isSuitable() {
2332
+ return false;
2333
+ }
2334
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ServerErrorActionCreator, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
2335
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ServerErrorActionCreator }); }
2336
+ }
2337
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: ServerErrorActionCreator, decorators: [{
2338
+ type: Injectable
2339
+ }] });
2340
+
2282
2341
  const nextActionsToken = new InjectionToken('Action');
2283
2342
  const nextActions = [
2284
2343
  GoogleThreeDsRedirectActionCreator,
@@ -2296,6 +2355,7 @@ const flowUpdateNextActions = [
2296
2355
  StatusUpdatedActionCreator,
2297
2356
  ThreeDsActionCreator,
2298
2357
  ThreeDsRedirectActionCreator,
2358
+ ServerErrorActionCreator,
2299
2359
  ];
2300
2360
 
2301
2361
  const oneTimeAnalyticsEvents = new Set([]);
@@ -3220,7 +3280,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
3220
3280
  }] }, { type: SettingsService }] });
3221
3281
 
3222
3282
  class InitializeService {
3223
- constructor(responseFactory, xpsApiService, settingsService, countryService, nextActionService, xpsResponseErrorsMappingService, encryptCreditCardService, showErrorsActionCreator, userBehaviourAnalyticsService, paymentSettingsService, sessionService) {
3283
+ constructor(responseFactory, xpsApiService, settingsService, countryService, nextActionService, xpsResponseErrorsMappingService, encryptCreditCardService, showErrorsActionCreator, serverErrorActionCreator, userBehaviourAnalyticsService, paymentSettingsService, sessionService) {
3224
3284
  this.responseFactory = responseFactory;
3225
3285
  this.xpsApiService = xpsApiService;
3226
3286
  this.settingsService = settingsService;
@@ -3229,6 +3289,7 @@ class InitializeService {
3229
3289
  this.xpsResponseErrorsMappingService = xpsResponseErrorsMappingService;
3230
3290
  this.encryptCreditCardService = encryptCreditCardService;
3231
3291
  this.showErrorsActionCreator = showErrorsActionCreator;
3292
+ this.serverErrorActionCreator = serverErrorActionCreator;
3232
3293
  this.userBehaviourAnalyticsService = userBehaviourAnalyticsService;
3233
3294
  this.paymentSettingsService = paymentSettingsService;
3234
3295
  this.sessionService = sessionService;
@@ -3273,6 +3334,13 @@ class InitializeService {
3273
3334
  return initializeResponse;
3274
3335
  })
3275
3336
  .catch((error) => {
3337
+ if (error instanceof HttpError) {
3338
+ const httpErrorData = error.getHttpErrorData();
3339
+ this.nextActionService.emitFlowUpdates(this.serverErrorActionCreator.getActionData({
3340
+ status: httpErrorData.response.status,
3341
+ message: error.message,
3342
+ }));
3343
+ }
3276
3344
  throw new ResponseError(error.message);
3277
3345
  });
3278
3346
  }
@@ -3283,7 +3351,7 @@ class InitializeService {
3283
3351
  }
3284
3352
  this.encryptCreditCardService.setPublicKey(atob(publicKeyField.value));
3285
3353
  }
3286
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: InitializeService, deps: [{ token: initializeResponseFactoryToken }, { token: XpsApiService }, { token: SettingsService }, { token: CountryService }, { token: NextActionService }, { token: XpsResponseErrorsMappingService }, { token: EncryptCreditCardService }, { token: ShowErrorsActionCreator }, { token: UserBehaviourAnalyticsService }, { token: PaymentSettingsService }, { token: SessionService }], target: i0.ɵɵFactoryTarget.Injectable }); }
3354
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: InitializeService, deps: [{ token: initializeResponseFactoryToken }, { token: XpsApiService }, { token: SettingsService }, { token: CountryService }, { token: NextActionService }, { token: XpsResponseErrorsMappingService }, { token: EncryptCreditCardService }, { token: ShowErrorsActionCreator }, { token: ServerErrorActionCreator }, { token: UserBehaviourAnalyticsService }, { token: PaymentSettingsService }, { token: SessionService }], target: i0.ɵɵFactoryTarget.Injectable }); }
3287
3355
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: InitializeService, providedIn: 'root' }); }
3288
3356
  }
3289
3357
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: InitializeService, decorators: [{
@@ -3294,7 +3362,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
3294
3362
  }], ctorParameters: () => [{ type: undefined, decorators: [{
3295
3363
  type: Inject,
3296
3364
  args: [initializeResponseFactoryToken]
3297
- }] }, { type: XpsApiService }, { type: SettingsService }, { type: CountryService }, { type: NextActionService }, { type: XpsResponseErrorsMappingService }, { type: EncryptCreditCardService }, { type: ShowErrorsActionCreator }, { type: UserBehaviourAnalyticsService }, { type: PaymentSettingsService }, { type: SessionService }] });
3365
+ }] }, { type: XpsApiService }, { type: SettingsService }, { type: CountryService }, { type: NextActionService }, { type: XpsResponseErrorsMappingService }, { type: EncryptCreditCardService }, { type: ShowErrorsActionCreator }, { type: ServerErrorActionCreator }, { type: UserBehaviourAnalyticsService }, { type: PaymentSettingsService }, { type: SessionService }] });
3298
3366
 
3299
3367
  class XpsApiPartRequest {
3300
3368
  addXpsParameters(parameters) {
@@ -3425,7 +3493,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
3425
3493
  }], ctorParameters: () => [{ type: SettingsService }] });
3426
3494
 
3427
3495
  class SubmitService {
3428
- constructor(requestFactory, responseFactory, settingsService, deviceFingerPrintService, xpsApiService, xpsResponseErrorsMappingService, encryptCreditCardService, userBehaviourAnalyticsService, paymentSettingsService) {
3496
+ constructor(requestFactory, responseFactory, settingsService, deviceFingerPrintService, xpsApiService, xpsResponseErrorsMappingService, encryptCreditCardService, userBehaviourAnalyticsService, paymentSettingsService, nextActionService, serverErrorActionCreator) {
3429
3497
  this.requestFactory = requestFactory;
3430
3498
  this.responseFactory = responseFactory;
3431
3499
  this.settingsService = settingsService;
@@ -3435,6 +3503,8 @@ class SubmitService {
3435
3503
  this.encryptCreditCardService = encryptCreditCardService;
3436
3504
  this.userBehaviourAnalyticsService = userBehaviourAnalyticsService;
3437
3505
  this.paymentSettingsService = paymentSettingsService;
3506
+ this.nextActionService = nextActionService;
3507
+ this.serverErrorActionCreator = serverErrorActionCreator;
3438
3508
  }
3439
3509
  // NB: Never add 'async' statement for this method!
3440
3510
  // 'Async' statement wraps current promise into another.
@@ -3469,6 +3539,13 @@ class SubmitService {
3469
3539
  return this.responseFactory(response);
3470
3540
  })
3471
3541
  .catch((error) => {
3542
+ if (error instanceof HttpError) {
3543
+ const httpErrorData = error.getHttpErrorData();
3544
+ this.nextActionService.emitFlowUpdates(this.serverErrorActionCreator.getActionData({
3545
+ status: httpErrorData.response.status,
3546
+ message: error.message,
3547
+ }));
3548
+ }
3472
3549
  throw new ResponseError(error.message);
3473
3550
  });
3474
3551
  }));
@@ -3479,7 +3556,7 @@ class SubmitService {
3479
3556
  fields: Object.keys(xpsResponse.form).map((key) => xpsResponse.form[key]),
3480
3557
  });
3481
3558
  }
3482
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: SubmitService, deps: [{ token: submitRequestFactoryToken }, { token: submitResponseFactoryToken }, { token: SettingsService }, { token: DeviceFingerPrintService }, { token: XpsApiService }, { token: XpsResponseErrorsMappingService }, { token: EncryptCreditCardService }, { token: UserBehaviourAnalyticsService }, { token: PaymentSettingsService }], target: i0.ɵɵFactoryTarget.Injectable }); }
3559
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: SubmitService, deps: [{ token: submitRequestFactoryToken }, { token: submitResponseFactoryToken }, { token: SettingsService }, { token: DeviceFingerPrintService }, { token: XpsApiService }, { token: XpsResponseErrorsMappingService }, { token: EncryptCreditCardService }, { token: UserBehaviourAnalyticsService }, { token: PaymentSettingsService }, { token: NextActionService }, { token: ServerErrorActionCreator }], target: i0.ɵɵFactoryTarget.Injectable }); }
3483
3560
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: SubmitService, providedIn: 'root' }); }
3484
3561
  }
3485
3562
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: SubmitService, decorators: [{
@@ -3491,7 +3568,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
3491
3568
  }] }, { type: undefined, decorators: [{
3492
3569
  type: Inject,
3493
3570
  args: [submitResponseFactoryToken]
3494
- }] }, { type: SettingsService }, { type: DeviceFingerPrintService }, { type: XpsApiService }, { type: XpsResponseErrorsMappingService }, { type: EncryptCreditCardService }, { type: UserBehaviourAnalyticsService }, { type: PaymentSettingsService }] });
3571
+ }] }, { type: SettingsService }, { type: DeviceFingerPrintService }, { type: XpsApiService }, { type: XpsResponseErrorsMappingService }, { type: EncryptCreditCardService }, { type: UserBehaviourAnalyticsService }, { type: PaymentSettingsService }, { type: NextActionService }, { type: ServerErrorActionCreator }] });
3495
3572
 
3496
3573
  class EmitDataService {
3497
3574
  constructor() {
@@ -3566,7 +3643,7 @@ const syncResponseFactoryProvider = {
3566
3643
  };
3567
3644
 
3568
3645
  class SyncService extends EmitDataService {
3569
- constructor(requestFactory, responseFactory, xpsApiService, nextActionService, settingsService, xpsResponseErrorsMappingService, encryptCreditCardService, showErrorsActionCreator, userBehaviourAnalyticsService, paymentSettingsService, sessionService) {
3646
+ constructor(requestFactory, responseFactory, xpsApiService, nextActionService, settingsService, xpsResponseErrorsMappingService, encryptCreditCardService, showErrorsActionCreator, serverErrorActionCreator, userBehaviourAnalyticsService, paymentSettingsService, sessionService) {
3570
3647
  super();
3571
3648
  this.requestFactory = requestFactory;
3572
3649
  this.responseFactory = responseFactory;
@@ -3576,6 +3653,7 @@ class SyncService extends EmitDataService {
3576
3653
  this.xpsResponseErrorsMappingService = xpsResponseErrorsMappingService;
3577
3654
  this.encryptCreditCardService = encryptCreditCardService;
3578
3655
  this.showErrorsActionCreator = showErrorsActionCreator;
3656
+ this.serverErrorActionCreator = serverErrorActionCreator;
3579
3657
  this.userBehaviourAnalyticsService = userBehaviourAnalyticsService;
3580
3658
  this.paymentSettingsService = paymentSettingsService;
3581
3659
  this.sessionService = sessionService;
@@ -3687,6 +3765,16 @@ class SyncService extends EmitDataService {
3687
3765
  this.emitFormErrors(response);
3688
3766
  this.emit(response);
3689
3767
  return this.responseFactory(field, response);
3768
+ })
3769
+ .catch((error) => {
3770
+ if (error instanceof HttpError) {
3771
+ const httpErrorData = error.getHttpErrorData();
3772
+ this.nextActionService.emitFlowUpdates(this.serverErrorActionCreator.getActionData({
3773
+ status: httpErrorData.response.status,
3774
+ message: error.message,
3775
+ }));
3776
+ }
3777
+ throw error;
3690
3778
  });
3691
3779
  }
3692
3780
  isReadyField(field) {
@@ -3719,7 +3807,7 @@ class SyncService extends EmitDataService {
3719
3807
  }
3720
3808
  this.fieldSyncTimers[field.name] = timerId;
3721
3809
  }
3722
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: SyncService, deps: [{ token: syncRequestFactoryToken }, { token: syncResponseFactoryToken }, { token: XpsApiService }, { token: NextActionService }, { token: SettingsService }, { token: XpsResponseErrorsMappingService }, { token: EncryptCreditCardService }, { token: ShowErrorsActionCreator }, { token: UserBehaviourAnalyticsService }, { token: PaymentSettingsService }, { token: SessionService }], target: i0.ɵɵFactoryTarget.Injectable }); }
3810
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: SyncService, deps: [{ token: syncRequestFactoryToken }, { token: syncResponseFactoryToken }, { token: XpsApiService }, { token: NextActionService }, { token: SettingsService }, { token: XpsResponseErrorsMappingService }, { token: EncryptCreditCardService }, { token: ShowErrorsActionCreator }, { token: ServerErrorActionCreator }, { token: UserBehaviourAnalyticsService }, { token: PaymentSettingsService }, { token: SessionService }], target: i0.ɵɵFactoryTarget.Injectable }); }
3723
3811
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: SyncService, providedIn: 'root' }); }
3724
3812
  }
3725
3813
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImport: i0, type: SyncService, decorators: [{
@@ -3733,7 +3821,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
3733
3821
  }] }, { type: undefined, decorators: [{
3734
3822
  type: Inject,
3735
3823
  args: [syncResponseFactoryToken]
3736
- }] }, { type: XpsApiService }, { type: NextActionService }, { type: SettingsService }, { type: XpsResponseErrorsMappingService }, { type: EncryptCreditCardService }, { type: ShowErrorsActionCreator }, { type: UserBehaviourAnalyticsService }, { type: PaymentSettingsService }, { type: SessionService }] });
3824
+ }] }, { type: XpsApiService }, { type: NextActionService }, { type: SettingsService }, { type: XpsResponseErrorsMappingService }, { type: EncryptCreditCardService }, { type: ShowErrorsActionCreator }, { type: ServerErrorActionCreator }, { type: UserBehaviourAnalyticsService }, { type: PaymentSettingsService }, { type: SessionService }] });
3737
3825
 
3738
3826
  function isObject(value) {
3739
3827
  return typeof value === 'object' && value !== null && !Array.isArray(value);
@@ -8872,45 +8960,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.3", ngImpor
8872
8960
  }]
8873
8961
  }], ctorParameters: () => [{ type: SettingsService }, { type: LoggerService }, { type: CountryService }, { type: PaymentMethodsService }, { type: SavedMethodsService }, { type: UserBalanceService }, { type: PaymentConfigService }, { type: PaymentService }, { type: DeviceFingerPrintService }, { type: FinanceDetailsService }, { type: LegalService }, { type: StatusService }, { type: NextActionService }, { type: CreditCardService }, { type: CreditCardStateService }, { type: FormMessagesService }, { type: EditSavedMethodsService }, { type: UserBehaviourAnalyticsService }, { type: PerformanceService }, { type: CombinedPaymentMethodsService }, { type: CountriesApiService }, { type: SendInstructionService }, { type: ScriptTrackerService }, { type: i19.TranslateService }, { type: CommonLogAttributesService }] });
8874
8962
 
8875
- class HttpError extends AppError {
8876
- constructor(error, req) {
8877
- super(error.message);
8878
- this.RESTRICTED_KEYS_REGEXP = new RegExp('.*(card_number|number|cvv|cvn|month|year|cardholdername|client_data|dfp|password).*', 'i');
8879
- this.httpErrorData = {
8880
- request: {
8881
- url: req.url,
8882
- method: req.method,
8883
- headers: req.headers,
8884
- },
8885
- response: {
8886
- status: error.status,
8887
- headers: error.headers,
8888
- },
8889
- };
8890
- if (req.body) {
8891
- this.httpErrorData.request.data = this.cleanPersonalData(req.body);
8892
- }
8893
- if (error.statusText) {
8894
- const errorData = error.error;
8895
- this.httpErrorData.response.data = {
8896
- statusText: error.statusText,
8897
- errors: errorData?.errors ?? [],
8898
- };
8899
- }
8900
- }
8901
- getHttpErrorData() {
8902
- return this.httpErrorData;
8903
- }
8904
- cleanPersonalData(data) {
8905
- return Object.entries(data).reduce((acc, [key, val]) => {
8906
- return {
8907
- ...acc,
8908
- [key]: this.RESTRICTED_KEYS_REGEXP.test(key) ? '***' : val,
8909
- };
8910
- }, {});
8911
- }
8912
- }
8913
-
8914
8963
  class HttpExceptionsInterceptor {
8915
8964
  constructor(router) {
8916
8965
  this.router = router;