-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Checkout and Stripe setup #11
base: main
Are you sure you want to change the base?
Changes from all commits
868ca34
7f64317
be086f7
e87a8f0
ad1dace
a48d8c3
d7eb740
e1333ce
3a94f64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# <img src="public/assets/images/logo.svg" alt="logo" /> | ||
|
||
Build an event organization web app like Eventbrite or Meetup with authentication, event management, search, filtering, categories, checkout, and payments using Next JS 14, Tailwind CSS, Shadcn, React Hook Form, Zod, Uploadthing, React-Datepicker, Mongoose, Clerk, and Stripe. | ||
|
||
`ngrok tunnel --label edge=edghts_2jQbAk4QzC90ArEGm4eYkVIhI1v http://localhost:3000` | ||
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,45 @@ | ||||||||
import React, { useEffect } from "react"; | ||||||||
import { loadStripe } from "@stripe/stripe-js"; | ||||||||
|
||||||||
import { IEvent } from "@/lib/database/models/event.model"; | ||||||||
import { Button } from "../ui/button"; | ||||||||
import { checkoutOrder } from "@/lib/actions/order.actions"; | ||||||||
|
||||||||
loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY!); | ||||||||
|
||||||||
const Checkout = ({ event, userId }: { event: IEvent; userId: string }) => { | ||||||||
useEffect(() => { | ||||||||
const query = new URLSearchParams(window.location.search); | ||||||||
if (query.get("success")) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Consider using a more robust method for order confirmation Using console.log for order confirmation and cancellation may not be ideal in a production environment. Consider implementing a more user-friendly way of communicating the order status, such as displaying a message in the UI.
Suggested change
|
||||||||
console.log("Order placed! You will receive an email confirmation."); | ||||||||
} | ||||||||
|
||||||||
if (query.get("canceled")) { | ||||||||
console.log( | ||||||||
"Order canceled -- continue to shop around and checkout when you’re ready.", | ||||||||
); | ||||||||
} | ||||||||
}, []); | ||||||||
|
||||||||
const onCheckout = async () => { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Consider adding error handling to the onCheckout function Asynchronous operations, especially in checkout processes, should have proper error handling. Consider wrapping the checkoutOrder call in a try-catch block to handle potential errors gracefully. |
||||||||
const order = { | ||||||||
eventTitle: event.title, | ||||||||
eventId: event._id, | ||||||||
price: event.price, | ||||||||
isFree: event.isFree, | ||||||||
buyerId: userId, | ||||||||
}; | ||||||||
|
||||||||
await checkoutOrder(order); | ||||||||
}; | ||||||||
|
||||||||
return ( | ||||||||
<form action={onCheckout} method="post"> | ||||||||
<Button type="submit" role="link" size="lg" className="button sm:w-fit"> | ||||||||
{event.isFree ? "Get Tickets" : "Buy Tickets"} | ||||||||
</Button> | ||||||||
</form> | ||||||||
); | ||||||||
}; | ||||||||
|
||||||||
export default Checkout; |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,29 @@ | ||||||||
"use client"; | ||||||||
|
||||||||
import { SignedIn, SignedOut, useUser } from "@clerk/nextjs"; | ||||||||
import React from "react"; | ||||||||
import { Button } from "../ui/button"; | ||||||||
import Link from "next/link"; | ||||||||
import Checkout from "./Checkout"; | ||||||||
import { IEvent } from "@/lib/database/models/event.model"; | ||||||||
|
||||||||
const CheckoutButton = ({ event }: { event: IEvent }) => { | ||||||||
const { user } = useUser(); | ||||||||
const userId = user?.publicMetadata.userId as string; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Consider adding a comment explaining the use of publicMetadata While using publicMetadata to get the userId is likely intentional, it might be helpful to add a brief comment explaining why this approach is used, for the benefit of other developers who might work on this code in the future.
Suggested change
|
||||||||
|
||||||||
return ( | ||||||||
<div className="flex items-center gap-3"> | ||||||||
<SignedOut> | ||||||||
<Button asChild size="lg" className="button rounded-full"> | ||||||||
<Link href="/sign-in">Get Tickets</Link> | ||||||||
</Button> | ||||||||
</SignedOut> | ||||||||
|
||||||||
<SignedIn> | ||||||||
<Checkout event={event} userId={userId} /> | ||||||||
</SignedIn> | ||||||||
</div> | ||||||||
); | ||||||||
}; | ||||||||
|
||||||||
export default CheckoutButton; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question (documentation): Check if the ngrok label is sensitive.
Please verify if the label
edge=edghts_2jQbAk4QzC90ArEGm4eYkVIhI1v
is sensitive information. If it is, consider removing it or replacing it with a placeholder.