ng-easycommerce 0.0.689 → 0.0.690

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.
@@ -11160,7 +11160,8 @@ var PaymentEcComponent = /** @class */ (function (_super) {
11160
11160
  _this.isRedirectRedsys(code) ||
11161
11161
  _this.isRedirectCecaBank(code) ||
11162
11162
  _this.isPeyPalExpress(code) ||
11163
- _this.isPlaceToPay(code));
11163
+ _this.isPlaceToPay(code) ||
11164
+ _this.isMobbex(code));
11164
11165
  };
11165
11166
  _this.ecOnConstruct();
11166
11167
  return _this;
@@ -20200,111 +20201,298 @@ var __decorate$1F = (this && this.__decorate) || function (decorators, target, k
20200
20201
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
20201
20202
  return c > 3 && r && Object.defineProperty(target, key, r), r;
20202
20203
  };
20204
+ var __values$4 = (this && this.__values) || function(o) {
20205
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
20206
+ if (m) return m.call(o);
20207
+ if (o && typeof o.length === "number") return {
20208
+ next: function () {
20209
+ if (o && i >= o.length) o = void 0;
20210
+ return { value: o && o[i++], done: !o };
20211
+ }
20212
+ };
20213
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
20214
+ };
20203
20215
  var MobbexEcComponent = /** @class */ (function (_super) {
20204
20216
  __extends$_(MobbexEcComponent, _super);
20205
- function MobbexEcComponent(renderer, connection, toastrService, consts, cartService, toastr, activedRoute, sanitizer, modalService) {
20217
+ function MobbexEcComponent(toastrService, cartService) {
20206
20218
  var _this = _super.call(this) || this;
20207
- _this.renderer = renderer;
20208
- _this.connection = connection;
20209
20219
  _this.toastrService = toastrService;
20210
- _this.consts = consts;
20211
20220
  _this.cartService = cartService;
20212
- _this.toastr = toastr;
20213
- _this.activedRoute = activedRoute;
20214
- _this.sanitizer = sanitizer;
20215
- _this.modalService = modalService;
20216
20221
  _this.method = null;
20217
20222
  _this.total_amount = 0;
20218
20223
  _this.user_data = null;
20219
20224
  _this.ready = new EventEmitter();
20220
- _this.loading = false;
20221
- _this.isDobleAuth = false;
20222
- _this.urls = [];
20223
- _this.closeModal = '';
20224
- _this.dataRedirect = function () { return _this.consts.getUrlBase() + 'shop-api/' + _this.consts.getChannel() + '/redsys/redirect/' + _this.cartService.cart_token + '/process-payment'; };
20225
- _this.clearStorageState = function () {
20226
- sessionStorage.removeItem('state');
20227
- localStorage.removeItem('state');
20228
- };
20229
- _this.clickClose = function () {
20230
- _this.closeModal = 'cancel';
20231
- _this.modalRef.hide();
20232
- _this.processError('Se cancelo el pago con mobbex');
20233
- };
20234
- _this.callState = function () {
20225
+ _this.loading = true;
20226
+ _this.processing = false;
20227
+ _this.url = null;
20228
+ _this.checkoutData = null;
20229
+ _this.popup = null;
20230
+ _this.pollTimer = null;
20231
+ _this.startedAt = 0;
20232
+ _this.finished = false;
20233
+ _this.checkoutKey = '';
20234
+ _this.bc = null;
20235
+ _this.checkoutRequestInFlight = false;
20236
+ _this.openCheckout = function () {
20237
+ if (!_this.url || _this.processing || typeof window === 'undefined')
20238
+ return;
20239
+ _this.clearStateKeys();
20240
+ _this.finished = false;
20241
+ _this.processing = true;
20242
+ _this.startedAt = Date.now();
20243
+ _this.popup = window.open(_this.url, '_blank');
20244
+ if (!_this.popup || _this.popup.closed) {
20245
+ _this.processing = false;
20246
+ _this.toastrService.show('No se pudo abrir la pasarela de pago. Verifique que su navegador permita nuevas pestañas.');
20247
+ return;
20248
+ }
20235
20249
  try {
20236
- var state = _this.closeModal != '' ? _this.closeModal : localStorage.getItem('state');
20237
- _this.loading = true;
20238
- state && console.log(state);
20239
- if (state) {
20240
- _this.loading = false;
20241
- sessionStorage.removeItem('state');
20242
- localStorage.removeItem('state');
20243
- if (state == 'success') {
20244
- _this.ready.emit(true);
20245
- }
20246
- if (state == 'cancel') {
20247
- return;
20248
- }
20249
- if (state == 'failure') {
20250
- _this.processError('');
20251
- }
20252
- _this.modalRef.hide();
20253
- return;
20254
- }
20255
- setTimeout(function () {
20256
- _this.callState();
20257
- }, 5000);
20250
+ _this.popup.opener = null;
20258
20251
  }
20259
- catch (error) {
20260
- console.error(error);
20252
+ catch (_a) {
20253
+ // Nothing to do.
20261
20254
  }
20255
+ _this.startPolling();
20262
20256
  };
20263
- _this.processError = function (err) {
20264
- _this.toastrService.show(err != '' ? err : 'payment-error');
20265
- console.log("ERROR ENVIO BACK ", err);
20257
+ _this.cancelCheckout = function () {
20258
+ if (_this.finished)
20259
+ return;
20260
+ _this.finishWithState('cancel', true);
20266
20261
  };
20267
20262
  _this.getCheckoutMobbex = function () {
20263
+ if (_this.checkoutRequestInFlight)
20264
+ return;
20268
20265
  _this.loading = true;
20269
- _this.paymentServiceInst.getCheckoutMobbex(_this.allData).then(function (res) {
20266
+ _this.checkoutRequestInFlight = true;
20267
+ var payload = _this.user_data || _this.allData || {};
20268
+ _this.paymentServiceInst.getCheckoutMobbex(payload).then(function (res) {
20270
20269
  var _a, _b, _c, _d;
20271
- _this.dataMobbex = res;
20272
- _this.url = ((_b = (_a = res) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.url) && _this.sanitizer.bypassSecurityTrustResourceUrl((_d = (_c = res) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.url);
20270
+ _this.checkoutData = res || null;
20271
+ _this.checkoutKey = String(((_b = (_a = res) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.id) || _this.cartService.cart_token || '');
20272
+ _this.url = ((_d = (_c = res) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.url) || null;
20273
+ _this.safeSetStorage('mobbex:checkout-id', _this.checkoutKey);
20273
20274
  _this.loading = false;
20274
- }, function (err) {
20275
- _this.processError('operation-error');
20275
+ _this.checkoutRequestInFlight = false;
20276
+ if (!_this.url) {
20277
+ _this.processError('operation-error');
20278
+ }
20279
+ }, function () {
20276
20280
  _this.loading = false;
20281
+ _this.checkoutRequestInFlight = false;
20282
+ _this.processError('operation-error');
20277
20283
  });
20278
20284
  };
20285
+ _this.onStorage = function (event) {
20286
+ var _a;
20287
+ if (!((_a = event) === null || _a === void 0 ? void 0 : _a.key) || _this.finished)
20288
+ return;
20289
+ if (!_this.getStateKeys().includes(event.key))
20290
+ return;
20291
+ var state = _this.normalizeState(event.newValue);
20292
+ if (state) {
20293
+ _this.finishWithState(state, true);
20294
+ }
20295
+ };
20296
+ _this.onMessage = function (event) {
20297
+ _this.onBroadcastMessage(event);
20298
+ };
20299
+ _this.clearStorageState = function () {
20300
+ sessionStorage.removeItem('state');
20301
+ localStorage.removeItem('state');
20302
+ };
20303
+ _this.processError = function (err) {
20304
+ _this.toastrService.show(err !== '' ? err : 'payment-error');
20305
+ };
20279
20306
  _this.ecOnConstruct();
20280
20307
  return _this;
20281
20308
  }
20282
20309
  MobbexEcComponent.prototype.ngOnInit = function () {
20283
- this.getCheckoutMobbex();
20310
+ var _this = this;
20311
+ if (typeof window !== 'undefined') {
20312
+ window.addEventListener('storage', this.onStorage);
20313
+ window.addEventListener('message', this.onMessage);
20314
+ if (window.BroadcastChannel) {
20315
+ this.bc = new BroadcastChannel('mobbex_payment');
20316
+ this.bc.onmessage = function (event) { return _this.onBroadcastMessage(event); };
20317
+ }
20318
+ }
20319
+ this.loadCheckout();
20284
20320
  this.ecOnInit();
20285
20321
  };
20286
20322
  MobbexEcComponent.prototype.ngOnDestroy = function () {
20287
- // console.log("SE DESTROZA");
20323
+ if (typeof window !== 'undefined') {
20324
+ window.removeEventListener('storage', this.onStorage);
20325
+ window.removeEventListener('message', this.onMessage);
20326
+ }
20327
+ if (this.bc) {
20328
+ try {
20329
+ this.bc.close();
20330
+ }
20331
+ catch (_a) {
20332
+ // Nothing to do.
20333
+ }
20334
+ this.bc = null;
20335
+ }
20336
+ this.stopPolling();
20337
+ this.closePopup();
20288
20338
  };
20289
- MobbexEcComponent.prototype.ngOnChanges = function () {
20290
- // console.log("SE CAMBIO");
20339
+ MobbexEcComponent.prototype.loadCheckout = function () {
20340
+ if (!this.paymentServiceInst || !this.method)
20341
+ return;
20342
+ if (this.url && !this.loading)
20343
+ return;
20344
+ this.getCheckoutMobbex();
20291
20345
  };
20292
- MobbexEcComponent.prototype.openModal = function (template) {
20346
+ MobbexEcComponent.prototype.startPolling = function () {
20347
+ var _this = this;
20348
+ this.stopPolling();
20349
+ this.pollTimer = setInterval(function () {
20350
+ var _a, _b, _c, _d, _e, _f;
20351
+ if (_this.finished) {
20352
+ _this.stopPolling();
20353
+ return;
20354
+ }
20355
+ var state = _this.readState();
20356
+ if (state) {
20357
+ _this.finishWithState(state, true);
20358
+ return;
20359
+ }
20360
+ if ((_a = _this.popup) === null || _a === void 0 ? void 0 : _a.closed) {
20361
+ _this.finishWithState('cancel', true);
20362
+ return;
20363
+ }
20364
+ var rawTimeoutMinutes = Number((_f = (_d = (_c = (_b = _this.checkoutData) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.timeout, (_d !== null && _d !== void 0 ? _d : (_e = _this.checkoutData) === null || _e === void 0 ? void 0 : _e.timeout)), (_f !== null && _f !== void 0 ? _f : 60)));
20365
+ var timeoutMinutes = Number.isFinite(rawTimeoutMinutes) && rawTimeoutMinutes > 0 ? rawTimeoutMinutes : 60;
20366
+ var timeoutMs = Math.max(5, timeoutMinutes + 1) * 60 * 1000;
20367
+ if (Date.now() - _this.startedAt > timeoutMs) {
20368
+ _this.finishWithState('failure', true, 'Tiempo de espera agotado al procesar el pago con Mobbex.');
20369
+ }
20370
+ }, 1000);
20371
+ };
20372
+ MobbexEcComponent.prototype.onBroadcastMessage = function (event) {
20373
+ var _a;
20374
+ var payload = (_a = event) === null || _a === void 0 ? void 0 : _a.data;
20375
+ if (!payload || payload.type !== 'mobbex:state' || this.finished)
20376
+ return;
20377
+ if (this.checkoutKey && payload.checkoutKey && payload.checkoutKey !== this.checkoutKey)
20378
+ return;
20379
+ var state = this.normalizeState(payload.state);
20380
+ if (state) {
20381
+ this.finishWithState(state, true);
20382
+ }
20383
+ };
20384
+ MobbexEcComponent.prototype.finishWithState = function (state, closePopup, customMessage) {
20385
+ if (closePopup === void 0) { closePopup = false; }
20386
+ if (customMessage === void 0) { customMessage = ''; }
20387
+ if (this.finished)
20388
+ return;
20389
+ this.finished = true;
20390
+ this.processing = false;
20391
+ this.stopPolling();
20392
+ if (closePopup) {
20393
+ this.closePopup();
20394
+ }
20395
+ this.clearStateKeys();
20396
+ if (state === 'success' || state === 'pending') {
20397
+ this.ready.emit(true);
20398
+ return;
20399
+ }
20400
+ this.processError(customMessage || (state === 'cancel' ? 'Se canceló el pago con Mobbex' : ''));
20401
+ };
20402
+ MobbexEcComponent.prototype.readState = function () {
20403
+ var e_1, _a;
20404
+ var keys = this.getStateKeys();
20405
+ try {
20406
+ for (var keys_1 = __values$4(keys), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
20407
+ var key = keys_1_1.value;
20408
+ var value = this.safeGetStorage(key);
20409
+ var normalized = this.normalizeState(value);
20410
+ if (normalized)
20411
+ return normalized;
20412
+ }
20413
+ }
20414
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
20415
+ finally {
20416
+ try {
20417
+ if (keys_1_1 && !keys_1_1.done && (_a = keys_1.return)) _a.call(keys_1);
20418
+ }
20419
+ finally { if (e_1) throw e_1.error; }
20420
+ }
20421
+ return null;
20422
+ };
20423
+ MobbexEcComponent.prototype.normalizeState = function (value) {
20424
+ var raw = String(value || '').toLowerCase();
20425
+ if (!raw)
20426
+ return null;
20427
+ if (raw === '200' || raw === 'ok' || raw === 'success')
20428
+ return 'success';
20429
+ if (raw === 'pending' || raw === 'in_process' || raw === 'in_review' || raw === 'challenge')
20430
+ return 'pending';
20431
+ if (raw === 'cancel' || raw === '0' || raw === 'none')
20432
+ return 'cancel';
20433
+ if (raw === 'failure' || raw === 'error' || raw === 'expired' || raw === '401')
20434
+ return 'failure';
20435
+ return null;
20436
+ };
20437
+ MobbexEcComponent.prototype.getStateKeys = function () {
20438
+ var keys = ['state'];
20439
+ if (this.checkoutKey) {
20440
+ keys.unshift("mobbex:state:" + this.checkoutKey);
20441
+ }
20442
+ return keys;
20443
+ };
20444
+ MobbexEcComponent.prototype.clearStateKeys = function () {
20293
20445
  this.clearStorageState();
20294
- this.modalRef = this.modalService.show(template, { class: 'modal-lg modal-dialog-centered ', keyboard: false, backdrop: 'static', animated: true });
20295
- this.closeModal = '';
20296
- this.callState();
20446
+ if (this.checkoutKey) {
20447
+ this.safeRemoveStorage("mobbex:state:" + this.checkoutKey);
20448
+ this.safeRemoveStorage('mobbex:checkout-id');
20449
+ }
20450
+ };
20451
+ MobbexEcComponent.prototype.stopPolling = function () {
20452
+ if (this.pollTimer) {
20453
+ clearInterval(this.pollTimer);
20454
+ this.pollTimer = null;
20455
+ }
20456
+ };
20457
+ MobbexEcComponent.prototype.closePopup = function () {
20458
+ if (!this.popup)
20459
+ return;
20460
+ try {
20461
+ if (!this.popup.closed)
20462
+ this.popup.close();
20463
+ }
20464
+ catch (_a) {
20465
+ // Nothing to do.
20466
+ }
20467
+ this.popup = null;
20468
+ };
20469
+ MobbexEcComponent.prototype.safeGetStorage = function (key) {
20470
+ try {
20471
+ return localStorage.getItem(key);
20472
+ }
20473
+ catch (_a) {
20474
+ return null;
20475
+ }
20476
+ };
20477
+ MobbexEcComponent.prototype.safeRemoveStorage = function (key) {
20478
+ try {
20479
+ localStorage.removeItem(key);
20480
+ }
20481
+ catch (_a) {
20482
+ // Nothing to do.
20483
+ }
20484
+ };
20485
+ MobbexEcComponent.prototype.safeSetStorage = function (key, value) {
20486
+ try {
20487
+ localStorage.setItem(key, value);
20488
+ }
20489
+ catch (_a) {
20490
+ // Nothing to do.
20491
+ }
20297
20492
  };
20298
20493
  MobbexEcComponent.ctorParameters = function () { return [
20299
- { type: Renderer2 },
20300
- { type: ConnectionService },
20301
- { type: ToastService },
20302
- { type: Constants },
20303
- { type: CartService },
20304
20494
  { type: ToastService },
20305
- { type: ActivatedRoute },
20306
- { type: DomSanitizer },
20307
- { type: BsModalService }
20495
+ { type: CartService }
20308
20496
  ]; };
20309
20497
  __decorate$1F([
20310
20498
  Input()
@@ -20324,15 +20512,11 @@ var MobbexEcComponent = /** @class */ (function (_super) {
20324
20512
  __decorate$1F([
20325
20513
  Output()
20326
20514
  ], MobbexEcComponent.prototype, "ready", void 0);
20327
- __decorate$1F([
20328
- ViewChild('template')
20329
- ], MobbexEcComponent.prototype, "template", void 0);
20330
20515
  MobbexEcComponent = __decorate$1F([
20331
20516
  Component({
20332
20517
  selector: 'app-mobbex-ec',
20333
- template: "<div class=\"text-center\">\n <h3>Continuar con el pago en Mobbex</h3>\n <p *ngIf=\"method\" class=\"px-5\">{{ method?.description }}</p>\n <p *ngIf=\"method\" class=\"px-5\">{{ method?.instructions }}</p>\n <ng-container *ngIf=\"!loading ; else loadingUrl\">\n <button class=\"btn btn-outline-secondary comprar\" (click)=\"openModal(template)\">Pagar</button>\n </ng-container>\n</div>\n\n<ng-template #template>\n <div class=\"modal-content\">\n <div class=\"modal-header\">\n <button type=\"button\" class=\"btn-close\" aria-label=\"Close\" (click)=\"modalRef.hide(); loading = false;\">\n </button>\n </div>\n <div class=\"modal-body\">\n <iframe [src]=\"url\" frameborder=\"0\" class=\"iframeStyle\"></iframe>\n </div>\n </div>\n</ng-template>\n\n<ng-template #loadingUrl>\n <div class=\"d-flex flex-column jusitfy-content-center align-items-center mt-2\">\n <app-loading-full-ec></app-loading-full-ec>\n </div>\n</ng-template>",
20334
- providers: [BsModalService],
20335
- styles: [".half-width{width:49%!important}.ml-1{margin-left:1%}#card-form{height:450px}.iframeStyle{height:800px;width:100%;max-height:800px}"]
20518
+ template: "<div class=\"text-center\">\n <h3>Continuar con el pago en Mobbex</h3>\n <p *ngIf=\"method\" class=\"px-5\">{{ method?.description }}</p>\n <p *ngIf=\"method\" class=\"px-5\">{{ method?.instructions }}</p>\n\n <ng-container *ngIf=\"loading; else checkoutReady\">\n <div class=\"d-flex flex-column justify-content-center align-items-center mt-2\">\n <app-loading-full-ec></app-loading-full-ec>\n <p class=\"mt-3 px-5 mobbex-note\">Preparando la pasarela de pago...</p>\n </div>\n </ng-container>\n\n <ng-template #checkoutReady>\n <p class=\"mt-3 px-5 mobbex-note\">\n Se abrir\u00E1 una nueva pesta\u00F1a para completar el pago.\n </p>\n\n <div class=\"d-flex flex-column align-items-center\">\n <button\n class=\"btn btn-outline-secondary comprar\"\n [disabled]=\"processing || !url\"\n (click)=\"openCheckout()\">\n Ir al sitio de Mobbex\n </button>\n\n <a\n *ngIf=\"url\"\n class=\"mt-2 small mobbex-link\"\n [href]=\"url\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n (click)=\"$event.preventDefault(); openCheckout()\">\n Si el bot\u00F3n no abre una nueva pesta\u00F1a, toc\u00E1 aqu\u00ED para continuar.\n </a>\n\n <button\n *ngIf=\"processing\"\n type=\"button\"\n class=\"btn btn-link text-secondary mt-2\"\n (click)=\"cancelCheckout()\">\n Cancelar pago\n </button>\n\n <p *ngIf=\"!url\" class=\"mt-2 px-5 text-danger\">\n No fue posible preparar la pasarela de pago.\n </p>\n </div>\n </ng-template>\n</div>\n",
20519
+ styles: [".mobbex-note{color:#6c757d}"]
20336
20520
  })
20337
20521
  ], MobbexEcComponent);
20338
20522
  return MobbexEcComponent;