fix(stripe): use setup mode for trials - #1679
Conversation
📝 WalkthroughWalkthroughThe 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. ChangesStripe intent selection
Estimated code review effort: 2 (Simple) | ~5 minutes Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
🔨 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! Login credentials: |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
assets/js/gateways/stripe.js (1)
232-235: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd 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
📒 Files selected for processing (1)
assets/js/gateways/stripe.js
| // 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; |
There was a problem hiding this comment.
🩺 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.
| // 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.
|
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 |
|
REVIEW_FOLLOWUP_CREATED source_pr=1679 issue=1681 fingerprint=source-pr-1679 runner=superdav42 ts=2026-07-29T15:45:25Z |
Summary
Verification
npx eslint assets/js/gateways/stripe.jsgit diff --checksetupmode.Test limitation
vendor/bin/phpunitis 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