mirror of
https://github.com/lukevella/rallly.git
synced 2025-08-01 07:28:35 +02:00
💸 Apply early org discount
This commit is contained in:
parent
bfd8fea2e1
commit
a07f4a5e83
1 changed files with 11 additions and 3 deletions
|
@ -10,10 +10,10 @@ type Product = z.infer<typeof productSchema>;
|
|||
|
||||
const mapProductToLicenseType: Record<
|
||||
Product,
|
||||
{ type: LicenseType; seats: number }
|
||||
{ type: LicenseType; seats: number; promoCode?: string }
|
||||
> = {
|
||||
plus: { type: "PLUS", seats: 5 },
|
||||
organization: { type: "ORGANIZATION", seats: 50 },
|
||||
organization: { type: "ORGANIZATION", seats: 50, promoCode: "EARLYORG" },
|
||||
};
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
|
@ -49,7 +49,14 @@ export async function GET(request: NextRequest) {
|
|||
);
|
||||
}
|
||||
|
||||
const { type, seats } = mapProductToLicenseType[product];
|
||||
const { type, seats, promoCode } = mapProductToLicenseType[product];
|
||||
|
||||
const promotionCodes = await stripe.promotionCodes.list({
|
||||
code: promoCode,
|
||||
active: true,
|
||||
});
|
||||
|
||||
const promoCodeId = promotionCodes.data[0]?.id;
|
||||
|
||||
try {
|
||||
const session = await stripe.checkout.sessions.create({
|
||||
|
@ -61,6 +68,7 @@ export async function GET(request: NextRequest) {
|
|||
],
|
||||
mode: "payment",
|
||||
success_url: "https://rallly.co/licensing/thank-you",
|
||||
...(promoCodeId ? { discounts: [{ promotion_code: promoCodeId }] } : {}),
|
||||
metadata: {
|
||||
licenseType: type,
|
||||
version: 4,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue