Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

154
Vistas
Vue call method inside api callback

I'm using a payment api and there is a callback method from the api that will denote about the status of the transaction.

  async makePayment() {
            this.$launchFlutterwave({
                tx_ref: Date.now(),
                amount: this.amount,
                currency: "KES",
                customer: {
                    email: "user@gmail.com",
                    phonenumber: this.user.phone_number,
                    name: this.user.name,
                    plot_unique_id: this.plot_unique_id
                },
                callback: function(data) {
                    
                    console.log(data);
                    this.registerPayment(data);
                },
                customizations: {
                    title: "",
                    description: ",
                    logo: "https://assets.piedpiper.com/logo.png"
                }
            });
        },

 async registerPayment(data) {
            console.log("hit");
            await axios.post("/api/flutterwave/register/payment", data);
        }

Inside that callback, I want to register a method

  callback: function(data) {
        console.log(data);
        this.registerPayment(data);
     },

and then that method will post the received back data and other user specific data to the back-end

 async registerPayment(data) {
       console.log("hit");
       await axios.post("/api/flutterwave/register/payment", data);
  }

But when calling the method inside the callback I'm receiving the error Uncaught TypeError: this.registerPayment is not a function.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

That's because the context inside the callback is different:

callback: function(data) {
  console.log(this); // you will see registerPayment doesnt exist here
  this.registerPayment(data);
},

Why not use the registerPayment directly? You can do so with:

callback: this.registerPayment

If you still want to call registerPayment from within the callback you can use arrow functions to access the outside context:

callback: (data) => {
  this.registerPayment(data);
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda