Skip if env has no price ID

pull/11421/merge^2
Sean Brydon 2023-09-05 16:23:35 +01:00
parent e58f945915
commit 72cc95a0d7
3 changed files with 14 additions and 6 deletions

View File

@ -16,7 +16,7 @@ import {
acceptAllInvitesWithTeamId,
findTeam,
upsertUsersPasswordAndVerify,
joinOrgAndAcceptChildInivtes,
joinOrgAndAcceptChildInvites,
cleanUpInviteToken,
} from "@calcom/feature-auth/lib/signup/teamInviteUtils";
import { hashPassword } from "@calcom/features/auth/lib/hashPassword";
@ -87,7 +87,7 @@ async function handler(req: RequestWithUsernameStatus, res: NextApiResponse) {
const membership = await acceptAllInvitesWithTeamId(user.id, team.id);
closeComUpsertTeamUser(team, user, membership.role);
if (team.parentId) {
await joinOrgAndAcceptChildInivtes(user.id, team.parentId);
await joinOrgAndAcceptChildInvites(user.id, team.parentId);
}
await cleanUpInviteToken(foundToken.id);
}
@ -108,6 +108,9 @@ async function handler(req: RequestWithUsernameStatus, res: NextApiResponse) {
return res.status(201).json({ message: "Created user" });
} catch (e) {
console.log({
e,
});
if (e instanceof HttpError) {
return res.status(e.statusCode).json({ message: e.message });
}

View File

@ -1,5 +1,6 @@
import type Stripe from "stripe";
import { PREMIUM_MONTHLY_PLAN_PRICE } from "@calcom/app-store/stripepayment/lib";
import stripe from "@calcom/app-store/stripepayment/lib/server";
import { getPremiumMonthlyPlanPriceId } from "@calcom/app-store/stripepayment/lib/utils";
import { IS_CALCOM, IS_STRIPE_ENABLED, WEBAPP_URL } from "@calcom/lib/constants";
@ -67,6 +68,7 @@ export function parseSignupData(data: unknown) {
export async function createStripeCustomer({ email, username }: { email: string; username: string }) {
// Create the customer in Stripe
if (!IS_STRIPE_ENABLED) return;
console.log("Creating Stripe customer");
const customer = await stripe.customers.create({
email,
metadata: {
@ -74,7 +76,6 @@ export async function createStripeCustomer({ email, username }: { email: string;
username,
},
});
return customer;
}
@ -85,8 +86,7 @@ export async function handlePremiumUsernameFlow({
premiumUsernameStatusCode: number;
customer?: Stripe.Customer;
}) {
if (!IS_CALCOM) return;
if (!IS_STRIPE_ENABLED) return;
if (!IS_STRIPE_ENABLED || !PREMIUM_MONTHLY_PLAN_PRICE || !IS_CALCOM) return;
if (!customer) {
throw new HttpError({
@ -95,6 +95,11 @@ export async function handlePremiumUsernameFlow({
});
}
const metadata: {
stripeCustomerId?: string;
checkoutSessionId?: string;
} = {};
const returnUrl = `${WEBAPP_URL}/api/integrations/stripepayment/paymentCallback?checkoutSessionId={CHECKOUT_SESSION_ID}&callbackUrl=/auth/verify?sessionId={CHECKOUT_SESSION_ID}`;
if (premiumUsernameStatusCode === 402) {

View File

@ -82,7 +82,7 @@ export async function acceptAllInvitesWithTeamId(userId: number, teamId: number)
return membership;
}
export async function joinOrgAndAcceptChildInivtes(userId: number, orgId: number) {
export async function joinOrgAndAcceptChildInvites(userId: number, orgId: number) {
// Join ORG
await prisma.user.update({
where: {