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 viasubmit-inquiryEdge 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 todealflow/inquiry-success.phpordealflow/payment-success.php. - Stripe +
planovi-backend(submit-inquiry,stripe-webhook): Generates Checkout Session URL, handles duplicate inquiry suppression, and provisions accounts asynchronously via webhook.
- Prospective Cooperative Administrator: Completes the 4-step inquiry form (
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; optionalf-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
<= 1main tier selected (inquiry.php:710-720).
- Main plan group (radio-like exclusive selection):
- Step 2 (Deployment): Boolean toggle
deploymentHelp("Pomoc przy wdrożeniu"— up to 3 online setup sessions & admin training) + optionalf-notestextarea. - Step 3 (Summary & Submit): Renders summary table and
"💳 Przejdź do płatności"button. SendsPOST {SUPABASE_URL}/functions/v1/submit-inquirywithSUPABASE_ANON_KEY. - Response Branches (
inquiry.php:891-906):!res.ok→ shows#submit-errorinline banner and re-enables button.data.stripeUrl→ redirects browserwindow.location.href = data.stripeUrl.data.duplicate→ hides Step 3, displays#step-duplicate("Zgłoszenie już istnieje ✓", referencing 24-hour deduplication window).data.success(withoutstripeUrl) → hides Step 3, displays#step-success("Zgłoszenie wysłane!", 24h manual contact flow).
- Step 0 (Contact): Required
- 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-webhookhandles provisioning asynchronously).
- 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
- 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). DisplaysID sesji: {sessionId}if?session_id=is present.
- Static informational confirmation page explaining activation email (valid 24h), password setup, and login CTA button pointing to hardcoded
3. Hard Business Rules, Validations, Calculations & Edge Cases
BR-INQ-01(Hardcoded Catalog & Pricing):PACKAGE_DEFS(inquiry.php:639-644):starter:199PLN/seat/month (up to 10 members)pro:499PLN/seat/month (up to 50 members; default selected on load with1seat)enterprise:999PLN/seat/month (unlimited + API + SLA + onboarding)energy_coop:299PLN/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_coopmay 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 viaMath.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 todata-theme="dark"and persist toggle state inlocalStorage['planovi_theme'].BR-INQ-05(Submission Payload Contract):submitInquiry()(inquiry.php:864-875) sendsclientName,clientEmail,clientPhone,clientCompany,packages[]({tier, label, seats, pricePerSeat, totalPrice}),totalPrice,deploymentHelp,notes,source: 'website_form',submittedAt(ISO-8601). Note:inquiry.phpdoes NOT useincludes/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
| Caller | Callee | Protocol & Auth | Exact 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.php | planovi-flutter-app (web panel) | Anchor link | https://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 atinquiry.php:647notes the same rule is enforced server-side insubmit-inquiry. - Two Separate Post-Payment Confirmation Pages (
inquiry-success.phpvspayment-success.php):inquiry-success.phpserves the onboarding flow where Stripe payment triggers a legal company-details form email (submit-company-details), whereaspayment-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 Message | Root Cause in Code | How to Verify / Exact Log or Query | Fix |
|---|---|---|---|
"Przejdź do platformy Planovi →" on production sends users to dev panel | Hardcoded $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.php | Typo 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 Summary | buildSummary() (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 submit | submit-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). |