Skip to content

Commit

Permalink
Add support for customer.discount.couponId
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-tey committed Jan 2, 2025
1 parent ecccee4 commit dfc9e6f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 48 deletions.
12 changes: 7 additions & 5 deletions apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { withWorkspace } from "@/lib/auth";
import { getDubCustomer } from "@/lib/dub";
import { stripe } from "@/lib/stripe";
import { APP_DOMAIN } from "@dub/utils";
import { NextResponse } from "next/server";
Expand Down Expand Up @@ -46,7 +47,7 @@ export const POST = withWorkspace(async ({ req, workspace, session }) => {
});
return NextResponse.json({ url });
} else {
// const customer = await getDubCustomer(session.user.id);
const customer = await getDubCustomer(session.user.id);

// For both new users and users with canceled subscriptions
const stripeSession = await stripe.checkout.sessions.create({
Expand All @@ -66,14 +67,15 @@ export const POST = withWorkspace(async ({ req, workspace, session }) => {
success_url: `${APP_DOMAIN}/${workspace.slug}?${onboarding ? "onboarded" : "upgraded"}=true&plan=${plan}&period=${period}`,
cancel_url: baseUrl,
line_items: [{ price: prices.data[0].id, quantity: 1 }],
...(false
...(customer?.discount?.couponId
? {
discounts: [
{
coupon:
process.env.NODE_ENV === "production"
? "pEVpzGQE"
: "k8v8KtqG",
process.env.NODE_ENV !== "production" &&
customer.discount.couponTestId
? customer.discount.couponTestId
: customer.discount.couponId,
},
],
}
Expand Down
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"concurrently": "^8.0.1",
"csv-parse": "^5.5.6",
"date-fns": "^3.6.0",
"dub": "^0.46.8",
"dub": "^0.46.9",
"framer-motion": "^10.16.16",
"fuse.js": "^6.6.2",
"geist": "^1.3.1",
Expand Down
48 changes: 6 additions & 42 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dfc9e6f

Please sign in to comment.