Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
There was a problem hiding this comment.
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
2fdd67d to
a6f04e7
Compare
|
📝 Documentation updates detected! New suggestion: Add comprehensive refund handling documentation for PR #4728 |

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