(request: NextRequest)
| 10 | import Stripe from "stripe" |
| 11 | |
| 12 | export async function GET(request: NextRequest) { |
| 13 | const stripeSessionId = request.nextUrl.searchParams.get("stripeSessionId") |
| 14 | if (stripeSessionId == null) redirect("/products/purchase-failure") |
| 15 | |
| 16 | let redirectUrl: string |
| 17 | try { |
| 18 | const checkoutSession = await stripeServerClient.checkout.sessions.retrieve( |
| 19 | stripeSessionId, |
| 20 | { expand: ["line_items"] } |
| 21 | ) |
| 22 | const productId = await processStripeCheckout(checkoutSession) |
| 23 | |
| 24 | redirectUrl = `/products/${productId}/purchase/success` |
| 25 | } catch { |
| 26 | redirectUrl = "/products/purchase-failure" |
| 27 | } |
| 28 | |
| 29 | return NextResponse.redirect(new URL(redirectUrl, request.url)) |
| 30 | } |
| 31 | |
| 32 | export async function POST(request: NextRequest) { |
| 33 | const event = await stripeServerClient.webhooks.constructEvent( |
nothing calls this directly
no test coverage detected