-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
116 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const stripe = require("stripe")(process.env.STRIPE_PRIVATE_KEY); | ||
const HOST = process.env.NEXT_PUBLIC_WEBSITE_URL || "http://localhost:3000"; | ||
export default async function handler(req, res) { | ||
if (req.method === "POST") { | ||
const { email, priceId, bookingInputId } = req.body; | ||
const session = await stripe.checkout.sessions.create({ | ||
line_items: [ | ||
{ | ||
price: priceId, | ||
quantity: 1, | ||
}, | ||
], | ||
customer_email: email, | ||
mode: "payment", | ||
success_url: `${HOST}/create-booking?bookingInputId=${bookingInputId}`, | ||
cancel_url: `${HOST}`, | ||
}); | ||
res.status(200).json({ url: session.url }); | ||
} else { | ||
res.status(405).json({ message: "Method not allowed" }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useRouter } from "next/router"; | ||
import { useEffect } from "react"; | ||
|
||
import { createBooking, mapBookingToMutationInput } from "@calcom/features/bookings/lib"; | ||
|
||
import Spinner from "../ui/spinner"; | ||
|
||
const createBookingUtility = async (bookingInput) => { | ||
const responseData = await createBooking(mapBookingToMutationInput(bookingInput)); | ||
return responseData; | ||
}; | ||
|
||
const CreateBooking = () => { | ||
const router = useRouter(); | ||
const { bookingInputId } = router.query; | ||
useEffect(() => { | ||
const confirmBooking = async () => { | ||
if (bookingInputId) { | ||
const bookingData = JSON.parse(localStorage.getItem(bookingInputId)); | ||
try { | ||
const data = await createBookingUtility(bookingData); | ||
console.log("Booking created:", data); | ||
router.push(`/booking/${data.uid}`); | ||
} catch (error) { | ||
console.error("Error creating booking:", error); | ||
} | ||
} | ||
}; | ||
|
||
confirmBooking(); | ||
}, [bookingInputId]); | ||
|
||
return ( | ||
<main className="flex h-screen items-center justify-center"> | ||
<Spinner label="Confirming your booking..." /> | ||
</main> | ||
); | ||
}; | ||
|
||
export default CreateBooking; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters