Buen día, estoy tratando de procesar el pago usando Firestore Cloud Function y una pasarela de pago llamada Yoco. Mi código de pago funciona y devuelve un objeto de falla o éxito. Cuando hago logger.log, puedo ver el objeto, pero el problema es cuando intento devolver el resultado al Cliente. Me sigo sin definir. Mis métodos son asíncronos.
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; }); });Eliminé la espera en mi llamada axios y la reemplacé con return. en mis devoluciones de llamada .then y catch en lugar de regresar
return reso
return errorAccedo a la propiedad de datos de esta manera
return res.dataTambién eliminó el error que estaba recibiendo en mis registros de funciones en la nube Se excedió el tamaño máximo de la pila de llamadas