#ghandlin - Checkout Metadata
1 messages · Page 1 of 1 (latest)
Hello! Metadata on a Checkout Session doesn't need to be expanded, it should be included by default. Can you give me the request ID showing the error you received? Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request
That request succeeded, not seeing an error there.
You can view that request in your Dashboard here: https://dashboard.stripe.com/test/logs/req_bIQyjfSXN2oL4H
I get an error when I am trying to access the metadata in my code.
Can you give me a screenshot of the error?
If I take the expand out, I don't get any values in there ...
Is this the error you're referring to? https://dashboard.stripe.com/test/logs/req_KTMBH9o9Jgh8gF
Yes ... but when I just retrieve the session, the metadata seems to be empty. One sec.
That request is associated with a Checkout Session which has no metadata.
Oh, I see the issue. You created that Checkout Session here: https://dashboard.stripe.com/test/logs/req_fw81z0j0gXzozQ
var session = await _sessionService.GetAsync(id);//, options);
_ = session.Metadata.TryGetValue("userId", out var userId);
_ = session.Metadata.TryGetValue("id", out var tournamentId);
Metadata has a count of 0
In that request you specified metadata inside product_data, which means you're setting the metadata on the Product you're creating, not on the Checkout Session. If you want to set metadata on the Checkout Session you need to set it at the top level.
This is the metadata for the Checkout Session itself: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-metadata
And this is the metadata for the Product created by using product_data: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data-product_data-metadata
Ah, so there is Metadata for each node ... alright, I see what you are saying.
You can get the Product metadata you set on the Product by fetching the Product from the API: https://stripe.com/docs/api/products
It's important to understand that using product_data when creating a Checkout Session creates a brand new Product.
hmmm... I don't want that. I just want a one off checkout
Here are my options:
var options = new SessionCreateOptions
{
LineItems = new List<SessionLineItemOptions>
{
new SessionLineItemOptions
{
PriceData = new SessionLineItemPriceDataOptions
{
UnitAmount = 2000,
Currency = "usd",
ProductData = new SessionLineItemPriceDataProductDataOptions
{
Name = tournament.Name,
Description = tournament.Description,
Metadata = new Dictionary<string, string>
{
{ "id", tournament.Id.ToString() },
{ "userId", _userManager.GetUserId(User) }
}
},
},
Quantity = 1,
},
},
Mode = "payment",
SuccessUrl = $"{Request.Scheme}://{Request.Host}/payment/success/" + "{CHECKOUT_SESSION_ID}",
CancelUrl = $"{Request.Scheme}://{Request.Host}/payment/cancel" + "{CHECKOUT_SESSION_ID}",
};
Backing up, what are you trying to build? What's your goal?
These are payments for a single sporting event. So, no product needs to be in stripe, I have that information in my database. I'm looking to pass the user id and the id for the event through stripe so I can put the payment id on the rsvp record
Checkout requires a Product and Price to work. If these are ad-hoc events that you're only going to be creating a single Checkout Session for it makes sense to use product_data and price_data to create the ad-hoc Products and Prices for each one.
However, if you're going to be creating multiple Checkout Sessions for the same event you should probably create a Product and Price first so they can be reused across many Checkout Sessions.
Is there a different option that I could use? Simply to make a payment without creating a product?
Why do you not want to create a Product?
Let me think more on this ... you've given me stuff to think about ... thank you!
Happy to help, and I'd be happy to make a recommendation or answer more questions if you want to provide more details!
👍