#drewzoviek_webhooks
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1420168194534146199
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi there,
can you give me a bit more context? What exactly are you doing, what are you expecting to happen and what happens instead? Especially when you say "nothing is happening", what exactly do you mean?
So my react project website. Users can create their listings and have feature credits to use. Everytime it comes to the billing end the subscription should repeat, keeping the user's listings and resetting the feature credits again. When a user cancels their subscription, I have it set to the end of the cycle. When cancellation is final, the user's listings should be archived and feature credits not resetted but trashed.
I tried getting a test subscription. It links to the user's account but when i cancel via the stripe 'Subscriptions' page, nothing is happening to the user's listings or feature credits
Basically, I think Stripe and my Project is not connected properly when it comes to cancellations because there's no update in my backend when subscriptions are cancelled, hence nothing else is happening as expected
Hi solanum! Been a while. Was really grateful for your help last time
hello! fyi i am taking over this thread. do you have a webhook set up to handle stripe events yet? we have a full guide on handling cancellation here
https://docs.stripe.com/billing/subscriptions/cancel#events
oh hello!!
I tried, and I'm not sure why it's not working. When cancellations take place, nothings updating on my end. If that's the guide I'm missing, I'll try it out again.
i would start with this guide if you haven't already:
https://docs.stripe.com/webhooks
I want it to cancel the user's subscription at the end of the billing, no refunds. Are those links the right place?
this will show you how to set up webhooks to handle events. then you just need to handle the event customer.subscription.deleted
I'll try that. Thank you Solanum
yep of course! let me know if you need any more help as you work through it
I'll keep you updated. Should be less than half an hour
Bro so my stripe account just got closed and stripe is saying they'll withhold the money. Isn't that illegal under us law
@glossy owl please read the rules in #help , the server is for developer questions only. for questions like this please chat with our support team
My email to them from 24 hours ago still isnt responded to
Ok, so I got some stuff moving. I made a button in my application which supposedly cancels subscription. It's pushing properly and actually saying in Stripe subscription that it will cancel 'Oct 23'. But then my project still says 'active' when i push cancel via Stripe
bro get out of my stuff
stop responding in this thread, each thread is for the person asking the question only. i won't be able to help you out with your question here
go get your own thread
Solanum, im trying to explain it to you as clear as possible. If you need any more details please let me know
did you follow the guide i sent earlier about setting up webhook handlers? if so have you set up a listener and is it listening for the customer.subscription.deleted event?
I do have a listener called 'customer.subscription.deleted' in my backend system
is your server running locally? if so you'll also need to use the stripe CLI to set up event forwarding
https://docs.stripe.com/webhooks#local-listener
i would set up logging in your webhook handler to just log something every time the endpoint is called, and then you can set up additional logging around how you're actually handling the specific event type
It is running locally
ok cool, have you set up the stripe CLI yet and gone through that section i linked to?
on it
I don't understand solanum. It's listening properly but my project isnt updating
is your webhook being called and have you set up logging to verify that?
are you using a node.js backend?
the example on our docs looks like this, does yours look similiar?
const express = require('express');
const app = express();
// Match the raw body to content type application/json
// If you are using Express v4 - v4.16 you need to use body-parser, not express, to retrieve the request body
// Replace this endpoint secret with your unique endpoint secret key
// If you're testing with the CLI, run 'stripe listen' to find the secret key
// # If you defined your endpoint using the API or the Dashboard, check your webhook settings for your endpoint secret: https://dashboard.stripe.com/webhooks
const endpointSecret = 'whsec_...';
app.post('/webhook', express.json({type: 'application/json'}), (request, response) => {
const event = request.body;
if (endpointSecret) {
// Get the signature sent by Stripe
const signature = request.headers['stripe-signature'];
try {
event = stripe.webhooks.constructEvent(
request.body,
signature,
endpointSecret
);
} catch (err) {
console.log(`โ ๏ธ Webhook signature verification failed.`, err.message);
return response.sendStatus(400);
}
// Handle the event
switch (event.type) {
case 'customer.subscription.deleted':
const paymentIntent = event.data.object;
// Then define and call a method to handle the successful payment intent.
// handlePaymentIntentSucceeded(paymentIntent);
break;
default:
console.log(`Unhandled event type ${event.type}`);
}
// Return a response to acknowledge receipt of the event
response.json({received: true});
});
app.listen(4242, () => console.log('Running on port 4242'));```
if so can you add a simple console.log("webhook called!") type line on the next line after the app.post line?
comparing now
Your docs use express.json() which parses the body into a JavaScript object
My implementation uses express.raw() which keeps the body as a raw Buffer
does that make a difference
for our purposes that should be fine! that might have implications if you're running into signature verification issues, but i'm not even sure if your webhook is being called
so can you add the log line i suggested above and try again, then tell me if you're getting any logs?
just create and delete a subscription
I'll add the log right after their app.post definitions
Will do it now
adding the consolelog
you can also try curl -X POST localhost:5000/webhook real quick to see if anything happens
i would expect a signature verification error
So far i dont see any console logs creating and deleting the subscription, let me try that too
obviously if your URL is different you'll need to change it
is this the culprit HTTP/1.1 400 Bad Request
that could be fine, again that might indicate that you're having signature verification issues. did you see the "webhook called!" i asked you to add?
Negative, i checked the web console
can you share your webhook handler code real quick?
ummm
[0] [Webhook] BYPASSING signature verification for development
[0] [Webhook] Parsed event from raw body: customer.subscription.deleted
[0] [Webhook] Received event: customer.subscription.deleted
ok cool! was that from a subscription deletion?
or from you calling the endpoint with cURL
ok, that at least means that your webhook endpoint is doing something, so the issue is probably with how your CLI forwarding is set up. i would run through the steps in this doc again very carefully and make sure you're doing everything properly
https://docs.stripe.com/webhooks#test-webhook
when you run the CLI command does it look kinda like this?
stripe listen --forward-to localhost:5000/webhook
In this app the active endpoints are http://localhost:5000/api/webhook and http://localhost:5000/stripe/webhook (not /webhook).
ok, and you're forwarding to those using the CLI?
can you share your webhook handler code where you added the logging?
is this it?
// Handle Stripe webhooks
async function handleStripeWebhook(req, res) {
const sig = req.headers['stripe-signature'];
let event;
// Temporary bypass for debugging - remove in production
if (process.env.NODE_ENV === 'development' && process.env.STRIPE_WEBHOOK_SECRET === 'whsec_test_webhook_secret_here') {
console.log('[Webhook] BYPASSING signature verification for development');
try {
const rawBody = Buffer.isBuffer(req.body)
? req.body.toString('utf8')
: (typeof req.body === 'string' ? req.body : JSON.stringify(req.body));
event = JSON.parse(rawBody);
console.log('[Webhook] Parsed event from raw body:', event.type);
} catch (err) {
console.error('[Webhook] Failed to parse webhook body:', err.message);
return res.status(400).send(Webhook Error: ${err.message});
}
} else {
try {
event = stripe.webhooks.constructEvent(req.body, sig, process.env.STRIPE_WEBHOOK_SECRET);
} catch (err) {
console.error('[Webhook] Stripe signature verification failed:', err.message);
return res.status(400).send(Webhook Error: ${err.message});
}
}
console.log('[Webhook] Received event:', event.type);
if (event.type.startsWith('customer.subscription')) {
console.log('[Webhook] Subscription event:', JSON.stringify(event, null, 2));
}
// ...existing switch(event.type) with cancellation handling...
}
sorry
app.post('/api/webhook', express.raw({ type: 'application/json' }), (req, res, next) => {
console.log('webhook called!');
console.log('[WEBHOOK DEBUG] Received webhook request');
console.log('[WEBHOOK DEBUG] Headers:', JSON.stringify(req.headers, null, 2));
console.log('[WEBHOOK DEBUG] Body length:', req.body ? req.body.length : 'no body');
next();
}, handleStripeWebhook);
// Also support '/stripe/webhook' for compatibility
app.post('/stripe/webhook', express.raw({ type: 'application/json' }), (req, res, next) => {
console.log('webhook called!');
next();
}, handleStripeWebhook);
FYI it makes code much easier to read if you wrap it in triple `
so i'm assuming you've tried stripe listen --forward-to localhost:5000/api/webhook?
it's not working
Let me check something
Solanum
I just realized Stripe CLI wasn't installed
but how was I able to connect stripe subscriptions and payments to my react project?
hello! taking over from solanum! can you share what you mean by "connect stripe subscriptions and payments to your react project"?
Hi Alex, glad to have you here
So I have stripe hooked up so that when payment goes through my react project grants the user data subscription and coins
When I cancel a user's test subscription via stripe, it's not updating my user's backend information
alright, and I believe you're getting your webhook endpoint set up to listen for the relevant events to process it? Have you gotten your CLI up and running yet and is your localhost successfully receiving the webhook events?
I just activated the CLI, didn't know about that until now
Testing to see if the webhook listens
okay, let me know if you're running into issues as you work through it
roger
I can't seem to find the backend log
I'm expecting a 'webhook called!' but theres none
can you share the event id which you expected to be received / sent to your webhook endpoint? it'll have the prefix evt_
getting it
I can't find it alex
does this help?
A newer version of the Stripe CLI is available, please update to: v1.30.0
Setting up fixture for: customer
Running fixture for: customer
Setting up fixture for: product
Running fixture for: product
Setting up fixture for: price
Running fixture for: price
Setting up fixture for: subscription
Running fixture for: subscription
Setting up fixture for: subscription_deleted
Running fixture for: subscription_deleted
Trigger succeeded! Check dashboard for event details.
I trigger customer.subscription.deleted
did you run stripe listen --forward-to commands which we mentioned previously to your endpoints on a separate terminal window?
ran it in a separate terminal and itโs currently forwarding to my webhook.
okay, in that window it should list the event ids when you trigger events from another window?
I'm not too familiar with that
what do you see in the window where you ran stripe listen --forward-to can you share a screenshot?
I'm sorry if im not being helpful, its my first ever project so im still learning
Let me get that for you
my laptops overheating just a moment
i get the signing secret ket?
A newer version of the Stripe CLI is available, please update to: v1.30.0
Ready! You are using Stripe API Version [2025-01-27.acacia]. Your webhook signing secret is
ah no, redact (don't show) the signing key. What I wanted to mention is that if you trigger a webhook in terminal window A, then you should see in terminal window B that events are being forwarded to your webhook endpoint, assuming it's all working as expected. Gimme a second to give you a screenshot of how it looks like in mine
this is an example, ignore the error cause I didn't actually set up my endpoint here that's why it's unable to post the webhook event
Hold on Alex, that looks familiar.
Isn't that what it looks like whe you start up the stripe front end and backend?
I have a vivid memory from a tutorial I watched on youtube about a year ago
Unfortunately I don't have that
do you at least see the corresponding events being sent on the terminal window, when you trigger the events on another terminal window?
I'm on a react project, I'm not sure how id do that
but yes
I did see both of those messages in the same termianl
cd backend/stripe-cli; .\stripe.exe listen --forward-to http://localhost:3001/webhook/stripe
A newer version of the Stripe CLI is available, please update to: v1.30.0
Ready! You are using Stripe API Version [2025-01-27.acacia]. Your webhook signing secret is
can you maybe share a screenshot of how you're running both commands? remember to redact (cover) the webhook secret before sharing your screenshot
I have seen the trigger succeeded as well
getting that now
here
is that what you're looking for?
@glacial moth @wanton lantern ?
yep, that's what I'm looking for!
Now leave the left terminal alone, it's ready and listening now. And if you now trigger a webhook on the right terminal again, does anything happen on the left terminal?
getting errors
2025-09-23 20:57:49 --> charge.succeeded [evt_3SAh1iRvfEABTXBO0QotBeE2]
2025-09-23 20:57:49 --> payment_intent.succeeded [evt_3SAh1iRvfEABTXBO0sOSzQ5W]
2025-09-23 20:57:50 --> payment_intent.created [evt_3SAh1iRvfEABTXBO0Wt5gHjm]
2025-09-23 20:57:52 [ERROR] Failed to POST: Post "http://localhost:3001/webhook/stripe": dial tcp [::1]:3001: connectex: No connection could be made because the target machine actively refused it.
2025-09-23 20:57:52 [ERROR] Failed to POST: Post "http://localhost:3001/webhook/stripe": dial tcp [::1]:3001: connectex: No connection could be made because the target machine actively refused it.
2025-09-23 20:57:52 --> charge.updated [evt_3SAh1iRvfEABTXBO0cezocqN]
2025-09-23 20:57:52 [ERROR] Failed to POST: Post "http://localhost:3001/webhook/stripe": dial tcp [::1]:3001: connectex: No connection could be made because the target machine actively refused it.
2025-09-23 20:57:54 [ERROR] Fai
okay so yep, ^ is what i was expecting to see in that the CLI should be attempting to deliver events to the defined endpoint
about the error, are you sure that your webhook endpoint is listening on 3001?
then it shouldn't be http://localhost:3001/webhook/stripe and should probably be http://localhost:3000/webhook/stripe
Let me get that restarted
2025-09-23 21:04:07 --> customer.subscription.deleted [evt_1SAh7oRvfEABTXBOHBpTXSvR]
2025-09-23 21:04:08 <-- [200] POST http://localhost:5000/api/webhook [evt_1SAh7oRvfEABTXBO3peUOr5K]
2025-09-23 21:04:09 <-- [200] POST http://localhost:5000/api/webhook [evt_1SAh7oRvfEABTXBOHBpTXSvR]
2025-09-23 21:04:07 --> customer.subscription.deleted [evt_1SAh7oRvfEABTXBOHBpTXSvR]
2025-09-23 21:04:08 <-- [200] POST http://localhost:5000/api/webhook [evt_1SAh7oRvfEABTXBO3peUOr5K]
2025-09-23 21:04:09 <-- [200] POST http://localhost:5000/api/webhook [evt_1SAh7oRvfEABTXBOHBpTXSvR]
2025-09-23 21:04:49 --> payment_intent.succeeded [evt_3SAh8URvfEABTXBO0tlxtwlD]
2025-09-23 21:04:50 <-- [200] POST http://localhost:5000/api/webhook [evt_3SAh8URvfEABTXBO0tlxtwlD]
Your endpoint is returning 200 so it looks good now
is it working as expected for you now?
[0] [WEBHOOK DEBUG] Body length: 2330
[0] [Webhook] BYPASSING signature verification for development
[0] [Webhook] Parsed event from raw body: payment_intent.succeeded
[0] [Webhook] Received event: payment_intent.succeeded
[0] [AUDIT] stripe_webhook_received - system:evt_3SAh8URvfEABTXBO0tlxtwlD by user:null
[0] Unhandled event type payment_intent.succeeded
[0] [AUDIT] stripe_webhook_received - system:evt_3SAh8URvfEABTXBO0tlxtwlD by user:null
[0] Unhandled event type payment_intent.succeeded
testing now
ALEX
ALEX ITS WORKING
Thanks to you and Solanum!
So I guess
- I didn't have Stripe CLI downloaded
- It was posting to the wrong port
I hope you both have a good night, thank you for staying up late to help me
happy to have been able to help! ๐
really thankful guys