@xsolla/payment-client-core 0.1.14-test15 → 0.1.14-test17

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.
@@ -1,11 +1,11 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { InjectionToken, Injectable, Inject, Pipe, isDevMode, NgModule } from '@angular/core';
3
- import { firstValueFrom, lastValueFrom, map, Subject, BehaviorSubject, filter as filter$1, takeUntil, catchError, skip, throwError } from 'rxjs';
3
+ import { firstValueFrom, lastValueFrom, map, Subject, BehaviorSubject, 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 JSEncrypt from 'jsencrypt';
7
7
  import { UntypedFormGroup, Validators, UntypedFormControl, ReactiveFormsModule } from '@angular/forms';
8
- import { filter, map as map$1, tap, catchError as catchError$1 } from 'rxjs/operators';
8
+ import { filter, map as map$1, tap, catchError } from 'rxjs/operators';
9
9
  import * as i1$1 from '@angular/router';
10
10
  import { CommonModule } from '@angular/common';
11
11
 
@@ -3890,7 +3890,7 @@ const checkStatusResponseFactoryProvider = {
3890
3890
  useValue: (...args) => new CheckStatusResponse(...args),
3891
3891
  };
3892
3892
 
3893
- let CheckStatusService$1 = class CheckStatusService extends XpsApiPart {
3893
+ class CheckStatusService extends XpsApiPart {
3894
3894
  constructor(xpsApiService, settingsService, xpsResponseErrorsMappingService, requestFactory, responseFactory) {
3895
3895
  super();
3896
3896
  this.xpsApiService = xpsApiService;
@@ -3919,10 +3919,10 @@ let CheckStatusService$1 = class CheckStatusService extends XpsApiPart {
3919
3919
  throw new ResponseError(error.message);
3920
3920
  });
3921
3921
  }
3922
- };
3923
- CheckStatusService$1.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckStatusService$1, deps: [{ token: XpsApiService }, { token: SettingsService }, { token: XpsResponseErrorsMappingService }, { token: checkStatusRequestFactoryToken }, { token: checkStatusResponseFactoryToken }], target: i0.ɵɵFactoryTarget.Injectable });
3924
- CheckStatusService$1.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckStatusService$1, providedIn: 'root' });
3925
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckStatusService$1, decorators: [{
3922
+ }
3923
+ CheckStatusService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckStatusService, deps: [{ token: XpsApiService }, { token: SettingsService }, { token: XpsResponseErrorsMappingService }, { token: checkStatusRequestFactoryToken }, { token: checkStatusResponseFactoryToken }], target: i0.ɵɵFactoryTarget.Injectable });
3924
+ CheckStatusService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckStatusService, providedIn: 'root' });
3925
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckStatusService, decorators: [{
3926
3926
  type: Injectable,
3927
3927
  args: [{
3928
3928
  providedIn: 'root',
@@ -4559,14 +4559,14 @@ class ListenStatusService {
4559
4559
  this.websocketOpenedSubject.next(statusSettings);
4560
4560
  }
4561
4561
  }
4562
- ListenStatusService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ListenStatusService, deps: [{ token: StatusRequestService }, { token: CheckStatusService$1 }, { token: WebsocketStatusService }], target: i0.ɵɵFactoryTarget.Injectable });
4562
+ 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 });
4563
4563
  ListenStatusService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ListenStatusService, providedIn: 'root' });
4564
4564
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ListenStatusService, decorators: [{
4565
4565
  type: Injectable,
4566
4566
  args: [{
4567
4567
  providedIn: 'root',
4568
4568
  }]
4569
- }], ctorParameters: function () { return [{ type: StatusRequestService }, { type: CheckStatusService$1 }, { type: WebsocketStatusService }]; } });
4569
+ }], ctorParameters: function () { return [{ type: StatusRequestService }, { type: CheckStatusService }, { type: WebsocketStatusService }]; } });
4570
4570
 
4571
4571
  var TitleClass;
4572
4572
  (function (TitleClass) {
@@ -4623,98 +4623,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
4623
4623
  }]
4624
4624
  }], ctorParameters: function () { return [{ type: SettingsService }, { type: SecureApiClient }]; } });
4625
4625
 
4626
- // import { SessionService } from '../session/session.service';
4627
- // import { StateService } from '../state.service';
4628
- // import { ElkLoggerService } from '../analytics/elk-logger.service';
4629
- // import { AppError } from '../../../models/app-error.model';
4630
- // import { SerializationHelper } from '../../../helpers/serialization.helper';
4631
- // import { AppConfig } from '../../../models/app-config.model';
4632
- // import { Observable } from 'rxjs/Observable';
4633
- // import { ApiOptions } from './api-options.interface';
4634
- // import { defaultApiUrl, sandboxApiUrl } from './api-url.const';
4635
- class CheckStatusService {
4636
- constructor(http) {
4637
- this.http = http;
4638
- this.apiUrl = sandboxApiUrl;
4639
- }
4640
- // public getRequestParams() {
4641
- // return this.session.getRequest();
4642
- // }
4643
- /**
4644
- * Запрос
4645
- * @param route
4646
- * @param params
4647
- * @param options
4648
- * @returns {Observable<any>}
4649
- */
4650
- request(route, params = {}, options = {}) {
4651
- params = Object.assign({}, params);
4652
- Object.keys(params).forEach((key) => {
4653
- if (!params[key]) {
4654
- delete params[key];
4655
- }
4656
- });
4657
- // const postData = SerializationHelper.paramSerializerJQLike(params);
4658
- // const postData = params;
4659
- const postData = new URLSearchParams(params);
4660
- const observable$ = this.http.post(this.apiUrl + route, postData, {
4661
- headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'),
4662
- responseType: 'json'
4663
- }).pipe(map((data) => {
4664
- const newData = { ...data };
4665
- if ((data.api || {}).ver !== '1.0.1') {
4666
- // Non PayStation API answer
4667
- // this.elkLoggerService.sendHttpError('Invalid PayStation API answer', data);
4668
- throw new Error();
4669
- }
4670
- delete newData.api;
4671
- return newData;
4672
- }), catchError((response) => {
4673
- // HTTP Error, Fatal PayStation API error
4674
- // this.elkLoggerService.sendHttpError('HTTP Error', response);
4675
- throw {
4676
- errors: response.error && response.error.errors,
4677
- httpCode: response.status
4678
- };
4679
- }));
4680
- // .catch((response: any) => {
4681
- // // HTTP Error, Fatal PayStation API error
4682
- // this.elkLoggerService.sendHttpError('HTTP Error', response);
4683
- // throw {
4684
- // errors: response.error && response.error.errors,
4685
- // httpCode: response.status
4686
- // };
4687
- // });
4688
- // if (options.catchError) {
4689
- // observable$.catch((reason) => {
4690
- // this.state.showError((reason || {}).errors ||
4691
- // (new AppError(this.translate.instant('api_error_message'), '10000001')));
4692
- //
4693
- // return Observable.of();
4694
- // });
4695
- // }
4696
- return observable$;
4697
- }
4698
- /**
4699
- * Запрос
4700
- * @param route
4701
- * @param params
4702
- * @param options
4703
- * @returns {Promise<any>}
4704
- */
4705
- requestPromise(route, params = {}, options = {}) {
4706
- return this.request(route, params, options).toPromise();
4707
- }
4708
- }
4709
- CheckStatusService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckStatusService, deps: [{ token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
4710
- CheckStatusService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckStatusService, providedIn: 'root' });
4711
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckStatusService, decorators: [{
4712
- type: Injectable,
4713
- args: [{
4714
- providedIn: 'root',
4715
- }]
4716
- }], ctorParameters: function () { return [{ type: i1.HttpClient }]; } });
4717
-
4718
4626
  class SavePaymentMethodStatusService {
4719
4627
  constructor(statusRequestService, listenStatusService, savedPaymentAccountChangesService, nextActionService, checkStatusService) {
4720
4628
  this.statusRequestService = statusRequestService;
@@ -4724,28 +4632,39 @@ class SavePaymentMethodStatusService {
4724
4632
  this.checkStatusService = checkStatusService;
4725
4633
  }
4726
4634
  async getStatus(params) {
4727
- console.log('getStatus', params);
4728
4635
  this.statusRequestService.setRequestParams(params);
4729
- const paramsCheck = {
4730
- section: 'getstatus',
4731
- action: 'getstatus',
4732
- // invoice: params.invoice,
4733
- ...params,
4734
- access_token: params.token
4735
- };
4736
- const check = await this.checkStatusService.requestPromise('directpayment', paramsCheck);
4737
- console.log('requestPromise', check);
4738
- // todo: get account
4636
+ this.statusRequestService.request();
4637
+ const statusResponse = await firstValueFrom(this.statusRequestService.response$);
4638
+ statusResponse.status.isSavePaymentAccount = true;
4739
4639
  const accountData = await this.getPaymentAccountData(params.invoice);
4640
+ if (this.savingFailedOrCancel(statusResponse?.status) || this.savingSuccessful(accountData, statusResponse?.status)) {
4641
+ return statusResponse.status;
4642
+ }
4643
+ this.checkStatus(params);
4644
+ statusResponse.status.isSavePaymentAccount = true;
4645
+ return statusResponse.status;
4646
+ }
4647
+ checkStatus(params) {
4648
+ this.startWaitingStatusUpdates(params.invoice);
4649
+ this.statusRequestService.request();
4650
+ }
4651
+ async getStatusOld(params) {
4652
+ console.log('getStatus', params);
4653
+ this.statusRequestService.setRequestParams(params);
4740
4654
  // this.startWaitingStatusUpdates(params.invoice);
4741
4655
  this.statusRequestService.request();
4742
4656
  const statusResponse = await firstValueFrom(this.statusRequestService.response$);
4743
- // const savingFailedOrCancel = statusResponse.status?.titleClass === TitleClass.cancel || statusResponse.status?.titleClass === TitleClass.cancelUser;
4744
- // const savingSuccessful = statusResponse.status?.titleClass === TitleClass.done && accountData?.new_account;
4745
- // if (!accountData) {
4746
- // this.startWaitingStatusUpdates(params.invoice);
4747
- // statusResponse.status.statusState = StatusEnum.processing;
4748
- // }
4657
+ this.checkStatusService.setRequestParams(params.invoice);
4658
+ this.checkStatusService.request();
4659
+ const checkStatusResponse = await firstValueFrom(this.checkStatusService.response$);
4660
+ if (!checkStatusResponse.final) {
4661
+ this.startWaitingStatusUpdates(params.invoice);
4662
+ statusResponse.status.isSavePaymentAccount = true;
4663
+ statusResponse.status.statusState = StatusEnum.processing;
4664
+ return statusResponse.status;
4665
+ }
4666
+ // todo: get account
4667
+ const accountData = await this.getPaymentAccountData(params.invoice);
4749
4668
  if (!this.savingFailedOrCancel(statusResponse?.status) && !this.savingSuccessful(accountData, statusResponse?.status)) {
4750
4669
  // todo is proccessing
4751
4670
  this.startWaitingStatusUpdates(params.invoice);
@@ -4753,6 +4672,46 @@ class SavePaymentMethodStatusService {
4753
4672
  }
4754
4673
  statusResponse.status.isSavePaymentAccount = true;
4755
4674
  return statusResponse.status;
4675
+ // this.listenStatusService.listen(params.invoice);
4676
+ // this.statusRequestService.request();
4677
+ // const paramsCheck = {
4678
+ // section: 'getstatus',
4679
+ // action: 'getstatus',
4680
+ // // invoice: params.invoice,
4681
+ // ...params,
4682
+ // access_token: params.token || '8sogPLisB328Snf9M9aChSwkZn4IzOzf_lc_en'
4683
+ // };
4684
+ // // const check = await this.checkStatusService.requestPromise('directpayment', paramsCheck);
4685
+ // // console.log('requestPromise', check);
4686
+ // // todo: get account
4687
+ // // const accountData = await this.getPaymentAccountData(params.invoice);
4688
+ // // this.startWaitingStatusUpdates(params.invoice);
4689
+ // // this.listenStatusService.statusUpdated$
4690
+ // this.startWaitingStatusUpdates(params.invoice);
4691
+ // this.statusRequestService.request();
4692
+ // this.checkStatusService.setRequestParams(params.invoice);
4693
+ // this.checkStatusService.request();
4694
+ // this.checkStatusService.response$.subscribe((resp) => {
4695
+ // console.log('checkSt', resp);
4696
+ // });
4697
+ // const statusResponse = await firstValueFrom(
4698
+ // this.statusRequestService.response$
4699
+ // );
4700
+ // const savingFailedOrCancel = statusResponse.status?.titleClass === TitleClass.cancel || statusResponse.status?.titleClass === TitleClass.cancelUser;
4701
+ // const savingSuccessful = statusResponse.status?.titleClass === TitleClass.done && accountData?.new_account;
4702
+ // if (!accountData) {
4703
+ // this.startWaitingStatusUpdates(params.invoice);
4704
+ // statusResponse.status.statusState = StatusEnum.processing;
4705
+ // }
4706
+ // if (!this.savingFailedOrCancel(statusResponse?.status) && !this.savingSuccessful(accountData, statusResponse?.status)) {
4707
+ // // todo is proccessing
4708
+ //
4709
+ // // this.startWaitingStatusUpdates(params.invoice);
4710
+ // statusResponse.status.statusState = StatusEnum.processing;
4711
+ // }
4712
+ // statusResponse.status.isSavePaymentAccount = true;
4713
+ // return statusResponse.status;
4714
+ // return null;
4756
4715
  // if (!this.savePaymentMethodStatus) {
4757
4716
  // statusResponse.status.statusState = StatusEnum.processing;
4758
4717
  // }
@@ -4762,8 +4721,8 @@ class SavePaymentMethodStatusService {
4762
4721
  savingFailedOrCancel(status) {
4763
4722
  return status?.titleClass === TitleClass.cancel || status?.titleClass === TitleClass.cancelUser;
4764
4723
  }
4765
- savingSuccessful(accountData, status) {
4766
- return !!(status?.titleClass === TitleClass.done && accountData?.new_account);
4724
+ savingSuccessful(accountData, status, checkStatus) {
4725
+ return !!(status?.titleClass === TitleClass.done && (accountData?.new_account || checkStatus?.isPaymentAccountAttached));
4767
4726
  }
4768
4727
  getPaymentAccountData(invoice) {
4769
4728
  return this.savedPaymentAccountChangesService
@@ -4779,15 +4738,30 @@ class SavePaymentMethodStatusService {
4779
4738
  this.listenStatusSubscription.unsubscribe();
4780
4739
  this.listenStatusService.stopListening();
4781
4740
  }
4741
+ // debugger
4782
4742
  this.listenStatusService.listen(invoice);
4783
4743
  this.listenStatusSubscription = this.listenStatusService.statusUpdated$
4784
- .subscribe(({ statusResponse }) => {
4785
- if (statusResponse.status) {
4786
- this.loadNewPaymentAccountData(statusResponse.status);
4787
- }
4744
+ .subscribe((statusSettings) => {
4745
+ // this.checkStatusService.response$.subscribe((res) => {
4746
+ // if (res.final) {
4747
+ // if (statusSettings?.statusResponse.status) {
4748
+ // this.loadNewPaymentAccountData(statusSettings?.statusResponse.status, res)
4749
+ // }
4750
+ // }
4751
+ // });
4752
+ void firstValueFrom(this.checkStatusService.response$).then((checkStatusResponse) => {
4753
+ if (checkStatusResponse.final && statusSettings?.statusResponse.status) {
4754
+ this.loadNewPaymentAccountData(statusSettings?.statusResponse.status, checkStatusResponse);
4755
+ }
4756
+ });
4757
+ // this.checkStatusService.request();
4758
+ // const checkStatusResponse = await firstValueFrom(
4759
+ // this.checkStatusService.response$
4760
+ // );
4788
4761
  });
4762
+ // this.statusRequestService.request();
4789
4763
  }
4790
- loadNewPaymentAccountData(status) {
4764
+ loadNewPaymentAccountData(status, checkStatus) {
4791
4765
  if (!status.invoice) {
4792
4766
  return;
4793
4767
  }
@@ -4795,22 +4769,26 @@ class SavePaymentMethodStatusService {
4795
4769
  .request(status.invoice)
4796
4770
  .then((accountChanges) => {
4797
4771
  if (accountChanges) {
4798
- this.handleSavingStatus(status, accountChanges);
4772
+ this.handleSavingStatus(status, accountChanges, checkStatus);
4799
4773
  }
4800
4774
  });
4801
4775
  }
4802
- handleSavingStatus(status, account) {
4776
+ handleSavingStatus(status, account, checkStatus) {
4803
4777
  // const savingFailedOrCancel = status?.titleClass === TitleClass.cancel || status?.titleClass === TitleClass.cancelUser;
4804
4778
  //
4805
4779
  // const savingSuccessful = status?.titleClass === TitleClass.done && account;
4806
- if (!this.savingFailedOrCancel(status) && !this.savingSuccessful(account, status)) {
4807
- return;
4780
+ if (this.savingSuccessful(account, status, checkStatus)) {
4781
+ this.savePaymentMethodStatus = SavePaymentMethodStatus.success;
4782
+ }
4783
+ else {
4784
+ this.savePaymentMethodStatus = SavePaymentMethodStatus.failed;
4808
4785
  }
4809
4786
  this.listenStatusService.stopListening();
4810
4787
  this.listenStatusSubscription.unsubscribe();
4811
4788
  // const paymentAccountWasSaved = status?.titleClass === TitleClass.done && account !== null;
4812
4789
  const isSavePaymentMethod = true;
4813
- this.savePaymentMethodStatus = this.savingFailedOrCancel(status) ? SavePaymentMethodStatus.success : SavePaymentMethodStatus.failed;
4790
+ // this.savePaymentMethodStatus = this.savingFailedOrCancel(status) ? SavePaymentMethodStatus.success : SavePaymentMethodStatus.failed;
4791
+ console.log(status, isSavePaymentMethod, this.savePaymentMethodStatus);
4814
4792
  this.nextActionService.emitFlowUpdates(new StatusUpdatedAction(status, isSavePaymentMethod, this.savePaymentMethodStatus));
4815
4793
  }
4816
4794
  }
@@ -5778,7 +5756,7 @@ class HttpExceptionsInterceptor {
5778
5756
  this.router = router;
5779
5757
  }
5780
5758
  intercept(req, next) {
5781
- return next.handle(req).pipe(catchError$1((error) => {
5759
+ return next.handle(req).pipe(catchError((error) => {
5782
5760
  return throwError(() => new HttpError(error, req));
5783
5761
  }));
5784
5762
  }