Skip to content

Billing, Stripe & Monthly Invoicing

PLANOVI runs two separate financial pipelines inside planovi-backend and planovi-flutter-app:

  1. SaaS Platform Licensing (Stripe): Organizations subscribe to Planovi plans, apply operator coupons, upgrade/downgrade, and sync entitlements via signed Stripe webhooks.
  2. Cooperative Energy Invoicing: Monthly kWh settlement between energy cooperative members (billing-calculator → PDF generation → Resend email).

Where Is It in Code?

Symptom / TaskRepositoryExact File / Path
Billing UI, plan upgrade modal & invoice history in appplanovi-flutter-applib/features/billing/, lib/features/operator/
Starting Stripe Checkout or Customer Billing Portalplanovi-backendsupabase/functions/start-checkout/, create-portal-session/
Plan upgrades, proration preview, coupons & auto-renewplanovi-backendsupabase/functions/{preview-plan-change,change-plan,operator-coupons,set-auto-renew}/
Incoming Stripe webhooks (Stripe-Signature HMAC check)planovi-backendsupabase/functions/stripe-webhook/, handle-stripe-webhook/
Subscription updated / cancelled emailsplanovi-backendsupabase/functions/send-subscription-updated/, send-subscription-cancelled/
Cooperative tariff math & energy balancingplanovi-backendsupabase/functions/billing-calculator/, ai-energy-balancer/
Monthly batch PDF invoices & CSV exportsplanovi-backendsupabase/functions/{generate-monthly-invoices,generate-invoice-pdf,generate-report,export-csv}/
Delivering & fetching member invoicesplanovi-backendsupabase/functions/send-invoice-email/, get-billing-invoices/

Common Issues & How to Debug

1. Stripe Payment Succeeded, But Plan Didn’t Unlock in App

  1. Check Stripe Dashboard → Developers → Webhooks for delivery status (200 vs 400/500) targeting https://api.planovi.app/functions/v1/stripe-webhook (or handle-stripe-webhook).
  2. Verify STRIPE_WEBHOOK_SECRET in /opt/vps-stack/.env matches the signing secret of the active Stripe endpoint (PROD vs DEV have different secrets!).
  3. Inspect Edge Runtime logs on the VPS:
    Terminal window
    docker logs --tail 150 supabase-edge-runtime-prod | grep -i stripe

2. Monthly Invoice PDF Failed or Email Not Received

  • Check RESEND_API_KEY and FROM_EMAIL in supabase-edge-runtime-prod.
  • Verify aggregate-daily completed for the target billing month before generate-monthly-invoices ran.
  • Check stored PDFs in Supabase Studio → Storage (https://supabase-studio.planovi.app, VPN required).