Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughPayout balance cron route now scopes updates to a specific partner (partner.id added) and broadens the payout update filter to an OR of: (status "sent" && stripePayoutId null && stripeTransferId in transfers) OR (status "failed" && stripePayoutId not null). Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick 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. Comment |
|
@coderabbitai full review, any breaking changes? |
🧩 Analysis chain🏁 Script executed: Length of output: 7521 🏁 Script executed: Length of output: 27 🏁 Script executed: Length of output: 1772 🏁 Script executed: Length of output: 6335 🏁 Script executed: Length of output: 2672 🏁 Script executed: Length of output: 2656 🏁 Script executed: Length of output: 4005 🏁 Script executed: Length of output: 2631
🎯 SummaryThis PR fixes a critical bug and adds automatic retry logic for failed Stripe payouts. No breaking changes detected. 📋 Changes OverviewFile:
|
| Category | Impact | Reasoning |
|---|---|---|
| Database Schema | None | No schema modifications |
| Public API | None | Internal cron endpoint only |
| Query Behavior | Safer | More restrictive (partnerId filter) |
| Failed Payouts | Enhanced | Automatic retry now enabled |
| Data Migration | Not needed | Handles existing data correctly |
🐛 Bug Fixed
Missing partnerId filter: According to Stripe documentation, when a payout fails, Stripe reattempts the payout at the next scheduled payout interval. The previous code could theoretically match payouts from different partners if transfer IDs coincidentally overlapped (extremely unlikely but possible in edge cases).
✨ Feature Added
Automatic failed payout retry: The new OR condition allows payouts with status "failed" and existing stripePayoutId to be automatically retried when new balance becomes available. This aligns with the pattern where failed payouts get a new stripePayoutId for the retry attempt.
Behavior:
- When
balance.availablewebhook fires → creates new Stripe payout - Updates both:
- Payouts with status "sent" that haven't been withdrawn yet
- Payouts with status "failed" that failed previously ← NEW
- All matching payouts get the new
stripePayoutId
⚠️ Considerations
-
Multiple failed payouts: If a partner has multiple failed payouts, they all get updated with the same new
stripePayoutId. This appears intentional - one withdrawal attempt covers all pending/failed payouts. -
Transfer limit: The code fetches up to 100 transfers (
limit: 100). If there are more, some "sent" payouts won't be matched. This is a pre-existing limitation, not introduced by this PR. -
Race conditions: Multiple simultaneous webhooks for the same partner could theoretically conflict, but Prisma's
updateManyshould handle this atomically.
✅ Recommendation
Approve and merge. This is a well-implemented bug fix with an important enhancement for handling failed payouts. The changes are:
- Backwards compatible
- More restrictive (safer)
- Additive (enables retry functionality)
- Properly scoped to prevent cross-partner issues
✅ Actions performed
Full review triggered.
Summary by CodeRabbit