I got 2 files, app.js and bot.js. App.js is supposed to receive data off stripe which successfully does so and send that data to bot.js which does receive it.
Issue I’m having is SyntaxError: Unexpected token < in JSON at position 0 (can be seen on second image)
Here’s parts of code which sends and receives that data:
app.js
app.post('/cantshowthispart', express.json({
type: 'application/json'
}), async (request, response) => {
const event = request.body;
try {
switch (event.type) {
case 'checkout.session.completed':
console.log('Checkout session was successful!');
const sessionPaymentData = event.data.object;
if (sessionPaymentData.payment_method_types.includes('paypal')) {
console.log('Payment method: PayPal');
}
console.log(sessionPaymentData);
await axios.post('http://localhost:3001/checkoutSessionCompleted', sessionPaymentData, {
headers: {
'Content-Type': 'application/json'
}
});
break;
default:
console.log(`Unhandled event type ${event.type}`);
}
response.json({ received: true });
} catch (error) {
console.error('Error handling the event', error);
response.status(500).json({ error: 'Internal Server Error' });
}
});
bot.js
app.post('/checkoutSessionCompleted', async (req, res) => {
console.log('RECEIVED SOME DATA')
// Handle the received data
const reqData = req.body
console.log(reqData)
if (!reqData) {
console.log('Request body is undefined!')
return
}
console.log(reqData)
})
Everything else works, this part is only thing that’s bugging me.
Any help is appreciated!