I am currently setting up stripe webhooks for my application.
I am having an issue for price updates for prices that are tiered. Currently if I update the price of a tier then no webhook gets triggered for this event.
My webhooks for everything else are working fine, for instance for a price that is just a flat rate, when I update the price the webhook gets triggered.
I have tried to find information on this in the documentation but cannot find anything explicitly referencing this. Does stripe just not emit events for updates in pricing tiers?
I've looked at the documentation and have working test implementation for all the other web hooks relevant for my app.
Please see below for my code:
stripeWebhookRoute.mjs:
import express from "express";
import bodyParser from "body-parser"
import stripePackage from 'stripe'
import { handleStripeWebhooks } from "../services/stripeServices/handleWebhooks.mjs";
const stripe = stripePackage(process.env.STRIPE_API_KEY);
const router = express.Router();
router.post('/webhook', bodyParser.raw({ type: 'application/json' }), async (req, res) => {
let event;
const sig = req.headers['stripe-signature'];
const webHookSecret = process.env.STRIPE_WEBHOOK_KEY;
try {
if (webHookSecret) {
event = stripe.webhooks.constructEvent(req.body, sig, webHookSecret);
}
} catch (error) {
console.error('⚠️ Webhook signature verification failed.', error.message);
return res.status(400).send(`Webhook Error: ${error.message}`);
}
// Acknowledge receipt of the event right away
res.status(200).json({ received: true });
handleStripeWebhooks(event);
})
export default router;
my handleWebHook.mjs file
import { handlePriceUpdate } from "./pricing/handlePricingUpdate.mjs";
/**
*
* @param {*} event a stripe event
* Receives a stripe webhook event and triggers execution logic.
*/
export const handleStripeWebhooks = async(event) => {
switch (event.type) {
case 'price.updated':
console.log("Price updated");
handlePriceUpdate(event);
break;
default:
console.log(`Unhandled event type ${event.type}.`);
}
}
Not sending price.updated
event is expected for changing the amount on tier prices since tiers
property is not included in the Price object by default.
tiers
is an expandable field, i.e. it will only be available upon requesting additional information of this specific property.
For any expandable property which isn't included in the object by default, no update event will be sent.