I m fairly new to Firebase cloud functions and I ve been trying to integrate Stripe into my RN project using FB but keep getting a bad request response. I ll see a few things when I try to run this:
- Request is missing body.
- Invalid request, unable to process.
- Bad Request (400).
Does anyone know where I should go from here?
In my index.js file:
exports.payWithStripe = functions.https.onCall(async (data, response) => {
try {
const paymentIntent = await stripe.paymentIntents.create({
data: {
amount: 100,
currency: "usd",
payment_method_types: ["card"]
}
});
const clientSecret = paymentIntent.client_secret;
response.json({
clientSecret: clientSecret,
})
} catch (e) {
console.log(e.message);
response.json({ error: e.message });
}
})
On the app side:
const fetchPaymentIntentClientSecret = async () => {
const response = await fetch(`${FUNCTION_URL}/create-payment-intent`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
});
const { clientSecret, error } = await response.json();
return { clientSecret, error };
}