Skip to content

payment test mode fixes#957

Merged
BilalG1 merged 8 commits intodevfrom
payment-test-mode-fixes
Oct 16, 2025
Merged

payment test mode fixes#957
BilalG1 merged 8 commits intodevfrom
payment-test-mode-fixes

Conversation

@BilalG1
Copy link
Contributor

@BilalG1 BilalG1 commented Oct 15, 2025

High-level PR Summary

This PR fixes payment test mode behavior by changing the default test mode setting to true and refactoring the test mode bypass UI. The bypass functionality is moved from a floating card in the purchase page into the checkout form itself, providing a cleaner and more integrated experience. Additionally, the database migration configuration is updated to increase the maxWait timeout to handle concurrent migration attempts more gracefully in high-contention scenarios like CI environments.

⏱️ Estimated Review Time: 5-15 minutes

💡 Review Order Suggestion
Order File Path
1 packages/stack-shared/src/config/schema.ts
2 apps/dashboard/src/app/(main)/purchase/[code]/page-client.tsx
3 apps/dashboard/src/components/payments/checkout.tsx
4 apps/backend/src/auto-migrations/index.tsx
⚠️ Inconsistent Changes Detected
File Path Warning
apps/backend/src/auto-migrations/index.tsx Database migration timeout configuration changes appear unrelated to payment test mode fixes, which is the stated purpose of this PR

Need help? Join our Discord

Analyze latest changes


Important

Sets payment test mode to default true, integrates test mode bypass into checkout form, and updates migration timeout.

  • Behavior:
    • Default testMode set to true in schema.ts.
    • Integrates test mode bypass into CheckoutForm in checkout.tsx.
    • Removes separate bypass panel from page-client.tsx.
  • Database:
    • Increases maxWait timeout in index.tsx to handle concurrent migration attempts.
  • Tests:
    • Updates tests in backend-helpers.ts and validate-code.test.ts to reflect test mode behavior.

This description was created by Ellipsis for 6313c0b. You can customize this summary. It will automatically update as commits are pushed.


Summary by CodeRabbit

  • New Features
    • Added a test-mode checkout path with a “Complete test purchase” action when test mode is active.
  • Refactor
    • Consolidated test-mode bypass into the checkout component and removed the separate bypass UI.
  • Bug Fixes
    • Improved reliability of database migrations by extending the transaction wait window, reducing timeout errors under load.
  • Chores
    • Payments now default to test mode enabled.
  • Tests
    • Updated tests and payload expectations to reflect test mode defaults and behavior.

@vercel
Copy link

vercel bot commented Oct 15, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
stack-backend Ready Ready Preview Comment Oct 16, 2025 2:07am
stack-dashboard Ready Ready Preview Comment Oct 16, 2025 2:07am
stack-demo Ready Ready Preview Comment Oct 16, 2025 2:07am
stack-docs Ready Ready Preview Comment Oct 16, 2025 2:07am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 15, 2025

Walkthrough

Updates Prisma transaction options to add maxWait, introduces a test-mode bypass path in CheckoutForm and wires it from the purchase page, changes payments.testMode default to true, and adjusts e2e tests/configs to reflect test mode behavior and payloads.

Changes

Cohort / File(s) Summary
Auto-migrations transaction options
apps/backend/src/auto-migrations/index.tsx
Adds Prisma $transaction option maxWait: 30,000 alongside existing timeout: 80,000. No exported API changes.
Dashboard payments UI
apps/dashboard/src/app/(main)/purchase/[code]/page-client.tsx, apps/dashboard/src/components/payments/checkout.tsx
Removes standalone test-mode bypass UI from the page; introduces optional prop onTestModeBypass in CheckoutForm. CheckoutForm renders a test-mode block with a “Complete test purchase” button when onTestModeBypass is provided; otherwise proceeds with normal PaymentElement flow.
Shared config defaults
packages/stack-shared/src/config/schema.ts
Sets organizationConfigDefaults.payments.testMode default from false to true.
E2E: backend helpers
apps/e2e/tests/backend/backend-helpers.ts
Explicitly sets payments.config.testMode: false in create-purchase-url test setup payload.
E2E: validate-code test
apps/e2e/tests/backend/endpoints/api/v1/payments/validate-code.test.ts
Updates expectation: test_mode value is now true in success payload.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant P as Purchase Page (page-client)
  participant CF as CheckoutForm
  participant S as Stripe/PaymentElement
  participant B as Bypass Handler

  U->>P: Open purchase page
  P->>CF: Render with props (may include onTestModeBypass)
  alt Test mode bypass provided
    CF->>U: Show test-mode notice + "Complete test purchase"
    U-->>CF: Click bypass
    CF->>B: onTestModeBypass()
    B-->>CF: Resolve
    CF-->>P: Completion callback/refresh
  else Normal checkout
    CF->>S: Mount PaymentElement
    U-->>CF: Submit payment
    CF->>S: confirmPayment(...)
    S-->>CF: Result (success/error)
    CF-->>P: Propagate result
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Payments test mode toggle #929 — Also modifies payments test-mode surfaces, including flags in validate-code and purchase flows, and related wiring.
  • Payments return url #923 — Touches the same CheckoutForm component, adding returnUrl handling; intersects with new onTestModeBypass prop.
  • fix dev failing tests #955 — Changes in the same auto-migrations file, affecting migration handling alongside this PR’s transaction timing.

Poem

A nibble of code, a hop through the flow,
Test mode by moonlight, green lights aglow.
Click—bypass complete! no carrots at stake,
While Prisma waits longer, no timeouts to make.
Configs flip softly, e2e bunnies cheer—
Another smooth checkout, springing this year. 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title "payment test mode fixes" directly addresses the primary focus of the PR—fixing and refactoring payment test mode behavior, including the default testMode change and the integration of test-mode bypass UI into the CheckoutForm. While the PR also includes a secondary change to database migration timeout configuration (maxWait increase in auto-migrations), this appears tangential to the main purpose, as noted in the PR description's own "Inconsistent Changes Detected" warning section. The title is specific and descriptive rather than vague, accurately capturing the central theme of the changeset.
Description Check ✅ Passed The PR description is comprehensive and well-organized, significantly exceeding the minimal template requirement (which only asks authors to acknowledge reading CONTRIBUTING.md guidelines). The description includes a clear high-level summary, estimated review time, a suggested review order with file prioritization, an explicit warning about inconsistent changes, and detailed bullet-point explanations of behavior, database, and test modifications. All major file changes are documented with clear context for reviewers.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch payment-test-mode-fixes

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7083de6 and 6313c0b.

📒 Files selected for processing (1)
  • apps/e2e/tests/backend/endpoints/api/v1/payments/validate-code.test.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.test.{ts,tsx,js}

📄 CodeRabbit inference engine (AGENTS.md)

In tests, prefer .toMatchInlineSnapshot where possible; refer to snapshot-serializer.ts for snapshot formatting and handling of non-deterministic values

Files:

  • apps/e2e/tests/backend/endpoints/api/v1/payments/validate-code.test.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Prefer ES6 Map over Record when representing key–value collections

Files:

  • apps/e2e/tests/backend/endpoints/api/v1/payments/validate-code.test.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: Vercel Agent Review
  • GitHub Check: build (22.x)
  • GitHub Check: docker
  • GitHub Check: check_prisma_migrations (22.x)
  • GitHub Check: all-good
  • GitHub Check: restart-dev-and-test
  • GitHub Check: build (22.x)
  • GitHub Check: lint_and_build (latest)
  • GitHub Check: docker
  • GitHub Check: setup-tests
  • GitHub Check: Security Check
🔇 Additional comments (1)
apps/e2e/tests/backend/endpoints/api/v1/payments/validate-code.test.ts (1)

330-330: LGTM! Snapshot correctly updated for new default.

The change from "test_mode": false to "test_mode": true correctly reflects the new global default (payments.testMode: true) introduced in this PR. The test doesn't explicitly configure testMode in its payments config (lines 250-262), so it inherits the new default.

This is consistent with:

  • Line 60 showing false (uses helper that explicitly sets testMode: false)
  • Line 239 showing true (test explicitly sets testMode: true on line 151)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Oct 15, 2025

Greptile encountered an error while reviewing this PR. Please reach out to support@greptile.com for assistance.

Copy link

@recurseml recurseml bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by RecurseML

🔍 Review performed on 0ac2b00..c69dc14

  Severity     Location     Issue     Delete  
High apps/dashboard/src/app/(main)/purchase/[code]/page-client.tsx:285 Undefined prop passed to component
High apps/dashboard/src/app/(main)/purchase/[code]/page-client.tsx:287 Undefined prop passed to component
High apps/dashboard/src/app/(main)/purchase/[code]/page-client.tsx:286 Payment form never renders
✅ Files analyzed, no issues (3)

apps/backend/src/auto-migrations/index.tsx
apps/dashboard/src/components/payments/checkout.tsx
packages/stack-shared/src/config/schema.ts

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0ac2b00 and a6828d9.

📒 Files selected for processing (4)
  • apps/backend/src/auto-migrations/index.tsx (1 hunks)
  • apps/dashboard/src/app/(main)/purchase/[code]/page-client.tsx (2 hunks)
  • apps/dashboard/src/components/payments/checkout.tsx (3 hunks)
  • packages/stack-shared/src/config/schema.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Prefer ES6 Map over Record when representing key–value collections

Files:

  • packages/stack-shared/src/config/schema.ts
  • apps/dashboard/src/components/payments/checkout.tsx
  • apps/backend/src/auto-migrations/index.tsx
  • apps/dashboard/src/app/(main)/purchase/[code]/page-client.tsx
{apps/dashboard,apps/dev-launchpad,packages/stack-ui,packages/react}/**/*.{tsx,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

For blocking alerts and errors in UI, do not use toast notifications; use alerts instead

Files:

  • apps/dashboard/src/components/payments/checkout.tsx
  • apps/dashboard/src/app/(main)/purchase/[code]/page-client.tsx
{apps/dashboard,apps/dev-launchpad,packages/stack-ui,packages/react}/**/*.{tsx,jsx,css}

📄 CodeRabbit inference engine (AGENTS.md)

Keep hover/click animations snappy; avoid pre-transition delays on hover and apply transitions after the action (e.g., fade-out on hover end)

Files:

  • apps/dashboard/src/components/payments/checkout.tsx
  • apps/dashboard/src/app/(main)/purchase/[code]/page-client.tsx
🧬 Code graph analysis (1)
apps/dashboard/src/components/payments/checkout.tsx (1)
packages/stack-ui/src/components/ui/typography.tsx (1)
  • Typography (46-46)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: docker
  • GitHub Check: all-good
  • GitHub Check: Vercel Agent Review
  • GitHub Check: check_prisma_migrations (22.x)
  • GitHub Check: lint_and_build (latest)
  • GitHub Check: build (22.x)
  • GitHub Check: build (22.x)
  • GitHub Check: docker
  • GitHub Check: restart-dev-and-test
  • GitHub Check: setup-tests
  • GitHub Check: Security Check
🔇 Additional comments (2)
packages/stack-shared/src/config/schema.ts (1)

539-539: Approve safer default for payments.testMode Defaulting to true prevents accidental real charges when unset; no code assumes false as default.

apps/backend/src/auto-migrations/index.tsx (1)

189-192: LGTM!

The addition of maxWait: 30_000 is a sensible operational improvement that increases resilience during connection pool contention, especially in CI environments where multiple workers may race to apply migrations. The comment clearly explains the rationale.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
apps/dashboard/src/app/(main)/purchase/[code]/page-client.tsx (1)

284-284: Add !selectedPriceId to the disabled condition.

The disabled prop should include !selectedPriceId to prevent checkout when no price is selected. Without this check, users could potentially trigger payment or test mode bypass without a price, causing backend errors.

Apply this diff:

-              disabled={quantityNumber < 1 || isTooLarge || data.already_bought_non_stackable === true}
+              disabled={quantityNumber < 1 || isTooLarge || data.already_bought_non_stackable === true || !selectedPriceId}
🧹 Nitpick comments (1)
apps/dashboard/src/app/(main)/purchase/[code]/page-client.tsx (1)

123-126: Add defensive null check for selectedPriceId.

Although selectedPriceId is initialized when data loads, adding a null check provides defense-in-depth and prevents potential issues if the product has no prices.

Apply this diff:

 const handleBypass = useCallback(async () => {
-  if (quantityNumber < 1 || isTooLarge) {
+  if (!selectedPriceId || quantityNumber < 1 || isTooLarge) {
     return;
   }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a6828d9 and 68908e0.

📒 Files selected for processing (1)
  • apps/dashboard/src/app/(main)/purchase/[code]/page-client.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
{apps/dashboard,apps/dev-launchpad,packages/stack-ui,packages/react}/**/*.{tsx,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

For blocking alerts and errors in UI, do not use toast notifications; use alerts instead

Files:

  • apps/dashboard/src/app/(main)/purchase/[code]/page-client.tsx
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Prefer ES6 Map over Record when representing key–value collections

Files:

  • apps/dashboard/src/app/(main)/purchase/[code]/page-client.tsx
{apps/dashboard,apps/dev-launchpad,packages/stack-ui,packages/react}/**/*.{tsx,jsx,css}

📄 CodeRabbit inference engine (AGENTS.md)

Keep hover/click animations snappy; avoid pre-transition delays on hover and apply transitions after the action (e.g., fade-out on hover end)

Files:

  • apps/dashboard/src/app/(main)/purchase/[code]/page-client.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: build (22.x)
  • GitHub Check: build (22.x)
  • GitHub Check: restart-dev-and-test
  • GitHub Check: lint_and_build (latest)
  • GitHub Check: docker
  • GitHub Check: all-good
  • GitHub Check: setup-tests
  • GitHub Check: Security Check
🔇 Additional comments (1)
apps/dashboard/src/app/(main)/purchase/[code]/page-client.tsx (1)

285-285: Conditional onTestModeBypass logic is correct.

The conditional data.test_mode ? handleBypass : undefined ensures that the test mode bypass is only available when test mode is enabled, addressing the critical issue raised in past review comments.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 68908e0 and 7083de6.

📒 Files selected for processing (3)
  • apps/e2e/tests/backend/backend-helpers.ts (1 hunks)
  • apps/e2e/tests/backend/endpoints/api/v1/payments/before-offer-to-product-rename/outdated--validate-code.test.ts (1 hunks)
  • apps/e2e/tests/backend/endpoints/api/v1/payments/validate-code.test.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.test.{ts,tsx,js}

📄 CodeRabbit inference engine (AGENTS.md)

In tests, prefer .toMatchInlineSnapshot where possible; refer to snapshot-serializer.ts for snapshot formatting and handling of non-deterministic values

Files:

  • apps/e2e/tests/backend/endpoints/api/v1/payments/before-offer-to-product-rename/outdated--validate-code.test.ts
  • apps/e2e/tests/backend/endpoints/api/v1/payments/validate-code.test.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Prefer ES6 Map over Record when representing key–value collections

Files:

  • apps/e2e/tests/backend/endpoints/api/v1/payments/before-offer-to-product-rename/outdated--validate-code.test.ts
  • apps/e2e/tests/backend/backend-helpers.ts
  • apps/e2e/tests/backend/endpoints/api/v1/payments/validate-code.test.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: all-good
  • GitHub Check: setup-tests
  • GitHub Check: Vercel Agent Review
  • GitHub Check: restart-dev-and-test
  • GitHub Check: build (22.x)
  • GitHub Check: build (22.x)
  • GitHub Check: check_prisma_migrations (22.x)
  • GitHub Check: docker
  • GitHub Check: docker
  • GitHub Check: lint_and_build (latest)
  • GitHub Check: Security Check
🔇 Additional comments (2)
apps/e2e/tests/backend/endpoints/api/v1/payments/before-offer-to-product-rename/outdated--validate-code.test.ts (1)

60-60: LGTM!

The test expectation correctly reflects the new default payments.testMode: true setting.

apps/e2e/tests/backend/endpoints/api/v1/payments/validate-code.test.ts (1)

60-60: LGTM!

Both test expectations correctly updated to reflect the new payments.testMode: true default.

Also applies to: 330-330

@zeropath-ai
Copy link

zeropath-ai bot commented Oct 15, 2025

Some new issue(s) might be present. Please use the following link(s) to view them:

https://zeropath.com/app/issues/f3606a04-82f4-4312-ba84-01a2dcdd5a85

Reply to this PR with @zeropath-ai followed by a description of what change you want and we'll auto-submit a change to this PR to implement it.

@BilalG1 BilalG1 merged commit 89554a3 into dev Oct 16, 2025
22 checks passed
@BilalG1 BilalG1 deleted the payment-test-mode-fixes branch October 16, 2025 02:14
N2D4 pushed a commit that referenced this pull request Oct 16, 2025
<!--

Make sure you've read the CONTRIBUTING.md guidelines:
https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md

-->

<!-- RECURSEML_SUMMARY:START -->
## High-level PR Summary
This PR fixes payment test mode behavior by changing the default test
mode setting to `true` and refactoring the test mode bypass UI. The
bypass functionality is moved from a floating card in the purchase page
into the checkout form itself, providing a cleaner and more integrated
experience. Additionally, the database migration configuration is
updated to increase the `maxWait` timeout to handle concurrent migration
attempts more gracefully in high-contention scenarios like CI
environments.

⏱️ Estimated Review Time: 5-15 minutes

<details>
<summary>💡 Review Order Suggestion</summary>

| Order | File Path |
|-------|-----------|
| 1 | `packages/stack-shared/src/config/schema.ts` |
| 2 | `apps/dashboard/src/app/(main)/purchase/[code]/page-client.tsx` |
| 3 | `apps/dashboard/src/components/payments/checkout.tsx` |
| 4 | `apps/backend/src/auto-migrations/index.tsx` |
</details>

<details>
<summary>⚠️ Inconsistent Changes Detected</summary>

| File Path | Warning |
|-----------|---------|
| `apps/backend/src/auto-migrations/index.tsx` | Database migration
timeout configuration changes appear unrelated to payment test mode
fixes, which is the stated purpose of this PR |
</details>

[![Need help? Join our
Discord](https://img.shields.io/badge/Need%20help%3F%20Join%20our%20Discord-5865F2?style=plastic&logo=discord&logoColor=white)](https://discord.gg/n3SsVDAW6U)


[![Analyze latest
changes](https://img.shields.io/badge/Analyze%20latest%20changes-238636?style=plastic)](https://squash-322339097191.europe-west3.run.app/interactive/564b2cf6ef5a9aad7d43da76d2f9e14e8521bc4d3e7d31e2eb13fcd8dce00e43/?repo_owner=stack-auth&repo_name=stack-auth&pr_number=957)
<!-- RECURSEML_SUMMARY:END -->
<!-- ELLIPSIS_HIDDEN -->


----

> [!IMPORTANT]
> Sets payment test mode to default true, integrates test mode bypass
into checkout form, and updates migration timeout.
> 
>   - **Behavior**:
>     - Default `testMode` set to `true` in `schema.ts`.
> - Integrates test mode bypass into `CheckoutForm` in `checkout.tsx`.
>     - Removes separate bypass panel from `page-client.tsx`.
>   - **Database**:
> - Increases `maxWait` timeout in `index.tsx` to handle concurrent
migration attempts.
>   - **Tests**:
> - Updates tests in `backend-helpers.ts` and `validate-code.test.ts` to
reflect test mode behavior.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=stack-auth%2Fstack-auth&utm_source=github&utm_medium=referral)<sup>
for 6313c0b. You can
[customize](https://app.ellipsis.dev/stack-auth/settings/summaries) this
summary. It will automatically update as commits are pushed.</sup>

----


<!-- ELLIPSIS_HIDDEN -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added a test-mode checkout path with a “Complete test purchase” action
when test mode is active.
* **Refactor**
* Consolidated test-mode bypass into the checkout component and removed
the separate bypass UI.
* **Bug Fixes**
* Improved reliability of database migrations by extending the
transaction wait window, reducing timeout errors under load.
* **Chores**
  * Payments now default to test mode enabled.
* **Tests**
* Updated tests and payload expectations to reflect test mode defaults
and behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@coderabbitai coderabbitai bot mentioned this pull request Oct 28, 2025
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.

1 participant