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.

handle failed invoices

Steven Teybe8bcd6c55a1
diff --git a/apps/web/app/(ee)/api/stripe/webhook/utils/process-payout-invoice-failure.ts b/apps/web/app/(ee)/api/stripe/webhook/utils/process-payout-invoice-failure.ts
index ded6599952..36ca6778c4 100644
--- a/apps/web/app/(ee)/api/stripe/webhook/utils/process-payout-invoice-failure.ts
+++ b/apps/web/app/(ee)/api/stripe/webhook/utils/process-payout-invoice-failure.ts
@@ -24,8 +24,8 @@ export async function processPayoutInvoiceFailure({
mention: true,
});
- // Mark the payouts as pending again
- await prisma.payout.updateMany({
+ // reset the payouts to their initial state
+ const { count } = await prisma.payout.updateMany({
where: {
invoiceId: invoice.id,
},
@@ -33,9 +33,16 @@ export async function processPayoutInvoiceFailure({
status: "pending",
userId: null,
invoiceId: null,
+ initiatedAt: null,
+ paidAt: null,
+ mode: null,
},
});
+ console.log(
+ `Reset ${count} payouts to their initial state for invoice ${invoice.id}`,
+ );
+
const workspace = await prisma.project.update({
where: {
id: invoice.workspaceId,
diff --git a/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/route.tsx b/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/route.tsx
index b2148da385..32d632a34c 100644
--- a/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/route.tsx
+++ b/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/route.tsx
@@ -1,5 +1,6 @@
import { DubApiError } from "@/lib/api/errors";
import { withSession } from "@/lib/auth";
+import { INVOICE_AVAILABLE_PAYOUT_STATUSES } from "@/lib/constants/payouts";
import { prisma } from "@dub/prisma";
import { DomainRenewalInvoice } from "./domain-renewal-invoice";
import { PartnerPayoutInvoice } from "./partner-payout-invoice";
@@ -25,6 +26,13 @@ export const GET = withSession(async ({ session, params }) => {
},
});
+ if (!INVOICE_AVAILABLE_PAYOUT_STATUSES.includes(invoice.status)) {
+ throw new DubApiError({
+ code: "bad_request",
+ message: "This invoice is not available for download.",
+ });
+ }
+
const userInWorkspace = await prisma.projectUsers.findUnique({
where: {
userId_projectId: {
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/invoices/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/invoices/page-client.tsx
index 31af6587c7..dac0878104 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/invoices/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/invoices/page-client.tsx
@@ -1,6 +1,9 @@
"use client";
-import { INVOICE_PAYMENT_METHODS } from "@/lib/constants/payouts";
+import {
+ INVOICE_AVAILABLE_PAYOUT_STATUSES,
+ INVOICE_PAYMENT_METHODS,
+} from "@/lib/constants/payouts";
import useWorkspace from "@/lib/swr/use-workspace";
import { InvoiceProps } from "@/lib/types";
import { PayoutStatusBadges } from "@/ui/partners/payout-status-badges";
@@ -127,7 +130,8 @@ const InvoiceCard = ({
</div>
</div>
<div className="flex items-center">
- {invoice.pdfUrl ? (
+ {invoice.pdfUrl &&
+ INVOICE_AVAILABLE_PAYOUT_STATUSES.includes(invoice.status ?? "") ? (
<a
href={invoice.pdfUrl}
target="_blank"
@@ -140,7 +144,7 @@ const InvoiceCard = ({
</a>
) : (
<Button
- className="h-9 px-3"
+ className="h-9 w-fit px-3"
variant="secondary"
text="View invoice"
disabled
@@ -258,7 +262,8 @@ const InvoiceCard = ({
)}
<div className="flex items-center justify-end sm:col-span-1 sm:justify-end">
- {invoice.pdfUrl ? (
+ {invoice.pdfUrl &&
+ INVOICE_AVAILABLE_PAYOUT_STATUSES.includes(invoice.status ?? "") ? (
<a
href={invoice.pdfUrl}
target="_blank"
@@ -271,7 +276,7 @@ const InvoiceCard = ({
</a>
) : (
<Button
- className="h-9 px-3"
+ className="h-9 w-fit px-3"
variant="secondary"
text="View invoice"
disabled