Search code examples
stripe-paymentswebhooks

Stripe Connect: live-mode webhooks called for test-mode payments


Short version

On a platform which uses Stripe Connect to collect payments on behalf of clients, when a test-mode payment is transacted, Stripe calls live-mode webhooks. I want it to call test-mode webhooks for test payments.

Longer version

We have a simple, home-grown ticket-selling platform which allows people to register accounts and sell tickets for their events. The platform uses Stripe to process payments, and sets our clients up with Stripe connected accounts (as Stripe calls them). Our platform listens for webhook calls from Stripe to handle the outcomes of payments. I have webhooks set up in parallel for both live mode and test mode.

(In case you don't know how this works... There is one main Stripe account for the ticketing platform, and then accounts for our clients are connected to this. When a payment happens, the platform makes API calls to the platform's Stripe account, specifying the client account to receive the payment, and the money goes to the latter. Webhooks are set up in the platform's account.)

My issue is that when a client accepts a payment, and a webhook is fired by Stripe, it seems to be using the live-mode webhooks, no matter whether the payment was a live-mode or a test-mode one. I've made sure that the payment is a test one:

  • I've checked that platform uses the correct test-mode API keys when creating the PaymentIntent.
  • The transactions are showing up correctly in the test data of the client.

However, Stripe is still invoking live-mode webhooks for these test transactions.

Is this expected behaviour? Is there a way to convince it to use test-mode webhooks?


Solution

  • Stripe calls this out explicitly in their Connect webhook doc

    For Connect webhooks, it’s important to note that while only test webhooks will be sent to your development webhook URLs, both live and test webhooks will be sent to your production webhook URLs. This is due to the fact that you can perform both live and test transactions under a production application. For this reason, we recommend you check the livemode value when receiving an event webhook to know what action, if any, should be taken.

    You should follow the recommendation and check the livemode value on the Webhook event object to determine if it is a live or test mode event.