Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Refactor invoice completion

Kiran Kd1494f644060
diff --git a/apps/web/app/api/cron/payouts/charge-succeeded/route.ts b/apps/web/app/api/cron/payouts/charge-succeeded/route.ts
index 8f36d44bb3..52a47e679f 100644
--- a/apps/web/app/api/cron/payouts/charge-succeeded/route.ts
+++ b/apps/web/app/api/cron/payouts/charge-succeeded/route.ts
@@ -15,7 +15,7 @@ export async function POST(req: Request) {
await verifyQstashSignature({ req, rawBody });
const body = payloadSchema.parse(JSON.parse(rawBody));
- const { invoiceId, receiptUrl } = body;
+ const { invoiceId } = body;
const invoice = await prisma.invoice.findUnique({
where: {
@@ -84,17 +84,6 @@ export async function POST(req: Request) {
sendPaypalPayouts({ ...body, payouts: paypalPayouts }),
]);
- await prisma.invoice.update({
- where: {
- id: invoiceId,
- },
- data: {
- receiptUrl,
- status: "completed",
- paidAt: new Date(),
- },
- });
-
return new Response(`Invoice ${invoiceId} processed.`);
} catch (error) {
return handleAndReturnErrorResponse(error);
diff --git a/apps/web/app/api/stripe/webhook/charge-succeeded.ts b/apps/web/app/api/stripe/webhook/charge-succeeded.ts
index d8548c70fc..e8cd3089f4 100644
--- a/apps/web/app/api/stripe/webhook/charge-succeeded.ts
+++ b/apps/web/app/api/stripe/webhook/charge-succeeded.ts
@@ -49,12 +49,22 @@ export async function chargeSucceeded(event: Stripe.Event) {
return;
}
+ await prisma.invoice.update({
+ where: {
+ id: invoice.id,
+ },
+ data: {
+ receiptUrl: receipt_url,
+ status: "completed",
+ paidAt: new Date(),
+ },
+ });
+
const qstashResponse = await qstash.publishJSON({
url: `${APP_DOMAIN_WITH_NGROK}/api/cron/payouts/charge-succeeded`,
body: {
chargeId,
invoiceId: invoice.id,
- receiptUrl: receipt_url,
achCreditTransfer: Boolean(
charge.payment_method_details?.ach_credit_transfer,
),