#sarge_webhooks

1 messages ยท Page 1 of 1 (latest)

scenic belfryBOT
#

๐Ÿ‘‹ 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/1371476638566584431

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

wispy dagger
#

Hi, why do you expect this event, invoice.payment_succeeded when the payment method is updated? Are you saying that after the customer updates the payment method and attempts to pay for the invoice, that event is not triggered even if the invoice is paid with the new payment method? Or, something else?

autumn flower
#

Hi @wispy dagger, yes this is my assumption, only different thing I am able to observe is the payment method updated part. This is the second time I encountered this. previous one was the client's credit card was outdated, he updated it however still didnt receive the credits however he was charged.

I rely on capturing invoice.payment_succeeded and later on extracting some metadata decide what client have purchased. I assumed it would be bug in my code (which still might be) however when I test in the test environment and go through all the possible cases things work, I do not know how I can simulate such payment method changed case to see what might be going wrong.

wispy dagger
#

I see, it does not look like you set up your webhook endpoint to listen to that event: evt_1RNsP0GYWEsxhdnCsGaPzpx2

Here is our guide: https://docs.stripe.com/webhooks/quickstart

On your webhook endpoint, I do not see you added invoice.payment_succeeded event.

#

You're only listening to customer.subscription.deleted and invoice.paid

#

So you would need to add that event to listen to

autumn flower
#

I think my webhook listents to all and filters out what is useful/needed.

Here is where I capture events:

  const body = await req.text();
  const signature = headers().get("Stripe-Signature")!;

  let event: Stripe.Event;

  try {
    event = stripe.webhooks.constructEvent(body, signature, process.env.STRIPE_WEBHOOK_SECRET!);
  } catch (err) {
    return new NextResponse("Webhook signature verification failed", { status: 400 });
  }

  const { type, data } = event;

  switch (type) {
    case 'invoice.payment_succeeded':
      const invoice = data.object as Stripe.Invoice;
      const product_id = invoice.lines.data[0].price?.product;
      const product = await stripe.products.retrieve(product_id as string);
  ...      
wispy dagger
autumn flower
#

Understood I'll take a look at it, but again, this worked most of the time for many other payments. This was an exception.

wispy dagger
#

Can you share an event where it worked?

autumn flower
#

Sure, for example this one worked fine and was for similar scenario: evt_1RHeUwGYWEsxhdnCWCWacFgB

wispy dagger
#

That event was not sent to any webhook endpoint

#

Can you clarify what 'worked fine' means?

#

I think we're not on the same page here

autumn flower
#

I guess so yes.
I have an webhook created in Stripe with a destination ID and a endpoint URL to my web site.
Whenever some event happens on stripe stripe sends them to my backend.

#

What I do to give you these event IDs is:
Developers > Webhooks > Events Tab > Filter by event type invoice.payment_succeeded
Then I find the "invoice.payment_succeeded" with the customers ID i know that operation failed, which is evt_1RNsP0GYWEsxhdnCsGaPzpx2

Same followed for a customer, for whom same operation worked and event received: evt_1RHeUwGYWEsxhdnCWCWacFgB

wispy dagger
#

So you're using the Dashboard to attain these events?

autumn flower
#

Well, to share with you, yes.

#

I do not log the stripe event details on my databse. So I have to use dashboard to figure those.

wispy dagger
#

So what you're essentially saying is that you do not see 'evt_1RNsP0GYWEsxhdnCsGaPzpx2' when you filter it out on the Dashboard? I'm very confused on what you're asking here, sorry.

autumn flower
#

I do see it on the dashboard, however I did not receive it to my backend apparently. Sorry about the confusion, this was also my first time integrating Stripe, I am still learning some of the concepts.

#

Where can I see which events my webhook is subscibed to, I do not remember explicitly adding or removing some, so I assume everything is sent to me.

wispy dagger
#

You should be able to see the webhook endpoint there and add the events

autumn flower
#

Only time I remember using certain events was when I was filtering them out while testing so terminal would not looks so crowded. Yes I used the guides in this page.

wispy dagger
#

From the above two event ids, I do not see either of them being went to a webhook endpoint.

autumn flower
#

That is really strange: The one I didnt receive on my webhook I can see this on event dashboard

#

And same for the second id I sent which was alright.

#

Okay it seems like I received invoice.paid to webhook, but not invoice.payment_succeeded that must be why.

wispy dagger
#

I'm still not following, are you able to reword the issue please?

autumn flower
#
  • I create a webhook in Stripe
  • Stripe sends all events to my backend, to the destination endpoint
  • My backend receives all events, and filters them by event type
  • I expect invoice.payment_succeeded event to come through, to make changes on user account.
  • User pays, and stripe dashboard shows invoice.payment_succeeded in the logs (Transactions > Select transaction > page bottom "Events and logs")
  • Though, my backend does not receive invoice.payment_succeeded event, however Stripe charges user
  • When I check webhook > my event destination > event deliveries, I see invoice.paid there, however it is not the event I'm tracking.
  • This has not been issue with many other clients, with very same codebase. However with a couple of them only so far.
#

I understand it might be hard to follow, Stripe docs and integration process itself is very hard to follow ๐Ÿ˜„

#

I find it hard to figure what is the difference of this and other payments so I can replicate it in test environment and see what I can change to handle it correctly.

scenic belfryBOT
wispy dagger
#

Since you're not listenting to invoice.payment_succeeded event on that webhook endpoint, I'm having a hard time understanding how you're recieving it in your backend. Do you have another account?

autumn flower
#

I do not have any other Stripe account.

scenic belfryBOT
thick compass
#

Hi there ๐Ÿ‘‹ jumping in as my teammate needs to step away, I think I see where the misunderstanding is, but need a second to confirm.

#

Stripe sends all events to my backend, to the destination endpoint
This is inaccurate. Right now your webhook endpoint is only configured to receive two types of Events, not all Events will be sent to it.

Additionally, you likely shouldn't set up a webhook endpoint to listen for every Event that is generated, only the ones that are relevant to your flow.

You can adjust what types of Events your webhook endpoint is subscribed to in your Stripe dashboard or via our API:
https://dashboard.stripe.com/webhooks/we_1QLA5SGYWEsxhdnC2hn6KaDE
https://docs.stripe.com/api/webhook_endpoints/update

However, you're already listening for invoice.paid Events, which will be generated whenever an invoice.payment_suceeded Event would be, so you don't need to listen to both types of Events.

autumn flower
#

Hi @thick compass, thank you for clarification. Indeed when I click on edit destination button (which I didn't notice previously) I can see there are only 2 events. This should help a lot, I think I will switch from invoice.paid to invoice.payment_succeeded, still confused how it kept working as is though. I will update things accordingly and if I run into any issue I might come back here for help.

Thank you all guys!

#

I remmeber deciding not to use invoice paid, since I wasnt able to extract product metadata from it as i remember.

thick compass
#

They both return an Invoice object, and should contain the same details. If you need Product metadata, that won't be in the Invoice related Events and you'll need to fetch that from the API.

If you are using paid_out_of_band when paying for an Invoice, and still need to be notified when those Invoices are "paid", then you'll want to keep using invoice.paid instead of invoice.payment_succeeded:
https://docs.stripe.com/api/invoices/pay?api-version=2025-04-30.basil#pay_invoice-paid_out_of_band
(That's the difference between the Event types. invoice.paid is triggered whenever an Invoice moves to a paid state, but invoice.payment_succeeded only triggers when an Invoice is paid through Stripe)

autumn flower
#

I see, I will check this out too. Thank you again.