-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Payout updates #2635
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
Merged
Merged
Payout updates #2635
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
e0fc230
move the invoice to advanced settings
devkiran 11ab726
add sent to PayoutStatus
devkiran 3b9b5d5
Update partner-payout-settings-modal.tsx
devkiran 6f475de
Update partner-payout-settings-modal.tsx
devkiran 0c88486
Update payout-methods-dropdown.tsx
devkiran bafafb1
Update payout-methods-dropdown.tsx
devkiran 776d1d0
update the new stats UI
devkiran 8c708d7
Enhance PayoutStats component with dynamic tooltips and update Payout…
devkiran 2a77654
Update payout-stats.tsx
devkiran 51ea5a6
Update payout-stats.tsx
devkiran cbe7b89
Update payout-stats.tsx
devkiran bf5320e
Update payout-stats.tsx
devkiran 9702afa
Update send-stripe-payouts.ts
devkiran 124daf5
Update use-partner-payouts.ts
devkiran 0c214a1
wip "payout.paid"
devkiran 7f6e6a3
Update payout-stats.tsx
devkiran 8befba2
update URLs
devkiran 38140ee
your funds are on their way to your bank"
devkiran 518a173
Update payout-stats.tsx
devkiran b4b2430
Update payout-stats.tsx
devkiran bde5b6b
Enhance Stripe webhook handling: update balanceAvailable to associate…
devkiran dc610b5
Merge branch 'main' into payout-updates
steven-tey 5fa8017
update emails
steven-tey 7e58a47
Merge branch 'main' into payout-updates
steven-tey 4a76a05
Refactor payout processing
devkiran 8c35d66
Refactor payout email notifications and update payout model schema
devkiran 3f2f18b
Enhance payout processing logic and update UI tooltips for clarity
devkiran 63e5038
Improve error logging in Stripe webhook handlers for better clarity a…
devkiran e0b9ae6
Update payout-stats.tsx
devkiran 6017666
adjust column
devkiran 3e597a4
Merge branch 'main' into payout-updates
devkiran 51c52fa
Update utils.ts
devkiran db2aa0a
Update send-paypal-payouts.ts
devkiran 158182b
Update payout-paid.ts
devkiran c49f3b9
Update send-stripe-payouts.ts
devkiran 96c7b51
Update payouts-item-succeeded.ts
devkiran 97b7d13
Update payout-stats.tsx
devkiran 6b03cf2
Update partner-payout-confirmed.tsx
devkiran 1dc4d14
updated payouts logic
steven-tey 433b894
update icon
steven-tey dc4fd46
Merge branch 'main' into payout-updates
steven-tey e111702
improve PartnerPayoutProcessed
steven-tey f2f4f10
Update payout-stats.tsx
steven-tey ca03b06
convert to sheet
steven-tey 5d4977e
improve mobile view
steven-tey 18aa725
finalize email templates
steven-tey 8dff05c
final changes
steven-tey f0b4beb
Update route.ts
steven-tey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 60 additions & 11 deletions
71
apps/web/app/(ee)/api/cron/payouts/charge-succeeded/send-paypal-payouts.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,71 @@ | ||
| import { createPayPalBatchPayout } from "@/lib/paypal/create-batch-payout"; | ||
| import { Payload, Payouts } from "./utils"; | ||
| import { resend } from "@dub/email/resend"; | ||
| import { VARIANT_TO_FROM_MAP } from "@dub/email/resend/constants"; | ||
| import PartnerPayoutProcessed from "@dub/email/templates/partner-payout-processed"; | ||
| import { prisma } from "@dub/prisma"; | ||
| import { Payload } from "./utils"; | ||
|
|
||
| export async function sendPaypalPayouts({ payload }: { payload: Payload }) { | ||
| const { invoiceId } = payload; | ||
|
|
||
| const payouts = await prisma.payout.findMany({ | ||
| where: { | ||
| invoiceId, | ||
| status: { | ||
| not: "completed", | ||
| }, | ||
| partner: { | ||
| payoutsEnabledAt: { | ||
| not: null, | ||
| }, | ||
| paypalEmail: { | ||
| not: null, | ||
| }, | ||
| }, | ||
| }, | ||
| include: { | ||
| partner: { | ||
| select: { | ||
| email: true, | ||
| paypalEmail: true, | ||
| }, | ||
| }, | ||
| program: { | ||
| select: { | ||
| name: true, | ||
| logo: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| export async function sendPaypalPayouts({ | ||
| payload, | ||
| payouts, | ||
| }: { | ||
| payload: Payload; | ||
| payouts: Payouts[]; | ||
| }) { | ||
| if (payouts.length === 0) { | ||
| console.log("No payouts for sending via PayPal, skipping..."); | ||
| return; | ||
| } | ||
|
|
||
| const { invoiceId } = payload; | ||
|
|
||
| await createPayPalBatchPayout({ | ||
| const batchPayout = await createPayPalBatchPayout({ | ||
| payouts, | ||
| invoiceId, | ||
| }); | ||
|
|
||
| console.log("PayPal batch payout created", batchPayout); | ||
|
|
||
| const batchEmails = await resend?.batch.send( | ||
| payouts | ||
| .filter((payout) => payout.partner.email) | ||
| .map((payout) => ({ | ||
| from: VARIANT_TO_FROM_MAP.notifications, | ||
| to: payout.partner.email!, | ||
| subject: "You've been paid!", | ||
| react: PartnerPayoutProcessed({ | ||
| email: payout.partner.email!, | ||
| program: payout.program, | ||
| payout, | ||
| variant: "paypal", | ||
| }), | ||
| })), | ||
| ); | ||
|
|
||
| console.log("Resend batch emails sent", batchEmails); | ||
| } |
170 changes: 134 additions & 36 deletions
170
apps/web/app/(ee)/api/cron/payouts/charge-succeeded/send-stripe-payouts.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🛠️ Refactor suggestion
Potential issue: Unsafe non-null assertion.
The non-null assertion
!assumes an invoice payout exists, but this could fail if the invoice contains no payouts.Add proper validation:
📝 Committable suggestion
🤖 Prompt for AI Agents