-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add source_transaction to stripe.transfers.create
#2888
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.
|
WalkthroughThreads Stripe chargeId through the payouts flow. The API route parses chargeId from invoice.stripeChargeMetadata and passes it to sendStripePayouts. sendStripePayouts updates its signature to accept chargeId and forwards it to createStripeTransfer, which conditionally sets source_transaction when no prior payouts exist. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant CR as Charge-Succeeded Route
participant DB as DB (Invoice)
participant SP as sendStripePayouts
participant PT as createStripeTransfer
participant ST as Stripe Transfers API
CR->>DB: Fetch invoice by invoiceId
DB-->>CR: Invoice with stripeChargeMetadata
Note over CR: Parse chargeId via stripeChargeMetadataSchema
CR->>SP: sendStripePayouts({ invoiceId, chargeId })
loop For each partner
SP->>PT: createStripeTransfer({ ..., chargeId })
alt No prior payouts
PT->>ST: Create Transfer { source_transaction: chargeId }
else Prior payouts exist
PT->>ST: Create Transfer { no source_transaction }
end
ST-->>PT: Transfer result
PT-->>SP: Transfer outcome
end
SP-->>CR: Payouts processed
Note over CR,SP: Existing error handling unchanged
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
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: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/web/app/(ee)/api/cron/payouts/charge-succeeded/send-stripe-payouts.ts (1)
7-95: Propagate optional chargeId through the payout flowOnce we allow the route to continue without a charge id, this signature needs to match. Treating
chargeIdas required will keep TypeScript satisfied yet still handundefinedtocreateStripeTransfer, producing an invalidsource_transaction. Please make the parameter optional and only forward it when present.-export async function sendStripePayouts({ - invoiceId, - chargeId, -}: { - invoiceId: string; - chargeId: string; -}) { +export async function sendStripePayouts({ + invoiceId, + chargeId, +}: { + invoiceId: string; + chargeId?: string; +}) { ... - chargeId, + chargeId,
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
apps/web/app/(ee)/api/cron/payouts/charge-succeeded/route.ts(2 hunks)apps/web/app/(ee)/api/cron/payouts/charge-succeeded/send-stripe-payouts.ts(2 hunks)apps/web/lib/partners/create-stripe-transfer.ts(2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 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.
📚 Learning: 2025-07-11T16:28:55.693Z
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.
Applied to files:
apps/web/app/(ee)/api/cron/payouts/charge-succeeded/send-stripe-payouts.tsapps/web/lib/partners/create-stripe-transfer.ts
🧬 Code graph analysis (1)
apps/web/app/(ee)/api/cron/payouts/charge-succeeded/route.ts (1)
apps/web/app/(ee)/api/cron/payouts/charge-succeeded/send-stripe-payouts.ts (1)
sendStripePayouts(7-118)
⏰ 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
Summary by CodeRabbit