Skip to content

feat(payments): pay-at-finalize frontend (itemized cost, payment dialogs, return page) - #1794

Draft
ArendPeter wants to merge 3 commits into
stripe-webhookfrom
pay-at-finalize-frontend
Draft

ArendPeter wants to merge 3 commits into
stripe-webhookfrom
pay-at-finalize-frontend

Conversation

@ArendPeter

Copy link
Copy Markdown
Member

Human Summary

This primarily adds an itemized quote above the finalize button for elections that require it. It also adds some copy in the add voter flow to clarify the process, and adjusts the confirmation popups after finalizing.

To account for additional voters after finalizing, this PR includes the quote in a popup once the voter limit is exceeded

This gives a frontend entry point to the stripe features that were added to the backend

Summary

Closes #1793. Stacked on #1792. Everything is behind a new frontend-only FF_PAYMENTS flag; with it off the UI is unchanged (the stop-gap override message and today's confirm stay).

Publish & Share (draft, closed voter list)
  itemize({ roll_count }, entitlements)
  <FinalizeCostSection id="finalize-cost">   nothing owed → "No cost to finalize: …" note
    <ItemizedCost>                           owed → Free tier / Already paid / line items / Total
  Finalize click → <FinalizeDialog>
    nothing owed → today's confirm → finalize + invite prompt
    owed → "Proceed to payment ($X)" → POST /Election/:id/CheckoutSession → window.location = url

Add Voters (after finalize), roll + upload > voter limit   (also the 402 backstop)
  <UploadPaymentDialog> with <ItemizedCost>, priced for roll + upload → checkout, no voters added

/:id/admin?checkout_session_id=…  → <CheckoutReturn>
  poll GET /Election/:id until entitlements cover what was saved in sessionStorage before redirect
    draft → finalize + invite prompt
    else  → Manage Voters, Add Voters open, "Payment received. Please re-submit your list."
  ~30s without the grant → "Stripe hasn't confirmed your payment yet… you can leave"
/:id/admin?checkout=cancelled → Publish & Share (draft) or Manage Voters, nothing changed

Also: the "N voters, see the cost of finalizing" link on Manage Voters (drafts with a closed list), the two-line tier copy at the bottom of Add Voters (quote link in drafts only), and the removal of the old "approved for N" / "Free tier elections are limited to…" lines.

 packages/shared/src/
+├── utils/numberFormat.ts          # formatCount / formatCents ("25,700", "$1,536")
 └── domain_model/ProductCatalog.ts
+    cartTotal, entitlementsAfter
 packages/frontend/src/components/Election/Admin/
+├── Payments/                      # ItemizedCost, FinalizeCostSection, FinalizeDialog, UploadPaymentDialog,
+│                                  # CheckoutReturn, FinalizeCostLink, AddVotersPricingNote, useCheckout, paymentsUtils
+├── useFinalizeAndInvite.ts        # finalize + invite prompt, shared by Publish & Share and CheckoutReturn
 ├── PublishAndShare.tsx
 ├── AddElectionRoll.tsx
 ├── ViewElectionRolls.tsx
 └── Admin.tsx                      # index route renders CheckoutReturn on Stripe's return params

Evidence

  • Before: with FF_PAYMENTS forced off, the new testing/tests/payments.spec.ts fails 3/3.
    After: with it on, it passes 3/3:

    • free: the note, no table, today's confirm, then finalized;
    • owed (150 voters): Manage Voters link → #finalize-cost, the table ("Based on 150 voters", "From 100 to 200 · $6 per 100", Total $6), the dialog's "Proceed to payment ($6)" posts { line_items: [{ voter_limit, quantity: 1, unit_entitlement: 100, unit_amount: 600 }] }, and the cancel return lands back on Publish & Share as a draft;
    • over-limit upload (98 voters + 5, finalized): the dialog shows the table priced for 103, and nothing is added on Cancel.
  • Full Chromium Playwright suite: 15/15. Backend jest: 324/324 (new numberFormat and cartTotal/entitlementsAfter tests).

  • Manual end-to-end against Stripe test checkout with stripe listen forwarding to the webhook:

    • a draft with 150 voters finalized through payment, and its voter limit went to 200;
    • a finalized election with 98 voters paid during a 5-voter upload, and the re-submitted list was added (103 voters).

    This ran before the review-fix commit, which changed the return page's "no saved expectation" path and split the components into files.

Merge Danger

Door: two-way

Flag-gated and frontend-only, apart from the shared helpers.

Blast Radius: small

With the flag off, the visible changes are none, but Publish & Share's finalize now goes through the extracted useFinalizeAndInvite (same calls), and /:id/admin renders the return page if Stripe's query params are present. Note for whoever turns the flag on: the backend builds the checkout return URL from mainUrl (ALLOWED_URLS, default https://bettervoting.com), so a local or staging setup without it set returns to production.

🤖 Generated with Claude Code

ArendPeter and others added 3 commits November 15, 2026 15:35
Itemized cost on Publish & Share (#finalize-cost) and in the over-limit
upload dialog, a Finalize dialog that proceeds to payment when something
is owed, Stripe Checkout via POST /Election/:id/CheckoutSession, and a
return page that waits for the entitlement grant before finalizing or
reopening Add Voters. With the flag off the UI is unchanged.

Shared: formatCount/formatCents, cartTotal, entitlementsAfter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Split payment components into default-exported files; hooks are named
  exports; URL/storage constants move to Payments/paymentsUtils.
- Finalize dialog can't be dismissed by clicking outside, like today's confirm.
- Finalize stays disabled until the roll is priced, so an owed election
  never gets the free confirm.
- Returning from an upload checkout without the saved expectation shows the
  pending message instead of claiming the payment landed.
- The upload dialog says how many voters were already added when the
  server's 402 backstop stopped an upload part-way.
- "Proceed to payment" stays disabled while the browser leaves for Stripe.
- Comma-format the voter-limit error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ArendPeter
ArendPeter added this pull request to stack #1791 November 15, 2026 23:50
@netlify

netlify Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for bettervoting ready!

Name Link
🔨 Latest commit c81ecc6
🔍 Latest deploy log https://app.netlify.com/projects/bettervoting/deploys/6afa4547b36051c7518ed0a7
😎 Deploy Preview https://deploy-preview-1794--bettervoting.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build pay-at-finalize frontend (itemized cost, payment dialogs, return page)

1 participant