📦 server.js — Checkout one-shot 500€
// POST /create-payment-intent
app.post('/create-payment-intent', async (req, res) => {
const { amount, email, plan } = req.body;
const paymentIntent = await stripe.paymentIntents.create({
amount: amount * 100, // en centimes
currency: 'eur',
metadata: { email, plan },
receipt_email: email,
});
res.json({
clientSecret: paymentIntent.client_secret
});
});
🔄 Abonnements récurrents (Stripe Billing)
// POST /create-subscription
app.post('/create-subscription', async (req, res) => {
const { email, priceId } = req.body;
const customer = await stripe.customers.create({ email });
const subscription = await stripe.subscriptions.create({
customer: customer.id,
items: [{ price: priceId }],
// priceId: price_basic_29 ou price_pro_59
payment_behavior: 'default_incomplete',
expand: ['latest_invoice.payment_intent'],
});
res.json({
subscriptionId: subscription.id,
clientSecret: subscription.latest_invoice
.payment_intent.client_secret
});
});
🪝 Webhook Stripe (activer/désactiver)
// POST /webhook
app.post('/webhook', express.raw({type:'application/json'}),
(req, res) => {
const sig = req.headers['stripe-signature'];
const event = stripe.webhooks.constructEvent(
req.body, sig, process.env.STRIPE_WEBHOOK_SECRET
);
switch(event.type) {
case 'payment_intent.succeeded':
// → Créer client en BDD MySQL
// → Envoyer email confirmation
// → Envoyer lien onboarding
break;
case 'invoice.payment_succeeded':
// → Renouveler abonnement en BDD
break;
case 'customer.subscription.deleted':
// → Désactiver site client
break;
}
res.json({ received: true });
});
🗄️ Schéma MySQL O2switch
-- Table clients
CREATE TABLE clients (
id INT AUTO_INCREMENT PRIMARY KEY,
stripe_customer_id VARCHAR(100),
stripe_subscription_id VARCHAR(100),
business_name VARCHAR(200) NOT NULL,
email VARCHAR(200) NOT NULL,
plan ENUM('launch','basic','pro') DEFAULT 'launch',
status ENUM('pending','active','paused') DEFAULT 'pending',
site_url VARCHAR(300),
gmb_created BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Table sites
CREATE TABLE sites (
id INT AUTO_INCREMENT PRIMARY KEY,
client_id INT REFERENCES clients(id),
html_content LONGTEXT,
subdomain VARCHAR(100),
deployed_at TIMESTAMP,
o2switch_path VARCHAR(300)
);