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.

fix coupon

Steven Tey7dfceb6db927
diff --git a/apps/web/app/(ee)/api/admin/domains/register-premium/route.ts b/apps/web/app/(ee)/api/admin/domains/register-premium/route.ts
index 728c8bcee2..3a39162446 100644
--- a/apps/web/app/(ee)/api/admin/domains/register-premium/route.ts
+++ b/apps/web/app/(ee)/api/admin/domains/register-premium/route.ts
@@ -13,80 +13,88 @@ const schema = z.object({
});
// POST /api/admin/domains/register-premium
-export const POST = withAdmin(async ({ req }) => {
- const parsed = schema.safeParse(await req.json());
- if (!parsed.success) {
- return NextResponse.json({ error: parsed.error.message }, { status: 400 });
- }
+export const POST = withAdmin(
+ async ({ req }) => {
+ const parsed = schema.safeParse(await req.json());
+ if (!parsed.success) {
+ return NextResponse.json(
+ { error: parsed.error.message },
+ { status: 400 },
+ );
+ }
- const { domain, workspaceSlug } = parsed.data;
+ const { domain, workspaceSlug } = parsed.data;
- if (!domain) {
- return NextResponse.json({ error: "Invalid domain." }, { status: 400 });
- }
+ if (!domain) {
+ return NextResponse.json({ error: "Invalid domain." }, { status: 400 });
+ }
- if (!domain.endsWith(".link")) {
- return NextResponse.json(
- { error: "Only .link domains are supported." },
- { status: 400 },
- );
- }
+ if (!domain.endsWith(".link")) {
+ return NextResponse.json(
+ { error: "Only .link domains are supported." },
+ { status: 400 },
+ );
+ }
- const workspace = await prisma.project.findUnique({
- where: { slug: workspaceSlug },
- select: {
- id: true,
- slug: true,
- plan: true,
- stripeId: true,
- trialEndsAt: true,
- invoicePrefix: true,
- },
- });
+ const workspace = await prisma.project.findUnique({
+ where: { slug: workspaceSlug },
+ select: {
+ id: true,
+ slug: true,
+ plan: true,
+ stripeId: true,
+ trialEndsAt: true,
+ invoicePrefix: true,
+ },
+ });
- if (!workspace) {
- return NextResponse.json(
- { error: `Workspace "${parsed.data.workspaceSlug}" not found.` },
- { status: 404 },
- );
- }
+ if (!workspace) {
+ return NextResponse.json(
+ { error: `Workspace "${parsed.data.workspaceSlug}" not found.` },
+ { status: 404 },
+ );
+ }
- try {
- const response = await initiatePremiumDomainRegistration({
- domain,
- workspace,
- skipWorkspaceChecks: true,
- });
+ try {
+ const response = await initiatePremiumDomainRegistration({
+ domain,
+ workspace,
+ skipWorkspaceChecks: true,
+ });
+
+ const status = response.paymentIntentStatus;
- const status = response.paymentIntentStatus;
+ if (status === "succeeded") {
+ return NextResponse.json({
+ success: true,
+ message: `Charge succeeded (${currencyFormatter(response.registrationPriceCents)}). Domain registration will finalize via Stripe webhook.`,
+ ...response,
+ });
+ }
- if (status === "succeeded") {
return NextResponse.json({
success: true,
- message: `Charge succeeded (${currencyFormatter(response.registrationPriceCents)}). Domain registration will finalize via Stripe webhook.`,
+ message: `Payment initiated (${currencyFormatter(response.registrationPriceCents)}). Domain registration will finalize via Stripe webhook once payment succeeds.`,
...response,
});
- }
+ } catch (error) {
+ if (error instanceof DubApiError) {
+ const status =
+ error.code === "conflict"
+ ? 409
+ : error.code === "unprocessable_entity"
+ ? 422
+ : error.code === "forbidden"
+ ? 403
+ : 400;
- return NextResponse.json({
- success: true,
- message: `Payment initiated (${currencyFormatter(response.registrationPriceCents)}). Domain registration will finalize via Stripe webhook once payment succeeds.`,
- ...response,
- });
- } catch (error) {
- if (error instanceof DubApiError) {
- const status =
- error.code === "conflict"
- ? 409
- : error.code === "unprocessable_entity"
- ? 422
- : error.code === "forbidden"
- ? 403
- : 400;
+ return NextResponse.json({ error: error.message }, { status });
+ }
- return NextResponse.json({ error: error.message }, { status });
+ throw error;
}
-
- throw error;
- }
-});
+ },
+ {
+ requiredRoles: ["owner"],
+ },
+);
diff --git a/apps/web/lib/dynadot/register-domain.ts b/apps/web/lib/dynadot/register-domain.ts
index 352cfc7b36..e1043750db 100644
--- a/apps/web/lib/dynadot/register-domain.ts
+++ b/apps/web/lib/dynadot/register-domain.ts
@@ -49,8 +49,7 @@ export const registerDomain = async ({
command: "register",
duration: "1",
currency: "USD",
- ...(premium ? { premium: "1" } : {}),
- coupon: DYNADOT_COUPON,
+ ...(premium ? { premium: "1" } : { coupon: DYNADOT_COUPON }),
key: DYNADOT_API_KEY,
});