2021-09-22 18:36:13 +00:00
|
|
|
import { CreditCardIcon } from "@heroicons/react/solid";
|
|
|
|
import { Elements } from "@stripe/react-stripe-js";
|
2022-04-25 04:33:00 +00:00
|
|
|
import classNames from "classnames";
|
2021-09-22 18:36:13 +00:00
|
|
|
import dayjs from "dayjs";
|
|
|
|
import timezone from "dayjs/plugin/timezone";
|
|
|
|
import toArray from "dayjs/plugin/toArray";
|
|
|
|
import utc from "dayjs/plugin/utc";
|
|
|
|
import Head from "next/head";
|
|
|
|
import React, { FC, useEffect, useState } from "react";
|
|
|
|
import { FormattedNumber, IntlProvider } from "react-intl";
|
|
|
|
|
2022-04-25 04:33:00 +00:00
|
|
|
import { sdkActionManager, useIsEmbed } from "@calcom/embed-core";
|
2022-03-09 22:56:05 +00:00
|
|
|
import getStripe from "@calcom/stripe/client";
|
2021-09-22 19:52:38 +00:00
|
|
|
import PaymentComponent from "@ee/components/stripe/Payment";
|
|
|
|
import { PaymentPageProps } from "@ee/pages/payment/[uid]";
|
|
|
|
|
2022-03-17 23:28:43 +00:00
|
|
|
import { useLocale } from "@lib/hooks/useLocale";
|
2021-09-22 19:52:38 +00:00
|
|
|
import useTheme from "@lib/hooks/useTheme";
|
2022-04-14 21:25:24 +00:00
|
|
|
import { LocationOptionsToString } from "@lib/locationOptions";
|
2022-02-23 12:37:15 +00:00
|
|
|
import { isBrowserLocale24h } from "@lib/timeFormat";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2021-09-22 18:36:13 +00:00
|
|
|
dayjs.extend(utc);
|
|
|
|
dayjs.extend(toArray);
|
|
|
|
dayjs.extend(timezone);
|
|
|
|
|
|
|
|
const PaymentPage: FC<PaymentPageProps> = (props) => {
|
2021-10-28 22:58:26 +00:00
|
|
|
const { t } = useLocale();
|
2022-02-23 12:37:15 +00:00
|
|
|
const [is24h, setIs24h] = useState(isBrowserLocale24h());
|
2021-09-22 18:36:13 +00:00
|
|
|
const [date, setDate] = useState(dayjs.utc(props.booking.startTime));
|
2022-02-10 11:07:14 +00:00
|
|
|
const { isReady, Theme } = useTheme(props.profile.theme);
|
2022-04-25 04:33:00 +00:00
|
|
|
const isEmbed = useIsEmbed();
|
2021-09-22 18:36:13 +00:00
|
|
|
useEffect(() => {
|
2022-04-25 04:33:00 +00:00
|
|
|
let embedIframeWidth = 0;
|
2021-09-22 18:36:13 +00:00
|
|
|
setDate(date.tz(localStorage.getItem("timeOption.preferredTimeZone") || dayjs.tz.guess()));
|
|
|
|
setIs24h(!!localStorage.getItem("timeOption.is24hClock"));
|
2022-04-25 04:33:00 +00:00
|
|
|
if (isEmbed) {
|
|
|
|
requestAnimationFrame(function fixStripeIframe() {
|
|
|
|
// HACK: Look for stripe iframe and center position it just above the embed content
|
|
|
|
const stripeIframeWrapper = document.querySelector(
|
|
|
|
'iframe[src*="https://js.stripe.com/v3/authorize-with-url-inner"]'
|
|
|
|
)?.parentElement;
|
|
|
|
if (stripeIframeWrapper) {
|
|
|
|
stripeIframeWrapper.style.margin = "0 auto";
|
|
|
|
stripeIframeWrapper.style.width = embedIframeWidth + "px";
|
|
|
|
}
|
|
|
|
requestAnimationFrame(fixStripeIframe);
|
|
|
|
});
|
|
|
|
sdkActionManager?.on("__dimensionChanged", (e) => {
|
|
|
|
embedIframeWidth = e.detail.data.iframeWidth as number;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, [isEmbed]);
|
2021-09-22 18:36:13 +00:00
|
|
|
|
|
|
|
const eventName = props.booking.title;
|
|
|
|
|
|
|
|
return isReady ? (
|
2022-04-25 04:33:00 +00:00
|
|
|
<div className="h-screen">
|
2022-02-10 11:07:14 +00:00
|
|
|
<Theme />
|
2021-09-22 18:36:13 +00:00
|
|
|
<Head>
|
2021-10-28 22:58:26 +00:00
|
|
|
<title>
|
|
|
|
{t("payment")} | {eventName} | Cal.com
|
|
|
|
</title>
|
2021-09-22 18:36:13 +00:00
|
|
|
<link rel="icon" href="/favicon.ico" />
|
|
|
|
</Head>
|
2022-02-09 00:05:13 +00:00
|
|
|
<main className="mx-auto max-w-3xl py-24">
|
2022-03-17 23:28:43 +00:00
|
|
|
<div className="fixed inset-0 z-50 overflow-y-auto">
|
|
|
|
<div className="flex min-h-screen items-end justify-center px-4 pt-4 pb-20 text-center sm:block sm:p-0">
|
|
|
|
<div className="fixed inset-0 my-4 transition-opacity sm:my-0" aria-hidden="true">
|
|
|
|
<span className="hidden sm:inline-block sm:h-screen sm:align-middle" aria-hidden="true">
|
|
|
|
​
|
|
|
|
</span>
|
|
|
|
<div
|
2022-04-25 04:33:00 +00:00
|
|
|
className={classNames(
|
|
|
|
"main inline-block transform overflow-hidden rounded-lg border border-neutral-200 bg-white px-8 pt-5 pb-4 text-left align-bottom transition-all dark:border-neutral-700 dark:bg-gray-800 sm:w-full sm:max-w-lg sm:py-6 sm:align-middle",
|
|
|
|
isEmbed ? "" : "sm:my-8"
|
|
|
|
)}
|
2022-03-17 23:28:43 +00:00
|
|
|
role="dialog"
|
|
|
|
aria-modal="true"
|
|
|
|
aria-labelledby="modal-headline">
|
|
|
|
<div>
|
|
|
|
<div className="mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-green-100">
|
|
|
|
<CreditCardIcon className="h-8 w-8 text-green-600" />
|
|
|
|
</div>
|
2022-04-14 21:25:24 +00:00
|
|
|
|
2022-03-17 23:28:43 +00:00
|
|
|
<div className="mt-3 text-center sm:mt-5">
|
|
|
|
<h3
|
|
|
|
className="text-2xl font-semibold leading-6 text-neutral-900 dark:text-white"
|
|
|
|
id="modal-headline">
|
|
|
|
{t("payment")}
|
|
|
|
</h3>
|
|
|
|
<div className="mt-3">
|
|
|
|
<p className="text-sm text-neutral-600 dark:text-gray-300">
|
|
|
|
{t("pay_later_instructions")}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div className="mt-4 grid grid-cols-3 border-t border-b py-4 text-left text-gray-700 dark:border-gray-900 dark:text-gray-300">
|
|
|
|
<div className="font-medium">{t("what")}</div>
|
|
|
|
<div className="col-span-2 mb-6">{eventName}</div>
|
|
|
|
<div className="font-medium">{t("when")}</div>
|
|
|
|
<div className="col-span-2 mb-6">
|
|
|
|
{date.format("dddd, DD MMMM YYYY")}
|
|
|
|
<br />
|
|
|
|
{date.format(is24h ? "H:mm" : "h:mma")} - {props.eventType.length} mins{" "}
|
|
|
|
<span className="text-gray-500">
|
|
|
|
({localStorage.getItem("timeOption.preferredTimeZone") || dayjs.tz.guess()})
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
{props.booking.location && (
|
|
|
|
<>
|
|
|
|
<div className="font-medium">{t("where")}</div>
|
2022-04-14 21:25:24 +00:00
|
|
|
<div className="col-span-2 mb-6">
|
|
|
|
{LocationOptionsToString(props.booking.location, t)}
|
|
|
|
</div>
|
2022-03-17 23:28:43 +00:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
<div className="font-medium">{t("price")}</div>
|
|
|
|
<div className="col-span-2 mb-6">
|
|
|
|
<IntlProvider locale="en">
|
|
|
|
<FormattedNumber
|
|
|
|
value={props.eventType.price / 100.0}
|
|
|
|
style="currency"
|
|
|
|
currency={props.eventType.currency.toUpperCase()}
|
|
|
|
/>
|
|
|
|
</IntlProvider>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-03-17 13:20:49 +00:00
|
|
|
</div>
|
2022-03-17 23:28:43 +00:00
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
{props.payment.success && !props.payment.refunded && (
|
|
|
|
<div className="mt-4 text-center text-gray-700 dark:text-gray-300">{t("paid")}</div>
|
2021-09-22 18:36:13 +00:00
|
|
|
)}
|
2022-03-17 23:28:43 +00:00
|
|
|
{!props.payment.success && (
|
|
|
|
<Elements stripe={getStripe(props.payment.data.stripe_publishable_key)}>
|
|
|
|
<PaymentComponent
|
|
|
|
payment={props.payment}
|
|
|
|
eventType={props.eventType}
|
|
|
|
user={props.user}
|
|
|
|
location={props.booking.location}
|
2021-09-22 18:36:13 +00:00
|
|
|
/>
|
2022-03-17 23:28:43 +00:00
|
|
|
</Elements>
|
|
|
|
)}
|
|
|
|
{props.payment.refunded && (
|
|
|
|
<div className="mt-4 text-center text-gray-700 dark:text-gray-300">{t("refunded")}</div>
|
|
|
|
)}
|
2022-03-17 13:20:49 +00:00
|
|
|
</div>
|
2022-03-17 23:28:43 +00:00
|
|
|
{!props.profile.hideBranding && (
|
|
|
|
<div className="mt-4 border-t pt-4 text-center text-xs text-gray-400 dark:border-gray-900 dark:text-white">
|
|
|
|
<a href="https://cal.com/signup">{t("create_booking_link_with_calcom")}</a>
|
|
|
|
</div>
|
2022-03-17 13:20:49 +00:00
|
|
|
)}
|
|
|
|
</div>
|
2021-09-22 18:36:13 +00:00
|
|
|
</div>
|
2022-03-17 23:28:43 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-09-22 18:36:13 +00:00
|
|
|
</main>
|
|
|
|
</div>
|
|
|
|
) : null;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default PaymentPage;
|