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.

YouTube Screengrab of crazy looking queen

The What?

Trigger Stripe Checkout Session with metadata

The Why?

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.

The How

You can add or override the data on resources when triggering events using the add flag.

The documentation lets us know:

--add [resource]:[path1].[path2]=[value]

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":

--add checkout_session:metadata.github=olavea

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,
Queen Raae

Interested in more daily treasures like this one?
Sent directly to your inbox?