Good Day,
We have “fully” integrated Stripe into our website, but I’m having trouble with webhook events coming from Stripe. I would like to run functions based on a successful Payment Intent or a Subscription is expired/cancelled.
I have scoured YouTube, Google, and this Forum for any information and can’t see to find someone who has done this. Does anyone know of a link or video of someone getting this to work? I’ve watched and read the forum posts on webhooks already and attempted to get it to work, but no success.
Here is my code and information, if someone wants to help:
webhook endpoint entered on Stripe - https://[mysite]/_functions/webhook
import { printToConsole } from 'backend/payStripe';
import Stripe from 'stripe';
const stripe = new Stripe('[my_secret_key]');
const endpointSecret = '[my_webhook_secret_key]';
export function webhook(request, response) {
const sig = request.headers['stripe-signature'];
let event;
try {
event = stripe.webhooks.constructEvent(request.body, sig, endpointSecret);
} catch (err) {
response.status(400).send(`Webhook Error: ${err.message}`);
return;
}
// Handle the event
if(event.type === 'payment_intent.succeeded') {
const paymentIntent = event.data.object;
printToConsole(paymentIntent);
}
else {
printToConsole(`Unhandled event type ${event.type}`);
}
response.send();
}
Response according to Stripe:
404 ERR