I'm struggling to work with the data posted by Stripe to my web hook.
I'm using the basic checkout. I have everything working as intended. CLI is forwarding the web hooks after "checkout.session.completed". My hook is being hit as expected. However, I can't work out how to extract the meta data. I can see it in the object but I can't work out how. What is an "IhasObject"? I copied the code from the docs below.
var json = await new StreamReader(HttpContext.Request.Body).ReadToEndAsync();
try
{
// check if was from Stripe
var stripeEvent = EventUtility.ConstructEvent(json,Request.Headers["Stripe-Signature"], endpointSecret);
// Handle the event
if (stripeEvent.Type == Events.CheckoutSessionCompleted)
{
// TODO update the DB and set the booking to PAID based on the transaction Id
// in Metadata
var session = stripeEvent.Data.Object;
I can see the correct data in the session object in VS debug and in the raw json. But how do I get it out of the session object or event? It's unclear and there are no examples in the documentation. I am tempted to read the json into a POCO but isn't this the point of the event object?
Can someone point me in the right direction? I just want to fulfill the order but the examples don't show how to work with the session object.
You can cast the payload of the event to a CheckoutSession and read the metadata.
var session = (Stripe.Checkout.Session) stripeEvent.Data.Object;
var metadata = session.Metadata;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With