#TheDevGod

1 messages ยท Page 1 of 1 (latest)

alpine moatBOT
umbral thistle
#

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

ruby cedar
#

@umbral thistle yes I am, ๐Ÿค” ,,,, I think

umbral thistle
#

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

ruby cedar
#

Yes I am restarting my server to double check again

ruby cedar
#

@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?

umbral thistle