Skip to content

Commit

Permalink
fix: dual-sided incentives on webapp (#18846)
Browse files Browse the repository at this point in the history
  • Loading branch information
zomars authored Jan 23, 2025
1 parent fec8019 commit 161aece
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/features/ee/teams/lib/payments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { z } from "zod";

import { getStripeCustomerIdFromUserId } from "@calcom/app-store/stripepayment/lib/customer";
import stripe from "@calcom/app-store/stripepayment/lib/server";
import { getDubCustomer } from "@calcom/features/auth/lib/dub";
import {
IS_PRODUCTION,
MINIMUM_NUMBER_OF_ORG_SEATS,
Expand Down Expand Up @@ -53,11 +54,25 @@ export const generateTeamCheckoutSession = async ({
teamSlug: string;
userId: number;
}) => {
const customer = await getStripeCustomerIdFromUserId(userId);
const [customer, dubCustomer] = await Promise.all([
getStripeCustomerIdFromUserId(userId),
getDubCustomer(userId.toString()),
]);
const session = await stripe.checkout.sessions.create({
customer,
mode: "subscription",
allow_promotion_codes: true,
...(dubCustomer?.discount?.couponId
? {
discounts: [
{
coupon:
process.env.NODE_ENV !== "production" && dubCustomer.discount.couponTestId
? dubCustomer.discount.couponTestId
: dubCustomer.discount.couponId,
},
],
}
: { allow_promotion_codes: true }),
success_url: `${WEBAPP_URL}/api/teams/create?session_id={CHECKOUT_SESSION_ID}`,
cancel_url: `${WEBAPP_URL}/settings/my-account/profile`,
line_items: [
Expand Down

0 comments on commit 161aece

Please sign in to comment.