mirror of
https://github.com/lukevella/rallly.git
synced 2025-08-06 09:59:00 +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<
|
const mapProductToLicenseType: Record<
|
||||||
Product,
|
Product,
|
||||||
{ type: LicenseType; seats: number }
|
{ type: LicenseType; seats: number; promoCode?: string }
|
||||||
> = {
|
> = {
|
||||||
plus: { type: "PLUS", seats: 5 },
|
plus: { type: "PLUS", seats: 5 },
|
||||||
organization: { type: "ORGANIZATION", seats: 50 },
|
organization: { type: "ORGANIZATION", seats: 50, promoCode: "EARLYORG" },
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function GET(request: NextRequest) {
|
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 {
|
try {
|
||||||
const session = await stripe.checkout.sessions.create({
|
const session = await stripe.checkout.sessions.create({
|
||||||
|
@ -61,6 +68,7 @@ export async function GET(request: NextRequest) {
|
||||||
],
|
],
|
||||||
mode: "payment",
|
mode: "payment",
|
||||||
success_url: "https://rallly.co/licensing/thank-you",
|
success_url: "https://rallly.co/licensing/thank-you",
|
||||||
|
...(promoCodeId ? { discounts: [{ promotion_code: promoCodeId }] } : {}),
|
||||||
metadata: {
|
metadata: {
|
||||||
licenseType: type,
|
licenseType: type,
|
||||||
version: 4,
|
version: 4,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue