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 create-coupon.ts

Kiran K262d1e6b58f2
diff --git a/apps/web/lib/stripe/create-coupon.ts b/apps/web/lib/stripe/create-coupon.ts
index 1c2e0b1fa8..0432becb47 100644
--- a/apps/web/lib/stripe/create-coupon.ts
+++ b/apps/web/lib/stripe/create-coupon.ts
@@ -20,12 +20,20 @@ export async function createStripeCoupon({
return;
}
- const duration =
- coupon.maxDuration === null
- ? "forever"
- : coupon.maxDuration === 1
- ? "once"
- : "repeating";
+ let duration: "once" | "repeating" | "forever" = "once";
+ let durationInMonths: number | undefined = undefined;
+
+ if (coupon.maxDuration === null) {
+ duration = "forever";
+ } else if (coupon.maxDuration === 0) {
+ duration = "once";
+ } else {
+ duration = "repeating";
+ }
+
+ if (duration === "repeating" && coupon.maxDuration) {
+ durationInMonths = coupon.maxDuration;
+ }
try {
return await stripe.coupons.create(
@@ -33,7 +41,7 @@ export async function createStripeCoupon({
currency: "usd",
duration,
...(duration === "repeating" && {
- duration_in_months: coupon.maxDuration!,
+ duration_in_months: durationInMonths,
}),
...(coupon.type === "percentage"
? { percent_off: coupon.amount }