HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/pwa.sports-crowd.com/src/app/pages/cards/cards.ts
import { Component, OnInit } from "@angular/core";
import { IonItemSliding, AlertController } from "@ionic/angular";
import { StorageService } from '../../services/storage.service';
import { TranslateService } from "@ngx-translate/core";
import { Router } from "@angular/router";
import { UserService } from "../../services/user.service";
import { UtilsService } from "../../services/utils.service";

@Component({
  selector: "page-cards",
  templateUrl: "cards.html",
  styleUrls: ["./cards.scss"],
})
export class CardsPage implements OnInit {
  creditCardUser: any = [];
  constructor(
    private storage: StorageService,
    public userProvider: UserService,
    public alertCtrl: AlertController,
    private utilsService: UtilsService,
    private translateService: TranslateService,
    private router: Router
  ) {}

  ngOnInit() {
  }

  ionViewDidLoad() {}

  ionViewWillEnter() {
    this.listCreditCard();
  }

  addNewCard() {
    this.router.navigate(["/app/tabs/settings/card-add"]);
  }

  listCreditCard() {
    this.storage.get("token").then(async (token) => {
      if (token) {
        this.utilsService.presentLoading(this.translateService.instant("all.loading"));
        (await this.userProvider.listCreditCard(token.access_token)).subscribe(
          (resp) => {
            this.utilsService.dismissLoading();
            this.creditCardUser = resp;
          },
          (error) => {
            this.utilsService.dismissLoading();
          }
        );
      }
    });
  }

  deleteCreditCard(slidingItem: IonItemSliding, id) {
    this.storage.get("token").then(async (token) => {
      if (token) {
        this.utilsService.presentLoading(this.translateService.instant("all.loading"));
        (await this.userProvider.deleteCreditCard(id, token.access_token)).subscribe(
          (resp) => {
            slidingItem.close();
            this.utilsService.dismissLoading();
            this.listCreditCard();
          },
          (error) => {
            this.utilsService.dismissLoading();
          }
        );
      }
    });
  }

  selectDefaultCard(id) {
    this.storage.get("token").then((token) => {
      if (token) {
        this.utilsService.presentLoading(this.translateService.instant("all.loading"));
        this.userProvider.selectDefaultCard(id, token.access_token).subscribe(
          (resp) => {
            this.utilsService.dismissLoading();
            this.listCreditCard();
          },
          (error) => {
            this.utilsService.dismissLoading();
          }
        );
      }
    });
  }

  verifyCard(id) {
    this.storage.get("token").then((token) => {
      if (token) {
        this.utilsService.presentLoading(this.translateService.instant("all.loading"));
        this.userProvider.generateVerifyCard(id, token.access_token).subscribe(
          (resp) => {
            this.utilsService.dismissLoading();
            if (resp["r"] && resp["b"].transactionResponse.state == "APPROVED") {
              this.nextProcessVerifyCardAPPROVED(resp, token, id);
            } else {
              this.nextProcessVerifyCard_OTHER_STATE(resp);
            }
          },
          (error) => {
            console.log("error listCreditCard", error);
            this.utilsService.dismissLoading();
          }
        );
      }
    });
  }

  async nextProcessVerifyCard_OTHER_STATE(resp) {
    const prompt = await this.alertCtrl.create({
      header: "Verificación",
      message: resp["m"],
      buttons: [
        {
          text: "Cancelar",
          handler: (data) => {
            console.log("Cancel clicked");
          },
        },
      ],
    });
    await prompt.present();
  }

  async nextProcessVerifyCardAPPROVED(resp, token, id) {
    const prompt = await this.alertCtrl.create({
      header: "Verificación",
      message: resp["m"],
      inputs: [
        {
          name: "value",
          placeholder: "Valor cobrado",
        },
      ],
      buttons: [
        {
          text: "Cancelar",
          handler: (data) => {
            console.log("Cancel clicked");
          },
        },
        {
          text: "Enviar",
          handler: (data) => {
            this.utilsService.presentLoading(this.translateService.instant("all.loading"));
            this.userProvider.sendValueVerifyCard(id, data.value, token.access_token).subscribe(
              (result) => {
                this.utilsService.dismissLoading();
                this.utilsService.presentToast(3000, "success", "top", result["m"]);
                if (result["r"]) {
                  this.listCreditCard();
                }
              },
              (error) => {
                console.log("error sendValueVerifyCard: ", error);
                this.utilsService.dismissLoading();
              }
            );
          },
        },
      ],
    });
    prompt.present();
  }
}