@xsolla/payment-client-core 0.1.14-test16 → 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,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,41 @@ 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
+ return statusResponse.status;
4760
+ });
4761
+ }
4762
+ checkStatus(params) {
4763
+ this.startWaitingStatusUpdates(params.invoice);
4764
+ this.statusRequestService.request();
4765
+ }
4766
+ getStatusOld(params) {
4767
+ return __awaiter(this, void 0, void 0, function* () {
4768
+ console.log('getStatus', params);
4769
+ this.statusRequestService.setRequestParams(params);
4848
4770
  // this.startWaitingStatusUpdates(params.invoice);
4849
4771
  this.statusRequestService.request();
4850
4772
  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
- // }
4773
+ this.checkStatusService.setRequestParams(params.invoice);
4774
+ this.checkStatusService.request();
4775
+ const checkStatusResponse = yield firstValueFrom(this.checkStatusService.response$);
4776
+ if (!checkStatusResponse.final) {
4777
+ this.startWaitingStatusUpdates(params.invoice);
4778
+ statusResponse.status.isSavePaymentAccount = true;
4779
+ statusResponse.status.statusState = StatusEnum.processing;
4780
+ return statusResponse.status;
4781
+ }
4782
+ // todo: get account
4783
+ const accountData = yield this.getPaymentAccountData(params.invoice);
4857
4784
  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
4785
  // todo is proccessing
4859
4786
  this.startWaitingStatusUpdates(params.invoice);
@@ -4861,6 +4788,46 @@ class SavePaymentMethodStatusService {
4861
4788
  }
4862
4789
  statusResponse.status.isSavePaymentAccount = true;
4863
4790
  return statusResponse.status;
4791
+ // this.listenStatusService.listen(params.invoice);
4792
+ // this.statusRequestService.request();
4793
+ // const paramsCheck = {
4794
+ // section: 'getstatus',
4795
+ // action: 'getstatus',
4796
+ // // invoice: params.invoice,
4797
+ // ...params,
4798
+ // access_token: params.token || '8sogPLisB328Snf9M9aChSwkZn4IzOzf_lc_en'
4799
+ // };
4800
+ // // const check = await this.checkStatusService.requestPromise('directpayment', paramsCheck);
4801
+ // // console.log('requestPromise', check);
4802
+ // // todo: get account
4803
+ // // const accountData = await this.getPaymentAccountData(params.invoice);
4804
+ // // this.startWaitingStatusUpdates(params.invoice);
4805
+ // // this.listenStatusService.statusUpdated$
4806
+ // this.startWaitingStatusUpdates(params.invoice);
4807
+ // this.statusRequestService.request();
4808
+ // this.checkStatusService.setRequestParams(params.invoice);
4809
+ // this.checkStatusService.request();
4810
+ // this.checkStatusService.response$.subscribe((resp) => {
4811
+ // console.log('checkSt', resp);
4812
+ // });
4813
+ // const statusResponse = await firstValueFrom(
4814
+ // this.statusRequestService.response$
4815
+ // );
4816
+ // const savingFailedOrCancel = statusResponse.status?.titleClass === TitleClass.cancel || statusResponse.status?.titleClass === TitleClass.cancelUser;
4817
+ // const savingSuccessful = statusResponse.status?.titleClass === TitleClass.done && accountData?.new_account;
4818
+ // if (!accountData) {
4819
+ // this.startWaitingStatusUpdates(params.invoice);
4820
+ // statusResponse.status.statusState = StatusEnum.processing;
4821
+ // }
4822
+ // if (!this.savingFailedOrCancel(statusResponse?.status) && !this.savingSuccessful(accountData, statusResponse?.status)) {
4823
+ // // todo is proccessing
4824
+ //
4825
+ // // this.startWaitingStatusUpdates(params.invoice);
4826
+ // statusResponse.status.statusState = StatusEnum.processing;
4827
+ // }
4828
+ // statusResponse.status.isSavePaymentAccount = true;
4829
+ // return statusResponse.status;
4830
+ // return null;
4864
4831
  // if (!this.savePaymentMethodStatus) {
4865
4832
  // statusResponse.status.statusState = StatusEnum.processing;
4866
4833
  // }
@@ -4871,8 +4838,8 @@ class SavePaymentMethodStatusService {
4871
4838
  savingFailedOrCancel(status) {
4872
4839
  return (status === null || status === void 0 ? void 0 : status.titleClass) === TitleClass.cancel || (status === null || status === void 0 ? void 0 : status.titleClass) === TitleClass.cancelUser;
4873
4840
  }
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));
4841
+ savingSuccessful(accountData, status, checkStatus) {
4842
+ 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
4843
  }
4877
4844
  getPaymentAccountData(invoice) {
4878
4845
  return this.savedPaymentAccountChangesService
@@ -4888,15 +4855,30 @@ class SavePaymentMethodStatusService {
4888
4855
  this.listenStatusSubscription.unsubscribe();
4889
4856
  this.listenStatusService.stopListening();
4890
4857
  }
4858
+ // debugger
4891
4859
  this.listenStatusService.listen(invoice);
4892
4860
  this.listenStatusSubscription = this.listenStatusService.statusUpdated$
4893
- .subscribe(({ statusResponse }) => {
4894
- if (statusResponse.status) {
4895
- this.loadNewPaymentAccountData(statusResponse.status);
4896
- }
4861
+ .subscribe((statusSettings) => {
4862
+ // this.checkStatusService.response$.subscribe((res) => {
4863
+ // if (res.final) {
4864
+ // if (statusSettings?.statusResponse.status) {
4865
+ // this.loadNewPaymentAccountData(statusSettings?.statusResponse.status, res)
4866
+ // }
4867
+ // }
4868
+ // });
4869
+ void firstValueFrom(this.checkStatusService.response$).then((checkStatusResponse) => {
4870
+ if (checkStatusResponse.final && (statusSettings === null || statusSettings === void 0 ? void 0 : statusSettings.statusResponse.status)) {
4871
+ this.loadNewPaymentAccountData(statusSettings === null || statusSettings === void 0 ? void 0 : statusSettings.statusResponse.status, checkStatusResponse);
4872
+ }
4873
+ });
4874
+ // this.checkStatusService.request();
4875
+ // const checkStatusResponse = await firstValueFrom(
4876
+ // this.checkStatusService.response$
4877
+ // );
4897
4878
  });
4879
+ // this.statusRequestService.request();
4898
4880
  }
4899
- loadNewPaymentAccountData(status) {
4881
+ loadNewPaymentAccountData(status, checkStatus) {
4900
4882
  if (!status.invoice) {
4901
4883
  return;
4902
4884
  }
@@ -4904,22 +4886,26 @@ class SavePaymentMethodStatusService {
4904
4886
  .request(status.invoice)
4905
4887
  .then((accountChanges) => {
4906
4888
  if (accountChanges) {
4907
- this.handleSavingStatus(status, accountChanges);
4889
+ this.handleSavingStatus(status, accountChanges, checkStatus);
4908
4890
  }
4909
4891
  });
4910
4892
  }
4911
- handleSavingStatus(status, account) {
4893
+ handleSavingStatus(status, account, checkStatus) {
4912
4894
  // const savingFailedOrCancel = status?.titleClass === TitleClass.cancel || status?.titleClass === TitleClass.cancelUser;
4913
4895
  //
4914
4896
  // const savingSuccessful = status?.titleClass === TitleClass.done && account;
4915
- if (!this.savingFailedOrCancel(status) && !this.savingSuccessful(account, status)) {
4916
- return;
4897
+ if (this.savingSuccessful(account, status, checkStatus)) {
4898
+ this.savePaymentMethodStatus = SavePaymentMethodStatus.success;
4899
+ }
4900
+ else {
4901
+ this.savePaymentMethodStatus = SavePaymentMethodStatus.failed;
4917
4902
  }
4918
4903
  this.listenStatusService.stopListening();
4919
4904
  this.listenStatusSubscription.unsubscribe();
4920
4905
  // const paymentAccountWasSaved = status?.titleClass === TitleClass.done && account !== null;
4921
4906
  const isSavePaymentMethod = true;
4922
- this.savePaymentMethodStatus = this.savingFailedOrCancel(status) ? SavePaymentMethodStatus.success : SavePaymentMethodStatus.failed;
4907
+ // this.savePaymentMethodStatus = this.savingFailedOrCancel(status) ? SavePaymentMethodStatus.success : SavePaymentMethodStatus.failed;
4908
+ console.log(status, isSavePaymentMethod, this.savePaymentMethodStatus);
4923
4909
  this.nextActionService.emitFlowUpdates(new StatusUpdatedAction(status, isSavePaymentMethod, this.savePaymentMethodStatus));
4924
4910
  }
4925
4911
  }
@@ -5923,7 +5909,7 @@ class HttpExceptionsInterceptor {
5923
5909
  this.router = router;
5924
5910
  }
5925
5911
  intercept(req, next) {
5926
- return next.handle(req).pipe(catchError$1((error) => {
5912
+ return next.handle(req).pipe(catchError((error) => {
5927
5913
  return throwError(() => new HttpError(error, req));
5928
5914
  }));
5929
5915
  }