@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,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,40 @@ 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 || '8sogPLisB328Snf9M9aChSwkZn4IzOzf_lc_en'
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
+ statusResponse.status.statusState = StatusEnum.processing;
4646
+ return statusResponse.status;
4647
+ }
4648
+ checkStatus(params) {
4649
+ this.startWaitingStatusUpdates(params.invoice);
4650
+ this.statusRequestService.request();
4651
+ }
4652
+ async getStatusOld(params) {
4653
+ console.log('getStatus', params);
4654
+ this.statusRequestService.setRequestParams(params);
4740
4655
  // this.startWaitingStatusUpdates(params.invoice);
4741
4656
  this.statusRequestService.request();
4742
4657
  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
- // }
4658
+ this.checkStatusService.setRequestParams(params.invoice);
4659
+ this.checkStatusService.request();
4660
+ const checkStatusResponse = await firstValueFrom(this.checkStatusService.response$);
4661
+ if (!checkStatusResponse.final) {
4662
+ this.startWaitingStatusUpdates(params.invoice);
4663
+ statusResponse.status.isSavePaymentAccount = true;
4664
+ statusResponse.status.statusState = StatusEnum.processing;
4665
+ return statusResponse.status;
4666
+ }
4667
+ // todo: get account
4668
+ const accountData = await this.getPaymentAccountData(params.invoice);
4749
4669
  if (!this.savingFailedOrCancel(statusResponse?.status) && !this.savingSuccessful(accountData, statusResponse?.status)) {
4750
4670
  // todo is proccessing
4751
4671
  this.startWaitingStatusUpdates(params.invoice);
@@ -4753,6 +4673,46 @@ class SavePaymentMethodStatusService {
4753
4673
  }
4754
4674
  statusResponse.status.isSavePaymentAccount = true;
4755
4675
  return statusResponse.status;
4676
+ // this.listenStatusService.listen(params.invoice);
4677
+ // this.statusRequestService.request();
4678
+ // const paramsCheck = {
4679
+ // section: 'getstatus',
4680
+ // action: 'getstatus',
4681
+ // // invoice: params.invoice,
4682
+ // ...params,
4683
+ // access_token: params.token || '8sogPLisB328Snf9M9aChSwkZn4IzOzf_lc_en'
4684
+ // };
4685
+ // // const check = await this.checkStatusService.requestPromise('directpayment', paramsCheck);
4686
+ // // console.log('requestPromise', check);
4687
+ // // todo: get account
4688
+ // // const accountData = await this.getPaymentAccountData(params.invoice);
4689
+ // // this.startWaitingStatusUpdates(params.invoice);
4690
+ // // this.listenStatusService.statusUpdated$
4691
+ // this.startWaitingStatusUpdates(params.invoice);
4692
+ // this.statusRequestService.request();
4693
+ // this.checkStatusService.setRequestParams(params.invoice);
4694
+ // this.checkStatusService.request();
4695
+ // this.checkStatusService.response$.subscribe((resp) => {
4696
+ // console.log('checkSt', resp);
4697
+ // });
4698
+ // const statusResponse = await firstValueFrom(
4699
+ // this.statusRequestService.response$
4700
+ // );
4701
+ // const savingFailedOrCancel = statusResponse.status?.titleClass === TitleClass.cancel || statusResponse.status?.titleClass === TitleClass.cancelUser;
4702
+ // const savingSuccessful = statusResponse.status?.titleClass === TitleClass.done && accountData?.new_account;
4703
+ // if (!accountData) {
4704
+ // this.startWaitingStatusUpdates(params.invoice);
4705
+ // statusResponse.status.statusState = StatusEnum.processing;
4706
+ // }
4707
+ // if (!this.savingFailedOrCancel(statusResponse?.status) && !this.savingSuccessful(accountData, statusResponse?.status)) {
4708
+ // // todo is proccessing
4709
+ //
4710
+ // // this.startWaitingStatusUpdates(params.invoice);
4711
+ // statusResponse.status.statusState = StatusEnum.processing;
4712
+ // }
4713
+ // statusResponse.status.isSavePaymentAccount = true;
4714
+ // return statusResponse.status;
4715
+ // return null;
4756
4716
  // if (!this.savePaymentMethodStatus) {
4757
4717
  // statusResponse.status.statusState = StatusEnum.processing;
4758
4718
  // }
@@ -4762,8 +4722,8 @@ class SavePaymentMethodStatusService {
4762
4722
  savingFailedOrCancel(status) {
4763
4723
  return status?.titleClass === TitleClass.cancel || status?.titleClass === TitleClass.cancelUser;
4764
4724
  }
4765
- savingSuccessful(accountData, status) {
4766
- return !!(status?.titleClass === TitleClass.done && accountData?.new_account);
4725
+ savingSuccessful(accountData, status, checkStatus) {
4726
+ return !!(status?.titleClass === TitleClass.done && (accountData?.new_account || checkStatus?.isPaymentAccountAttached));
4767
4727
  }
4768
4728
  getPaymentAccountData(invoice) {
4769
4729
  return this.savedPaymentAccountChangesService
@@ -4779,15 +4739,30 @@ class SavePaymentMethodStatusService {
4779
4739
  this.listenStatusSubscription.unsubscribe();
4780
4740
  this.listenStatusService.stopListening();
4781
4741
  }
4742
+ // debugger
4782
4743
  this.listenStatusService.listen(invoice);
4783
4744
  this.listenStatusSubscription = this.listenStatusService.statusUpdated$
4784
- .subscribe(({ statusResponse }) => {
4785
- if (statusResponse.status) {
4786
- this.loadNewPaymentAccountData(statusResponse.status);
4787
- }
4745
+ .subscribe((statusSettings) => {
4746
+ // this.checkStatusService.response$.subscribe((res) => {
4747
+ // if (res.final) {
4748
+ // if (statusSettings?.statusResponse.status) {
4749
+ // this.loadNewPaymentAccountData(statusSettings?.statusResponse.status, res)
4750
+ // }
4751
+ // }
4752
+ // });
4753
+ void firstValueFrom(this.checkStatusService.response$).then((checkStatusResponse) => {
4754
+ if (checkStatusResponse.final && statusSettings?.statusResponse.status) {
4755
+ this.loadNewPaymentAccountData(statusSettings?.statusResponse.status, checkStatusResponse);
4756
+ }
4757
+ });
4758
+ // this.checkStatusService.request();
4759
+ // const checkStatusResponse = await firstValueFrom(
4760
+ // this.checkStatusService.response$
4761
+ // );
4788
4762
  });
4763
+ // this.statusRequestService.request();
4789
4764
  }
4790
- loadNewPaymentAccountData(status) {
4765
+ loadNewPaymentAccountData(status, checkStatus) {
4791
4766
  if (!status.invoice) {
4792
4767
  return;
4793
4768
  }
@@ -4795,22 +4770,26 @@ class SavePaymentMethodStatusService {
4795
4770
  .request(status.invoice)
4796
4771
  .then((accountChanges) => {
4797
4772
  if (accountChanges) {
4798
- this.handleSavingStatus(status, accountChanges);
4773
+ this.handleSavingStatus(status, accountChanges, checkStatus);
4799
4774
  }
4800
4775
  });
4801
4776
  }
4802
- handleSavingStatus(status, account) {
4777
+ handleSavingStatus(status, account, checkStatus) {
4803
4778
  // const savingFailedOrCancel = status?.titleClass === TitleClass.cancel || status?.titleClass === TitleClass.cancelUser;
4804
4779
  //
4805
4780
  // const savingSuccessful = status?.titleClass === TitleClass.done && account;
4806
- if (!this.savingFailedOrCancel(status) && !this.savingSuccessful(account, status)) {
4807
- return;
4781
+ if (this.savingSuccessful(account, status, checkStatus)) {
4782
+ this.savePaymentMethodStatus = SavePaymentMethodStatus.success;
4783
+ }
4784
+ else {
4785
+ this.savePaymentMethodStatus = SavePaymentMethodStatus.failed;
4808
4786
  }
4809
4787
  this.listenStatusService.stopListening();
4810
4788
  this.listenStatusSubscription.unsubscribe();
4811
4789
  // const paymentAccountWasSaved = status?.titleClass === TitleClass.done && account !== null;
4812
4790
  const isSavePaymentMethod = true;
4813
- this.savePaymentMethodStatus = this.savingFailedOrCancel(status) ? SavePaymentMethodStatus.success : SavePaymentMethodStatus.failed;
4791
+ // this.savePaymentMethodStatus = this.savingFailedOrCancel(status) ? SavePaymentMethodStatus.success : SavePaymentMethodStatus.failed;
4792
+ console.log(status, isSavePaymentMethod, this.savePaymentMethodStatus);
4814
4793
  this.nextActionService.emitFlowUpdates(new StatusUpdatedAction(status, isSavePaymentMethod, this.savePaymentMethodStatus));
4815
4794
  }
4816
4795
  }
@@ -5778,7 +5757,7 @@ class HttpExceptionsInterceptor {
5778
5757
  this.router = router;
5779
5758
  }
5780
5759
  intercept(req, next) {
5781
- return next.handle(req).pipe(catchError$1((error) => {
5760
+ return next.handle(req).pipe(catchError((error) => {
5782
5761
  return throwError(() => new HttpError(error, req));
5783
5762
  }));
5784
5763
  }