#TheDevGod
1 messages ยท Page 1 of 1 (latest)
Have you confirmed that you're actually making a post request to your own server? It looks like your own server responds with a 405 if it doesn't believe it's a post request, so that's the first thing I'd check
Have you actually checked in your server logs and made sure that req.method is POST? I know it says it in the screenshot, but just want to make sure that if/else check is actually doing what you expect
Yes I am restarting my server to double check again
@umbral thistle you are right ๐ - error No HTTP methods exported
this is my api/payment/route.ts file:
import { NextApiResponse, NextApiRequest } from "next";
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
console.log('THIS IS THE METHOD',req.method);
if (req.method === 'POST') {
let data= await req.body;
let priceId = data.priceId
let user = data.userEmail
const session = await stripe.checkout.sessions.create({
line_items: [
{
price: priceId,
quantity: 1,
user
},
],
mode: 'payment',
success_url: ${process.env.HOST}/success,
cancel_url: ${process.env.HOST}/checkout,
})
return res.status(200).json({url: session.url});
} else {
res.setHeader('Allow', ['POST'])
res.status(405).end(Method ${req.method} Not Allowed)
}
}
@umbral thistle am I missing something wrong?
I'm not really a nextjs expert, but looks like you need to be defining something like export async function POST
https://stackoverflow.com/questions/76214029/no-http-methods-exported-in-export-a-named-export-for-each-http-method