_best_ — Camwhores.v
// routes/purchases.js const express = require('express'); const router = express.Router(); const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY); const requireAuth = require('../middleware/auth'); const Stream, Purchase = require('../models');
-- 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() ); camwhores.v
const buyAccess = async () => const data = await axios.post(`/api/purchases/$id`); window.location.href = data.checkoutUrl; ; // routes/purchases
// 3️⃣ Store a pending purchase record (optional) await Purchase.create( user_id: userId, model_id: stream.model_id, stream_id: stream.id, stripe_charge_id: null, // will be filled in webhook amount_cents: stream.price_cents, ); // routes/purchases.js const express = require('express')