How can I trigger a Stripe webhook event for a specific test customer with the Stripe CLI?

Viewed 48

I have installed the Stripe CLI and I'm using it to test some PHP code I've written in the Drupal CMS.

Stripe and Drupal are linked through Stripe's webhooks functionality.

I have a test customer in Stripe with a valid subscription.

Now I want to test the webhook event when the subscription renewal payment fails for this customer.

Based on the Stripe trigger docs, I tried this:

stripe trigger invoice.payment_failed --stripe-account=cus_abcdefg

Where cus_abcdefg is the customer ID shown in the stripe dashboard at

https://dashboard.stripe.com/test/customers/cus_abcdefg

However, this gives the following error:

Running fixture for: customer
Trigger failed: Request failed, status=403, body={
  "error": {
    "code": "platform_account_required",
    "doc_url": "https://stripe.com/docs/error-codes/platform-account-required",
    "message": "Only Stripe Connect platforms can work with other accounts. If you specified a client_id parameter, make sure it's correct. If you need to setup a Stripe Connect platform, you can do so at https://dashboard.stripe.com/account/applications/settings.",
    "type": "invalid_request_error"
  }
}

It seems this error isn't relevant because I am using the official Stripe CLI, not some platform. So I guess I have the ID wrong.

What ID am I supposed to use for --stripe-account?

1 Answers

Actually with Stripe you can create and manage multiple Connected Accounts [1]. In order to do api calls on behalf of these accounts, Stripe provides header authentication [2] feature in order to achieve this. The Stripe cli –stripe-account [3] flag that you are trying is that header authentication feature. Thus, you can't use --stripe-account flag to trigger a webhook event for a specific customer.

As an alternative, you can take a look at stripe cli fixtures[4], you can create your own fixture that trigger a Failed payment for a specific customer, or if you just want to test your endpoint regardless of what customer the event[5] is generated for then you can simply resend an existing event using Stripe CLI[6].

[1] https://stripe.com/docs/connect

[2] https://stripe.com/docs/connect/authentication

[3] https://stripe.com/docs/cli/trigger#trigger-stripe_account:~:text=Set%20a%20header%20identifying%20the%20connected%20account.

[4] https://github.com/stripe/stripe-cli/wiki/fixtures-command

[5] https://dashboard.stripe.com/test/events

[6] https://stripe.com/docs/cli/events/resend

Related