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.

Update charge-failed.ts

Kiran Kd1154368cc26
diff --git a/apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts b/apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts
index c223794817..26765fa526 100644
--- a/apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts
+++ b/apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts
@@ -1,4 +1,5 @@
import { qstash } from "@/lib/cron";
+import { setRenewOption } from "@/lib/dynadot/set-renew-option";
import {
DIRECT_DEBIT_PAYMENT_METHOD_TYPES,
PAYOUT_FAILURE_FEE_CENTS,
@@ -205,6 +206,18 @@ async function processPayoutInvoice({
}
async function processRenewalInvoice({ invoice }: { invoice: Invoice }) {
+ const domains = await prisma.registeredDomain.findMany({
+ where: {
+ slug: {
+ in: invoice.registeredDomains as string[],
+ },
+ },
+ select: {
+ slug: true,
+ expiresAt: true,
+ },
+ });
+
if (invoice.failedAttempts < 3) {
await qstash.publishJSON({
url: `${APP_DOMAIN_WITH_NGROK}/api/cron/invoices/retry-failed`,
@@ -214,6 +227,15 @@ async function processRenewalInvoice({ invoice }: { invoice: Invoice }) {
invoiceId: invoice.id,
},
});
+ } else {
+ await Promise.allSettled(
+ domains.map((domain) =>
+ setRenewOption({
+ domain: domain.slug,
+ autoRenew: false,
+ }),
+ ),
+ );
}
const workspace = await prisma.project.findUniqueOrThrow({
@@ -239,18 +261,6 @@ async function processRenewalInvoice({ invoice }: { invoice: Invoice }) {
return;
}
- const domains = await prisma.registeredDomain.findMany({
- where: {
- slug: {
- in: invoice.registeredDomains as string[],
- },
- },
- select: {
- slug: true,
- expiresAt: true,
- },
- });
-
await resend?.batch.send(
workspaceOwners.map(({ user }) => ({
from: VARIANT_TO_FROM_MAP.notifications,