-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Payout failed email reminder + charge the failure fee #2488
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 ↗︎
|
WalkthroughA new email notification system for failed partner payouts was implemented. Constants for payout thresholds and failure fees were updated and clarified. When a payout fails, the system logs the event, resets payout status, charges a failure fee to the workspace's card if applicable, and sends non-blocking notification emails to all workspace users with relevant details using a new email template. Changes
Sequence Diagram(s)sequenceDiagram
participant Stripe
participant WebhookHandler
participant DB
participant StripeAPI
participant EmailService
Stripe->>WebhookHandler: charge.failed event
WebhookHandler->>DB: Mark invoice as failed, reset payouts
WebhookHandler->>DB: Fetch workspace, users, programs
alt No Stripe customer ID or payment method
WebhookHandler-->>Stripe: Exit early
else Valid payment method
WebhookHandler->>StripeAPI: Charge failure fee (if ACH)
WebhookHandler->>EmailService: Send notification emails (async)
end
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used🧬 Code Graph Analysis (1)apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts (3)
⏰ Context from checks skipped due to timeout of 90000ms (1)
🔇 Additional comments (6)
✨ Finishing Touches
🪧 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
🧹 Nitpick comments (3)
apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts (1)
53-73: Potential performance issue with workspace query.The query fetches all users and programs for the workspace, which could be inefficient for workspaces with many users/programs. Consider if you need all users or if there's a more targeted approach.
const workspace = await prisma.project.findUniqueOrThrow({ where: { id: invoice.workspaceId, }, include: { users: { + take: 50, // Limit to avoid excessive data select: { user: { select: { email: true, }, }, }, }, programs: { + take: 1, // Only need the first program for email template select: { name: true, }, }, }, });packages/email/src/templates/partner-payout-failed.tsx (2)
93-93: Consider making the URL configurable.The hardcoded URL
https://app.dub.coshould ideally be configurable to support different environments (staging, development).Consider extracting the base URL to an environment variable or configuration constant:
- href={`https://app.dub.co/${workspace.slug}/settings/billing`} + href={`${process.env.NEXT_PUBLIC_APP_URL || 'https://app.dub.co'}/${workspace.slug}/settings/billing`}
95-95: Consider improving link text for clarity.The link text "Update direct debit details" might be confusing since the context mentions a card payment. Consider using more generic text.
- Update direct debit details + Update payment method
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts(2 hunks)apps/web/lib/partners/constants.ts(1 hunks)packages/email/src/templates/partner-payout-failed.tsx(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts (3)
apps/web/lib/partners/constants.ts (1)
PAYOUT_FAILURE_FEE_CENTS(22-22)packages/email/src/index.ts (1)
sendEmail(6-29)packages/email/src/templates/partner-payout-failed.tsx (1)
PartnerPayoutFailed(17-109)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build
🔇 Additional comments (6)
apps/web/lib/partners/constants.ts (1)
20-22: LGTM - Clear constant definitions with helpful comments.The clarifying comment for the minimum payout amount and the new failure fee constant are well-documented and follow consistent naming conventions.
apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts (3)
1-7: LGTM - Well-organized imports.The imports are cleanly organized and all necessary for the enhanced functionality.
13-17: LGTM - Clear destructuring with descriptive variable names.The destructuring properly extracts the needed properties with clear, descriptive names.
19-23: LGTM - Appropriate error logging.The logging includes essential information (invoice ID) and correctly uses the "errors" type with mention flag for alerts.
packages/email/src/templates/partner-payout-failed.tsx (2)
17-43: LGTM - Well-structured component with proper TypeScript types.The component has clear prop definitions, helpful default values for development, and proper TypeScript typing with inline comments for clarity.
44-47: LGTM - Proper currency formatting.The currency formatting correctly converts from cents to dollars and ensures consistent decimal place formatting.
|
@CodeRabbit final review |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain@steven-tey, I've conducted a comprehensive final review of this PR. Here are my findings: ✅ Strengths & Well-Implemented Features
🔍 Key Implementation Details
|
Summary by CodeRabbit
New Features
Improvements