Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@devkiran
Copy link
Collaborator

@devkiran devkiran commented Jun 24, 2025

Summary by CodeRabbit

  • New Features
    • Introduced a configurable payout fee for direct debit payments, now visible in billing and payout interfaces.
  • Bug Fixes
    • Improved accuracy of payout fee calculations based on the workspace’s specific payout fee setting.
  • Chores
    • Updated the database and workspace schema to support the new payout fee property.
    • Removed legacy payout fee constants and updated related calculations to use the new payout fee value.

- 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.
@vercel
Copy link
Contributor

vercel bot commented Jun 24, 2025

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Updated (UTC)
dub βœ… Ready (Inspect) Visit Preview Jun 24, 2025 9:30pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 24, 2025

Walkthrough

The changes introduce a new payoutFee property to the workspace model and schema, update fee calculation logic to use this explicit value, and refactor related components and backend logic to use a new calculatePayoutFeeForMethod function. The payout fee is now directly stored and referenced, rather than derived from plan types.

Changes

File(s) Change Summary
.../api/cron/payouts/confirm/confirm-payouts.ts Refactored payout fee calculation to use calculatePayoutFeeForMethod and updated workspace type for payoutFee.
.../(dashboard)/[slug]/(ee)/settings/billing/plan-usage.tsx Removed reference to plan-based payout fees; now uses payoutFee from workspace context.
.../lib/payment-methods.ts Renamed and refactored fee calculation: calculatePayoutFee β†’ calculatePayoutFeeForMethod, changed signature and logic.
.../lib/zod/schemas/workspaces.ts Added payoutFee numeric field to WorkspaceSchema.
.../ui/partners/payout-invoice-sheet.tsx Updated to use calculatePayoutFeeForMethod and extract payoutFee from workspace.
packages/prisma/schema/workspace.prisma Added payoutFee Float @default(0.05) to the Project model.
.../lib/partners/constants.ts Removed the PAYOUT_FEES constant object.
packages/embeds/core/package.json Version bump from 0.0.14 to 0.0.15.
packages/embeds/react/package.json Version bump from 0.0.14 to 0.0.15.

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
Loading

Possibly related PRs

  • dubinc/dub#2433: Refactored payout fee calculation, introduced dynamic payout fee logic, and expanded supported payment methods in the same area of code.

Poem

In the garden of code where payouts grow,
A fee now blooms, precise and slow.
No more guessing by plan or chance,
The payoutFee leads the invoice dance.
Rabbits rejoice, the logic is neat,
With every payout, the cycle’s complete! πŸ‡πŸ’Έ


πŸ“œ Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 1b7c35c and 0ed681c.

πŸ“’ Files selected for processing (1)
  • apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
✨ Finishing Touches
  • πŸ“ Generate Docstrings

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.

❀️ Share
πŸͺ§ Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 plan but the memoized computation now uses payoutFee. 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

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between d922bea and 721194d.

πŸ“’ 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 payoutFee field 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 payoutFee from 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 payoutFee might 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 payoutFee to 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 payoutFee value instead of the plan, 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 payoutFee field 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.

@devkiran
Copy link
Collaborator Author

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 24, 2025

βœ… Actions performed

Full review triggered.

@steven-tey
Copy link
Collaborator

@CodeRabbit final review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 24, 2025

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 Merge

The 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 Strengths

1. Clean Architecture

  • Proper separation of concerns with database schema, backend logic, and frontend updates
  • Cohesive refactoring from calculatePayoutFee to calculatePayoutFeeForMethod
  • Elimination of unused PAYOUT_FEES constant reduces technical debt

2. Backward Compatibility

  • Default value of 0.05 (5%) ensures existing workspaces continue functioning
  • Gradual migration approach without breaking existing functionality

3. Comprehensive Implementation

  • Database schema updated with proper field type and default
  • Backend payout confirmation logic correctly uses workspace-specific fee
  • Frontend components (billing page, payout invoice sheet) display accurate fees
  • Proper error handling for invalid payout fee values

πŸ“‹ Implementation Review

Database Changes βœ…

payoutFee Float @default(0.05)
  • Appropriate field type and sensible default value

API Logic βœ…

  • Workspace type properly extended to include payoutFee property
  • Error handling for null/undefined payout fees
  • Logging added for debugging purposes

Frontend Updates βœ…

  • UI components correctly extract and display workspace payoutFee
  • Percentage formatting updated to show exact values without rounding
  • Proper integration with useWorkspace hook

Function Refactoring βœ…

  • Clear parameter signature: (paymentMethod, payoutFee) vs previous (paymentMethod, plan)
  • Improved error handling for unsupported payment methods
  • Cleaner logic flow

🎯 Meets PR Objectives

The implementation successfully enables:

  • βœ… Dynamic payout fee configuration at workspace level
  • βœ… Removal of plan-based fee constraints
  • βœ… Flexible fee management for different workspaces
  • βœ… Maintained compatibility with existing systems

πŸš€ Ready to Ship

The 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 πŸŽ‰

@steven-tey
Copy link
Collaborator

@CodeRabbit final review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 24, 2025

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 Confirmation

The dynamic payout fee implementation continues to meet all requirements:

βœ… Core Functionality: Workspace-level payout fee configuration working correctly
βœ… Data Integrity: Proper database schema with sensible defaults (5%)
βœ… Backward Compatibility: Existing workspaces unaffected
βœ… Code Quality: Clean refactoring and error handling
βœ… Frontend Integration: UI components displaying accurate fees

πŸš€ Status: Ready to Ship

The 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?

@steven-tey steven-tey merged commit 020b9d8 into main Jun 24, 2025
7 of 8 checks passed
@steven-tey steven-tey deleted the dynamic-payout-fee branch June 24, 2025 21:40
@steven-tey steven-tey restored the dynamic-payout-fee branch June 24, 2025 21:40
@steven-tey steven-tey deleted the dynamic-payout-fee branch June 24, 2025 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants