ANYBODY KNOW? CAN YOU HELP ME FIX THIS ERROR WITH STRIPE PAYMENT METHOD? #389
douglasmarianodev
started this conversation in
General
Replies: 1 comment
-
@douglasmarianodev with app based routing instead of pages you can't call req.method === instead you need to name the methods, in this case export async function POST(request: NextRequest) {
} Use NextRequest or Request NOT NextApiRequest |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
`
import { NextApiRequest, NextApiResponse } from 'next';
import Stripe from 'stripe';
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY as string,{
apiVersion: '2023-10-16',
})
export default async(req: NextApiRequest, res:NextApiResponse) => {
if (req.method === 'POST') {
try {
const session = await stripe.checkout.sessions.create({
line_items: [
{
price: 'price_1NxCcxLr6KnvPPSp5AK2e87N',
quantity: 1,
},
],
mode: 'subscription',
success_url:
${req.headers.origin}/?success=true
,cancel_url:
${req.headers.origin}/?canceled=true
,});
return res.redirect(303, session.url as string)
} catch (err) {
return res.send({ message: 'error' })
}
} else {
return res.send({ message: 'error' })
}
}
`
the error that appears is: ⨯ No HTTP methods exported /app/api/stripe/route.ts'. Export a named export for each HTTP method.
HTTP ERROR 405.
Beta Was this translation helpful? Give feedback.
All reactions