Skip to content
📦 ARCHIVED SNAPSHOT (v1.0) You are viewing historical business logic and documentation for Microservices (PHP) v1.0 (frozen on 2026-11-23, commit 96144c89). Switch to Latest →

4. SaaS Cooperative Onboarding Inquiry & Stripe Payment Confirmation

Repository: Microservices (planovi-microservices) • Rule Prefix: BR-INQ • Documented Rules: 5 • Open [TEAM_WHY_NEEDED] Questions: 3

1. Business Purpose & Actors

  • Problem Solved: Public self-serve SaaS signup wizard for Energy Cooperatives (Spółdzielnia Energetyczna) to pick a subscription tier + optional Energy Cooperative module + per-package seat counts, launch Stripe Checkout via submit-inquiry Edge Function, and land on branded post-payment confirmation screens.
  • Actors:
    • Prospective Cooperative Administrator: Completes the 4-step inquiry form (dealflow/inquiry.php), pays on Stripe Checkout, and is redirected back to dealflow/inquiry-success.php or dealflow/payment-success.php.
    • Stripe + planovi-backend (submit-inquiry, stripe-webhook): Generates Checkout Session URL, handles duplicate inquiry suppression, and provisions accounts asynchronously via webhook.

2. All Features & End-to-End Flows (Happy Path + Error Paths)

  • Feature A: 4-Step Inquiry Wizard (GET dealflow/inquiry.php)
    • Step 0 (Contact): Required f-name, f-email (regex /^[^\s@]+@[^\s@]+\.[^\s@]+$/), f-company; optional f-phone.
    • Step 1 (Packages & Seats):
      • Main plan group (radio-like exclusive selection): starter (199 PLN/seat), pro (499 PLN/seat — selected by default, 1 seat), enterprise (999 PLN/seat). Clicking a selected main plan toggles it off (allowing Energy module standalone).
      • Optional add-on: energy_coop (Energy Cooperative Module, 299 PLN/seat).
      • Per-package seat counter (min="1", − / + buttons or manual input). Live per-row and grand monthly total updates.
      • Validation: At least one package selected AND <= 1 main tier selected (inquiry.php:710-720).
    • Step 2 (Deployment): Boolean toggle deploymentHelp ("Pomoc przy wdrożeniu" — up to 3 online setup sessions & admin training) + optional f-notes textarea.
    • Step 3 (Summary & Submit): Renders summary table and "💳 Przejdź do płatności" button. Sends POST {SUPABASE_URL}/functions/v1/submit-inquiry with SUPABASE_ANON_KEY.
    • Response Branches (inquiry.php:891-906):
      • !res.ok → shows #submit-error inline banner and re-enables button.
      • data.stripeUrl → redirects browser window.location.href = data.stripeUrl.
      • data.duplicate → hides Step 3, displays #step-duplicate ("Zgłoszenie już istnieje ✓", referencing 24-hour deduplication window).
      • data.success (without stripeUrl) → hides Step 3, displays #step-success ("Zgłoszenie wysłane!", 24h manual contact flow).
  • Feature B: Cooperative Details Post-Stripe Confirmation (GET dealflow/inquiry-success.php?session_id=...&deal_id=...)
    • Static informational confirmation page explaining the 3-step post-payment flow (1: email with legal details form NIP/address/KRS, 2: fill 2-minute form, 3: account activated). Displays Ref: {dealId} if ?deal_id= is present. Performs zero API calls (stripe-webhook handles provisioning asynchronously).
  • Feature C: Direct Account Activation Post-Stripe Confirmation (GET dealflow/payment-success.php?session_id=...)
    • Static informational confirmation page explaining activation email (valid 24h), password setup, and login CTA button pointing to hardcoded $appUrl = 'https://dev-panel.planovi.app' (payment-success.php:20). Displays ID sesji: {sessionId} if ?session_id= is present.

3. Hard Business Rules, Validations, Calculations & Edge Cases

  • BR-INQ-01 (Hardcoded Catalog & Pricing): PACKAGE_DEFS (inquiry.php:639-644):
    • starter: 199 PLN/seat/month (up to 10 members)
    • pro: 499 PLN/seat/month (up to 50 members; default selected on load with 1 seat)
    • enterprise: 999 PLN/seat/month (unlimited + API + SLA + onboarding)
    • energy_coop: 299 PLN/seat/month (Telemetry, Balance, Governance, Finance)
  • BR-INQ-02 (One Main Plan + Optional Energy Module): MAIN_TIERS = ['starter', 'pro', 'enterprise'] (inquiry.php:648). Selecting a main tier automatically deselects the other two main tiers (inquiry.php:731-737). energy_coop may be combined with one main tier OR purchased standalone (if the user unchecks the active main tier). Selecting zero packages blocks navigation with 'Wybierz plan główny lub moduł Energy.'.
  • BR-INQ-03 (Seat Floor & Grand Total Formula): Seat count per package is clamped via Math.max(1, parseInt(input.value) || 1) (inquiry.php:748, 757). No maximum seat limit is enforced client-side. $$\text{grandTotal} = \sum_{p \in \text{selected}} (\text{seats}_p \times \text{pricePerSeat}_p)$$
  • BR-INQ-04 (Theme Persistence): All three pages (inquiry.php, inquiry-success.php, payment-success.php) default to data-theme="dark" and persist toggle state in localStorage['planovi_theme'].
  • BR-INQ-05 (Submission Payload Contract): submitInquiry() (inquiry.php:864-875) sends clientName, clientEmail, clientPhone, clientCompany, packages[] ({tier, label, seats, pricePerSeat, totalPrice}), totalPrice, deploymentHelp, notes, source: 'website_form', submittedAt (ISO-8601). Note: inquiry.php does NOT use includes/security.php (no CSRF, no Turnstile).

4. State Machines & Data Lifecycle

Inquiry Wizard & Checkout Flow:

stateDiagram-v2
    [*] --> Step0_Contact
    Step0_Contact --> Step1_Packages: Valid name, email, company
    Step1_Packages --> Step0_Contact: Back
    Step1_Packages --> Step2_Deployment: >=1 package AND <=1 main tier
    Step2_Deployment --> Step1_Packages: Back
    Step2_Deployment --> Step3_Summary: Next
    Step3_Summary --> Step2_Deployment: Back
    Step3_Summary --> Submitting: POST submit-inquiry
    Submitting --> StripeRedirect: data.stripeUrl -> external Stripe Checkout
    Submitting --> DuplicateState: data.duplicate (24h window)
    Submitting --> ManualSuccess: data.success (no stripeUrl)
    Submitting --> Step3_Summary: Error (inline message + retry)
    StripeRedirect --> InquirySuccessPage: Stripe return -> inquiry-success.php
    StripeRedirect --> PaymentSuccessPage: Stripe return -> payment-success.php

5. Technical Contract (Inputs → Processing → Side Effects)

  • Endpoints Exposed:
    • GET /dealflow/inquiry.php → HTML 4-step wizard.
    • GET /dealflow/inquiry-success.php?session_id={id}&deal_id={id} → HTML confirmation page.
    • GET /dealflow/payment-success.php?session_id={id} → HTML confirmation page.
  • External APIs Called: POST {SUPABASE_URL}/functions/v1/submit-inquiry (headers: Content-Type: application/json, apikey: {SUPABASE_ANON_KEY}, Authorization: Bearer {SUPABASE_ANON_KEY}).
  • Side Effects in This Repo: None (stateless PHP views; localStorage['planovi_theme'] in browser).

6. Cross-Repository Dependencies

CallerCalleeProtocol & AuthExact Endpoint / Contract
dealflow/inquiry.php (browser JS)planovi-backend (Supabase Edge Function)HTTPS POST + apikey & Bearer (SUPABASE_ANON_KEY)POST /functions/v1/submit-inquiry
Stripe Checkout (configured by planovi-backend)planovi-microservices (dealflow)Browser redirect (GET)/inquiry-success.php?session_id=...&deal_id=... or /payment-success.php?session_id=...
dealflow/payment-success.phpplanovi-flutter-app (web panel)Anchor linkhttps://dev-panel.planovi.app (hardcoded!)

7. Why It Works This Way (Decisions, Trade-offs & Workarounds)

  • One Main Plan + Optional Energy Module (33663b82): Updated from unconstrained multi-select so buyers cannot accidentally stack Starter + Pro + Enterprise, while still allowing standalone Energy module purchases; comment at inquiry.php:647 notes the same rule is enforced server-side in submit-inquiry.
  • Two Separate Post-Payment Confirmation Pages (inquiry-success.php vs payment-success.php): inquiry-success.php serves the onboarding flow where Stripe payment triggers a legal company-details form email (submit-company-details), whereas payment-success.php (82f0cb27, 51d1c666) serves direct subscription activation where the user immediately gets a password-setup email and a CTA to the web panel.
  • [TEAM_WHY_NEEDED: Why is $appUrl hardcoded to 'https://dev-panel.planovi.app' in dealflow/payment-success.php:20 instead of reading an environment variable or config.php for production vs dev?]
  • [TEAM_WHY_NEEDED: Are both inquiry-success.php and payment-success.php actively referenced as Stripe success_url targets in planovi-backend, or did one supersede the other?]
  • [TEAM_WHY_NEEDED: Why does dealflow/inquiry.php have no Cloudflare Turnstile or rate limiting before calling the public submit-inquiry Edge Function?]

8. Debugging, Logs & Common Failure Modes

Symptom / Error MessageRoot Cause in CodeHow to Verify / Exact Log or QueryFix
"Przejdź do platformy Planovi →" on production sends users to dev panelHardcoded $appUrl = 'https://dev-panel.planovi.app' (payment-success.php:20).Inspect CTA href in payment-success.php.Read panel URL from .env (e.g. PLANOVI_PANEL_URL).
Broken "Regulamin" link on payment-success.phpTypo domain https://dev-main.planowi.app/assets/for_preview/index (payment-success.php:262, “planowi” with w).Inspect footer links in payment-success.php:260-262.Fix domain typo and point to production legal URLs.
Self-XSS in Step 3 SummarybuildSummary() (inquiry.php:836-849) interpolates raw f-name, f-email, f-phone, f-company, f-notes into innerHTML without HTML escaping.Enter <img src=x onerror=alert(1)> in Step 0 and proceed to Step 3.Escape user input or build DOM nodes with .textContent.
"Błąd: Server error 500" on submitsubmit-inquiry Edge Function failed or SUPABASE_URL/SUPABASE_ANON_KEY has literal surrounding quotes (inquiry_load_env does NOT strip quotes, inquiry.php:12).View page source of inquiry.php and inspect SUPABASE_URL / SUPABASE_ANON_KEY JS constants.Strip surrounding quotes in .env loader (or reuse includes/security.php).