Skip to content

Commit

Permalink
Merge pull request #3 from stcalica/stripe
Browse files Browse the repository at this point in the history
Stripe
  • Loading branch information
stcalica authored Aug 4, 2024
2 parents e2cac03 + e7b11ee commit e731160
Show file tree
Hide file tree
Showing 13 changed files with 1,892 additions and 3,255 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
.next
next-env.d.ts
.DS_Store
.env*
47 changes: 47 additions & 0 deletions app/api/checkout_sessions/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { NextRequest, NextResponse } from 'next/server';
import Stripe from 'stripe';

const stripe = new Stripe(process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY!);

export async function POST(req: NextRequest) {

const resp = await req.json();

try {

const data = JSON.parse(resp.body)
const priceId = data.priceId

const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: [
{
price: priceId,
quantity: 1,
adjustable_quantity: {
enabled: true,
minimum: 1,
maximum: 999
}
},
],
mode: 'payment',
success_url: `${process.env.HOST}/products/success`,
cancel_url: `${process.env.HOST}/products/canceled`,
custom_fields: [
{
key: "troop_number",
label: {
type: "custom",
custom: "Troop Number"
},
type: "text"
}
]
});

return NextResponse.json({ session: session, ok: true });
} catch (err: any) {
return NextResponse.json({ error: err.message, ok: false }, { status: 500 });
}
}
13 changes: 13 additions & 0 deletions app/api/products/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NextRequest, NextResponse } from 'next/server';
import Stripe from 'stripe';

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);

export async function GET() {
try {
const products = await stripe.products.list({ limit: 10 });
return NextResponse.json(products.data);
} catch (error: any) {
return NextResponse.json({ error: error.message });
}
}
8 changes: 8 additions & 0 deletions app/products/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { NextPage } from "next";
import { ProductPage } from "@/templates/ProductPage";

const Products: NextPage = () => {
return <ProductPage />;
};

export default Products;
10 changes: 10 additions & 0 deletions constants/navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export const navigation = [
id: "5",
title: "Contact Us",
url: "/contact-us",
},
{
id: "6",
title: "T-Shirts",
url: "/products"
}
];

Expand Down Expand Up @@ -96,6 +101,11 @@ export const menu = [
id: "5",
title: "Forms",
url: "/forms",
},
{
id: "6",
title: "T-Shirts",
url: "/tshirts"
}
],
},
Expand Down
20 changes: 18 additions & 2 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,26 @@ const isProd = process.env.NODE_ENV === 'production';

const nextConfig = {
// Enables static exports
output: "export",
//output: "export",
reactStrictMode: true,
images: {
unoptimized: true // Disable Image Optimization
unoptimized: true, // Disable Image Optimization
domains: ["files.stripe.com"],

},
async headers() {
return [
{
source: "/:path*",
headers: [
{ key: "Access-Control-Allow-Credentials", value: "true" },
{ key: "Access-Control-Allow-Origin", value: "*" },
{ key: "Access-Control-Allow-Methods", value: "GET,DELETE,PATCH,POST,PUT" },
{ key: "Access-Control-Allow-Headers", value: "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version" },
{ key: "Access-Control-Max-Age", value: "1800" }
]
}
]
}

// Conditionally set basePath and assetPrefix for GitHub Pages in production
Expand Down
Loading

0 comments on commit e731160

Please sign in to comment.