Back

Issue with Data Transfer to Cloud Function in React App

  • 0
  • Functions
  • Web
  • REST API
  • Cloud
Moin Khan
10 Jun, 2024, 09:41

I am trying to implement the Razorpay payment gateway in my React app, using Appwrite for the backend and Appwrite functions for handling payments. I have created a cloud function to process the payment, receiving data such as amount, currency, and orderId from the frontend. However, I am encountering an issue where these values (amount, currency, orderId) appear as undefined when checked via console logs in the cloud function. It seems like the data is not being properly passed to the cloud function. Below, I am providing the relevant code for both my placeYourOrder function and the cloud function.

placeYourOrder Code:) let amountInPaisa = Math.round(total * 100); if (isNaN(amountInPaisa) || amountInPaisa < 100) { toast.warn("The minimum amount should be ₹1", { autoClose: 1500 }); return; }

TypeScript
fetch(
  "https://cloud.appwrite.io/v1/functions/function_id/executions",
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-Appwrite-Project": "projectId",
      "X-Appwrite-Key":"API_KEY",
    },
    body: JSON.stringify({
      amount: amountInPaisa ,
      currency: "INR",
      receipt: "receipt123",
    }),
  }
)
  .then((response) => response.json())
  .then((data) => {
    console.log("Response from cloud function:", data);
  })
  .catch((error) => {
    console.error("Error calling cloud function:", error);
  });

Also attach the cloud function code.

Please help me as soon as possible.

TL;DR
Developers encountering issue with passing data to cloud function for Razorpay payment gateway integration. Values like amount, currency, and orderId are showing as undefined in the cloud function. Check if data is being properly sent to the cloud function within the fetch request. Double-check parameter names and ensure proper data format.
Moin Khan
10 Jun, 2024, 09:46

Please somebody help me!

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more