vk-payments 0.2.14 → 0.2.16

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.
@@ -3515,6 +3515,7 @@
3515
3515
  this.modoApi = modoApi;
3516
3516
  this.statusPay = new core.EventEmitter();
3517
3517
  this.isLoading = false;
3518
+ this.executionEnv = 'desktop';
3518
3519
  }
3519
3520
  /**
3520
3521
  * @return {?}
@@ -3523,7 +3524,41 @@
3523
3524
  * @return {?}
3524
3525
  */
3525
3526
  function () {
3526
- this.loadModoScript();
3527
+ this.detectEnvironment();
3528
+ if (this.executionEnv === 'desktop') {
3529
+ this.loadModoScript();
3530
+ }
3531
+ };
3532
+ /**
3533
+ * @private
3534
+ * @return {?}
3535
+ */
3536
+ ModoComponent.prototype.detectEnvironment = /**
3537
+ * @private
3538
+ * @return {?}
3539
+ */
3540
+ function () {
3541
+ try {
3542
+ if (this.mobileAppEnv === 'iOS' || this.mobileAppEnv === 'Android') {
3543
+ this.executionEnv = 'native-app';
3544
+ this.devicePlatform = this.mobileAppEnv;
3545
+ console.log("MODO Payment: Entorno detectado -> Nativo (" + (this.devicePlatform || 'app') + ")");
3546
+ return;
3547
+ }
3548
+ }
3549
+ catch (error) {
3550
+ console.warn('MODO Payment: No se pudo leer los parámetros de la ruta. Se continuará con la detección por User Agent.');
3551
+ }
3552
+ /** @type {?} */
3553
+ var userAgent = navigator.userAgent || navigator.vendor || ((/** @type {?} */ (window))).opera;
3554
+ if (/android/i.test(userAgent) || /iPad|iPhone|iPod/.test(userAgent)) {
3555
+ this.executionEnv = 'mobile-browser';
3556
+ console.log('MODO Payment: Entorno detectado -> Navegador Móvil');
3557
+ }
3558
+ else {
3559
+ this.executionEnv = 'desktop';
3560
+ console.log('MODO Payment: Entorno detectado -> Desktop');
3561
+ }
3527
3562
  };
3528
3563
  /**
3529
3564
  * @return {?}
@@ -3533,8 +3568,7 @@
3533
3568
  */
3534
3569
  function () {
3535
3570
  return __awaiter(this, void 0, void 0, function () {
3536
- var initialData_1, modalObject, error_1;
3537
- var _this = this;
3571
+ var initialData, error_1;
3538
3572
  return __generator(this, function (_a) {
3539
3573
  switch (_a.label) {
3540
3574
  case 0:
@@ -3544,49 +3578,23 @@
3544
3578
  _a.trys.push([1, 3, , 4]);
3545
3579
  return [4 /*yield*/, this.createModoPayment()];
3546
3580
  case 2:
3547
- initialData_1 = _a.sent();
3581
+ initialData = _a.sent();
3548
3582
  this.isLoading = false;
3549
- modalObject = {
3550
- version: '2',
3551
- qrString: initialData_1.qrString,
3552
- checkoutId: initialData_1.checkoutId,
3553
- deeplink: {
3554
- url: initialData_1.deeplink,
3555
- callbackURL: this.callbackUrl,
3556
- callbackURLSuccess: this.callbackUrlSuccess
3557
- },
3558
- callbackURL: this.callbackUrl,
3559
- refreshData: (/**
3560
- * @return {?}
3561
- */
3562
- function () { return _this.createModoPayment(); }),
3563
- onSuccess: (/**
3564
- * @return {?}
3565
- */
3566
- function () {
3567
- _this.statusPay.emit({ success: true, paymentId: initialData_1.checkoutId });
3568
- }),
3569
- onFailure: (/**
3570
- * @return {?}
3571
- */
3572
- function () {
3573
- _this.statusPay.emit({ success: false, paymentId: initialData_1.checkoutId });
3574
- }),
3575
- onCancel: (/**
3576
- * @return {?}
3577
- */
3578
- function () {
3579
- console.log('Pago cancelado por el usuario en el celular.');
3580
- }),
3581
- onClose: (/**
3582
- * @return {?}
3583
- */
3584
- function () {
3585
- console.log('Modal de MODO cerrado.');
3586
- }),
3587
- };
3588
- // 3. Inicia el SDK de MODO
3589
- ModoSDK.modoInitPayment(modalObject);
3583
+ switch (this.executionEnv) {
3584
+ case 'native-app':
3585
+ // Llama a la función nativa para abrir en un navegador externo
3586
+ this.openOnNativeNavigator(initialData.deeplink);
3587
+ break;
3588
+ case 'mobile-browser':
3589
+ // Abre el deeplink en una nueva pestaña
3590
+ window.open(initialData.deeplink, '_blank');
3591
+ break;
3592
+ case 'desktop':
3593
+ default:
3594
+ // Abrir el modal del SDK
3595
+ this.initModoSdkModal(initialData);
3596
+ break;
3597
+ }
3590
3598
  return [3 /*break*/, 4];
3591
3599
  case 3:
3592
3600
  error_1 = _a.sent();
@@ -3600,18 +3608,92 @@
3600
3608
  });
3601
3609
  };
3602
3610
  /**
3603
- * Esta función se encarga de llamar a tu backend.
3604
- * Se usa tanto para la carga inicial como para el refresco del SDK.
3611
+ * @private
3612
+ * @param {?} url
3613
+ * @return {?}
3605
3614
  */
3615
+ ModoComponent.prototype.openOnNativeNavigator = /**
3616
+ * @private
3617
+ * @param {?} url
3618
+ * @return {?}
3619
+ */
3620
+ function (url) {
3621
+ try {
3622
+ if (this.devicePlatform === 'iOS') {
3623
+ ((/** @type {?} */ (window))).webkit.messageHandlers.externalURL.postMessage(url);
3624
+ }
3625
+ else if (this.devicePlatform === 'Android') {
3626
+ ((/** @type {?} */ (window))).externalURL.postMessage(url);
3627
+ }
3628
+ else {
3629
+ // Fallback si por alguna razón no se detectó la plataforma pero sí el entorno nativo
3630
+ window.open(url, '_blank');
3631
+ }
3632
+ }
3633
+ catch (e) {
3634
+ console.error('Error al intentar invocar el message handler nativo:', e);
3635
+ }
3636
+ };
3637
+ /**
3638
+ * @private
3639
+ * @param {?} initialData
3640
+ * @return {?}
3641
+ */
3642
+ ModoComponent.prototype.initModoSdkModal = /**
3643
+ * @private
3644
+ * @param {?} initialData
3645
+ * @return {?}
3646
+ */
3647
+ function (initialData) {
3648
+ var _this = this;
3649
+ /** @type {?} */
3650
+ var modalObject = {
3651
+ version: '2',
3652
+ qrString: initialData.qrString,
3653
+ checkoutId: initialData.checkoutId,
3654
+ deeplink: {
3655
+ url: initialData.deeplink,
3656
+ callbackURL: this.callbackUrl,
3657
+ callbackURLSuccess: this.callbackUrlSuccess
3658
+ },
3659
+ callbackURL: this.callbackUrl,
3660
+ refreshData: (/**
3661
+ * @return {?}
3662
+ */
3663
+ function () { return _this.createModoPayment(); }),
3664
+ onSuccess: (/**
3665
+ * @return {?}
3666
+ */
3667
+ function () {
3668
+ _this.statusPay.emit({ success: true, paymentId: initialData.checkoutId });
3669
+ }),
3670
+ onFailure: (/**
3671
+ * @return {?}
3672
+ */
3673
+ function () {
3674
+ _this.statusPay.emit({ success: false, paymentId: initialData.checkoutId });
3675
+ }),
3676
+ onCancel: (/**
3677
+ * @return {?}
3678
+ */
3679
+ function () {
3680
+ console.log('Pago cancelado por el usuario en el celular.');
3681
+ }),
3682
+ onClose: (/**
3683
+ * @return {?}
3684
+ */
3685
+ function () {
3686
+ console.log('Modal de MODO cerrado.');
3687
+ }),
3688
+ };
3689
+ // 3. Inicia el SDK de MODO
3690
+ ModoSDK.modoInitPayment(modalObject);
3691
+ };
3606
3692
  /**
3607
- * Esta función se encarga de llamar a tu backend.
3608
- * Se usa tanto para la carga inicial como para el refresco del SDK.
3609
3693
  * @private
3610
3694
  * @return {?}
3611
3695
  */
3612
3696
  ModoComponent.prototype.createModoPayment = /**
3613
- * Esta función se encarga de llamar a tu backend.
3614
- * Se usa tanto para la carga inicial como para el refresco del SDK.
3615
3697
  * @private
3616
3698
  * @return {?}
3617
3699
  */
@@ -3682,6 +3764,7 @@
3682
3764
  data: [{ type: core.Input }],
3683
3765
  amount: [{ type: core.Input }],
3684
3766
  orderId: [{ type: core.Input }],
3767
+ mobileAppEnv: [{ type: core.Input }],
3685
3768
  vkUrlApi: [{ type: core.Input }],
3686
3769
  callbackUrl: [{ type: core.Input }],
3687
3770
  callbackUrlSuccess: [{ type: core.Input }],
@@ -3703,6 +3786,8 @@
3703
3786
  /** @type {?} */
3704
3787
  ModoComponent.prototype.orderId;
3705
3788
  /** @type {?} */
3789
+ ModoComponent.prototype.mobileAppEnv;
3790
+ /** @type {?} */
3706
3791
  ModoComponent.prototype.vkUrlApi;
3707
3792
  /** @type {?} */
3708
3793
  ModoComponent.prototype.callbackUrl;
@@ -3712,6 +3797,16 @@
3712
3797
  ModoComponent.prototype.statusPay;
3713
3798
  /** @type {?} */
3714
3799
  ModoComponent.prototype.isLoading;
3800
+ /**
3801
+ * @type {?}
3802
+ * @private
3803
+ */
3804
+ ModoComponent.prototype.executionEnv;
3805
+ /**
3806
+ * @type {?}
3807
+ * @private
3808
+ */
3809
+ ModoComponent.prototype.devicePlatform;
3715
3810
  /**
3716
3811
  * @type {?}
3717
3812
  * @private