How to trigger a Stripe (checkout.session.completed) Event with metadata
We had fun with the Stripe CLI in yesterday's unauthorized and rum-fueled treasure hunt in the sharky waters around the Gatsby islands while refactoring the Stripe Webhook of our price-winning Gatsby FuncJam entry to use the raw body for Stripe verification.
Trigger Stripe Checkout Session with metadata
Sometimes your Stripe Webhook expects there to be metadata attached to the Checkout Session. In our case, we want to grant access to a private Github repository and therefore add the Github username to the Checkout Session.
You can add or override the data on resources when triggering events using the add flag.
The documentation lets us know:
To add metadata to a Stripe Checkout Session,
resource should be swapped for "checkout_session
path1 for "metadata" and
path2 for your custom metadata key. In our case, "github":
Then we use the above when triggering events, such as "checkout.session.completed":
stripe trigger checkout.session.completed --add checkout_session:metadata.github=olavea
I had to upgrade my Stripe CLI to get this functionality, so I believe this is a new addition in the last year or so.
All the best,