Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cristian9509's avatar

How to avoid processing API generated Stripe webhooks?

I am using Stripe and I need to understand how to only process webhooks that are generated by Stripe behind the scenes. When my server sends something to Stripe (new subscription, new individual charge) Stripe will generate events that are sent via the webhooks I provide. Well, I don't need to process those since it will create a mess. I only want to process Stripe generated webhooks in situations like: failed charge at subscription renewal, manual modifications via the Stripe dashboard, refunds generated in the dashboard, etc).

I went through the events generated and I cannot find anything that would make a difference from those my API calls generate or those generated behind the scenes.

Is there something I am missing?

0 likes
5 replies
MikeHopley's avatar

There are two options:

  1. Tell Stripe which webhooks you want it to send. You can do this from your Stripe dashboard. By default Stripe sends all webhooks.
  2. In your webhook handler, listen for only the types of events you want to process.
cristian9509's avatar

@MikeHopley That is not the problem I am facing. There are three types of webhooks that get generated:

  1. Api calls (webhook event has a valid request id)
  2. Stripe behind the scenes (webhook event has a null request id)
  3. Stripe dashboard (webhook event has a valid request id)

So I want to discard all the webhooks that are not null and this way at least I can process Stripe behind the scenes webhooks. But I am left with the problem of how not to discard Stripe dashboard generated events. I don't find anyway to differentiate between the two.

MikeHopley's avatar

Not sure what you mean by "request id", or "Stripe behind the scenes webhooks".

Anyway, every Stripe webhook has an type property, with values like customer.created or customer.subscription.created. As I said, you can check the event type and only take action for the events you are interested in.

cristian9509's avatar
cristian9509
OP
Best Answer
Level 4

First of all, Stripe currently does not support identifying the incoming webhook event type. Looking in the Dashboard I indeed can see what initiated the event (API, Dashboard or Automatic) but Stripe's people said they don't support it.

However, there is a workaround. For anyone struggling with this I will describe what I did. An automatic Stripe generated event is easy to differentiate. It contains a null request field. Any other type of event will have a request id (ex: re_123h2kj18321hjk3218). The problem remains with differentiating between API and Stripe Dashboard generated requests. Therefore, the solution is to capture the request id for every request generated by the API. Whenever a webhook arrives to your server, you check for the request field NOT to be in the Storage System (DB, etc) OR that the request is null. This means that the event was generated by either the Dashboard or Automatically by Stripe (subscription renewal).

Steps:

  • Hook into the CurlClient provided by Stripe. Extend that class and override the request() method. The request method returns the response generated by Stripe servers. Capture the headers of the response which would contain a Request-id. Store that in your Storage (in my case a DB)
  • In your configuration files you need to specify that Stripe should use your own CurlClient. ApiRequestor::setHttpClient(new CurlClient()); (I've named my CurlClient too but you can name it whatever)
  • When a webhook arrives, you have three options to identify the type:
    1. Automatic: if the event has a request=null
    2. Dashboard: the request is not null and the request is not in you Storage
    3. API: you're left with one situation. The request is not null but exists in your DB

As you can see, there's quite a lot of work for something really easy. All Stripe needs to do is provide another field in their webhook event name something like request-type with three options (api, automatic, dashboard). They already have this build but they don't allow it to be shown in the webhook event.

cristian9509's avatar

@MikeHopley Stripe behind the scenes events, I meant by Stripe Automatic generated events like charging the subscription at next billing cycle, etc. I found a way in the end but it involves a bit more work than I had anticipated. In the end all I wanted from stripe is to give me an identifier for who initiated the request. Was it an API call, change done from the Dashboard or an Automatic event. They have it implemented but not for API calls. Too bad!

Please or to participate in this conversation.