fix: checkout session completed (#25767)
* fix: checkout session completed * refactor: code quality
This commit is contained in:
@@ -45,6 +45,10 @@ const handler = async (data: SWHMap["checkout.session.completed"]["data"]) => {
|
||||
return await handleCalAIPhoneNumberSubscription(session);
|
||||
}
|
||||
|
||||
if (session.metadata?.type === CHECKOUT_SESSION_TYPES.TEAM_CREATION) {
|
||||
return await handleTeamCreationCheckoutSessionComplete(session);
|
||||
}
|
||||
|
||||
// Handle credit purchases (existing logic)
|
||||
if (!session.amount_total) {
|
||||
throw new HttpCode(400, "Missing required payment details");
|
||||
@@ -105,6 +109,17 @@ async function saveToCreditBalance({
|
||||
}
|
||||
}
|
||||
|
||||
async function handleTeamCreationCheckoutSessionComplete(
|
||||
session: SWHMap["checkout.session.completed"]["data"]["object"]
|
||||
) {
|
||||
log.info("Team creation checkout session completed - handled via redirect flow", {
|
||||
sessionId: session.id,
|
||||
teamName: session.metadata?.teamName,
|
||||
teamSlug: session.metadata?.teamSlug,
|
||||
});
|
||||
return { success: true, message: "Team checkout handled via redirect" };
|
||||
}
|
||||
|
||||
async function handleCalAIPhoneNumberSubscription(
|
||||
session: SWHMap["checkout.session.completed"]["data"]["object"]
|
||||
) {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
export const CHECKOUT_SESSION_TYPES = {
|
||||
PHONE_NUMBER_SUBSCRIPTION: "phone_number_subscription",
|
||||
TEAM_CREATION: "team_creation",
|
||||
} as const;
|
||||
|
||||
export type CheckoutSessionType = (typeof CHECKOUT_SESSION_TYPES)[keyof typeof CHECKOUT_SESSION_TYPES];
|
||||
|
||||
@@ -4,6 +4,7 @@ import { z } from "zod";
|
||||
import { getStripeCustomerIdFromUserId } from "@calcom/app-store/stripepayment/lib/customer";
|
||||
import { getDubCustomer } from "@calcom/features/auth/lib/dub";
|
||||
import stripe from "@calcom/features/ee/payments/server/stripe";
|
||||
import { CHECKOUT_SESSION_TYPES } from "@calcom/features/ee/billing/constants";
|
||||
import {
|
||||
IS_PRODUCTION,
|
||||
ORGANIZATION_SELF_SERVE_PRICE,
|
||||
@@ -98,6 +99,7 @@ export const generateTeamCheckoutSession = async ({
|
||||
trial_period_days: 14, // Add a 14-day trial
|
||||
},
|
||||
metadata: {
|
||||
type: CHECKOUT_SESSION_TYPES.TEAM_CREATION,
|
||||
teamName,
|
||||
teamSlug,
|
||||
userId,
|
||||
|
||||
Reference in New Issue
Block a user