Skip to content

fix(stripe): use setup mode for trials - #1679

Merged
superdav42 merged 1 commit into
mainfrom
feature/auto-20260728-173244
Jul 29, 2026
Merged

fix(stripe): use setup mode for trials#1679
superdav42 merged 1 commit into
mainfrom
feature/auto-20260728-173244

Conversation

@superdav42

@superdav42 superdav42 commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Use Stripe Payment Element setup mode when a checkout order has a trial.
  • Keep payment mode for real immediate charges, matching the server-side PaymentIntent versus SetupIntent selection.

Verification

  • npx eslint assets/js/gateways/stripe.js
  • git diff --check
  • Local browser checkout: a trial with a $15 renewal total initialized the Payment Element in setup mode.

Test limitation

  • vendor/bin/phpunit is unavailable in the local dependency installation.

aidevops.sh v3.32.192 plugin for OpenCode v1.18.5 with gpt-5.6-terra

Summary by CodeRabbit

  • Bug Fixes
    • Improved Stripe checkout handling for trial renewals.
    • Ensured payment details are collected using the appropriate flow when a renewal requires future billing.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The Stripe Payment Element now selects payment mode only for positive-total, non-trial orders. Trial orders use setup behavior consistently with server-side intent selection.

Changes

Stripe intent selection

Layer / File(s) Summary
Trial-aware payment mode selection
assets/js/gateways/stripe.js
hasImmediateCharge now requires a positive order total and excludes trial orders, with comments documenting trial renewal intent behavior.

Estimated code review effort: 2 (Simple) | ~5 minutes

Possibly related PRs

Suggested labels: status:in-review, origin:interactive, type:bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: Stripe now uses setup mode for trial orders.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/auto-20260728-173244

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.

@github-actions

Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
assets/js/gateways/stripe.js (1)

232-235: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add regression coverage for both Stripe modes.

Cover a positive-total trial (setup) and a positive-total non-trial order (payment), plus zero-total behavior. This protects the server/client intent-selection contract from future regressions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@assets/js/gateways/stripe.js` around lines 232 - 235, Add regression tests
around the Stripe intent-selection logic that verify positive-total trial orders
choose “setup,” positive-total non-trial orders choose “payment,” and zero-total
orders preserve the existing behavior. Anchor the coverage to the order-total
and trial checks in the client flow, and assert the resulting intent mode
matches the server-side contract.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@assets/js/gateways/stripe.js`:
- Around line 232-235: Update the hasImmediateCharge calculation alongside
orderTotal so form.order is validated before accessing has_trial. Treat a
missing order as having no immediate charge, while preserving the existing
positive-total and non-trial behavior when an order exists.

---

Nitpick comments:
In `@assets/js/gateways/stripe.js`:
- Around line 232-235: Add regression tests around the Stripe intent-selection
logic that verify positive-total trial orders choose “setup,” positive-total
non-trial orders choose “payment,” and zero-total orders preserve the existing
behavior. Anchor the coverage to the order-total and trial checks in the client
flow, and assert the resulting intent mode matches the server-side contract.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f228a247-936a-48fe-a493-3fe887d355f8

📥 Commits

Reviewing files that changed from the base of the PR and between 2febb44 and b86dcac.

📒 Files selected for processing (1)
  • assets/js/gateways/stripe.js

Comment on lines +232 to +235
// Match the server-side intent selection: trials collect a card for
// off-session renewal with a SetupIntent, even when their renewal total is positive.
const orderTotal = form.order ? form.order.totals.total : 0;
const hasImmediateCharge = orderTotal > 0;
const hasImmediateCharge = orderTotal > 0 && ! form.order.has_trial;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Guard form.order consistently before reading has_trial.

Line 234 handles a missing order, but Line 235 immediately dereferences form.order.has_trial. During an update without order data, this throws before the try/catch at Line 264 and can break checkout initialization.

Proposed fix
-		const orderTotal = form.order ? form.order.totals.total : 0;
-		const hasImmediateCharge = orderTotal > 0 && ! form.order.has_trial;
+		const order = form.order || {};
+		const orderTotal = order.totals ? order.totals.total : 0;
+		const hasImmediateCharge = orderTotal > 0 && ! order.has_trial;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Match the server-side intent selection: trials collect a card for
// off-session renewal with a SetupIntent, even when their renewal total is positive.
const orderTotal = form.order ? form.order.totals.total : 0;
const hasImmediateCharge = orderTotal > 0;
const hasImmediateCharge = orderTotal > 0 && ! form.order.has_trial;
// Match the server-side intent selection: trials collect a card for
// off-session renewal with a SetupIntent, even when their renewal total is positive.
const order = form.order || {};
const orderTotal = order.totals ? order.totals.total : 0;
const hasImmediateCharge = orderTotal > 0 && ! order.has_trial;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@assets/js/gateways/stripe.js` around lines 232 - 235, Update the
hasImmediateCharge calculation alongside orderTotal so form.order is validated
before accessing has_trial. Treat a missing order as having no immediate charge,
while preserving the existing positive-total and non-trial behavior when an
order exists.

@superdav42
superdav42 merged commit cde1920 into main Jul 29, 2026
11 checks passed
@superdav42 superdav42 added the review-feedback-scanned Merged PR already scanned for quality feedback label Jul 29, 2026
@superdav42

Copy link
Copy Markdown
Collaborator Author

DISPATCH_CLAIM nonce=2008bdb89f1db691e4b6ae642c40f504 runner=superdav42 ts=2026-07-29T15:45:03Z max_age_s=120 version=3.32.194 opencode_version=1.18.5 lease_token=2008bdb89f1db691e4b6ae642c40f504 device=device-1783824528-2609248-26808 session=issue-1679 phase=prelaunch expires_at=1785340024

@superdav42

Copy link
Copy Markdown
Collaborator Author

REVIEW_FOLLOWUP_CREATED source_pr=1679 issue=1681 fingerprint=source-pr-1679 runner=superdav42 ts=2026-07-29T15:45:25Z

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

Labels

review-feedback-scanned Merged PR already scanned for quality feedback

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant