-
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.
Merge pull request #3 from stcalica/stripe
Stripe
- Loading branch information
Showing
13 changed files
with
1,892 additions
and
3,255 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ node_modules | |
.next | ||
next-env.d.ts | ||
.DS_Store | ||
.env* |
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,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 }); | ||
} | ||
} |
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,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 }); | ||
} | ||
} |
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,8 @@ | ||
import type { NextPage } from "next"; | ||
import { ProductPage } from "@/templates/ProductPage"; | ||
|
||
const Products: NextPage = () => { | ||
return <ProductPage />; | ||
}; | ||
|
||
export default Products; |
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
Oops, something went wrong.