I don’t know how to fix this problem. Someone please help me !
enter image description here
router.post("/create-payment-intent", async (req, res) => {
const { items, user_id } = req.body;
const customer = await stripe.customers.create();
const ephemeralKey = await stripe.ephemeralKeys.create(
{ customer: customer.id },
{ apiVersion: '2024-04-10' }
);
try {
const paymentIntent = await stripe.paymentIntents.create({
amount: 1099,
currency: 'usd',
confirm: true,
payment_method: 'pm_card_visa',
payment_method_types: ['card'],
});
const response = {
paymentIntent: paymentIntent.client_secret,
ephemeralKey: ephemeralKey.secret,
customer: customer.id,
publishableKey: 'pk_test_51PA9vlRsfm3Ucs22ixDUZ8mt2Ki9E7WR4tSil67ONZD4dptsAwjVZ0J2IFNEEf0iHQhDNEaTT87f6mTD9dnY1lAW00TQcuO9MO'
};
return res.json(response);
} catch (error) {
console.error(error);
return res.status(500).json({ error: 'An error occurred while creating Payment Intent' });
}
});
My coding very very bad, i don’t know how to fix that.
I know my code is wrong somewhere in here or missing a lot of things. I can identify what error I am facing but I can’t fix it because I am not good at coding and this is my graduation project. I hope someone will help me and code for me to be able to fix the error! Please!