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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions apps/web/app/(ee)/api/cron/payouts/charge-succeeded/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import { handleAndReturnErrorResponse } from "@/lib/api/errors";
import { verifyQstashSignature } from "@/lib/cron/verify-qstash";
import { prisma } from "@dub/prisma";
import { log } from "@dub/utils";
import { z } from "zod";
import { sendPaypalPayouts } from "./send-paypal-payouts";
import { sendStripePayouts } from "./send-stripe-payouts";
import { payloadSchema } from "./utils";

export const dynamic = "force-dynamic";

const payloadSchema = z.object({
invoiceId: z.string(),
});

// POST /api/cron/payouts/charge-succeeded
// This route is used to process the charge-succeeded event from Stripe
// we're intentionally offloading this to a cron job to avoid blocking the main thread
Expand All @@ -17,8 +21,7 @@ export async function POST(req: Request) {
const rawBody = await req.text();
await verifyQstashSignature({ req, rawBody });

const body = payloadSchema.parse(JSON.parse(rawBody));
const { invoiceId } = body;
const { invoiceId } = payloadSchema.parse(JSON.parse(rawBody));

const invoice = await prisma.invoice.findUnique({
where: {
Expand Down Expand Up @@ -53,11 +56,11 @@ export async function POST(req: Request) {

await Promise.allSettled([
sendStripePayouts({
payload: body,
invoiceId,
}),

sendPaypalPayouts({
payload: body,
invoiceId,
}),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ 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;

export async function sendPaypalPayouts({ invoiceId }: { invoiceId: string }) {
const payouts = await prisma.payout.findMany({
where: {
invoiceId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ import PartnerPayoutProcessed from "@dub/email/templates/partner-payout-processe
import { prisma } from "@dub/prisma";
import { currencyFormatter, pluralize } from "@dub/utils";
import { Prisma } from "@prisma/client";
import { Payload } from "./utils";

export async function sendStripePayouts({ payload }: { payload: Payload }) {
const { invoiceId } = payload;

export async function sendStripePayouts({ invoiceId }: { invoiceId: string }) {
const commonInclude = Prisma.validator<Prisma.PayoutInclude>()({
partner: {
select: {
Expand Down
9 changes: 0 additions & 9 deletions apps/web/app/(ee)/api/cron/payouts/charge-succeeded/utils.ts

This file was deleted.

4 changes: 0 additions & 4 deletions apps/web/app/(ee)/api/stripe/webhook/charge-succeeded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ export async function chargeSucceeded(event: Stripe.Event) {
const qstashResponse = await qstash.publishJSON({
url: `${APP_DOMAIN_WITH_NGROK}/api/cron/payouts/charge-succeeded`,
body: {
chargeId,
invoiceId: invoice.id,
achCreditTransfer: Boolean(
charge.payment_method_details?.ach_credit_transfer,
),
},
});

Expand Down