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

92
Vistas
Firestore Cloud Function returns undefined to client when I perform axios post operation

Good day, I am trying to process payment using Firestore Cloud Function and a payment Gateway called Yoco. My payment code works and returns an object of failure or success. When I do logger.log I can view the object but the problem is when I try returning the result to the Client. I keep getting undefined. My methods are async.

CLIENT SIDE

I want to response from server and update my UI

const handlePay = () => {
    if (amount > 100) {
      yoco.showPopup({
        amountInCents: amount, // 2 decimal places begining from left
        currency: "ZAR",
        name: "Student Angel",
        description: "Helping students deal with student debt",

        callback: function (result) {
          // This function returns a token that your server can use to capture a payment
          if (result.error) {
            const errorMessage = result.error.message;
            alert("error occured: " + errorMessage);
          } else {
            paymentMethod({ token: result.id, amount: amount });
          }
          // In a real integration - you would now pass this chargeToken back to your
          // server along with the order/basket that the customer has purchased.
        },
      });
    } else {
      toast.error(
        "Due to high transaction charges, We can only process R100 and above. Thank you"
      );
    }
  };

  const paymentMethod = ({ token, amount }) => {
    const handlePayments = httpsCallable(functions, "handlePayments");
    handlePayments({ token, amount })
      .then((result) => {
        console.log(result);
      })
      .catch((result) => {
        console.log(result);
      });
  };

THIS IS CLOUD FUNCTION
exports.handlePayments = functions.https.onCall(async (data, context) => {
  // Using a testing key Not Production Key
  const SECRET_KEY = "sk_test_5ca384cdyerp8kY188a435e95fbe"; 
  // check auth state
  if (!context.auth) {
    throw new functions.https.HttpsError(
      "unauthenticated",
      "You are not authenticated"
    );
  }

  const token = data.token;
  const amount = data.amount;


  await axios  // I have tried this     return await axios.post but nothing
    .post(
      "https://online.yoco.com/v1/charges/",
      {
        token: token,
        amountInCents: amount,
        currency: "ZAR",
      },
      {
        headers: {
          "X-Auth-Secret-Key": SECRET_KEY,
        },
      }
    )
    .then((res) => {
      // res.status will contain the HTTP status code
      // res.data will contain the response body
      functions.logger.log(res);
      return res;
    })
    .catch((error) => {
      return error;
    });
});

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

0

I removed the await on my axios call and replaced it with return. on my callbacks .then and catch instead of returning

return res

or

return error

I access the data property like this

return res.data 

It also got rid of the Error I was getting in my cloud functions logs Maximum call stack size exceeded

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