Skip to content

feat(checkout): smart Back button + Mock Pay on Netlify previews - #1508

Draft
teetangh wants to merge 1 commit into
devfrom
fix/checkout-ui-back-and-mock-pay
Draft

feat(checkout): smart Back button + Mock Pay on Netlify previews#1508
teetangh wants to merge 1 commit into
devfrom
fix/checkout-ui-back-and-mock-pay

Conversation

@teetangh

@teetangh teetangh commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Summary

UI + mock-payment gating changes to the checkout flow, targeting a Draft PR to dev.

1. Smart Back button

New shared CheckoutBackButton (app/checkout/components/CheckoutBackButton.tsx):

  • If window.history.length > 1router.back()
  • Else (fresh deep link / first-time sign-in + onboarding via router.replace) → router.replace(sourceHref) so a later Back never lands back on checkout.

Wired into the error state and the main sidebar of all four plan checkout pages (consultation, subscription, webinar, class) and above the card on the trial page. The onboarding edge self-heals: an onboarded user who lands back on /form/onboarding is bounced to /dashboard by requireNotOnboarded.

Source hrefs:

  • consultation → /explore/experts/{consultantProfile.id}
  • subscription → /explore/programs/plans/subscriptions/{planId}
  • webinar → /explore/programs/plans/webinars/{planId}
  • class → /explore/programs/plans/classes/{planId}
  • trial → /dashboard

2. Mock Pay on Netlify previews (never prod)

Single source of truth shouldEnableMockPayments() in lib/payments/operations/mock.ts, re-exported as isMockPayEnabled():

  • NODE_ENV === "development" (local)
  • CONTEXT ∈ {deploy-preview, branch-deploy} (server-side)
  • ENABLE_MOCK_PAYMENTS === "true" (ops escape hatch, unchanged)
  • NEXT_PUBLIC_MOCK_PAYMENTS_ENABLED === "true" (inlined client-side)

netlify.toml now exports the NEXT_PUBLIC flag under [context.deploy-preview.environment] and [context.branch-deploy.environment] — the client bundle cannot see Netlify's CONTEXT.

Money boundary note: the same gate powers createPaymentIntent's mock branch (lib/payments/index.ts). Without extending it, a preview would accept isMockPayment: true at the route and then fall through to a REAL gateway call. Keep both in lockstep.

3. Lifecycle doc

app/checkout/lifecycle.md: booking status→action matrix (AppointmentStatus + TrialSessionStatus) and a follow-up inventory (server-first data fetching; preview webhook simulation behind a future preview password/ACL).

Verification (local)

  • npx tsc --noEmit — clean
  • npx eslint on all touched files — clean (1 pre-existing react-hooks/exhaustive-deps warning in class page, untouched by this PR)
  • npx prettier on all touched code files — clean (.env.sample / netlify.toml are not prettier-parseable, same as before)
  • netlify.toml validated with a TOML parser

Not done here (per repo rules): no db:push / seeding against shared Supabase; full npm run test + npm run build run in CI.

Deliberately not changed

  • The 4 plan pages stay client components; no server actions on this money path; POST /api/checkout stays.
  • Success / failure pages unchanged.
  • Preview scope is Mock Pay only — webhook simulation ships separately after previews are password/ACL-protected.

- Add shared CheckoutBackButton: history-aware back with a sourceHref
  fallback (replace, so a later Back never lands back on checkout). Used
  on all four plan checkout pages (error state + sidebar) and the trial page.
- Extend shouldEnableMockPayments to cover deploy-preview/branch-deploy
  CONTEXT and NEXT_PUBLIC_MOCK_PAYMENTS_ENABLED; re-export as
  isMockPayEnabled for the checkout route + client buttons. netlify.toml
  exports the flag for previews so the client bundle can see it. Without
  this, a preview would accept isMockPayment at the route but fall through
  to a real gateway call.
- Add lifecycle.md: booking status->action matrix and follow-up inventory.
@teetangh teetangh added enhancement New feature or request booking Booking, scheduling, slots, reschedule, cancellation dashboard Dashboard IA, tabs, semantics, UX across all roles labels Sep 5, 2026
@netlify

netlify Bot commented Sep 5, 2026

Copy link
Copy Markdown

Deploy Preview for familiarise ready!

Name Link
🔨 Latest commit d7472f3
🔍 Latest deploy log https://app.netlify.com/projects/familiarise/deploys/6a9c10a7872fa3000802693b
😎 Deploy Preview https://deploy-preview-1508--familiarise.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 39 (🔴 down 14 from production)
Accessibility: 90 (no change from production)
Best Practices: 83 (no change from production)
SEO: 90 (🟢 up 8 from production)
PWA: -
View the detailed breakdown and full score reports

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

@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

sonarqubecloud Bot commented Sep 5, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
8.7% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

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

Labels

booking Booking, scheduling, slots, reschedule, cancellation dashboard Dashboard IA, tabs, semantics, UX across all roles enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant