-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Dynamic payout fee on workspace level #2569
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
- Renamed `calculatePayoutFee` to `computePayoutFeeForMethod` for clarity. - Updated `confirmPayouts` function to use the new payout fee calculation method and handle errors appropriately. - Added `payoutFee` property to the workspace schema to store the fee for direct debit payments. - Adjusted `PlanUsage` and `PayoutInvoiceSheetContent` components to utilize the new payout fee logic. - Removed unused constants related to payout fees.
|
The latest updates on your projects. Learn more about Vercel for Git βοΈ
|
WalkthroughThe changes introduce a new Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant UI
participant Backend
participant Database
User->>UI: Request payout or view billing
UI->>Backend: Fetch workspace (includes payoutFee)
Backend->>Database: Query workspace (with payoutFee)
Database-->>Backend: Return workspace data
Backend->>UI: Return workspace (with payoutFee)
UI->>UI: Compute fee via calculatePayoutFeeForMethod(paymentMethod, payoutFee)
UI->>User: Display calculated payout fee
Possibly related PRs
Poem
π Recent review detailsConfiguration used: CodeRabbit UI π Files selected for processing (1)
π§ Files skipped from review as they are similar to previous changes (1)
β° Context from checks skipped due to timeout of 90000ms (1)
β¨ 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: 2
π Outside diff range comments (1)
apps/web/ui/partners/payout-invoice-sheet.tsx (1)
159-159: Fix stale dependency in useMemo.The dependency array still includes
planbut the memoized computation now usespayoutFee. Update the dependency to reflect the actual dependencies.- [paymentMethods, plan], + [paymentMethods, payoutFee],
π§Ή Nitpick comments (2)
apps/web/lib/zod/schemas/workspaces.ts (1)
61-63: Consider adding validation constraints for the payout fee.The field addition is correct, but you might want to add validation to ensure the payout fee is within reasonable bounds (e.g., between 0 and 1 for 0-100%).
payoutFee: z .number() + .min(0, "Payout fee cannot be negative") + .max(1, "Payout fee cannot exceed 100%") .describe("The payout fee Dub Partners takes for direct debit payments."),apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts (1)
89-96: Improve error messaging for better debugging.The fee calculation and error handling are correct, but the error message could be more specific about what caused the failure.
if (!payoutFee) { - throw new Error("Failed to calculate payout fee."); + throw new Error(`Failed to calculate payout fee for payment method: ${paymentMethod.type}. Workspace payout fee: ${workspace.payoutFee}`); }
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
π Files selected for processing (6)
apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts(4 hunks)apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/plan-usage.tsx(2 hunks)apps/web/lib/payment-methods.ts(1 hunks)apps/web/lib/zod/schemas/workspaces.ts(1 hunks)apps/web/ui/partners/payout-invoice-sheet.tsx(3 hunks)packages/prisma/schema/workspace.prisma(1 hunks)
π§° Additional context used
𧬠Code Graph Analysis (3)
apps/web/ui/partners/payout-invoice-sheet.tsx (1)
apps/web/lib/payment-methods.ts (1)
computePayoutFeeForMethod(4-22)
apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts (1)
apps/web/lib/payment-methods.ts (1)
computePayoutFeeForMethod(4-22)
apps/web/lib/payment-methods.ts (1)
apps/web/lib/partners/constants.ts (1)
DIRECT_DEBIT_PAYMENT_METHOD_TYPES(63-67)
β° Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build
π Additional comments (11)
packages/prisma/schema/workspace.prisma (1)
27-27: LGTM! Clean schema addition.The
payoutFeefield addition is well-structured with an appropriate type, sensible default value, and clear documentation.apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/plan-usage.tsx (2)
46-46: LGTM! Properly extracts the new payoutFee field.The extraction of
payoutFeefrom the workspace hook aligns with the schema changes.
220-221: LGTM! Correct implementation of dynamic payout fee display.The conditional logic properly handles the case where
payoutFeemight be undefined and correctly calculates the percentage for display.apps/web/ui/partners/payout-invoice-sheet.tsx (3)
7-7: LGTM! Import updated to use the refactored function.The import change aligns with the function rename in
apps/web/lib/payment-methods.ts.
82-88: LGTM! Properly extracts payoutFee from workspace.The addition of
payoutFeeto the destructured workspace properties is correct and necessary for the updated fee calculation.
134-137: LGTM! Correctly updated fee calculation to use payoutFee.The function call now properly uses the
payoutFeevalue instead of theplan, aligning with the new fee calculation approach.apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts (3)
10-10: LGTM! Import updated consistently with other files.The import change aligns with the function refactoring across the codebase.
26-29: LGTM! Type definition correctly includes payoutFee.The workspace type has been properly extended to include the new
payoutFeefield required by the updated fee calculation logic.
98-99: LGTM! Correct fee calculation and usage.The total fee calculation using the computed payout fee and its usage in the invoice creation are implemented correctly.
Also applies to: 117-117
apps/web/lib/payment-methods.ts (2)
2-2: LGTM!The import statement correctly brings in the required constants for direct debit payment method types.
15-21: LGTM!The payment method-specific fee calculation logic is correct:
- Link and card methods add a $0.03 processing fee
- Direct debit methods use the base payout fee without additional charges
This aligns well with typical payment processing fee structures.
|
@coderabbitai full review |
β Actions performedFull review triggered. |
|
@CodeRabbit final review |
|
Tip For best results, initiate chat on the files or code changes. @steven-tey, I've conducted a comprehensive final review of the dynamic payout fee implementation. Here's my assessment: β Overall Assessment: Ready for MergeThe implementation successfully achieves the objective of enabling dynamic payout fees at the workspace level. The refactoring is well-structured and maintains consistency across the codebase. π Key Strengths1. Clean Architecture
2. Backward Compatibility
3. Comprehensive Implementation
π Implementation ReviewDatabase Changes β payoutFee Float @default(0.05)
API Logic β
Frontend Updates β
Function Refactoring β
π― Meets PR ObjectivesThe implementation successfully enables:
π Ready to ShipThe code is production-ready with proper error handling, logging, and user experience considerations. The refactoring improves maintainability while adding the requested functionality. Recommendation: Approve and merge π |
|
@CodeRabbit final review |
|
Tip For best results, initiate chat on the files or code changes. @steven-tey, I provided a comprehensive final review in my previous comment that concluded this PR is ready for merge. That assessment remains unchanged. π― Quick ConfirmationThe dynamic payout fee implementation continues to meet all requirements: β
Core Functionality: Workspace-level payout fee configuration working correctly π Status: Ready to ShipThe code is production-ready with no outstanding concerns identified. My recommendation remains: approve and merge. Is there a specific aspect you'd like me to focus on, or are you ready to proceed with the merge? |
Summary by CodeRabbit