Skip to content

Guard payment view if no payment intent returned#56

Closed
carl-lee-lu wants to merge 1 commit intospree:mainfrom
carl-lee-lu:fix/guard-loading-payment-on-zero-order
Closed

Guard payment view if no payment intent returned#56
carl-lee-lu wants to merge 1 commit intospree:mainfrom
carl-lee-lu:fix/guard-loading-payment-on-zero-order

Conversation

@carl-lee-lu
Copy link

@carl-lee-lu carl-lee-lu commented Feb 24, 2026

When applying coupon codes that give a full discount, this stops a payment intent from being created which in turn breaks the route helper as it expects an ID.

Fix

Simply guard against not having a payment intent

Steps to reproduce

  1. Create a promotion coupon code to give a 100% discount
  2. Ensure you have stripe enabled as a payment provider
  3. On the checkout, apply coupon code
  4. The turbo stream throws back a 500
  5. The issue is that it tries to create a payment intent but the amount is zero now due to the coupon, but it still tries to create the payment intent route and fails on constraints of no id.

Note

Low Risk
Small view-only guard that avoids nil route generation; behavior change is limited to hiding Stripe UI when a payment intent is unavailable.

Overview
Prevents checkout crashes when Stripe is enabled but no PaymentIntent is created (e.g., 100% discount orders) by guarding the Stripe payment partial behind current_stripe_gateway.present? && current_stripe_payment_intent.present?.

This avoids generating Stripe route helpers that require a payment_intent.id when the intent is nil, eliminating the 500 during the payment step.

Written by Cursor Bugbot for commit 978a39f. This will update automatically on new commits. Configure here.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced the checkout flow to ensure the Stripe payment option displays only when the necessary configuration is available, preventing display issues during payment selection.

@coderabbitai
Copy link

coderabbitai bot commented Feb 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fbd483e and 978a39f.

📒 Files selected for processing (1)
  • app/views/spree/checkout/payment/_spree_stripe.html.erb

Walkthrough

A conditional guard is added to the Stripe payment checkout template, ensuring the checkout block renders only when both the Stripe gateway and payment intent objects are present.

Changes

Cohort / File(s) Summary
Stripe Payment View Guard
app/views/spree/checkout/payment/_spree_stripe.html.erb
Wrapped entire checkout block in conditional that checks for presence of current_stripe_gateway and current_stripe_payment_intent before rendering.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A guard clause stands at the door so neat,
Checking if Stripe and intent both greet,
No render 'til both have arrived,
Safe and protected, the checkout thrives! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding a guard condition to prevent rendering the payment view when no payment intent exists, which directly addresses the core issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

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