nextjs-subscription-payments
nextjs-subscription-payments copied to clipboard
No signatures found matching the expected signature for payload
I followed the Readme step by step multiple times and tried test and production. It was never able to connect to Stripe.
No subscription pricing plans found.
Here is the error/warning in the Vercel Logs:
Function /api/webhooks
❌ Error message: No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe?
Learn more about webhook signing and explore webhook integration examples for various frameworks at https://github.com/stripe/stripe-node#webhook-signing
I changed the code to const sig = req.headers.get('stripe-signature');
The warning message is gone, however, it still says No subscription pricing plans found.
I'm facing the same issue
Spent all day reading old threads and attempting the recommended fixes, no luck. Has anyone resolved this error?
@thorwebdev @leerob any insight?
@thorwebdev ? ^
My issue was that i was using the incorrect secret
For me, when I pasted the key on vercel, it added a new line, which caused the error. I removed the new line, and the error was fixed.
This worked for me . change headers().get'Stripe-Signature') line to
const sig = req.headers.get('stripe-signature') as string;
I've opened a PR for it. Please approve @thorwebdev https://github.com/vercel/nextjs-subscription-payments/pull/242
the pr seems to have been committed to main, and im updated to the most recent push; however, im still facing this exact issue, even with const sig = req.headers.get('stripe-signature') as string;
in the app/webhooks/route.ts
Stripe example how to use with NextJS: https://github.com/stripe/stripe-node/blob/master/examples/webhook-signing/nextjs/pages/api/webhooks.ts
import {NextApiRequest, NextApiResponse} from 'next';
const handler = async (
req: NextApiRequest,
res: NextApiResponse
): Promise<void> => {
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
const webhookSecret: string = process.env.STRIPE_WEBHOOK_SECRET;
if (req.method === 'POST') {
const sig = req.headers['stripe-signature'];
let event: Stripe.Event;
try {
const body = await buffer(req);
event = stripe.webhooks.constructEvent(body, sig, webhookSecret);
} catch (err) {
// On error, log and return the error message
console.log(`❌ Error message: ${err.message}`);
res.status(400).send(`Webhook Error: ${err.message}`);
return;
}
// Successfully constructed event
console.log('✅ Success:', event.id);
// Cast event data to Stripe object
if (event.type === 'payment_intent.succeeded') {
const stripeObject: Stripe.PaymentIntent = event.data
.object as Stripe.PaymentIntent;
console.log(`💰 PaymentIntent status: ${stripeObject.status}`);
} else if (event.type === 'charge.succeeded') {
const charge = event.data.object as Stripe.Charge;
console.log(`💵 Charge id: ${charge.id}`);
} else {
console.warn(`🤷♀️ Unhandled event type: ${event.type}`);
}
// Return a response to acknowledge receipt of the event
res.json({received: true});
} else {
res.setHeader('Allow', 'POST');
res.status(405).end('Method Not Allowed');
}
};
export const config = {
api: {
bodyParser: false,
},
};
const buffer = (req: NextApiRequest) => {
return new Promise<Buffer>((resolve, reject) => {
const chunks: Buffer[] = [];
req.on('data', (chunk: Buffer) => {
chunks.push(chunk);
});
req.on('end', () => {
resolve(Buffer.concat(chunks));
});
req.on('error', reject);
});
};
export default handler;```
Double-check the secret in your env, it should be this one: