Skip to content

Conversation

@hbjORbj
Copy link
Contributor

@hbjORbj hbjORbj commented Jan 26, 2026

What does this PR do?

Improves error handling in the Stripe collectCard method to provide more descriptive error messages instead of a generic "Payment method could not be collected" error.

The previous implementation threw a generic error that masked the actual cause of payment failures, making debugging difficult. This change:

  • Adds a new CollectCardFailure error code for better error categorization
  • Replaces the generic Error with ErrorWithCode for consistent error handling across the codebase
  • Adds error mappings for common Stripe errors (customer not found, invalid API key, rate limit, account deactivated)
  • Includes the actual Stripe error message when available for better debugging

This follows the same pattern already used in the chargeCard method in the same file.

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. N/A - no documentation changes needed.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

  1. Set up a Stripe integration with an event type that uses HOLD payment option
  2. Trigger various error scenarios:
    • Invalid Stripe credentials
    • Non-existent customer
    • Rate limiting (harder to reproduce)
  3. Verify that the error messages returned are more descriptive than the previous generic message

Checklist

  • My code follows the style guidelines of this project
  • I have checked if my changes generate no new warnings
  • My PR is small and focused

Human Review Checklist

  • Verify the error mappings cover the most common Stripe errors that occur in production
  • Check if the type casting for Stripe errors is safe
  • Consider if unit tests should be added for the error handling logic

Link to Devin run: https://app.devin.ai/sessions/8966676a87544b428d8db1ddcc935d2f
Requested by: @hbjORbj

- Add CollectCardFailure error code for better error categorization
- Replace generic error with ErrorWithCode for consistent error handling
- Add error mappings for common Stripe errors (customer not found, invalid API key, rate limit, etc.)
- Include Stripe error message when available for better debugging
- Follow the same pattern used in chargeCard method

Co-Authored-By: benny@cal.com <sldisek783@gmail.com>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants