gabfiocchi / ngx-mercadopago

🚀 MercadoPago PX bridge for Angular and Ionic - Angular
MIT License
18 stars 6 forks source link

Error when registering credit card in producton enviroment #2

Closed moises-alphacode closed 3 years ago

moises-alphacode commented 4 years ago

Hi, after firing the createToken method, it freezes up on IOS, and on android it gets the token but after sending the card token the sdk or the api return: {code: "120", description: "card not found"}.

By the way thank you so much for this plugins it makes life a lot easier with mercadopago and angular.

gabfiocchi commented 4 years ago

Hi, how are you implementing it? Have you checked that your credentials are correct? Could you upload a part of your code and the way you do this to be able to reproduce it?

moycs777 commented 4 years ago

Hi, sorry for the delay, i update the credentials, generating new ones, and the error in iIOS i asume that is abouts ssl, but in android i'm still getting the same error: {code: "120", description: "card not found"}. on the log of the plugin when generating the token for the it shows the test public key, but i have set the production key, it is very weird, i hardcoded the production but it stil takes the test, take a look: [image: Screen Shot 2020-11-05 at 11.28.08.png]

I am no able to share the hole project but i will send you the ts file where i am doing this process.

Thank you so much for your help.

El mar., 3 nov. 2020 a las 5:57, Gabriel Fiocchi (notifications@github.com) escribió:

Hi, how are you implementing it? Have you checked that your credentials are correct? Could you upload a part of your code and the way you do this to be able to reproduce it?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/gabfiocchi/ngx-mercadopago/issues/2#issuecomment-720986811, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB37URSVZM5PENMAT4IQVD3SN7AWFANCNFSM4TFGMPPA .

-- Moises A. Serrano P.

 Whatsapp: +584249661188

import { NavController, AlertController } from "@ionic/angular"; import { Router } from "@angular/router"; import { Component, OnInit, Inject } from "@angular/core"; import { UtilsService } from "src/app/services/utils/utils.service"; import { RequisicoeshttpService } from "src/app/services/requisicoes/requisicoes.service"; import { MERCADOPAGO_PUBLIC_KEY } from "src/environments/environment"; import { DOCUMENT } from "@angular/common"; import { NgxMercadopagoService } from "ngx-mercadopago";

@Component({ selector: "app-adicionar-cartao-paciente", templateUrl: "./adicionar-cartao-paciente.page.html", styleUrls: ["./adicionar-cartao-paciente.page.scss"], }) export class AdicionarCartaoPacientePage implements OnInit { public cartao = { number: null, nome: null, date: null, cvv: null, payment_method_id: null, cliente_id: null, oferta_id: null, cpf: null, token_usuario: null, token: null, month: null, year: null, }; public data: any; public ofertas: any; public imagens: any; public usuario: any = {}; public form: any; public endereco: any; public request = false; private publickey = MERCADOPAGO_PUBLIC_KEY; public doSubmit = false; public isLoading = false;

constructor( @Inject(DOCUMENT) document, private utils: UtilsService, private _http: RequisicoeshttpService, private navCtrl: NavController, private alertCtrl: AlertController, private router: Router, private ngxMercadopago: NgxMercadopagoService ) {}

async ngOnInit() { this.ngxMercadopago.initialize(this.publickey); }

async ionViewDidEnter() { // this.utils.statusEscuro(); this.usuario = await JSON.parse(localStorage.getItem("solucare.usuario")); this.inputsCleaner(); }

inputsCleaner() { this.cartao = { number: null, nome: null, date: null, cvv: null, payment_method_id: null, cliente_id: null, oferta_id: null, cpf: null, token_usuario: null, token: null, month: null, year: null, }; }

onChangeDate(e) { const month = e; const year = e;

this.cartao.year = year.substring(3, 9);
this.cartao.month = month.substring(0, 2);

}

async confirmarSaida(): Promise { let resolveFunction: (confirm: boolean) => void; const promise = new Promise((resolve) => { resolveFunction = resolve; });

const alert = await this.alertCtrl.create({
  message:
    "Você possui alterações que ainda não foram salvas, se sair irá perdê-las. Deseja continuar?",
  buttons: [
    {
      text: "Cancelar",
      role: "cancel",
      handler: () => resolveFunction(false),
    },
    {
      text: "Sim, quero sair",
      handler: () => resolveFunction(true),
    },
  ],
});

await alert.present();
return promise;

}

async voltar(rota, padrao = true) { let campos = ["cpf", "number", "cvv", "date", "nome"]; let camposVazios = await this.utils.verificaCamposVazios( this.cartao, campos, false ); let paraRequisicao = false; camposVazios.forEach((dado) => { if (dado.status == "preenchidos") { paraRequisicao = true; } });

if (paraRequisicao) {
  let confirma = await this.confirmarSaida();

  if (confirma) {
    if (padrao) {
      this.navCtrl.navigateBack(rota);
    } else {
      this.navegacao(rota);
    }
  }
} else {
  if (padrao) {
    this.navCtrl.navigateBack(rota);
  } else {
    this.navegacao(rota);
  }
}

}

navegacao(rota) { this.navCtrl.setDirection("root"); this.router.navigateByUrl(rota); }

async saveTokenPlugin() { if ( this.cartao.nome == null || this.cartao.number == null || this.cartao.cvv == null || this.cartao.date == null || this.cartao.cpf == null ) { this.utils.presentToast("Deve preencher todos os dados."); return; } this.isLoading = true;

this.ngxMercadopago
  .createToken({
    cardNumber: Number(this.cartao.number.replace(/\s/g, "")),
    securityCode: this.cartao.cvv,
    cardExpirationMonth: this.cartao.month,
    cardExpirationYear: this.cartao.year.toString().replace(/\s/g, ""),
    cardholderName: this.cartao.nome,
    docType: "CPF",
    docNumber: this.cartao.cpf.replace(/[.-]/g, ""),
  })
  .subscribe(
    (res) => {
      console.log("__ res", res);
      this.isLoading = false;
      if (res.status == 200) {
        this.salvar({
          token: res.data.id,
        });
      } else {
        const errosFormatados = this.utils.formatarErrosNoCartao(
          res.error.cause
        );
        this.isLoading = false;
        this.utils.presentToast(`Houve um problema tente mais tarde.`);
      }
    },
    (error) => {
      console.log("__ error", error);
      this.isLoading = false;
      this.utils.presentToast("Houve um problema, verifique os dados.");
    }
  );

}

async salvar(dados) { this.isLoading = true;

let obj = {
  token: dados.token,
  token_usuario: this.usuario.token,
};
this._http.post("cartoes", obj).subscribe(
  async (resposta: any) => {
    this.isLoading = false;
    if (resposta.status == "sucesso") {
      this.utils.mostrarModal(
        "Você cadastrou o cartão com sucesso!",
        "/pagamentos-paciente"
      );
    } else {
      this.utils.presentToast(resposta.mensagem);
    }
  },
  (erro) => {
    this.isLoading = false;
    this.utils.presentToast(
      "Houve um problema, verifique sua conexão com a internet."
    );
  }
);

} }

gabfiocchi commented 3 years ago

Hello, the screenshot cannot be seen. I have updated the readme with some information about how to configure the Schema on Android and the hostname on iOS to simulate an SSL environment so that it works.

The error that you are seeing of "Card not found", is typical of MercadoPago, you should check that the data entered is correct as well as your credentials.

Cheers

moycs777 commented 3 years ago

Hi, thank you so much

El jue, 10 dic 2020 a las 20:23, Gabriel Fiocchi (notifications@github.com) escribió:

Hello, the screenshot cannot be seen. I have updated the readme with some information about how to configure the Schema on Android and the hostname on iOS to simulate an SSL environment so that it works.

The error that you are seeing of "Card not found", is typical of MercadoPago, you should check that the data entered is correct as well as your credentials.

Cheers

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/gabfiocchi/ngx-mercadopago/issues/2#issuecomment-742864155, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB37URSS2LEC6O6X54TEI5TSUFKATANCNFSM4TFGMPPA .

-- Moises A. Serrano P.

 Whatsapp: +584249661188