Files
Matt Aitken 48a0b83ec6 feat(webapp): promo credits — /promo signup landing, redeem at plan selection, usage display (#4138)
## What & why

Signup promo credits. A new logged-out `/promo?code=<code>` landing page
validates the code and carries it through signup via a cookie. When the
new organization is activated by selecting a plan, the code is redeemed
and its credits are applied; the usage page then shows the remaining
promo credits and their expiry.

## Notes

- The code is redeemed at **plan selection**, not org creation: the
credit grant targets the org's usage allowance, which only exists once a
plan is selected — applying at creation would have nothing to grant
onto. Redemption is best-effort and never blocks plan selection.
- Pairs with the corresponding billing-service change (promo code
validate/apply/credits + grant issuance); the two are released together.

## Testing

Verified locally end to end: `/promo` shows the offer, a new account
carries the code through signup, selecting the Free plan redeems it, and
the usage page shows the remaining credits.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-07-10 17:48:39 +02:00

27 lines
984 B
TypeScript

import { createCookie } from "@remix-run/node";
import { env } from "~/env.server";
// Carries a promo code from the landing page through signup to first-org
// creation. httpOnly + sameSite=lax so it survives the OAuth round-trip,
// matching the existing redirect-to cookie.
export const promoCodeCookie = createCookie("promo-code", {
maxAge: 60 * 60, // 1 hour — enough to complete signup
httpOnly: true,
sameSite: "lax",
secure: env.NODE_ENV === "production",
path: "/",
});
export async function setPromoCodeCookie(code: string): Promise<string> {
return await promoCodeCookie.serialize(code);
}
export async function getPromoCodeFromCookie(request: Request): Promise<string | null> {
const value = await promoCodeCookie.parse(request.headers.get("Cookie"));
return typeof value === "string" && value.length > 0 ? value : null;
}
export async function clearPromoCodeCookie(): Promise<string> {
return await promoCodeCookie.serialize("", { maxAge: 0 });
}