feat: store utm tags in stripe on signup (#26838)
* feat: store utm params in stripe on signup * fix: fallback to cookie when query params don't contain valid UTM data Changed from else-if to separate if statement so that when query params exist but don't contain valid UTM data, the cookie fallback is still tried. Previously, any request with non-UTM query params would skip the stored cookie data entirely. Co-Authored-By: unknown <> * fix: e2e --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
7 files changed
+106
-41
No files matched your search
@@ -35,7 +35,7 @@ import {
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["signupCalcomHandler"] });
|
||||
|
||||
const handler: CustomNextApiHandler = async (body, usernameStatus) => {
|
||||
const handler: CustomNextApiHandler = async (body, usernameStatus, query) => {
|
||||
const {
|
||||
email: _email,
|
||||
password,
|
||||
@@ -122,7 +122,7 @@ const handler: CustomNextApiHandler = async (body, usernameStatus) => {
|
||||
// Create the customer in Stripe with ad tracking metadata
|
||||
const cookieStore = await cookies();
|
||||
const cookiesObj = Object.fromEntries(cookieStore.getAll().map((c) => [c.name, c.value]));
|
||||
const tracking = getTrackingFromCookies(cookiesObj);
|
||||
const tracking = getTrackingFromCookies(cookiesObj, query);
|
||||
|
||||
const customer = await billingService.createCustomer({
|
||||
email,
|
||||
@@ -179,7 +179,7 @@ const handler: CustomNextApiHandler = async (body, usernameStatus) => {
|
||||
},
|
||||
});
|
||||
if (team) {
|
||||
const organizationId = team.isOrganization ? team.id : team.parent?.id ?? null;
|
||||
const organizationId = team.isOrganization ? team.id : (team.parent?.id ?? null);
|
||||
|
||||
if (username) {
|
||||
const existingUserByUsername = await prisma.user.findFirst({
|
||||
@@ -272,10 +272,7 @@ const handler: CustomNextApiHandler = async (body, usernameStatus) => {
|
||||
if (isPrismaError(error) && error.code === "P2002") {
|
||||
const target = String(error.meta?.target ?? "");
|
||||
if (target.includes("email") || target.includes("username")) {
|
||||
return NextResponse.json(
|
||||
{ message: SIGNUP_ERROR_CODES.USER_ALREADY_EXISTS },
|
||||
{ status: 409 }
|
||||
);
|
||||
return NextResponse.json({ message: SIGNUP_ERROR_CODES.USER_ALREADY_EXISTS }, { status: 409 });
|
||||
}
|
||||
}
|
||||
throw error;
|
||||
|
||||
@@ -47,6 +47,7 @@ async function handler(req: NextRequest) {
|
||||
});
|
||||
|
||||
const body = await parseRequestData(req);
|
||||
const query = Object.fromEntries(req.nextUrl.searchParams.entries());
|
||||
await checkCfTurnstileToken({
|
||||
token: req.headers.get("cf-access-token") as string,
|
||||
remoteIp,
|
||||
@@ -62,7 +63,7 @@ async function handler(req: NextRequest) {
|
||||
* @zomars: We need to be able to test this with E2E. They way it's done RN it will never run on CI.
|
||||
*/
|
||||
if (IS_PREMIUM_USERNAME_ENABLED) {
|
||||
return await calcomSignupHandler(body);
|
||||
return await calcomSignupHandler(body, query);
|
||||
}
|
||||
|
||||
return await selfHostedSignupHandler(body);
|
||||
|
||||
Reference in new issue
Block a user