2
votes

I am using stripe for payments. When I create the SessionCreateOptions object I add the CustomerId and ProductId for later usage in my Webhook.

 var options = new SessionCreateOptions
        {
            PaymentMethodTypes = new List<string> {
                "card",
            },
            CustomerEmail = buyer.Email,
            LineItems = new List<SessionLineItemOptions> {
                new SessionLineItemOptions {
                    Name = packages.First().Name,
                    Description = packages.First().Description,
                    Amount = (long)(totalAmount * 100),
                     Currency = "eur",
                    Quantity = 1,
               },
            },
            SuccessUrl = appSettings.RedirectHost.Url + "/Checkouts/Show/success?session_id={CHECKOUT_SESSION_ID}",
            CancelUrl = appSettings.RedirectHost.Url + "/Checkouts/Show/failed",
            Metadata = new Dictionary<String, String>()
            {
                 { "CustomerId", buyer.Id.ToString()},
                 { "ProductId", packages.First().Id.ToString()}
            },
        };

After a successful payment the webhook gets called and retrieves to object with customer data, price and other values, but the metadata dictionary is empty.

stripe webhook response

1

1 Answers

4
votes

You are retrieving the PaymentIntent that was created by the CheckoutSession, but you're setting the metadata on the CheckoutSession itself.

There are two options, depending on where you want to store and retrieve the metadata. You can retrieve the CheckoutSession directly [0], or you change your code to set the metadata on the PaymentIntent when creating the CheckoutSession, via payment_intent_data.metadata [1].

[0] https://stripe.com/docs/api/checkout/sessions/retrieve

[1] https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-payment_intent_data-metadata