Search code examples
stripe-payments

Append client_reference_id to stripe trigger webhook


I'm currently attempting to test receiving a client_reference_id from Stripe, via a webhook after a checkout session is completed.

Currently, I'm running the test triggers via the Stripe CLI, with this command:

stripe trigger checkout.session.completed

This successfully calls the endpoint on my backend, and logs the event.

However, in these trigger calls via the CLI, the client_reference_id is blank. I would like to populate this with my site's user id, so I can update my database to mark the user as a premium account.

To do this, I attempted this:

stripe trigger checkout.session.completed --add customer:client_reference_id=1234

Hoping that it would set the id to 1234. However, it stays at null.

Does anyone know what the command is to set the client_reference_id via the Stripe CLI?


Solution

  • The command you want is:

    stripe trigger checkout.session.completed --add checkout_session:client_reference_id=1234
    

    The trigger command ultimately makes a set of API calls defined in a fixture. Here's the fixture for the checkout.session.completed event.

    The Stripe CLI reference mentions that any parameters you add must specify the resource. In this case, you want to add a value for the client_reference_id to the checkout_session resource that is created when you trigger this event.