Skip to content

feat: handle refunds for cloud credits#4728

Merged
tomharmon merged 1 commit intomainfrom
tom/eng-3059
Sep 12, 2025
Merged

feat: handle refunds for cloud credits#4728
tomharmon merged 1 commit intomainfrom
tom/eng-3059

Conversation

@tomharmon
Copy link
Contributor

@tomharmon tomharmon commented Sep 11, 2025

one thing to note, is that when we issue refunds via stripe's dashboard, we need to ensure that we refund less than what their current effective balance is.

ie, we need to check what they've spent before we refund their whole purchase.

refunding the entire amount, including credits already spent, introduces a lot more complexity we dont want to manage right now

@vercel
Copy link

vercel bot commented Sep 11, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
helicone Canceled Canceled Sep 11, 2025 7:30pm
helicone-bifrost Canceled Canceled Sep 11, 2025 7:30pm
helicone-eu Canceled Canceled Sep 11, 2025 7:30pm

@claude
Copy link
Contributor

claude bot commented Sep 11, 2025

Claude encountered an error —— View job


I'll analyze this and get back to you.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR implements comprehensive refund handling for cloud credits purchased through Stripe. The changes add a complete end-to-end refund system that tracks refund status, processes refund webhooks, and displays refund information to users.

The implementation introduces new data structures (PaymentIntentRecord and StripePaymentIntentsResponse) that extend the existing payment intent system with refund-specific fields including isRefunded, refundedAmount, and refundIds. These types are consistently defined across both public and private API schemas.

On the backend, the StripeManager is enhanced to fetch and process refund data for each payment intent, categorizing transactions as fully refunded, partially refunded, or normal. A new deductCredits method is added to the Wallet class that validates refund amounts against effective balance before processing them as negative credit purchases, preventing overdrafts.

Webhook handling is expanded with a new refund.created event handler in the worker's StripeManager that processes Stripe refunds by validating the refund details and deducting credits from the organization's wallet. Enhanced error handling returns specific 400 status codes when refund amounts exceed available balance.

The frontend credits page receives a complete UI overhaul to display refund information, including visual indicators for refunded amounts (strikethrough for fully refunded, red text for refund amounts), net amount calculations for partial refunds, and appropriate status labels. The useCredits hook is updated to transform the enriched payment intent data into the format needed by the UI.

This change integrates seamlessly with the existing credit system architecture while adding the financial controls necessary for proper refund accounting and user transparency.

Confidence score: 4/5

  • This PR requires careful review due to complex financial logic and webhook handling that could impact billing accuracy
  • Score reflects solid implementation with comprehensive error handling, though the financial complexity and webhook processing introduce some risk
  • Pay close attention to the Wallet.ts deductCredits method and webhook handler logic for potential edge cases

14 files reviewed, 7 comments

Edit Code Review Bot Settings | Greptile

@promptless
Copy link
Contributor

promptless bot commented Sep 11, 2025

📝 Documentation updates detected!

New suggestion: Add comprehensive refund handling documentation for PR #4728

@tomharmon
Copy link
Contributor Author

this is how its rendered btw!
Screenshot 2025-09-11 at 12 05 38 PM

@tomharmon tomharmon merged commit 95a4c68 into main Sep 12, 2025
9 of 10 checks passed
@tomharmon tomharmon deleted the tom/eng-3059 branch September 12, 2025 19:23
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.

2 participants