Hi Netlify,
I created a netlify function (POST) for creating payment intent and sent the price over. On the handler, it all works pretty well in development but when deployed, the function returns error 502 and the response is - “error decoding lambda response: invalid status code returned from lambda: 0” - I have the call code and the handler code below. Any help to resolving this will be appreciated.
FRONTEND CALL CODE
const createPaymentIntent = async () => {
const price = totalDue;
if (user) {
try {
const { data } = await axios.post(
"/.netlify/functions/create-payment-intent-book",
JSON.stringify({ price })
);
setClientSecret(data.clientSecret);
setAllowProceed(true);
} catch (error) {
set_Error(
error?.response?.data ? "Please contact hairposey Admin..." : ""
);
}
} else if (userEmail) {
if (ValidateEmail(userEmail)) {
if (emailError) {
setEmailError(false);
}
try {
const { data } = await axios.post(
"/.netlify/functions/create-payment-intent-book",
JSON.stringify({ price })
);
setClientSecret(data.clientSecret);
setAllowProceed(true);
} catch (error) {
set_Error(
error?.response?.data ? "Please contact hairposey Admin..." : ""
);
}
} else {
setEmailError(true);
}
}
};
HANDLER CODE -
exports.handler = async function (event, context) {
const { price } = JSON.parse(event.body);
if (event.body) {
try {
const paymentIntent = await stripe.paymentIntents.create({
amount: price * 100,
currency: "cad",
});
return {
statusCode: 200,
body: JSON.stringify({ clientSecret: paymentIntent.client_secret}),
};
} catch (error) {
return {
statusCodes: 500,
body: JSON.stringify({ msg: error.message }),
};
}
}
return { statusCode: 200, body: "Please Create Payment Intent" };
};