-
Notifications
You must be signed in to change notification settings - Fork 7
feat/e-commerce-stripe-v2 #54
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
95760cb
feat(e-commerce): schema for stripe checkout, wishlist, order timeline
CarmenDou f3bf3f1
fix(e-commerce): non-negative discount check, align policy style, doc…
CarmenDou 8807b7f
feat(e-commerce): replace mock checkout with Stripe Checkout + promo …
CarmenDou aa4ef01
fix(e-commerce): error handling on price lookup, use NEXT_PUBLIC_APP_URL
CarmenDou b8e0437
feat(e-commerce): order timeline + checkout success polling
CarmenDou 5b127fa
fix(e-commerce): clear timers, parallel order fetch, conditional reva…
CarmenDou eedc264
feat(e-commerce): wishlist with optimistic toggle and account page
CarmenDou 1d9ad0c
fix(e-commerce): wider duplicate-key detection, parallelize wishlist …
CarmenDou 54fd824
docs(e-commerce): stripe payments config, promo code caveat, order li…
CarmenDou 9ef000b
docs(e-commerce): align timeline labels and clarify promo code state
CarmenDou 3f97ea7
fix(e-commerce): hoist new RLS to existing cluster and use current_us…
CarmenDou 03bfb17
fix(e-commerce): move click guards inside WishlistButton so ProductCa…
CarmenDou 9250572
fix(e-commerce): fulfill orders via payments.payment_history trigger,…
CarmenDou b40b38f
feat(e-commerce): admin mark-shipped and mark-delivered RPCs with det…
CarmenDou a480652
feat(marketplace): refresh e-commerce listing for stripe, timeline, w…
CarmenDou 871bdfb
fix(e-commerce): address pr review (parallel fetches, wishlist resili…
CarmenDou 539206e
fix(e-commerce): use greatest(0, ...) for trigger inventory decrement…
CarmenDou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,76 @@ | ||
| import Image from 'next/image'; | ||
| import Link from 'next/link'; | ||
| import { AccountHeader } from '@/components/account-header'; | ||
| import { SiteHeader } from '@/components/site-header'; | ||
| import { WishlistButton } from '@/components/wishlist-button'; | ||
| import { requireAuthenticatedSession } from '@/lib/auth-session'; | ||
| import { getWishlistWithProducts } from '@/lib/store'; | ||
| import { Button } from '@/components/ui/button'; | ||
|
|
||
| export const dynamic = 'force-dynamic'; | ||
|
|
||
| export default async function WishlistPage() { | ||
| const { viewer, accessToken } = await requireAuthenticatedSession(); | ||
| const items = await getWishlistWithProducts({ accessToken, userId: viewer.id }); | ||
|
|
||
| return ( | ||
| <div className="min-h-screen"> | ||
| <SiteHeader /> | ||
| <main className="page-shell space-y-8 py-10"> | ||
| <AccountHeader | ||
| activeTab="wishlist" | ||
| description="Products you have saved for later. Tap the heart to remove an item from your list." | ||
| title="Wishlist." | ||
| /> | ||
|
|
||
| <section> | ||
| {items.length === 0 ? ( | ||
| <div className="py-16 text-center"> | ||
| <p className="text-sm text-muted-foreground mb-6"> | ||
| Browse the catalog and tap the heart on anything you want to come back to. | ||
| </p> | ||
| <Button asChild> | ||
| <Link href="/products">Browse products</Link> | ||
| </Button> | ||
| </div> | ||
| ) : ( | ||
| <ul className="grid gap-5 md:grid-cols-2 xl:grid-cols-3"> | ||
| {items.map((item) => ( | ||
| <li key={item.id} className="glass-panel relative overflow-hidden"> | ||
| <div className="absolute right-3 top-3 z-10"> | ||
| <WishlistButton | ||
| productId={item.product_id} | ||
| initialInWishlist | ||
| size="sm" | ||
| /> | ||
| </div> | ||
| <Link href={`/products/${item.product?.slug ?? ''}`} className="block"> | ||
| {item.product?.image_url ? ( | ||
| <div className="relative aspect-[4/5] overflow-hidden rounded-t-[24px] bg-muted/60"> | ||
| <Image | ||
| src={item.product.image_url} | ||
| alt={item.product.image_alt || item.product.name} | ||
| fill | ||
| sizes="(min-width: 1280px) 25vw, (min-width: 768px) 50vw, 100vw" | ||
| className="object-cover" | ||
| /> | ||
| </div> | ||
| ) : null} | ||
| <div className="p-5"> | ||
| <p className="font-display text-2xl leading-none">{item.product?.name}</p> | ||
| {item.product?.short_description ? ( | ||
| <p className="mt-2 text-sm text-muted-foreground line-clamp-2"> | ||
| {item.product.short_description} | ||
| </p> | ||
| ) : null} | ||
| </div> | ||
| </Link> | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| )} | ||
| </section> | ||
| </main> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or 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,111 @@ | ||
| 'use client'; | ||
|
|
||
| import { Suspense, useEffect, useRef, useState } from 'react'; | ||
| import { useRouter, useSearchParams } from 'next/navigation'; | ||
| import { Loader2 } from 'lucide-react'; | ||
| import { pollOrderPaymentAction } from '@/lib/store-actions'; | ||
| import { Button } from '@/components/ui/button'; | ||
|
|
||
| const POLL_INTERVAL_MS = 1500; | ||
| const POLL_TIMEOUT_MS = 30_000; | ||
|
|
||
| function CheckoutSuccessContent() { | ||
| const router = useRouter(); | ||
| const searchParams = useSearchParams(); | ||
| const orderId = searchParams.get('order_id'); | ||
|
|
||
| const [status, setStatus] = useState<'polling' | 'paid' | 'timeout' | 'error'>('polling'); | ||
| const [errorMsg, setErrorMsg] = useState<string | null>(null); | ||
| const redirectTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null); | ||
| const pollTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| if (!orderId) { | ||
| setStatus('error'); | ||
| setErrorMsg('Missing order identifier.'); | ||
| return; | ||
| } | ||
|
|
||
| let cancelled = false; | ||
| const start = Date.now(); | ||
|
|
||
| async function poll() { | ||
| try { | ||
| const result = await pollOrderPaymentAction({ orderId: orderId! }); | ||
| if (cancelled) return; | ||
| if (result.paid) { | ||
| setStatus('paid'); | ||
| redirectTimerRef.current = setTimeout(() => router.replace(`/account/orders/${orderId}`), 600); | ||
| return; | ||
| } | ||
| if (Date.now() - start > POLL_TIMEOUT_MS) { | ||
| setStatus('timeout'); | ||
| return; | ||
| } | ||
| pollTimerRef.current = setTimeout(poll, POLL_INTERVAL_MS); | ||
| } catch (err) { | ||
| if (cancelled) return; | ||
| setStatus('error'); | ||
| setErrorMsg(err instanceof Error ? err.message : 'Unable to confirm payment.'); | ||
| } | ||
| } | ||
|
|
||
| poll(); | ||
| return () => { | ||
| cancelled = true; | ||
| if (pollTimerRef.current) clearTimeout(pollTimerRef.current); | ||
| if (redirectTimerRef.current) clearTimeout(redirectTimerRef.current); | ||
| }; | ||
| }, [orderId, router]); | ||
|
|
||
| return ( | ||
| <main className="mx-auto flex min-h-[60vh] max-w-md flex-col items-center justify-center gap-4 px-6 text-center"> | ||
| {status === 'polling' ? ( | ||
| <> | ||
| <Loader2 className="size-8 animate-spin" /> | ||
| <h1 className="font-display text-2xl">Confirming your payment</h1> | ||
| <p className="text-sm text-muted-foreground"> | ||
| Stripe is letting us know your payment went through. This usually takes a few seconds. | ||
| </p> | ||
| </> | ||
| ) : null} | ||
| {status === 'paid' ? ( | ||
| <> | ||
| <h1 className="font-display text-2xl">Payment confirmed</h1> | ||
| <p className="text-sm text-muted-foreground">Redirecting to your order details.</p> | ||
| </> | ||
| ) : null} | ||
| {status === 'timeout' ? ( | ||
| <> | ||
| <h1 className="font-display text-2xl">Still processing</h1> | ||
| <p className="text-sm text-muted-foreground"> | ||
| Your payment is taking longer than usual. We saved your order. You can refresh this page, or check your account to see the latest status. | ||
| </p> | ||
| <Button onClick={() => router.replace(`/account/orders/${orderId}`)}>View order</Button> | ||
| </> | ||
| ) : null} | ||
| {status === 'error' ? ( | ||
| <> | ||
| <h1 className="font-display text-2xl">Something went wrong</h1> | ||
| <p className="text-sm text-destructive">{errorMsg}</p> | ||
| <Button onClick={() => router.replace('/cart')}>Back to cart</Button> | ||
| </> | ||
| ) : null} | ||
| </main> | ||
| ); | ||
| } | ||
|
|
||
| export default function CheckoutSuccessPage() { | ||
| return ( | ||
| <Suspense | ||
| fallback={ | ||
| <main className="mx-auto flex min-h-[60vh] max-w-md flex-col items-center justify-center gap-4 px-6 text-center"> | ||
| <Loader2 className="size-8 animate-spin" /> | ||
| <p className="text-sm text-muted-foreground">Loading...</p> | ||
| </main> | ||
| } | ||
| > | ||
| <CheckoutSuccessContent /> | ||
| </Suspense> | ||
| ); | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.