Camwhores.v -

router.post('/webhooks/stripe', express.raw(type: 'application/json'), async (req, res) => const sig = req.headers['stripe-signature']; let event;

// Update purchase record await Purchase.update( stripe_charge_id: session.payment_intent , where: user_id: userId, stream_id: streamId, stripe_charge_id: null ); camwhores.v

try event = stripe.webhooks.constructEvent(req.body, sig, process.env.STRIPE_WEBHOOK_SECRET); catch (err) console.error('⚠️ Webhook signature verification failed.', err); return res.sendStatus(400); router

// 1️⃣ Validate stream & price const stream = await Stream.findByPk(streamId); if (!stream ); const sig = req.headers['stripe-signature']

-- One‑time purchases (Pay‑Per‑View) CREATE TABLE purchases ( id BIGSERIAL PRIMARY KEY, user_id BIGINT REFERENCES users(id) ON DELETE CASCADE, model_id BIGINT REFERENCES users(id), stream_id BIGINT NOT NULL, -- reference to a live/recorded stream stripe_charge_id VARCHAR(255) UNIQUE, amount_cents INTEGER NOT NULL, purchased_at TIMESTAMP DEFAULT NOW() );

if (event.type === 'checkout.session.completed') const session = event.data.object; const userId, streamId = session.metadata;