#Rylan-checkout-metadata
1 messages ยท Page 1 of 1 (latest)
Hi there! The easiest way to handle this is to add metadata to your Checkout Session.
The other option is to create the Customer ID ahead of the Checkout Session (create it when you customer authenticates) and then pass that Customer ID to the Checkout Session instead of having Checkout create it.
How do I add that metadata to the Checkout Session?
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
How do I test via the Stripe CLI?
If I do ./stripe trigger checkout.session.completed, what my webhook receives has no metadata
When you trigger you can use the --add flag to add metadata: https://stripe.com/docs/cli/trigger#trigger-add
wonderful thank you!
Sure thing!
I'm struggling to understand how to correctly add metadata to the PaymentIntent
./stripe trigger checkout.session.completed --add payment_intent:metadata={user_id: "123"}
`stripe trigger` accepts at maximum 1 positional argument. See `stripe trigger --help` for supported flags and usage
This seems to work. Am I using this correctly?
./stripe trigger --add payment_intent:metadata="{"user_id": "123"}" checkout.session.completed
So yes that works, but it mostly depends on which webhook event you are listening to for where you want to set the metadata.
Like with how you are doing it above, you are setting the metadata on the payment_intent.data.metadata: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-payment_intent_data-metadata
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
So that the metadata is carried down to the PaymentIntent
That is fine if you are using the payment_intent.succeeded event in your webhook handler.
If you are using checkout.session.completed then you want ./stripe trigger --add checkout_session:metadata="{"user_id": "123"}" checkout.session.completed I believe
Hmm actually that isn't right.
The previous snippet I posted doesn't work either
Let me show you:
deus-backend-app-1 | "id": "cs_test_a1oPOhqN9FpYbPsDitCMaBX6GQcTn0pNW7ZTGvQ4Be7t6DVh4Lg4GJ9K90",
deus-backend-app-1 | "livemode": false,
deus-backend-app-1 | "locale": null,
deus-backend-app-1 | "metadata": {},
deus-backend-app-1 | "mode": "payment",
deus-backend-app-1 | "object": "checkout.session",
metadata is empty
Do I want override, not add?
override didn't work either
Yeah it is empty because that is the session object, not the PaymentIntent
I don't remember the syntax for session object, one sec.