#jmak
1 messages · Page 1 of 1 (latest)
Hi, that Doc is the object. You would want to look at the Create Checkout API Doc instead: ~~https://stripe.com/docs/api/subscriptions/create#create_subscription-items~~
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Why would it be a subscription if this is the checkout session line item being formed?
Oops sorry wrong link
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
yes i've formed the checkout session using session.New(params) and am now trying to retrieve the fields from the params i stored
It should be inside this one https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items-data-price-product
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
It says that an id stored as a string, so how do i access the fields inside?
You would need to expand it (if you don't go past the expand limit level, 3 or 4 I think)
If you can't expand in one request, probably you will need to fire another Retrieve Product API request
got it. so in this case would the correct code to get the metadata be this:
modelId, err := uuid.FromString(session.LineItems.Data[0].Price.Product.Metadata["model_id"])
referencing my photo above
also is there a way to add a transaction ID in the redirect URL?
SuccessURL: stripe.String(host/" + modelId.String() + "/payment/success"),
Yeah I think the code looks correct, but it's easier if you just try it with all your debugging tool
Regard the redirection url, I am afraid you only can set the Checkout Session Id as a dynamic value https://stripe.com/docs/payments/checkout/custom-success-page
You can think of saving the checkout session id -> model id in your database. Then in success page when you retrieve the checkout session id, query back to get the model id
oh you mean a mapping of checkout session ID to model IDs
got it
I am just moreso wondering like because the redirect URL is a going to be a GET request, how I should handle payment success
because i need it to be a POST request to write to my DB and store their payment info
With a GET request you can well extract the checkout session id from URL
example: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/client/html/success.js#L2
yes im not talking about retrieving the checkout session id -- thats just retrieving a parameter but i need to write to the DB but it's not good practice to write to the DB on a GET request which is what the redirect is
Actually to fulfil the order, it's better to listen to checkout.session.complete webhook event. The success page, yes, should only a place holder
let's say your customer accidentally closed the tab or lost internet connection, they would never reach your success page even if the payment was successful
So asyncly write payment info should be done when you receive the webhook event, which is on your webhook endpoint logic
yeah thats where I have it right now
listening to the webhook
when is that stripe event emitted?
After a customer successfully paid in the Checkout page
got it okay so my frontend has to listen to that event and then send it back to my. backend endpoints
No, your backend should listen to Stripe webhook
frontend has nothing to do with webhook
Webhook means you have a backend endpoint, Stripe server will send json request directly to that
is there something i have to configure to prompt stripe to send the events to a particular endpoint
I would suggest starting here https://stripe.com/docs/webhooks
ah yes this is perfect
shows me how to configure it
if a customer is purchasing something offered by a connected account, the charges are emitted with teh conneted account ID right and that's what should be forwarded to me via this webhook in this config
are you asking us to confirm if your understanding is correct? or you're just sharing what you understood?
if my understanding is correct
yes, that's correct
im a bit confused when i run this command
stripe trigger checkout.session.async_payment_succeeded
is it supposed to propagate a random body
it throws an error for me in response
this is my repsonse body
looking at it, gimme a while
Perhaps I didn’t enable debit card payments, but I thought the trigger was customizable to send in webhook events for payloads that I wanted passed in, not random ones
hrm, i don't think that trigger would have ever passed actually. It's assuming you have bacs_debit has a payment method, and the trigger trying to confirm it with a card payment method
yeah really im just trying to try out whether application fees are going through to me and the purchases succeed
ah, then why not try it out via a Checkout Session which you've created then?
and not via the CLI triggers
oh i did do it via a checkout session alreayd
cause the triggers for a particular event are with predefined parameters
but i want to make sure that the webhooks are also properly configured
since payment success will trigger those events
yes, but if you tried it out with a Checkout Session also, that Checkout Session will also trigger events
can you share the Checkout Session id that you've tried it out with?
that id is fine too
i assume these connected fees are mine
can you paste that id here?
it properly hits the account linking, but idk how to auto trigger webhooks
py_1MZRFePXxdADnIZneCF4OumD
py_1MZRFePXxdADnIZneCF4OumD
you've run this command to forward webhooks to your local endpoint right? stripe listen --forward-to localhost:8080/stripe/webhook?
to clarify, right now you just want to trigger a webhook to your local webhook endpoint?
yeah with the proper payload for something i would expect
okay, so making sure you keep stripe listen / forwarding open, in another window, run stripe trigger checkout.session.completed
do you see the event in the window that's listening to webhooks?
and is it forwarded to your server?
it wasn't before?
then you need to debug it
500 is being returned from your code, and you should trace down which line it's erroring at
it goes back to my previous question
its in this
modelId, err := uuid.FromString(session.LineItems.Data[0].Price.Product.ID)
this is the line, but i know im storing my data correctly
my question remains the same in how to properly access this metadata field
I'm not familiar with, i think that's Go? It's not really a Stripe specific issue. Maybe asking on a more Go specific community might be more productive
do we have a stripe go community?
no, but you can try on asking on StackOverflow i guess
yeah i thought it was this
modelId, err := uuid.FromString(session.LineItems.Data[0].Price.Product.Metadata["model_id"])
but it doesnt seem like this is the proper way? it fits the documentation though....
have you tried verifying what's being returned in session.LineItems.Data[0].Price.Product.Metadata["model_id"] first?
let me try
stripe trigger checkout.session.completed
does this create a payment session
or do i need to just ping that myself?
what do you mean by "ping" that yourself?
oh like make a POST request to my endpoint to create a checkout session
no you don't have to create a Checkout Session, the trigger will create a Checkout Session as part of the steps to generate the checkout.session.completed event
ah hm its null
it turns out my line items are null?
does this line items line not establish a line items param in the session?
i think i understand the problem, you're expecting it to have a metadata. The Stripe CLI generates an event based on predefined parameters in the fixture file i.e. https://github.com/stripe/stripe-cli/blob/master/pkg/fixtures/triggers/checkout.session.completed.json. That doesn't have metadata.
if you want the triggered event to have a certain parameter/value, you may need to add or overwrite certain parameters
you can add metadata like the below command
stripe trigger checkout.session.completed --add checkout_session:metadata[test_key]=test_value
hmm, no i'm more so asking why my LineItems params are empty in the session
because I thought the LineItemsParams on line 3 would put data there
but it seems like all of it is empty
ah i misunderstood
then, you should probably trace backwards slowly
are you able to retrieve session?
yeah
all the otehr params i filled in in the request are there
except the line items lol
&{{0x1400079fb00} <nil> false 124 124 0x14000b41098 https://www.favo.ai/model/11076372-07e1-4a25-9625-5d87d98ed88a?payment=cancel 11076372-07e1-4a25-9625-5d87d98ed88a <nil> <nil> 1675931838 usd <nil> if_required <nil> 0x14000b4c0e0 1676018238 cs_test_a1UMJEgqowebeBH98a9QAqJkSc3RL2xZtY8lAZ9hxD4gbzDTMA8zwsV0op <nil> 0x14000b4c0f0 <nil> false map[] payment checkout.session <nil> <nil> always 0x14000174600 [card] unpaid 0x14000b3dd8a <nil> <nil> <nil> <nil> [] open <nil> https://www.favo.ai/model/11076372-07e1-4a25-9625-5d87d98ed88a/payment/success <nil> 0x1400039d160 https://checkout.stripe.com/c/pay/cs_test_a1UMJEgqowebeBH98a9QAqJkSc3RL2xZtY8lAZ9hxD4gbzDTMA8zwsV0op#fidkdWxOYHwnPyd1blpxYHZxWjA0SF1GT2NHPHEwaTN1dnFHdWREdUZialR0SG1oYmpDTUNPbEtjQG1ocEE9aF9VbDRxTGtNTmsxN3V3PXJRNmBXTDJXMmRENU5AaXdQQGdJN1ZEXEY1SXV%2FNTVMYXQ8MmJuYCcpJ2N3amhWYHdzYHcnP3F3cGApJ2lkfGpwcVF8dWAnPyd2bGtiaWBabHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic%2FcXdwYHgl}
sorry its not very legible because of the json
it's alright
anyway, checkout.session.completed wouldn't have line items cause it's not included by default : https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items
but it should be 23rd in that json
you can see its nil for some reason
so i wouldnt be able to expand it
umm i'm not sure we're on the same page here?
the line_items parameter wouldn't exist because it's not included
so i've established line items as a parameter in checkoutSessionParams (see line 3 in the code snippet), but upon obtaining the checkout session object via session.New(params), the line items parameter appears to be null
you need to make a subsequent request to retrieve the Checkout Session and expand the line_items
correct, so when you create the Checkout Session, expand line_items anyway
but when i do fmt.Println(s.LineItems) its already null
yep, as it's not returned by default, you need to use the expand feature to have it included in the response.
to be clear, that doesn't mean we did not accept the line items or it's not working or something
it's like a "write only" parameter, you pass line_items and they're not included in the response, but they were accepted, and you do have the ability to tell us to return them (params.AddExpand("line_items") if you want to look at them.
okay so are you saying before i make the session at the very bottom I should add in params.AddExpand("line_items")?
you can yes
note also this only applies to that one call(expanding the line_items in the response to creating the Session). Make sure to read https://stripe.com/docs/expand and specifically https://stripe.com/docs/expand#includable-properties
so like if you retrieve the CheckoutSession later, for example as part of a webhook handler, you will have to pass expand on the session.Get() call as well
is that all clear @tame hatch ?I'm conscious this thread is open for 6 hours already so would like to close it if everything is clear
instead of session.get its session.New(params) in my example right
because i dont believe im calling session.Get anywhere
I'm talking more about "so like if you retrieve the CheckoutSession later,for example as part of a webhook handler, you will have to pass expand on the session.Get() call as well" since I assume that would have been your next stumbling block and you were speaking to my colleagues about webhooks earlier too
can you take 5 minutes to test things out in your code right now and make sure everything is clear now?