Pattern pagamenti: Stripe setup, webhook, subscription, checkout, invoicing. Trigger: "stripe", "pagamenti", "subscription", "checkout", "webhook stripe"
Lingua: Sempre italiano. Riferimenti ufficiali:
Pagamento una tantum → Checkout Session mode='payment'
Abbonamento → Checkout Session mode='subscription' + trial_period_days
Upgrade/downgrade → Customer Portal (Stripe gestisce tutto)
Verifica piano → getSubscriptionPlan(userId) in ogni Server Action protetta
Webhook obbligatori da implementare:
checkout.session.completed → attiva abbonamento
customer.subscription.updated → aggiorna piano
customer.subscription.deleted → cancella abbonamento
invoice.payment_failed → stato PAST_DUE + email utente
invoice.paid → aggiorna periodo_fine
STRIPE_WEBHOOK_SECRET obbligatorio per validare firma webhookwebhook_events per evitare doppio processingutente_id nei metadata del checkout — necessario per associare il pagamentocheckout.session.completedautomatic_tax: true per IVA automatica per paese utentestato: PAST_DUE su invoice.payment_failed + email immediata all'utenteabbonamenti + webhook_events per idempotenza/api/checkout con userId nei metadata/api/stripe/webhook con signature verify + idempotencygetSubscriptionPlan() prima di operazioni PROstripe listen + card test 4242 4242 4242 4242STRIPE_WEBHOOK_SECRET aggiunto all'envwebhook_events)invoice.payment_failed con email all'utentestato e periodo_fine| Evento Stripe | Azione nella tua app |
|---|---|
checkout.session.completed | Crea/attiva abbonamento, stato=ACTIVE |
customer.subscription.updated | Aggiorna piano, periodo_fine |
customer.subscription.deleted | Stato=CANCELLED, disattiva feature PRO |
invoice.payment_failed | Stato=PAST_DUE, email utente |
invoice.paid | Estendi periodo_fine, stato=ACTIVE |
Stripe funziona su web senza restrizioni. Su mobile (iOS/Android) digital goods richiedono Apple IAP o Google Play Billing (Stripe VIETATO); physical goods e servizi fuori-app possono usare Stripe. Per un SaaS web + mobile valuta RevenueCat (unifica Stripe e IAP con un'unica API).
Dettagli, workaround legittimi (reader app, DMA UE, ruling Epic 2024),
strategia per SaaS multi-target e anti-pattern in
references/stripe-patterns.md → sezione "Web vs Mobile".
Per dettagli tecnici completi, leggi: