SL
Slimms Law Firm

Family Sponsorship Productized Intake & Onboarding

Engineering Handoff Specification

Full-Stack Architecture & Stripe Integration Guide

Everything your programmers need to wire this intake flow to your backend: live form state JSON serialization, Node.js + Stripe Checkout / Affirm / SetupIntent endpoints, webhook handlers, and PostgreSQL schema.

← Back to Interactive Form

Live Form State & API Payload

Updates automatically as you interact with the form

{
  "intakeMetadata": {
    "firm": "Slimms Law Firm",
    "assignedOfficeId": "rosemere_qc",
    "assignedOfficeAddress": "277 Boul. Labelle, Suite #120, Rosemère, QC J7A 2H3, Canada",
    "regulatoryCompliance": "Barreau du Québec",
    "currentStep": 1,
    "hadPriorConsultation": false,
    "consultationDate": null,
    "isComplexFlagged": false,
    "flagReasons": []
  },
  "eligibility": {
    "sponsorStatus": "citizen_ca",
    "isQuebecResident": true,
    "applicantLocation": "inland_valid",
    "childCount": 0,
    "redFlags": {
      "priorRefusal": "no",
      "criminalRecord": "no",
      "overstayOrRemoval": "no",
      "medicalOrUndertaking": "no"
    }
  },
  "parties": {
    "sponsor": {
      "firstName": "",
      "middleName": "",
      "lastName": "",
      "dob": "",
      "email": "",
      "phone": "",
      "address": ""
    },
    "applicant": {
      "firstName": "",
      "middleName": "",
      "lastName": "",
      "dob": ""
    },
    "accompanyingChildren": []
  },
  "compliance": {
    "sponsorIdUploaded": false,
    "applicantIdUploaded": false,
    "mandateAccepted": false,
    "sponsorSignature": "",
    "applicantSignature": ""
  },
  "billing": {
    "paymentOption": "stripe_standard",
    "cashPayMode": null,
    "taxJurisdiction": "QC_GST_QST",
    "currency": "CAD",
    "standardSubtotal": 4980.0,
    "cashDiscountAmount": 0.0,
    "consultationCreditAmount": 0.0,
    "effectiveLegalSubtotal": 4980.0,
    "gst5Percent": 249.0,
    "qst9975Percent": 496.76,
    "hst13Percent": 0.0,
    "totalLegalWithTax": 5725.76,
    "dueTodayOnline": 1724.63,
    "cashDueAtLaunchMeeting": 0.0,
    "dueAtSubmission": 4001.13,
    "barreauCashCapTriggered": false
  }
}

PostgreSQL / Prisma Schema

Audit trail for mandates, Stripe IDs & cash receipts

model SponsorshipIntake {
  id                  String   @id @default(uuid())
  createdAt           DateTime @default(now())
  updatedAt           DateTime @updatedAt

  // Triage & Eligibility
  sponsorStatus       String   // citizen_ca | pr_ca | citizen_abroad
  isQuebecResident    Boolean  @default(true)
  assignedOffice      String   @default("rosemere_qc") // rosemere_qc | ottawa_on
  applicantLocation   String   // inland_valid | outland
  childCount          Int      @default(0)
  isComplexFlagged    Boolean  @default(false)
  hadPriorConsultation Boolean @default(false)
  consultationDate    String?

  // Client & Family Details
  sponsorFullName     String
  sponsorDob          String
  sponsorEmail        String
  sponsorPhone        String
  sponsorAddress      String
  applicantFullName   String
  applicantDob        String
  childrenJson        Json?

  // Barreau du Québec ID Verification (S3 / Encrypted Storage Keys)
  sponsorIdFileKey    String
  applicantIdFileKey  String

  // Pricing & Payment Method (QC GST/QST vs. ON 13% HST)
  paymentOption       String   // stripe_standard | affirm | cash_in_person
  cashPayMode         String?  // two_part | full_at_meeting
  taxRegion           String   @default("QC_GST_QST") // QC_GST_QST | ON_HST
  consultationCredit  Decimal  @default(0) @db.Decimal(10, 2)
  legalFeeSubtotal    Decimal  @db.Decimal(10, 2)
  gstAmount           Decimal  @db.Decimal(10, 2)
  qstAmount           Decimal  @db.Decimal(10, 2)
  hstAmount           Decimal  @db.Decimal(10, 2)
  totalWithTax        Decimal  @db.Decimal(10, 2)
  dueTodayWithTax     Decimal  @db.Decimal(10, 2)
  dueAtSubmission     Decimal  @db.Decimal(10, 2)

  // Click-Wrap Mandate Audit Trail
  mandateAcceptedAt   DateTime
  mandateIpAddress    String
  mandateUserAgent    String
  sponsorSignature    String
  applicantSignature  String
  mandateTextSnapshot String   @db.Text

  // Stripe & Calendar Integration
  stripeCustomerId    String?
  stripeSessionId     String?
  stripeSetupIntentId String?  // $0 card hold for Cash No-Show protection
  cashReceiptNumber   String?  // Sequential Barreau du Québec receipt #
  launchMeetingAt     DateTime?
  status              String   @default("DRAFT") // DRAFT | PAID | CASH_SCHEDULED | OPENED
}

Node.js / Express + Stripe Checkout & Webhook Handler

Handles Option 1 (Standard), Option 2 (Affirm), & Option 3 (Cash + $0 Hold)

// server/routes/intake.js
import express from 'express';
import Stripe from 'stripe';

const router = express.Router();
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);

const BASE_LEGAL_FEE = 4980;
const CHILD_FEE = 950;
const RETAINER_BASE = 1500;
const CASH_DISCOUNT = 0.15;
const CONSULTATION_CREDIT = 200;
const GST_RATE = 0.05;
const QST_RATE = 0.09975;
const HST_RATE = 0.13;
const BARREAU_CASH_LIMIT_CAD = 7500; // Applies across both QC & ON offices under Barreau du Québec rules

const OFFICES = {
  rosemere_qc: {
    name: 'Rosemère Office',
    address: '277 Boul. Labelle, Suite #120, Rosemère, QC J7A 2H3'
  },
  ottawa_on: {
    name: 'Ottawa Office',
    address: '280 Metcalfe St Ste 200, Ottawa, ON K2P 1R7'
  }
};

function calculatePricing({ childCount, isQuebecResident = true, hadPriorConsultation = false, paymentOption, cashPayMode = 'two_part' }) {
  const rawLegal = BASE_LEGAL_FEE + (childCount * CHILD_FEE);
  const isCash = paymentOption === 'cash_in_person';
  const afterCashDiscount = isCash ? +(rawLegal * (1 - CASH_DISCOUNT)).toFixed(2) : rawLegal;
  const creditApplied = hadPriorConsultation ? CONSULTATION_CREDIT : 0;
  const legalSubtotal = Math.max(0, +(afterCashDiscount - creditApplied).toFixed(2));

  const gst = isQuebecResident ? +(legalSubtotal * GST_RATE).toFixed(2) : 0;
  const qst = isQuebecResident ? +(legalSubtotal * QST_RATE).toFixed(2) : 0;
  const hst = !isQuebecResident ? +(legalSubtotal * HST_RATE).toFixed(2) : 0;
  const totalWithTax = +(legalSubtotal + gst + qst + hst).toFixed(2);

  const retainerWithTax = isQuebecResident
    ? +(RETAINER_BASE * (1 + GST_RATE + QST_RATE)).toFixed(2) // $1,724.63 CAD
    : +(RETAINER_BASE * (1 + HST_RATE)).toFixed(2);           // $1,695.00 CAD

  let dueTodayWithTax = retainerWithTax;
  let cashDueAtMeeting = 0;

  if (paymentOption === 'affirm') {
    dueTodayWithTax = 0;
  } else if (isCash) {
    dueTodayWithTax = 0; // $0 charged online; cash collected in person at Launch Meeting
    const desiredCash = cashPayMode === 'full_at_meeting' ? totalWithTax : retainerWithTax;
    cashDueAtMeeting = Math.min(desiredCash, BARREAU_CASH_LIMIT_CAD - 1); // Max $7,499.00 CAD
  }

  const dueAtSubmission = isCash
    ? +(totalWithTax - cashDueAtMeeting).toFixed(2)
    : paymentOption === 'affirm'
    ? 0
    : +(totalWithTax - dueTodayWithTax).toFixed(2);

  return {
    legalSubtotal,
    gst,
    qst,
    hst,
    totalWithTax,
    retainerWithTax,
    dueTodayWithTax,
    cashDueAtMeeting,
    dueAtSubmission
  };
}

router.post('/create-checkout', async (req, res) => {
  try {
    const { intakeId, sponsorEmail, sponsorName, childCount, isQuebecResident = true, hadPriorConsultation = false, paymentOption, cashPayMode } = req.body;
    const pricing = calculatePricing({ childCount, isQuebecResident, hadPriorConsultation, paymentOption, cashPayMode });
    const assignedOffice = isQuebecResident ? OFFICES.rosemere_qc : OFFICES.ottawa_on;
    const taxLabel = isQuebecResident ? 'QC GST + QST' : 'ON 13% HST';

    // 1. Create or retrieve Stripe Customer
    const customer = await stripe.customers.create({
      email: sponsorEmail,
      name: sponsorName,
      metadata: {
        intakeId,
        assignedOffice: assignedOffice.name,
        regulatoryBody: 'Barreau du Québec',
        hadPriorConsultation: String(hadPriorConsultation)
      }
    });

    // 2. Option 3: In-Person Cash at Launch Meeting -> $0 SetupIntent No-Show Guardrail
    if (paymentOption === 'cash_in_person') {
      const setupIntent = await stripe.setupIntents.create({
        customer: customer.id,
        payment_method_types: ['card'],
        metadata: {
          intakeId,
          paymentOption: 'cash_in_person',
          assignedOffice: assignedOffice.name,
          cashDueAtMeeting: String(pricing.cashDueAtMeeting),
          noShowFeeCad: '150.00'
        }
      });
      return res.json({
        mode: 'setup_intent',
        clientSecret: setupIntent.client_secret,
        assignedOffice,
        pricing
      });
    }

    // 3. Option 2: Affirm Financing (100% of legal fee + tax financed upfront)
    if (paymentOption === 'affirm') {
      const session = await stripe.checkout.sessions.create({
        customer: customer.id,
        mode: 'payment',
        payment_method_types: ['affirm'],
        line_items: [{
          price_data: {
            currency: 'cad',
            product_data: {
              name: `Family Sponsorship Legal Fee (${assignedOffice.name} — ${childCount} Child(ren))`,
              description: `Includes ${taxLabel}. Financed via Affirm.`
            },
            unit_amount: Math.round(pricing.totalWithTax * 100)
          },
          quantity: 1
        }],
        metadata: { intakeId, paymentOption: 'affirm', childCount: String(childCount), assignedOffice: assignedOffice.name },
        success_url: `${process.env.APP_URL}/intake/confirmed?session_id={CHECKOUT_SESSION_ID}`,
        cancel_url: `${process.env.APP_URL}/intake?step=4`
      });
      return res.json({ mode: 'checkout', url: session.url, pricing });
    }

    // 4. Option 1: Standard Two-Part Payment ($1,500 + tax today; save card for submission)
    const session = await stripe.checkout.sessions.create({
      customer: customer.id,
      mode: 'payment',
      payment_method_types: ['card'],
      payment_intent_data: { setup_future_usage: 'off_session' },
      line_items: [{
        price_data: {
          currency: 'cad',
          product_data: {
            name: `File Opening, Launch Meeting & Attorney Availability (${assignedOffice.name})`,
            description: `$1,500.00 CAD + ${taxLabel}`
          },
          unit_amount: Math.round(pricing.dueTodayWithTax * 100)
        },
        quantity: 1
      }],
      metadata: { intakeId, paymentOption: 'stripe_standard', childCount: String(childCount), assignedOffice: assignedOffice.name },
      success_url: `${process.env.APP_URL}/intake/confirmed?session_id={CHECKOUT_SESSION_ID}`,
      cancel_url: `${process.env.APP_URL}/intake?step=4`
    });

    return res.json({ mode: 'checkout', url: session.url, pricing });
  } catch (err) {
    return res.status(500).json({ error: err.message });
  }
});

// Webhook: Trigger Matter Creation, Barreau du Québec ID Archiving & Launch Meeting Invite
router.post('/webhook', express.raw({ type: 'application/json' }), async (req, res) => {
  const event = stripe.webhooks.constructEvent(
    req.body,
    req.headers['stripe-signature'],
    process.env.STRIPE_WEBHOOK_SECRET
  );

  if (event.type === 'checkout.session.completed' || event.type === 'setup_intent.succeeded') {
    const obj = event.data.object;
    const { intakeId, paymentOption } = obj.metadata || {};
    // 1. Mark SponsorshipIntake as PAID / CASH_SCHEDULED in PostgreSQL
    // 2. Create Matter in Clio / Lawmatics & attach Sponsor/Applicant Photo IDs
    // 3. If cash_in_person, generate pre-filled Barreau du Québec Cash Receipt PDF
    // 4. Send Launch Meeting Calendar Link & Document Portal Checklist via Email/SMS
    console.log(`Onboarding triggered for intake ${intakeId} (${paymentOption})`);
  }

  res.json({ received: true });
});

export default router;