ng-easycommerce 0.0.684 → 0.0.685

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.
@@ -14285,6 +14285,7 @@ let RedSysRedirectEcComponent = class RedSysRedirectEcComponent extends Componen
14285
14285
  this.isDobleAuth = false;
14286
14286
  this.urls = [];
14287
14287
  this.closeModalReason = ''; // Renombrado para evitar confusión
14288
+ this.finished = false;
14288
14289
  this.dataRedirect = () => this.consts.getUrlBase() + 'shop-api/' + this.consts.getChannel() + '/redsys/redirect/' + this.cartService.cart_token + '/process-payment';
14289
14290
  this.clearStorageState = () => {
14290
14291
  sessionStorage.removeItem('state');
@@ -14293,31 +14294,23 @@ let RedSysRedirectEcComponent = class RedSysRedirectEcComponent extends Componen
14293
14294
  // Método que se llama desde la X de la cabecera del modal en el HTML
14294
14295
  this.clickClose = () => {
14295
14296
  this.closeModalReason = 'cancel';
14297
+ this.finished = true;
14298
+ if (this.stateTimeout) {
14299
+ clearTimeout(this.stateTimeout);
14300
+ this.stateTimeout = null;
14301
+ }
14296
14302
  if (this.modalRef) {
14297
14303
  this.modalRef.hide();
14298
14304
  }
14299
14305
  this.processError('Se canceló el pago con tarjeta');
14300
14306
  };
14301
14307
  this.callState = () => {
14302
- var _a, _b, _c;
14308
+ if (this.finished) {
14309
+ return;
14310
+ }
14303
14311
  let state = this.closeModalReason != '' ? this.closeModalReason : sessionStorage.getItem('state');
14304
14312
  if (state) {
14305
- this.clearStorageState();
14306
- if (state == 'ok') {
14307
- (_a = this.modalRef) === null || _a === void 0 ? void 0 : _a.hide();
14308
- this.ready.emit(true);
14309
- return;
14310
- }
14311
- if (state == 'menosuno') {
14312
- (_b = this.modalRef) === null || _b === void 0 ? void 0 : _b.hide();
14313
- this.processError('Error en el pago');
14314
- return;
14315
- }
14316
- if (state == 'cancel') {
14317
- return; // El modal ya se escondió dentro de clickClose()
14318
- }
14319
- (_c = this.modalRef) === null || _c === void 0 ? void 0 : _c.hide();
14320
- this.processError('Error desconocido en la transacción');
14313
+ this.handleState(state);
14321
14314
  return;
14322
14315
  }
14323
14316
  // Guardamos el timeout en una variable de clase
@@ -14325,6 +14318,33 @@ let RedSysRedirectEcComponent = class RedSysRedirectEcComponent extends Componen
14325
14318
  this.callState();
14326
14319
  }, 6000);
14327
14320
  };
14321
+ this.handleState = (state) => {
14322
+ var _a, _b, _c, _d;
14323
+ if (this.finished)
14324
+ return;
14325
+ this.finished = true;
14326
+ if (this.stateTimeout) {
14327
+ clearTimeout(this.stateTimeout);
14328
+ this.stateTimeout = null;
14329
+ }
14330
+ this.clearStorageState();
14331
+ if (state === 'ok') {
14332
+ (_a = this.modalRef) === null || _a === void 0 ? void 0 : _a.hide();
14333
+ this.ready.emit(true);
14334
+ return;
14335
+ }
14336
+ if (state === 'menosuno' || state === 'error' || state === 'failure') {
14337
+ (_b = this.modalRef) === null || _b === void 0 ? void 0 : _b.hide();
14338
+ this.processError('Error en el pago');
14339
+ return;
14340
+ }
14341
+ if (state === 'cancel') {
14342
+ (_c = this.modalRef) === null || _c === void 0 ? void 0 : _c.hide();
14343
+ return;
14344
+ }
14345
+ (_d = this.modalRef) === null || _d === void 0 ? void 0 : _d.hide();
14346
+ this.processError('Error desconocido en la transacción');
14347
+ };
14328
14348
  this.processError = (err) => {
14329
14349
  this.toastrService.show(err != '' ? err : 'payment-error');
14330
14350
  console.log("ERROR ENVIO BACK ", err);
@@ -14342,10 +14362,11 @@ let RedSysRedirectEcComponent = class RedSysRedirectEcComponent extends Componen
14342
14362
  }
14343
14363
  }
14344
14364
  ngOnChanges() {
14345
- console.log("SE CAMBIO");
14365
+ // console.log("SE CAMBIO");
14346
14366
  }
14347
14367
  openModal(template) {
14348
14368
  this.clearStorageState();
14369
+ this.finished = false;
14349
14370
  sessionStorage.setItem('dataRedirect', this.dataRedirect());
14350
14371
  // Abrimos el modal y guardamos la referencia en this.modalRef
14351
14372
  this.modalRef = this.modalService.show(template, { class: 'modal-lg modal-dialog-centered', keyboard: false, backdrop: 'static', animated: true });
@@ -14354,11 +14375,33 @@ let RedSysRedirectEcComponent = class RedSysRedirectEcComponent extends Componen
14354
14375
  }
14355
14376
  // Opcional pero recomendado: Capturar mensajes enviados desde el Iframe de Redsys
14356
14377
  onMessage(event) {
14357
- if (event.data === 'pago_completado' || event.data === 'ok') {
14358
- sessionStorage.setItem('state', 'ok');
14378
+ var _a, _b, _c, _d;
14379
+ const data = (_a = event) === null || _a === void 0 ? void 0 : _a.data;
14380
+ const state = typeof data === 'string'
14381
+ ? data
14382
+ : ((_b = data) === null || _b === void 0 ? void 0 : _b.state) || ((_c = data) === null || _c === void 0 ? void 0 : _c.status) || ((_d = data) === null || _d === void 0 ? void 0 : _d.result) || null;
14383
+ if (!state) {
14384
+ return;
14385
+ }
14386
+ if (state === 'pago_completado' || state === 'ok' || state === 'success') {
14387
+ this.handleState('ok');
14388
+ return;
14389
+ }
14390
+ if (state === 'pago_error' || state === 'menosuno' || state === 'error' || state === 'failure') {
14391
+ this.handleState('menosuno');
14392
+ }
14393
+ }
14394
+ onStorage(event) {
14395
+ var _a;
14396
+ if (!((_a = event) === null || _a === void 0 ? void 0 : _a.key) || event.key !== 'state' || !event.newValue) {
14397
+ return;
14398
+ }
14399
+ if (event.newValue === 'ok' || event.newValue === 'success') {
14400
+ this.handleState('ok');
14401
+ return;
14359
14402
  }
14360
- else if (event.data === 'pago_error' || event.data === 'menosuno') {
14361
- sessionStorage.setItem('state', 'menosuno');
14403
+ if (event.newValue === 'menosuno' || event.newValue === 'error' || event.newValue === 'failure') {
14404
+ this.handleState('menosuno');
14362
14405
  }
14363
14406
  }
14364
14407
  };
@@ -14389,6 +14432,9 @@ __decorate$1m([
14389
14432
  __decorate$1m([
14390
14433
  HostListener('window:message', ['$event'])
14391
14434
  ], RedSysRedirectEcComponent.prototype, "onMessage", null);
14435
+ __decorate$1m([
14436
+ HostListener('window:storage', ['$event'])
14437
+ ], RedSysRedirectEcComponent.prototype, "onStorage", null);
14392
14438
  RedSysRedirectEcComponent = __decorate$1m([
14393
14439
  Component({
14394
14440
  selector: 'app-redsys-redirect-ec',
@@ -16266,7 +16312,7 @@ let RedSysRedirectOutEcComponent = class RedSysRedirectOutEcComponent extends Co
16266
16312
  (_a = this.ventana) === null || _a === void 0 ? void 0 : _a.close();
16267
16313
  };
16268
16314
  this.callState = () => {
16269
- var _a, _b, _c, _d, _e;
16315
+ var _a, _b, _c, _d;
16270
16316
  let state = this.closeModal != '' ? this.closeModal : localStorage.getItem('state');
16271
16317
  !state && this.ventana.closed && (state = 'cancel');
16272
16318
  this.loading = true;
@@ -16274,27 +16320,22 @@ let RedSysRedirectOutEcComponent = class RedSysRedirectOutEcComponent extends Co
16274
16320
  if (state) {
16275
16321
  this.loading = false;
16276
16322
  localStorage.removeItem('state');
16277
- if (state == 'success' || state == 'ok') {
16323
+ if (state == 'success' || state == 'ok' || state == 'pending') {
16278
16324
  (_a = this.ventana) === null || _a === void 0 ? void 0 : _a.close();
16279
16325
  this.ready.emit(true);
16280
16326
  return;
16281
16327
  }
16282
- if (state == 'pending' || state == 'ok') {
16328
+ if (state == 'failure' || state == 'error' || state == 'menosuno') {
16283
16329
  (_b = this.ventana) === null || _b === void 0 ? void 0 : _b.close();
16284
- this.ready.emit(true);
16285
- return;
16286
- }
16287
- if (state == 'failure' || state == 'error') {
16288
- (_c = this.ventana) === null || _c === void 0 ? void 0 : _c.close();
16289
16330
  this.processError('');
16290
16331
  return;
16291
16332
  }
16292
16333
  if (state == 'cancel') {
16293
- (_d = this.ventana) === null || _d === void 0 ? void 0 : _d.close();
16334
+ (_c = this.ventana) === null || _c === void 0 ? void 0 : _c.close();
16294
16335
  this.processError('Se cancelo el pago con redsys');
16295
16336
  return;
16296
16337
  }
16297
- (_e = this.ventana) === null || _e === void 0 ? void 0 : _e.close();
16338
+ (_d = this.ventana) === null || _d === void 0 ? void 0 : _d.close();
16298
16339
  this.processError('');
16299
16340
  return;
16300
16341
  }