-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix withdrawal cron again #3016
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 GitHub.
|
WalkthroughThe withdrawal cron handler now uses Changes
Sequence Diagram(s)sequenceDiagram
participant Cron as Cron Trigger
participant DB as Database (Prisma)
participant Stripe as Stripe API
participant Log as Logger
Cron->>DB: Query currentAvailableBalance\nand groupBy payouts by status
DB-->>Cron: Return balance, processingPayouts, processedPayouts
Note over Cron: Compute balanceToWithdraw = currentAvailableBalance - processedPayouts
Note over Cron: reservedBalance = 50000
alt balanceToWithdraw <= reservedBalance
Cron->>Log: Log skip with formatted currency and totals
Cron-->>Cron: Return early
else balanceToWithdraw > reservedBalance
Cron->>Stripe: Create payout for balanceToWithdraw
Stripe-->>Cron: Return payout confirmation
Cron->>DB: Create payout record (store Stripe payout)
DB-->>Cron: Confirm stored
Cron->>Log: Log created payout details and totals
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)apps/web/app/(ee)/api/cron/trigger-withdrawal/route.ts (1)
⏰ 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 (5)
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 |
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: 1
🧹 Nitpick comments (1)
apps/web/app/(ee)/api/cron/trigger-withdrawal/route.ts (1)
53-58: Consider making the reserved balance configurable.The reserved balance is currently hardcoded to $500. While this may be appropriate for the current scale, consider making this value configurable via an environment variable or database setting to allow easier adjustments without code changes as transaction volumes grow.
Example:
const reservedBalance = Number(process.env.STRIPE_RESERVED_BALANCE) || 50000; // keep at least $500 in the account
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/web/app/(ee)/api/cron/trigger-withdrawal/route.ts(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/web/app/(ee)/api/cron/trigger-withdrawal/route.ts (1)
packages/prisma/index.ts (1)
prisma(3-9)
⏰ 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 (2)
apps/web/app/(ee)/api/cron/trigger-withdrawal/route.ts (2)
18-32: LGTM: groupBy query is well-structured.The query correctly groups payouts by status and filters for those that haven't been transferred to Stripe yet (stripeTransferId: null), representing money owed to partners.
60-63: Verify hardcoded USD currency assumption.The currency is hardcoded to "usd" for the payout creation. Ensure this aligns with your business requirements and that all Stripe accounts being used are USD-based. If you plan to support multiple currencies in the future, this will need to be refactored.
Summary by CodeRabbit