@xsolla/payment-client-core 0.1.14-test16 → 0.1.14-test18

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,12 +1,12 @@
1
1
  import { __awaiter } from 'tslib';
2
2
  import * as i0 from '@angular/core';
3
3
  import { InjectionToken, Injectable, Inject, Pipe, isDevMode, NgModule } from '@angular/core';
4
- import { firstValueFrom, lastValueFrom, map, Subject, BehaviorSubject, filter as filter$1, takeUntil, catchError, skip, throwError } from 'rxjs';
4
+ import { firstValueFrom, lastValueFrom, map, Subject, BehaviorSubject, filter as filter$1, takeUntil, skip, throwError } from 'rxjs';
5
5
  import * as i1 from '@angular/common/http';
6
6
  import { HttpParams, HttpHeaders, HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
7
7
  import JSEncrypt from 'jsencrypt';
8
8
  import { UntypedFormGroup, Validators, UntypedFormControl, ReactiveFormsModule } from '@angular/forms';
9
- import { filter, map as map$1, tap, catchError as catchError$1 } from 'rxjs/operators';
9
+ import { filter, map as map$1, tap, catchError } from 'rxjs/operators';
10
10
  import * as i1$1 from '@angular/router';
11
11
  import { CommonModule } from '@angular/common';
12
12
 
@@ -3967,7 +3967,7 @@ const checkStatusResponseFactoryProvider = {
3967
3967
  useValue: (...args) => new CheckStatusResponse(...args),
3968
3968
  };
3969
3969
 
3970
- let CheckStatusService$1 = class CheckStatusService extends XpsApiPart {
3970
+ class CheckStatusService extends XpsApiPart {
3971
3971
  constructor(xpsApiService, settingsService, xpsResponseErrorsMappingService, requestFactory, responseFactory) {
3972
3972
  super();
3973
3973
  this.xpsApiService = xpsApiService;
@@ -3996,10 +3996,10 @@ let CheckStatusService$1 = class CheckStatusService extends XpsApiPart {
3996
3996
  throw new ResponseError(error.message);
3997
3997
  });
3998
3998
  }
3999
- };
4000
- 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 });
4001
- CheckStatusService$1.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckStatusService$1, providedIn: 'root' });
4002
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckStatusService$1, decorators: [{
3999
+ }
4000
+ 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 });
4001
+ CheckStatusService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckStatusService, providedIn: 'root' });
4002
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckStatusService, decorators: [{
4003
4003
  type: Injectable,
4004
4004
  args: [{
4005
4005
  providedIn: 'root',
@@ -4670,14 +4670,14 @@ class ListenStatusService {
4670
4670
  this.websocketOpenedSubject.next(statusSettings);
4671
4671
  }
4672
4672
  }
4673
- 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 });
4673
+ 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 });
4674
4674
  ListenStatusService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ListenStatusService, providedIn: 'root' });
4675
4675
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ListenStatusService, decorators: [{
4676
4676
  type: Injectable,
4677
4677
  args: [{
4678
4678
  providedIn: 'root',
4679
4679
  }]
4680
- }], ctorParameters: function () { return [{ type: StatusRequestService }, { type: CheckStatusService$1 }, { type: WebsocketStatusService }]; } });
4680
+ }], ctorParameters: function () { return [{ type: StatusRequestService }, { type: CheckStatusService }, { type: WebsocketStatusService }]; } });
4681
4681
 
4682
4682
  var TitleClass;
4683
4683
  (function (TitleClass) {
@@ -4736,98 +4736,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
4736
4736
  }]
4737
4737
  }], ctorParameters: function () { return [{ type: SettingsService }, { type: SecureApiClient }]; } });
4738
4738
 
4739
- // import { SessionService } from '../session/session.service';
4740
- // import { StateService } from '../state.service';
4741
- // import { ElkLoggerService } from '../analytics/elk-logger.service';
4742
- // import { AppError } from '../../../models/app-error.model';
4743
- // import { SerializationHelper } from '../../../helpers/serialization.helper';
4744
- // import { AppConfig } from '../../../models/app-config.model';
4745
- // import { Observable } from 'rxjs/Observable';
4746
- // import { ApiOptions } from './api-options.interface';
4747
- // import { defaultApiUrl, sandboxApiUrl } from './api-url.const';
4748
- class CheckStatusService {
4749
- constructor(http) {
4750
- this.http = http;
4751
- this.apiUrl = sandboxApiUrl;
4752
- }
4753
- // public getRequestParams() {
4754
- // return this.session.getRequest();
4755
- // }
4756
- /**
4757
- * Запрос
4758
- * @param route
4759
- * @param params
4760
- * @param options
4761
- * @returns {Observable<any>}
4762
- */
4763
- request(route, params = {}, options = {}) {
4764
- params = Object.assign({}, params);
4765
- Object.keys(params).forEach((key) => {
4766
- if (!params[key]) {
4767
- delete params[key];
4768
- }
4769
- });
4770
- // const postData = SerializationHelper.paramSerializerJQLike(params);
4771
- // const postData = params;
4772
- const postData = new URLSearchParams(params);
4773
- const observable$ = this.http.post(this.apiUrl + route, postData, {
4774
- headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'),
4775
- responseType: 'json'
4776
- }).pipe(map((data) => {
4777
- const newData = Object.assign({}, data);
4778
- if ((data.api || {}).ver !== '1.0.1') {
4779
- // Non PayStation API answer
4780
- // this.elkLoggerService.sendHttpError('Invalid PayStation API answer', data);
4781
- throw new Error();
4782
- }
4783
- delete newData.api;
4784
- return newData;
4785
- }), catchError((response) => {
4786
- // HTTP Error, Fatal PayStation API error
4787
- // this.elkLoggerService.sendHttpError('HTTP Error', response);
4788
- throw {
4789
- errors: response.error && response.error.errors,
4790
- httpCode: response.status
4791
- };
4792
- }));
4793
- // .catch((response: any) => {
4794
- // // HTTP Error, Fatal PayStation API error
4795
- // this.elkLoggerService.sendHttpError('HTTP Error', response);
4796
- // throw {
4797
- // errors: response.error && response.error.errors,
4798
- // httpCode: response.status
4799
- // };
4800
- // });
4801
- // if (options.catchError) {
4802
- // observable$.catch((reason) => {
4803
- // this.state.showError((reason || {}).errors ||
4804
- // (new AppError(this.translate.instant('api_error_message'), '10000001')));
4805
- //
4806
- // return Observable.of();
4807
- // });
4808
- // }
4809
- return observable$;
4810
- }
4811
- /**
4812
- * Запрос
4813
- * @param route
4814
- * @param params
4815
- * @param options
4816
- * @returns {Promise<any>}
4817
- */
4818
- requestPromise(route, params = {}, options = {}) {
4819
- return this.request(route, params, options).toPromise();
4820
- }
4821
- }
4822
- CheckStatusService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckStatusService, deps: [{ token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
4823
- CheckStatusService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckStatusService, providedIn: 'root' });
4824
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CheckStatusService, decorators: [{
4825
- type: Injectable,
4826
- args: [{
4827
- providedIn: 'root',
4828
- }]
4829
- }], ctorParameters: function () { return [{ type: i1.HttpClient }]; } });
4830
-
4831
4739
  class SavePaymentMethodStatusService {
4832
4740
  constructor(statusRequestService, listenStatusService, savedPaymentAccountChangesService, nextActionService, checkStatusService) {
4833
4741
  this.statusRequestService = statusRequestService;
@@ -4838,22 +4746,42 @@ class SavePaymentMethodStatusService {
4838
4746
  }
4839
4747
  getStatus(params) {
4840
4748
  return __awaiter(this, void 0, void 0, function* () {
4841
- console.log('getStatus', params);
4842
4749
  this.statusRequestService.setRequestParams(params);
4843
- const paramsCheck = Object.assign(Object.assign({ section: 'getstatus', action: 'getstatus' }, params), { access_token: params.token || '8sogPLisB328Snf9M9aChSwkZn4IzOzf_lc_en' });
4844
- const check = yield this.checkStatusService.requestPromise('directpayment', paramsCheck);
4845
- console.log('requestPromise', check);
4846
- // todo: get account
4750
+ this.statusRequestService.request();
4751
+ const statusResponse = yield firstValueFrom(this.statusRequestService.response$);
4752
+ statusResponse.status.isSavePaymentAccount = true;
4847
4753
  const accountData = yield this.getPaymentAccountData(params.invoice);
4754
+ if (this.savingFailedOrCancel(statusResponse === null || statusResponse === void 0 ? void 0 : statusResponse.status) || this.savingSuccessful(accountData, statusResponse === null || statusResponse === void 0 ? void 0 : statusResponse.status)) {
4755
+ return statusResponse.status;
4756
+ }
4757
+ this.checkStatus(params);
4758
+ statusResponse.status.isSavePaymentAccount = true;
4759
+ statusResponse.status.statusState = StatusEnum.processing;
4760
+ return statusResponse.status;
4761
+ });
4762
+ }
4763
+ checkStatus(params) {
4764
+ this.startWaitingStatusUpdates(params.invoice);
4765
+ this.statusRequestService.request();
4766
+ }
4767
+ getStatusOld(params) {
4768
+ return __awaiter(this, void 0, void 0, function* () {
4769
+ console.log('getStatus', params);
4770
+ this.statusRequestService.setRequestParams(params);
4848
4771
  // this.startWaitingStatusUpdates(params.invoice);
4849
4772
  this.statusRequestService.request();
4850
4773
  const statusResponse = yield firstValueFrom(this.statusRequestService.response$);
4851
- // const savingFailedOrCancel = statusResponse.status?.titleClass === TitleClass.cancel || statusResponse.status?.titleClass === TitleClass.cancelUser;
4852
- // const savingSuccessful = statusResponse.status?.titleClass === TitleClass.done && accountData?.new_account;
4853
- // if (!accountData) {
4854
- // this.startWaitingStatusUpdates(params.invoice);
4855
- // statusResponse.status.statusState = StatusEnum.processing;
4856
- // }
4774
+ this.checkStatusService.setRequestParams(params.invoice);
4775
+ this.checkStatusService.request();
4776
+ const checkStatusResponse = yield firstValueFrom(this.checkStatusService.response$);
4777
+ if (!checkStatusResponse.final) {
4778
+ this.startWaitingStatusUpdates(params.invoice);
4779
+ statusResponse.status.isSavePaymentAccount = true;
4780
+ statusResponse.status.statusState = StatusEnum.processing;
4781
+ return statusResponse.status;
4782
+ }
4783
+ // todo: get account
4784
+ const accountData = yield this.getPaymentAccountData(params.invoice);
4857
4785
  if (!this.savingFailedOrCancel(statusResponse === null || statusResponse === void 0 ? void 0 : statusResponse.status) && !this.savingSuccessful(accountData, statusResponse === null || statusResponse === void 0 ? void 0 : statusResponse.status)) {
4858
4786
  // todo is proccessing
4859
4787
  this.startWaitingStatusUpdates(params.invoice);
@@ -4861,6 +4789,46 @@ class SavePaymentMethodStatusService {
4861
4789
  }
4862
4790
  statusResponse.status.isSavePaymentAccount = true;
4863
4791
  return statusResponse.status;
4792
+ // this.listenStatusService.listen(params.invoice);
4793
+ // this.statusRequestService.request();
4794
+ // const paramsCheck = {
4795
+ // section: 'getstatus',
4796
+ // action: 'getstatus',
4797
+ // // invoice: params.invoice,
4798
+ // ...params,
4799
+ // access_token: params.token || '8sogPLisB328Snf9M9aChSwkZn4IzOzf_lc_en'
4800
+ // };
4801
+ // // const check = await this.checkStatusService.requestPromise('directpayment', paramsCheck);
4802
+ // // console.log('requestPromise', check);
4803
+ // // todo: get account
4804
+ // // const accountData = await this.getPaymentAccountData(params.invoice);
4805
+ // // this.startWaitingStatusUpdates(params.invoice);
4806
+ // // this.listenStatusService.statusUpdated$
4807
+ // this.startWaitingStatusUpdates(params.invoice);
4808
+ // this.statusRequestService.request();
4809
+ // this.checkStatusService.setRequestParams(params.invoice);
4810
+ // this.checkStatusService.request();
4811
+ // this.checkStatusService.response$.subscribe((resp) => {
4812
+ // console.log('checkSt', resp);
4813
+ // });
4814
+ // const statusResponse = await firstValueFrom(
4815
+ // this.statusRequestService.response$
4816
+ // );
4817
+ // const savingFailedOrCancel = statusResponse.status?.titleClass === TitleClass.cancel || statusResponse.status?.titleClass === TitleClass.cancelUser;
4818
+ // const savingSuccessful = statusResponse.status?.titleClass === TitleClass.done && accountData?.new_account;
4819
+ // if (!accountData) {
4820
+ // this.startWaitingStatusUpdates(params.invoice);
4821
+ // statusResponse.status.statusState = StatusEnum.processing;
4822
+ // }
4823
+ // if (!this.savingFailedOrCancel(statusResponse?.status) && !this.savingSuccessful(accountData, statusResponse?.status)) {
4824
+ // // todo is proccessing
4825
+ //
4826
+ // // this.startWaitingStatusUpdates(params.invoice);
4827
+ // statusResponse.status.statusState = StatusEnum.processing;
4828
+ // }
4829
+ // statusResponse.status.isSavePaymentAccount = true;
4830
+ // return statusResponse.status;
4831
+ // return null;
4864
4832
  // if (!this.savePaymentMethodStatus) {
4865
4833
  // statusResponse.status.statusState = StatusEnum.processing;
4866
4834
  // }
@@ -4871,8 +4839,8 @@ class SavePaymentMethodStatusService {
4871
4839
  savingFailedOrCancel(status) {
4872
4840
  return (status === null || status === void 0 ? void 0 : status.titleClass) === TitleClass.cancel || (status === null || status === void 0 ? void 0 : status.titleClass) === TitleClass.cancelUser;
4873
4841
  }
4874
- savingSuccessful(accountData, status) {
4875
- return !!((status === null || status === void 0 ? void 0 : status.titleClass) === TitleClass.done && (accountData === null || accountData === void 0 ? void 0 : accountData.new_account));
4842
+ savingSuccessful(accountData, status, checkStatus) {
4843
+ return !!((status === null || status === void 0 ? void 0 : status.titleClass) === TitleClass.done && ((accountData === null || accountData === void 0 ? void 0 : accountData.new_account) || (checkStatus === null || checkStatus === void 0 ? void 0 : checkStatus.isPaymentAccountAttached)));
4876
4844
  }
4877
4845
  getPaymentAccountData(invoice) {
4878
4846
  return this.savedPaymentAccountChangesService
@@ -4888,15 +4856,30 @@ class SavePaymentMethodStatusService {
4888
4856
  this.listenStatusSubscription.unsubscribe();
4889
4857
  this.listenStatusService.stopListening();
4890
4858
  }
4859
+ // debugger
4891
4860
  this.listenStatusService.listen(invoice);
4892
4861
  this.listenStatusSubscription = this.listenStatusService.statusUpdated$
4893
- .subscribe(({ statusResponse }) => {
4894
- if (statusResponse.status) {
4895
- this.loadNewPaymentAccountData(statusResponse.status);
4896
- }
4862
+ .subscribe((statusSettings) => {
4863
+ // this.checkStatusService.response$.subscribe((res) => {
4864
+ // if (res.final) {
4865
+ // if (statusSettings?.statusResponse.status) {
4866
+ // this.loadNewPaymentAccountData(statusSettings?.statusResponse.status, res)
4867
+ // }
4868
+ // }
4869
+ // });
4870
+ void firstValueFrom(this.checkStatusService.response$).then((checkStatusResponse) => {
4871
+ if (checkStatusResponse.final && (statusSettings === null || statusSettings === void 0 ? void 0 : statusSettings.statusResponse.status)) {
4872
+ this.loadNewPaymentAccountData(statusSettings === null || statusSettings === void 0 ? void 0 : statusSettings.statusResponse.status, checkStatusResponse);
4873
+ }
4874
+ });
4875
+ // this.checkStatusService.request();
4876
+ // const checkStatusResponse = await firstValueFrom(
4877
+ // this.checkStatusService.response$
4878
+ // );
4897
4879
  });
4880
+ // this.statusRequestService.request();
4898
4881
  }
4899
- loadNewPaymentAccountData(status) {
4882
+ loadNewPaymentAccountData(status, checkStatus) {
4900
4883
  if (!status.invoice) {
4901
4884
  return;
4902
4885
  }
@@ -4904,22 +4887,26 @@ class SavePaymentMethodStatusService {
4904
4887
  .request(status.invoice)
4905
4888
  .then((accountChanges) => {
4906
4889
  if (accountChanges) {
4907
- this.handleSavingStatus(status, accountChanges);
4890
+ this.handleSavingStatus(status, accountChanges, checkStatus);
4908
4891
  }
4909
4892
  });
4910
4893
  }
4911
- handleSavingStatus(status, account) {
4894
+ handleSavingStatus(status, account, checkStatus) {
4912
4895
  // const savingFailedOrCancel = status?.titleClass === TitleClass.cancel || status?.titleClass === TitleClass.cancelUser;
4913
4896
  //
4914
4897
  // const savingSuccessful = status?.titleClass === TitleClass.done && account;
4915
- if (!this.savingFailedOrCancel(status) && !this.savingSuccessful(account, status)) {
4916
- return;
4898
+ if (this.savingSuccessful(account, status, checkStatus)) {
4899
+ this.savePaymentMethodStatus = SavePaymentMethodStatus.success;
4900
+ }
4901
+ else {
4902
+ this.savePaymentMethodStatus = SavePaymentMethodStatus.failed;
4917
4903
  }
4918
4904
  this.listenStatusService.stopListening();
4919
4905
  this.listenStatusSubscription.unsubscribe();
4920
4906
  // const paymentAccountWasSaved = status?.titleClass === TitleClass.done && account !== null;
4921
4907
  const isSavePaymentMethod = true;
4922
- this.savePaymentMethodStatus = this.savingFailedOrCancel(status) ? SavePaymentMethodStatus.success : SavePaymentMethodStatus.failed;
4908
+ // this.savePaymentMethodStatus = this.savingFailedOrCancel(status) ? SavePaymentMethodStatus.success : SavePaymentMethodStatus.failed;
4909
+ console.log(status, isSavePaymentMethod, this.savePaymentMethodStatus);
4923
4910
  this.nextActionService.emitFlowUpdates(new StatusUpdatedAction(status, isSavePaymentMethod, this.savePaymentMethodStatus));
4924
4911
  }
4925
4912
  }
@@ -5923,7 +5910,7 @@ class HttpExceptionsInterceptor {
5923
5910
  this.router = router;
5924
5911
  }
5925
5912
  intercept(req, next) {
5926
- return next.handle(req).pipe(catchError$1((error) => {
5913
+ return next.handle(req).pipe(catchError((error) => {
5927
5914
  return throwError(() => new HttpError(error, req));
5928
5915
  }));
5929
5916
  }