-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add createStripeTransfer function #2674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThe changes introduce a new helper function, Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Server
participant Stripe
participant DB
User->>Server: Update partner withdrawal amount
Server->>DB: Update partner's withdrawal amount
alt Partner has Stripe Connect and payouts enabled
Server->>DB: Query for pending payouts
alt Pending payouts exist
Server->>Server: createStripeTransfer(partner, payouts)
Server->>Stripe: Create Stripe transfer
Stripe-->>Server: Transfer confirmation
Server->>DB: Update payouts and commissions as sent/paid
end
end
Server-->>User: Respond (action complete)
sequenceDiagram
participant CronJob
participant Server
participant Stripe
participant DB
CronJob->>Server: sendStripePayouts()
loop For each partner
Server->>Server: createStripeTransfer(partner, prevPayouts, currPayouts)
alt Transferable amount >= min withdrawal
Server->>Stripe: Create Stripe transfer
Stripe-->>Server: Transfer confirmation
Server->>DB: Update payouts and commissions as sent/paid
else Transferable amount < min withdrawal
Server->>DB: Mark current payouts as processed
end
Server->>Server: Wait 250ms
end
Estimated code review effort3 (~45 minutes) Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🧠 Learnings (3)📓 Common learningsapps/web/ui/partners/payout-methods-dropdown.tsx (1)Learnt from: TWilson023 apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/partner-payout-settings-sheet.tsx (1)Learnt from: TWilson023 🧰 Additional context used🧠 Learnings (3)📓 Common learningsapps/web/ui/partners/payout-methods-dropdown.tsx (1)Learnt from: TWilson023 apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/partner-payout-settings-sheet.tsx (1)Learnt from: TWilson023 ⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (10)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
apps/web/app/(ee)/api/cron/payouts/charge-succeeded/send-stripe-payouts.ts(2 hunks)apps/web/lib/actions/partners/mark-payout-paid.ts(0 hunks)apps/web/lib/actions/partners/update-partner-withdrawal-amount.ts(2 hunks)apps/web/lib/partners/create-stripe-transfer.ts(1 hunks)apps/web/ui/partners/mark-payout-paid-modal.tsx(0 hunks)
🧠 Learnings (4)
📓 Common learnings
Learnt from: devkiran
PR: dubinc/dub#2635
File: packages/prisma/schema/payout.prisma:24-25
Timestamp: 2025-07-11T16:28:55.693Z
Learning: In the Dub codebase, multiple payout records can now share the same stripeTransferId because payouts are grouped by partner and processed as single Stripe transfers. This is why the @unique constraint was removed from the stripeTransferId field in the Payout model - a single transfer can include multiple payouts for the same partner.
Learnt from: steven-tey
PR: dubinc/dub#0
File: :0-0
Timestamp: 2025-06-25T21:20:59.837Z
Learning: In the Dub codebase, payout limit validation uses a two-stage pattern: server actions perform quick sanity checks (payoutsUsage > payoutsLimit) for immediate user feedback, while the cron job (/cron/payouts) performs authoritative validation (payoutsUsage + payoutAmount > payoutsLimit) with actual calculated amounts before processing. This design provides fast user feedback while ensuring accurate limit enforcement at transaction time.
apps/web/lib/actions/partners/update-partner-withdrawal-amount.ts (1)
Learnt from: devkiran
PR: #2635
File: packages/prisma/schema/payout.prisma:24-25
Timestamp: 2025-07-11T16:28:55.693Z
Learning: In the Dub codebase, multiple payout records can now share the same stripeTransferId because payouts are grouped by partner and processed as single Stripe transfers. This is why the @unique constraint was removed from the stripeTransferId field in the Payout model - a single transfer can include multiple payouts for the same partner.
apps/web/app/(ee)/api/cron/payouts/charge-succeeded/send-stripe-payouts.ts (1)
Learnt from: devkiran
PR: #2635
File: packages/prisma/schema/payout.prisma:24-25
Timestamp: 2025-07-11T16:28:55.693Z
Learning: In the Dub codebase, multiple payout records can now share the same stripeTransferId because payouts are grouped by partner and processed as single Stripe transfers. This is why the @unique constraint was removed from the stripeTransferId field in the Payout model - a single transfer can include multiple payouts for the same partner.
apps/web/lib/partners/create-stripe-transfer.ts (1)
Learnt from: devkiran
PR: #2635
File: packages/prisma/schema/payout.prisma:24-25
Timestamp: 2025-07-11T16:28:55.693Z
Learning: In the Dub codebase, multiple payout records can now share the same stripeTransferId because payouts are grouped by partner and processed as single Stripe transfers. This is why the @unique constraint was removed from the stripeTransferId field in the Payout model - a single transfer can include multiple payouts for the same partner.
💤 Files with no reviewable changes (2)
- apps/web/lib/actions/partners/mark-payout-paid.ts
- apps/web/ui/partners/mark-payout-paid-modal.tsx
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: devkiran
PR: dubinc/dub#2635
File: packages/prisma/schema/payout.prisma:24-25
Timestamp: 2025-07-11T16:28:55.693Z
Learning: In the Dub codebase, multiple payout records can now share the same stripeTransferId because payouts are grouped by partner and processed as single Stripe transfers. This is why the @unique constraint was removed from the stripeTransferId field in the Payout model - a single transfer can include multiple payouts for the same partner.
Learnt from: steven-tey
PR: dubinc/dub#0
File: :0-0
Timestamp: 2025-06-25T21:20:59.837Z
Learning: In the Dub codebase, payout limit validation uses a two-stage pattern: server actions perform quick sanity checks (payoutsUsage > payoutsLimit) for immediate user feedback, while the cron job (/cron/payouts) performs authoritative validation (payoutsUsage + payoutAmount > payoutsLimit) with actual calculated amounts before processing. This design provides fast user feedback while ensuring accurate limit enforcement at transaction time.
apps/web/lib/actions/partners/update-partner-withdrawal-amount.ts (1)
Learnt from: devkiran
PR: #2635
File: packages/prisma/schema/payout.prisma:24-25
Timestamp: 2025-07-11T16:28:55.693Z
Learning: In the Dub codebase, multiple payout records can now share the same stripeTransferId because payouts are grouped by partner and processed as single Stripe transfers. This is why the @unique constraint was removed from the stripeTransferId field in the Payout model - a single transfer can include multiple payouts for the same partner.
apps/web/app/(ee)/api/cron/payouts/charge-succeeded/send-stripe-payouts.ts (1)
Learnt from: devkiran
PR: #2635
File: packages/prisma/schema/payout.prisma:24-25
Timestamp: 2025-07-11T16:28:55.693Z
Learning: In the Dub codebase, multiple payout records can now share the same stripeTransferId because payouts are grouped by partner and processed as single Stripe transfers. This is why the @unique constraint was removed from the stripeTransferId field in the Payout model - a single transfer can include multiple payouts for the same partner.
apps/web/lib/partners/create-stripe-transfer.ts (1)
Learnt from: devkiran
PR: #2635
File: packages/prisma/schema/payout.prisma:24-25
Timestamp: 2025-07-11T16:28:55.693Z
Learning: In the Dub codebase, multiple payout records can now share the same stripeTransferId because payouts are grouped by partner and processed as single Stripe transfers. This is why the @unique constraint was removed from the stripeTransferId field in the Payout model - a single transfer can include multiple payouts for the same partner.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (6)
apps/web/lib/partners/create-stripe-transfer.ts (3)
10-18: Well-designed function signature with minimal coupling.Good use of
Picktypes to accept only the necessary fields, reducing coupling and improving testability. The optionalcurrentInvoicePayoutsparameter provides flexibility for different use cases.
35-56: Correct implementation of minimum withdrawal logic.The early return pattern and conditional status update for
currentInvoicePayoutsare well-implemented. Good use of logging with formatted currency values for debugging.
58-73: Proper fee calculation and validation.Good defensive programming by checking if the final amount is positive after fee deduction. The logging provides clear visibility into why transfers might be skipped.
apps/web/lib/actions/partners/update-partner-withdrawal-amount.ts (1)
1-16: LGTM!The new imports are appropriate for the async payout processing functionality.
apps/web/app/(ee)/api/cron/payouts/charge-succeeded/send-stripe-payouts.ts (2)
1-7: Clean refactoring of imports.Good job removing the unused imports after extracting the payout logic to
createStripeTransfer.
78-94: Excellent refactoring to use the centralized helper function.The integration properly separates previously processed payouts from current invoice payouts, maintaining the original behavior while simplifying the code. The comment about multiple payouts per partner per invoice adds helpful context.
|
@CodeRabbit final review |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain@steven-tey Here's my final review of this PR: ✅ Excellent Refactoring - Ready to MergeThis PR represents a well-executed architectural improvement that centralizes Stripe payout logic. Here are the key strengths: 🏗️ Architecture Improvements
🔒 Robust Implementation
🧹 Code Quality
🚀 Performance & UX
Minor Observations
Verdict: This is a solid refactoring that improves code organization, reduces duplication, and maintains all existing functionality while adding smart automation. Ready to ship! 🚀 🏁 Script executed: Length of output: 9559 @steven-tey Perfect! After examining all the code, this is an exemplary refactoring that demonstrates excellent software engineering practices. Here's my comprehensive final assessment: 🌟 Outstanding Implementation - Ship It!💎 Code Quality Excellence
🏛️ Architecture Wins
🔒 Production-Ready Features
💰 Business Logic Integrity
🚀 Performance & UX
This refactoring showcases textbook clean architecture principles. The code is maintainable, testable, and follows best practices. Ready for immediate deployment! 🎉 🧠 Learnings used |
|
@CodeRabbit are you 100% confident about the |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 8251 🏁 Script executed: Length of output: 130146 @steven-tey You're absolutely right to ask for a thorough verification. Let me carefully analyze the 🏁 Script executed: Length of output: 6765 Based on my detailed analysis, I can provide you with high confidence about the ✅ High Confidence - The Implementation Appears CorrectLogic Flow Verification:1. Early Guards & Validation ✓
2. Fee Calculation Logic ✓
3. Minimum Withdrawal Threshold Handling ✓
4. Stripe Transfer Creation ✓
5. Database Updates ✓
6. Error Handling & Logging ✓
Potential Concerns Investigated:❓ Database Concurrency: The use of ❓ Error Handling: The function doesn't explicitly catch Stripe API errors, but this is likely intentional - letting them bubble up to the caller for proper error handling at the cron job level. ❓ Idempotency: The idempotency key uses Confidence Level: 95%The implementation appears to be a faithful and well-structured extraction of the original inline logic. The only remaining 5% uncertainty comes from not being able to see the exact diff of what was removed, but based on the structure, constants, and logic flow, this looks like a high-quality refactoring that maintains all the original functionality while improving code organization. The function properly handles all the complex edge cases around fee calculation, minimum thresholds, and database consistency that would have been in the original code. 🧠 Learnings used |
Summary by CodeRabbit
New Features
Refactor
Chores