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.

Add Dynadot renew option API integration and invoice type

Kiran K86df4eb4eb9e
diff --git a/apps/web/app/api/domains/[domain]/route.ts b/apps/web/app/api/domains/[domain]/route.ts
index f502029576..f8f68501c3 100644
--- a/apps/web/app/api/domains/[domain]/route.ts
+++ b/apps/web/app/api/domains/[domain]/route.ts
@@ -10,6 +10,7 @@ import { transformDomain } from "@/lib/api/domains/transform-domain";
import { DubApiError } from "@/lib/api/errors";
import { parseRequestBody } from "@/lib/api/utils";
import { withWorkspace } from "@/lib/auth";
+import { setRenewOption } from "@/lib/dynadot/set-renew-option";
import { storage } from "@/lib/storage";
import { updateDomainBodySchema } from "@/lib/zod/schemas/domains";
import { prisma } from "@dub/prisma";
@@ -164,6 +165,13 @@ export const PATCH = withWorkspace(
autoRenewDisabledAt: autoRenew ? null : new Date(),
},
});
+
+ waitUntil(
+ setRenewOption({
+ domain,
+ autoRenew,
+ }),
+ );
}
}
diff --git a/apps/web/lib/dynadot/set-renew-option.ts b/apps/web/lib/dynadot/set-renew-option.ts
new file mode 100644
index 0000000000..699091f6c4
--- /dev/null
+++ b/apps/web/lib/dynadot/set-renew-option.ts
@@ -0,0 +1,57 @@
+import z from "@/lib/zod";
+import { log } from "@dub/utils";
+import { DYNADOT_API_KEY, DYNADOT_BASE_URL } from "./constants";
+
+const responseSchema = z.object({
+ SetDefaultRenewOptionResponse: z.object({
+ ResponseCode: z.number(),
+ Status: z.string(),
+ }),
+});
+
+export const setRenewOption = async ({
+ domain,
+ autoRenew,
+}: {
+ domain: string;
+ autoRenew: boolean;
+}) => {
+ const searchParams = new URLSearchParams({
+ key: DYNADOT_API_KEY,
+ command: "set_renew_option",
+ domain,
+ renew_option: autoRenew ? "auto" : "donot",
+ });
+
+ try {
+ const response = await fetch(
+ `${DYNADOT_BASE_URL}?${searchParams.toString()}`,
+ {
+ headers: {
+ "Content-Type": "application/x-www-form-urlencoded",
+ },
+ },
+ );
+
+ if (!response.ok) {
+ console.error(response);
+ throw new Error(`Failed to set renew option: ${response.statusText}`);
+ }
+
+ const {
+ SetDefaultRenewOptionResponse: { Status },
+ } = responseSchema.parse(await response.json());
+
+ if (Status !== "success") {
+ throw new Error(`Failed to set renew option: ${Status}`);
+ }
+ } catch (error) {
+ await log({
+ message: `Failed to set renew option for ${domain}: ${error.message}`,
+ type: "errors",
+ mention: true,
+ });
+
+ console.error(error);
+ }
+};
diff --git a/packages/prisma/schema/invoice.prisma b/packages/prisma/schema/invoice.prisma
index 58dfe56f95..dd49958048 100644
--- a/packages/prisma/schema/invoice.prisma
+++ b/packages/prisma/schema/invoice.prisma
@@ -4,20 +4,26 @@ enum InvoiceStatus {
failed
}
+enum InvoiceType {
+ partnerPayout
+ domainRenewal
+}
+
model Invoice {
- id String @id @default(cuid())
- programId String
- workspaceId String
- number String? @unique // This starts with the customer’s unique invoicePrefix
- status InvoiceStatus @default(processing)
- amount Int @default(0) // amount in usd cents
- fee Int @default(0) // fee in usd cents
- total Int @default(0) // amount + fee in usd cents
- receiptUrl String? @db.Text
- failedReason String? @db.Text
- stripeChargeMetadata Json? @db.Json // Stripe charge metadata
- createdAt DateTime @default(now())
- paidAt DateTime?
+ id String @id @default(cuid())
+ programId String
+ workspaceId String
+ number String? @unique // This starts with the customer’s unique invoicePrefix
+ status InvoiceStatus @default(processing)
+ type InvoiceType @default(partnerPayout)
+ amount Int @default(0) // amount in usd cents
+ fee Int @default(0) // fee in usd cents
+ total Int @default(0) // amount + fee in usd cents
+ receiptUrl String? @db.Text
+ failedReason String? @db.Text
+ stripeChargeMetadata Json? @db.Json // Stripe charge metadata
+ createdAt DateTime @default(now())
+ paidAt DateTime?
payouts Payout[]
program Program @relation(fields: [programId], references: [id])