require('dotenv').config(); const express = require('express'); const stripe = require('stripe')(process.env.REACT_APP_STRIPE_SKEY); const app = express(); app.use(express.json()); app.post('/api/create-payment-intent', async (req, res) => { try { const { amount, currency = 'usd', items } = req.body; // Create a PaymentIntent with the order amount and currency const paymentIntent = await stripe.paymentIntents.create({ amount: amount, currency: currency, metadata: { integration_check: 'accept_a_payment', items: JSON.stringify(items) } }); res.send({ clientSecret: paymentIntent.client_secret }); } catch (error) { console.error('Error creating payment intent:', error); res.status(400).send({ error: error.message }); } }); // Additional endpoints for order management app.post('/api/create-order', async (req, res) => { try { // Process order and save to database const order = { items: req.body.items, total: req.body.total, status: 'pending', createdAt: new Date() }; // Save to your database // const savedOrder = await saveOrderToDatabase(order); res.json({ order }); } catch (error) { res.status(400).json({ error: 'Failed to create order' }); } }); app.listen(process.env.SERVER_PORT || 4000, () => { console.log(`Server running on port ${process.env.SERVER_PORT || 4000}`); });