Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ MEETING_SCHEDULER_URL=
NEXT_PUBLIC_GOOGLE_ANALYTICS_ID=
NEXT_PUBLIC_POSTHOG_KEY=
NEXT_PUBLIC_POSTHOG_HOST=
NEXT_PUBLIC_SNIPCART_KEY=
SENDGRID_API_KEY=
MAILGUN_API_KEY=
MAILGUN_DOMAIN=
STRIPE_SECRET_KEY=sk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@radix-ui/react-tooltip": "^1.0.7",
"@sendgrid/mail": "^8.1.0",
"@types/react-syntax-highlighter": "^15.5.10",
"axios": "^1.15.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"form-data": "^4.0.4",
Expand All @@ -68,9 +69,11 @@
"sonner": "^1.3.1",
"sqlite": "^5.1.1",
"sqlite3": "^5.1.6",
"stripe": "^22.0.2",
"tailwind-merge": "^2.1.0",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.22.4"
"zod": "^3.22.4",
"zustand": "^5.0.12"
},
"devDependencies": {
"@next/bundle-analyzer": "^14.0.4",
Expand All @@ -80,7 +83,7 @@
"@testing-library/react": "^15.0.7",
"@types/jest": "^29.5.11",
"@types/lodash": "^4.17.6",
"@types/node": "^20",
"@types/node": "^20.9.2",
"@types/react": "^18",
"@types/react-dom": "^18",
"autoprefixer": "^10.0.1",
Expand Down
93 changes: 64 additions & 29 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 72 additions & 0 deletions src/app/api/checkout/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { NextResponse } from "next/server";
import { stripe } from "../../../lib/stripe";
import { photoPricing } from "../../../constants/photoPricing";
import { getPhotoName, PhotoIdType } from "../../../utils/cdn/cdnAssets";
import { getBaseUrl } from "../../../utils/getBaseUrl";

export async function POST(req: Request) {
try {
const { items } = await req.json();

if (!items || !Array.isArray(items)) {
return NextResponse.json({ error: "Invalid items" }, { status: 400 });
}

const line_items = items.map((item: { id: string; quantity: number }) => {
// id is photoID__priceID
const parts = item.id.split("__");
if (parts.length < 2) {
throw new Error(`Invalid item ID format: ${item.id}`);
}

const priceID = parts.pop()!;
const photoID = parts.join("__");

const priceVariant = photoPricing.find((p) => p.id === priceID);

if (!priceVariant) {
throw new Error(`Invalid price variant: ${priceID}`);
}

const name = `${getPhotoName(photoID as PhotoIdType)} (${priceVariant.name})`;

return {
price_data: {
currency: "usd",
product_data: {
name: name,
metadata: {
photoID,
priceID,
},
},
unit_amount: Math.round(priceVariant.price * 100), // convert to cents
},
quantity: item.quantity,
};
});

const baseUrl = getBaseUrl();

const session = await stripe.checkout.sessions.create({
payment_method_types: ["card"],
line_items,
mode: "payment",
success_url: `${baseUrl}/success?session_id={CHECKOUT_SESSION_ID}`,
cancel_url: `${baseUrl}/cart`,
// Collect customer email on every order
customer_creation: "always",
// Collect shipping address (US only — physical print fulfillment)
shipping_address_collection: {
allowed_countries: ["US"],
},
// Customer-facing receipts are handled by Stripe
// (enable in Stripe Dashboard → Settings → Emails → Successful payments)
});

return NextResponse.json({ url: session.url });
} catch (error: any) {
console.error("Stripe error:", error);
return NextResponse.json({ error: error.message }, { status: 500 });
}
}
66 changes: 0 additions & 66 deletions src/app/api/product/[photo_id]/pricing.json/route.ts

This file was deleted.

Loading