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 support for customer.discount.couponId

Steven Teydfc9e6ffd9a6
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.ts
index f88e00c313..05fd9a8a3d 100644
--- a/apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.ts
+++ b/apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.ts
@@ -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";
@@ -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({
@@ -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,
},
],
}
diff --git a/apps/web/package.json b/apps/web/package.json
index 00eeafbc0c..61067583a8 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -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",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 28d2bcd75a..ffcecef4f9 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -184,8 +184,8 @@ importers:
specifier: ^3.6.0
version: 3.6.0
dub:
- specifier: ^0.46.8
- version: 0.46.8([email protected])
+ specifier: ^0.46.9
+ version: 0.46.9([email protected])
framer-motion:
specifier: ^10.16.16
@@ -497,7 +497,7 @@ importers:
version: link:../../tsconfig
tsup:
specifier: ^6.1.3
typescript:
specifier: ^5.1.6
version: 5.6.2
@@ -829,7 +829,7 @@ importers:
version: link:../tsconfig
tsup:
specifier: ^6.1.3
- version: 6.1.3([email protected])
typescript:
specifier: ^5.1.6
version: 5.1.6
@@ -12560,8 +12560,8 @@ packages:
zod: 3.23.8
dev: false
- resolution: {integrity: sha512-48r051aekxXnRvHtxwaJeKeUYi0MgX3jiEE9BbCdGkAaNOBU6+hfl2bJPYMK+MO+qBRAc0uYOeBvIxcKKgrBCQ==}
+ resolution: {integrity: sha512-2ejL54dg2e/NqKGKUTtoHJwPFOFPPLu072HGCuHZODqxqCfc+SXzw2zZEVB2/U6xMns/koIt/ctWUaU4ce4mTQ==}
peerDependencies:
zod: '>= 3'
dependencies:
@@ -21033,42 +21033,6 @@ packages:
- ts-node
dev: true
- resolution: {integrity: sha512-eRpBnbfpDFng+EJNTQ90N7QAf4HAGGC7O3buHIjroKWK7D1ibk9/YnR/3cS8HsMU5T+6Oi+cnF+yU5WmCnB//Q==}
- engines: {node: '>=14'}
- hasBin: true
- peerDependencies:
- '@swc/core': ^1
- postcss: ^8.4.12
- typescript: ^4.1.0
- peerDependenciesMeta:
- '@swc/core':
- optional: true
- postcss:
- optional: true
- typescript:
- optional: true
- dependencies:
- bundle-require: 3.1.2([email protected])
- cac: 6.7.14
- chokidar: 3.5.3
- debug: 4.3.4
- esbuild: 0.14.54
- execa: 5.1.1
- globby: 11.1.0
- joycon: 3.1.1
- postcss-load-config: 3.1.4([email protected])
- resolve-from: 5.0.0
- rollup: 2.79.1
- source-map: 0.8.0-beta.0
- sucrase: 3.34.0
- tree-kill: 1.2.2
- typescript: 5.1.6
- transitivePeerDependencies:
- - supports-color
- - ts-node
- dev: true
-
resolution: {integrity: sha512-L3o8hGkaHnu5TdJns+mCqFsDBo83bJ44rlK7e6VdanIvpea4ArPcU3swWGsLVbXak1PqQx/V+SSmFPujBK+zEQ==}
engines: {node: '>=14.18'}