#ghandlin - Checkout Metadata

1 messages · Page 1 of 1 (latest)

arctic dragon
neon ridge
#

Hang on, let me run it again...

#

req_bIQyjfSXN2oL4H

arctic dragon
#

That request succeeded, not seeing an error there.

neon ridge
#

I get an error when I am trying to access the metadata in my code.

arctic dragon
#

Can you give me a screenshot of the error?

neon ridge
#

If I take the expand out, I don't get any values in there ...

arctic dragon
neon ridge
#

Yes ... but when I just retrieve the session, the metadata seems to be empty. One sec.

arctic dragon
#

That request is associated with a Checkout Session which has no metadata.

neon ridge
#

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

arctic dragon
#

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.

neon ridge
#

Ah, so there is Metadata for each node ... alright, I see what you are saying.

arctic dragon
#

It's important to understand that using product_data when creating a Checkout Session creates a brand new Product.

neon ridge
#

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}",
        };
arctic dragon
#

Backing up, what are you trying to build? What's your goal?

neon ridge
#

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

arctic dragon
#

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.

neon ridge
#

Is there a different option that I could use? Simply to make a payment without creating a product?

arctic dragon
#

Why do you not want to create a Product?

neon ridge
#

Let me think more on this ... you've given me stuff to think about ... thank you!

arctic dragon
#

Happy to help, and I'd be happy to make a recommendation or answer more questions if you want to provide more details!

neon ridge
#

👍