feat: redirect after booking: option to forward parameters (#14235)
* feat: redirect after booking: option to forward parameters * fix: unit test * fix: stripe passing its own params * fix: manually add stripe params --------- Co-authored-by: Joe Au-Yeung <[email protected]> Co-authored-by: Udit Takkar <[email protected]>
This commit is contained in:
16 files changed
+60
-26
No files matched your search
@@ -163,6 +163,10 @@ export const useBookings = ({ event, hashedLink, bookingForm, metadata }: IUseBo
|
||||
successRedirectUrl: event?.data?.successRedirectUrl || "",
|
||||
query,
|
||||
booking: responseData,
|
||||
forwardParamsSuccessRedirect:
|
||||
event?.data?.forwardParamsSuccessRedirect === undefined
|
||||
? true
|
||||
: event?.data?.forwardParamsSuccessRedirect,
|
||||
});
|
||||
},
|
||||
onError: (err, _, ctx) => {
|
||||
@@ -212,6 +216,10 @@ export const useBookings = ({ event, hashedLink, bookingForm, metadata }: IUseBo
|
||||
successRedirectUrl: event?.data?.successRedirectUrl || "",
|
||||
query,
|
||||
booking,
|
||||
forwardParamsSuccessRedirect:
|
||||
event?.data?.forwardParamsSuccessRedirect === undefined
|
||||
? true
|
||||
: event?.data?.forwardParamsSuccessRedirect,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -7,8 +7,7 @@ import type { SyntheticEvent } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import getStripe from "@calcom/app-store/stripepayment/lib/client";
|
||||
import { getBookingRedirectExtraParams, useBookingSuccessRedirect } from "@calcom/lib/bookingSuccessRedirect";
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import { useBookingSuccessRedirect } from "@calcom/lib/bookingSuccessRedirect";
|
||||
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { Button, CheckboxField } from "@calcom/ui";
|
||||
@@ -22,6 +21,7 @@ type Props = {
|
||||
eventType: {
|
||||
id: number;
|
||||
successRedirectUrl: EventType["successRedirectUrl"];
|
||||
forwardParamsSuccessRedirect: EventType["forwardParamsSuccessRedirect"];
|
||||
};
|
||||
user: {
|
||||
username: string | null;
|
||||
@@ -46,24 +46,6 @@ type States =
|
||||
status: "ok";
|
||||
};
|
||||
|
||||
const getReturnUrl = (props: Props) => {
|
||||
if (!props.eventType.successRedirectUrl) {
|
||||
return `${WEBAPP_URL}/booking/${props.booking.uid}`;
|
||||
}
|
||||
|
||||
const returnUrl = new URL(props.eventType.successRedirectUrl);
|
||||
const queryParams = getBookingRedirectExtraParams(props.booking);
|
||||
|
||||
Object.entries(queryParams).forEach(([key, value]) => {
|
||||
if (value === null || value === undefined) {
|
||||
return;
|
||||
}
|
||||
returnUrl.searchParams.append(key, String(value));
|
||||
});
|
||||
|
||||
return returnUrl.toString();
|
||||
};
|
||||
|
||||
const PaymentForm = (props: Props) => {
|
||||
const {
|
||||
user: { username },
|
||||
@@ -96,6 +78,9 @@ const PaymentForm = (props: Props) => {
|
||||
uid: string;
|
||||
email: string | null;
|
||||
location?: string;
|
||||
payment_intent?: string;
|
||||
payment_intent_client_secret?: string;
|
||||
redirect_status?: string;
|
||||
} = {
|
||||
uid: props.booking.uid,
|
||||
email: searchParams?.get("email"),
|
||||
@@ -103,17 +88,23 @@ const PaymentForm = (props: Props) => {
|
||||
if (paymentOption === "HOLD" && "setupIntent" in props.payment.data) {
|
||||
payload = await stripe.confirmSetup({
|
||||
elements,
|
||||
confirmParams: {
|
||||
return_url: getReturnUrl(props),
|
||||
},
|
||||
redirect: "if_required",
|
||||
});
|
||||
if (payload.setupIntent) {
|
||||
params.payment_intent = payload.setupIntent.id;
|
||||
params.payment_intent_client_secret = payload.setupIntent.client_secret || undefined;
|
||||
params.redirect_status = payload.setupIntent.status;
|
||||
}
|
||||
} else if (paymentOption === "ON_BOOKING") {
|
||||
payload = await stripe.confirmPayment({
|
||||
elements,
|
||||
confirmParams: {
|
||||
return_url: getReturnUrl(props),
|
||||
},
|
||||
redirect: "if_required",
|
||||
});
|
||||
if (payload.paymentIntent) {
|
||||
params.payment_intent = payload.paymentIntent.id;
|
||||
params.payment_intent_client_secret = payload.paymentIntent.client_secret || undefined;
|
||||
params.redirect_status = payload.paymentIntent.status;
|
||||
}
|
||||
}
|
||||
|
||||
if (payload?.error) {
|
||||
@@ -134,6 +125,7 @@ const PaymentForm = (props: Props) => {
|
||||
successRedirectUrl: props.eventType.successRedirectUrl,
|
||||
query: params,
|
||||
booking: props.booking,
|
||||
forwardParamsSuccessRedirect: props.eventType.forwardParamsSuccessRedirect,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -79,6 +79,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||
price: true,
|
||||
currency: true,
|
||||
successRedirectUrl: true,
|
||||
forwardParamsSuccessRedirect: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -92,6 +92,7 @@ const publicEventSelect = Prisma.validator<Prisma.EventTypeSelect>()({
|
||||
},
|
||||
},
|
||||
successRedirectUrl: true,
|
||||
forwardParamsSuccessRedirect: true,
|
||||
workflows: {
|
||||
include: {
|
||||
workflow: {
|
||||
|
||||
@@ -102,5 +102,6 @@ export type FormValues = {
|
||||
users: EventTypeSetup["users"];
|
||||
assignAllTeamMembers: boolean;
|
||||
useEventTypeDestinationCalendarEmail: boolean;
|
||||
forwardParamsSuccessRedirect: boolean | null;
|
||||
secondaryEmailId?: number;
|
||||
};
|
||||
Reference in new issue
Block a user