Skip to content

Fixed: gracefully handle unknown sources#59

Merged
damianlegawiec merged 1 commit intomainfrom
fix/graceful-custom-source
Mar 13, 2026
Merged

Fixed: gracefully handle unknown sources#59
damianlegawiec merged 1 commit intomainfrom
fix/graceful-custom-source

Conversation

@damianlegawiec
Copy link
Member

@damianlegawiec damianlegawiec commented Mar 13, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced compatibility with additional Stripe payment method types, including Cash App and other emerging payment sources. Previously, unknown payment types would trigger critical errors during payment processing. The system now gracefully handles these previously unsupported scenarios by creating appropriate payment sources, significantly improving checkout reliability, reducing transaction failures, and enabling support for newer payment methods your customers use.

@coderabbitai
Copy link

coderabbitai bot commented Mar 13, 2026

Walkthrough

The Stripe source creation service now handles unknown payment method types by creating a generic Spree::PaymentSource instead of raising an error. Corresponding test cases verify this fallback behavior for unsupported payment methods like cashapp and unknown types.

Changes

Cohort / File(s) Summary
Fallback Payment Handling
app/services/spree_stripe/create_source.rb
Changed default case from raising error to creating generic Spree::PaymentSource for unknown payment method types.
Test Coverage
spec/services/spree_stripe/create_source_spec.rb
Added test contexts for cashapp and unknown payment source types, verifying fallback creation of generic Spree::PaymentSource objects.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 When Stripe brings mysteries unknown,
No error now shall we bemoan,
A generic source, graceful and kind,
Leaves no payment type behind! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and concisely describes the main change: converting error handling for unknown Stripe payment sources to graceful fallback creation using generic Spree::PaymentSource.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/graceful-custom-source
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Copy link

@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.

🧹 Nitpick comments (1)
spec/services/spree_stripe/create_source_spec.rb (1)

235-247: Tighten assertions to enforce truly generic fallback.

be_a(Spree::PaymentSource) also matches subclasses, so these examples won’t fail if a specialized source class is returned later. Use exact-class checks here.

Proposed spec tightening
-        expect(subject).to be_a(Spree::PaymentSource)
+        expect(subject).to be_an_instance_of(Spree::PaymentSource)
         expect(subject.gateway_payment_profile_id).to eq source_id
         expect(subject.payment_method).to eq gateway
@@
-        expect(subject).to be_a(Spree::PaymentSource)
+        expect(subject).to be_an_instance_of(Spree::PaymentSource)
         expect(subject.gateway_payment_profile_id).to eq source_id
         expect(subject.payment_method).to eq gateway
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@spec/services/spree_stripe/create_source_spec.rb` around lines 235 - 247, The
spec uses loose type matching with expect(subject).to be_a(Spree::PaymentSource)
which would also pass for subclasses; change these assertions to enforce an
exact class match (e.g. use be_instance_of or compare subject.class ==
Spree::PaymentSource) in the examples that test the generic fallback (the
examples in the 'if source is an unknown type' context and the earlier generic
case), keeping the other expectations (gateway_payment_profile_id and
payment_method) unchanged so the spec fails if a specialized source class is
returned.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@spec/services/spree_stripe/create_source_spec.rb`:
- Around line 235-247: The spec uses loose type matching with expect(subject).to
be_a(Spree::PaymentSource) which would also pass for subclasses; change these
assertions to enforce an exact class match (e.g. use be_instance_of or compare
subject.class == Spree::PaymentSource) in the examples that test the generic
fallback (the examples in the 'if source is an unknown type' context and the
earlier generic case), keeping the other expectations
(gateway_payment_profile_id and payment_method) unchanged so the spec fails if a
specialized source class is returned.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 197abf5c-0ff0-432e-8789-c4af68a0b1b7

📥 Commits

Reviewing files that changed from the base of the PR and between 6039c81 and 174619b.

📒 Files selected for processing (2)
  • app/services/spree_stripe/create_source.rb
  • spec/services/spree_stripe/create_source_spec.rb

@damianlegawiec damianlegawiec merged commit 71fdd71 into main Mar 13, 2026
4 checks passed
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