The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Sanitize partner name in discount code to strip Stripe-invalid characters
Kiran Kfa98d8f36196
diff --git a/apps/web/lib/api/discounts/construct-discount-code.ts b/apps/web/lib/api/discounts/construct-discount-code.tsindex 6cbc8885bb..1f158cb234 100644--- a/apps/web/lib/api/discounts/construct-discount-code.ts+++ b/apps/web/lib/api/discounts/construct-discount-code.ts@@ -12,7 +12,10 @@ export function constructDiscountCode({);const [firstName] = partner.name.trim().toUpperCase().split(" ");- const prefix = firstName || "PARTNER";++ // Stripe promotion codes only allow alphanumeric characters and dashes+ const sanitized = firstName?.replace(/[^A-Z0-9\-_]/g, "") || "";+ const prefix = sanitized || "PARTNER";// account for edge case where the amount is 0return `${prefix}${amount > 0 ? `${amount}OFF` : ""}`;