Skip to content

Commit fd8f2a9

Browse files
authored
fix: checkout session completed (calcom#25767)
* fix: checkout session completed * refactor: code quality
1 parent 28f9c8f commit fd8f2a9

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

packages/features/ee/billing/api/webhook/_checkout.session.completed.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ const handler = async (data: SWHMap["checkout.session.completed"]["data"]) => {
4545
return await handleCalAIPhoneNumberSubscription(session);
4646
}
4747

48+
if (session.metadata?.type === CHECKOUT_SESSION_TYPES.TEAM_CREATION) {
49+
return await handleTeamCreationCheckoutSessionComplete(session);
50+
}
51+
4852
// Handle credit purchases (existing logic)
4953
if (!session.amount_total) {
5054
throw new HttpCode(400, "Missing required payment details");
@@ -105,6 +109,17 @@ async function saveToCreditBalance({
105109
}
106110
}
107111

112+
async function handleTeamCreationCheckoutSessionComplete(
113+
session: SWHMap["checkout.session.completed"]["data"]["object"]
114+
) {
115+
log.info("Team creation checkout session completed - handled via redirect flow", {
116+
sessionId: session.id,
117+
teamName: session.metadata?.teamName,
118+
teamSlug: session.metadata?.teamSlug,
119+
});
120+
return { success: true, message: "Team checkout handled via redirect" };
121+
}
122+
108123
async function handleCalAIPhoneNumberSubscription(
109124
session: SWHMap["checkout.session.completed"]["data"]["object"]
110125
) {

packages/features/ee/billing/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
export const CHECKOUT_SESSION_TYPES = {
66
PHONE_NUMBER_SUBSCRIPTION: "phone_number_subscription",
7+
TEAM_CREATION: "team_creation",
78
} as const;
89

910
export type CheckoutSessionType = (typeof CHECKOUT_SESSION_TYPES)[keyof typeof CHECKOUT_SESSION_TYPES];

packages/features/ee/teams/lib/payments.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { z } from "zod";
44
import { getStripeCustomerIdFromUserId } from "@calcom/app-store/stripepayment/lib/customer";
55
import { getDubCustomer } from "@calcom/features/auth/lib/dub";
66
import stripe from "@calcom/features/ee/payments/server/stripe";
7+
import { CHECKOUT_SESSION_TYPES } from "@calcom/features/ee/billing/constants";
78
import {
89
IS_PRODUCTION,
910
ORGANIZATION_SELF_SERVE_PRICE,
@@ -98,6 +99,7 @@ export const generateTeamCheckoutSession = async ({
9899
trial_period_days: 14, // Add a 14-day trial
99100
},
100101
metadata: {
102+
type: CHECKOUT_SESSION_TYPES.TEAM_CREATION,
101103
teamName,
102104
teamSlug,
103105
userId,

0 commit comments

Comments
 (0)