#jmak

1 messages · Page 1 of 1 (latest)

livid knollBOT
iron elbow
tame hatch
#

Why would it be a subscription if this is the checkout session line item being formed?

iron elbow
#

Oops sorry wrong link

tame hatch
#

yes i've formed the checkout session using session.New(params) and am now trying to retrieve the fields from the params i stored

iron elbow
tame hatch
#

It says that an id stored as a string, so how do i access the fields inside?

iron elbow
#

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

tame hatch
#

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"),
iron elbow
#

Yeah I think the code looks correct, but it's easier if you just try it with all your debugging tool

#

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

tame hatch
#

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

iron elbow
#

With a GET request you can well extract the checkout session id from URL

tame hatch
#

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

iron elbow
#

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

tame hatch
#

yeah thats where I have it right now

#

listening to the webhook

#

when is that stripe event emitted?

iron elbow
#

After a customer successfully paid in the Checkout page

tame hatch
#

got it okay so my frontend has to listen to that event and then send it back to my. backend endpoints

iron elbow
#

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

tame hatch
#

is there something i have to configure to prompt stripe to send the events to a particular endpoint

iron elbow
tame hatch
#

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

last frost
#

are you asking us to confirm if your understanding is correct? or you're just sharing what you understood?

tame hatch
#

if my understanding is correct

last frost
#

yes, that's correct

tame hatch
#

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

last frost
#

what error are you referring to?

#

in that screenshot there's no error

tame hatch
#

this is my repsonse body

last frost
#

looking at it, gimme a while

tame hatch
#

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

last frost
#

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

tame hatch
#

yeah really im just trying to try out whether application fees are going through to me and the purchases succeed

last frost
#

ah, then why not try it out via a Checkout Session which you've created then?

#

and not via the CLI triggers

tame hatch
#

oh i did do it via a checkout session alreayd

last frost
#

cause the triggers for a particular event are with predefined parameters

tame hatch
#

but i want to make sure that the webhooks are also properly configured

#

since payment success will trigger those events

last frost
#

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?

tame hatch
#

would it be this?

last frost
#

that id is fine too

tame hatch
#

i assume these connected fees are mine

last frost
#

can you paste that id here?

tame hatch
#

it properly hits the account linking, but idk how to auto trigger webhooks

#

py_1MZRFePXxdADnIZneCF4OumD

py_1MZRFePXxdADnIZneCF4OumD

last frost
#

you've run this command to forward webhooks to your local endpoint right? stripe listen --forward-to localhost:8080/stripe/webhook?

tame hatch
#

yep

#

i've done that already

last frost
#

to clarify, right now you just want to trigger a webhook to your local webhook endpoint?

tame hatch
#

yeah with the proper payload for something i would expect

last frost
#

okay, so making sure you keep stripe listen / forwarding open, in another window, run stripe trigger checkout.session.completed

tame hatch
#

yeah seems to function correctly

last frost
#

do you see the event in the window that's listening to webhooks?

#

and is it forwarded to your server?

tame hatch
#

oh it isnt

#

connection refused

last frost
#

it sounds like a problem with your localhost?

#

is your server up and running locally?

tame hatch
#

hmmm

#

yeah it is now

last frost
#

it wasn't before?

tame hatch
#

getting a 500 error now

last frost
#

then you need to debug it

tame hatch
#

ah ok

#

i think i know what it is

last frost
#

500 is being returned from your code, and you should trace down which line it's erroring at

tame hatch
#

it goes back to my previous question

tame hatch
#

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

last frost
#

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

tame hatch
#

do we have a stripe go community?

last frost
#

no, but you can try on asking on StackOverflow i guess

tame hatch
#

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....

last frost
#

have you tried verifying what's being returned in session.LineItems.Data[0].Price.Product.Metadata["model_id"] first?

tame hatch
#

let me try

#

stripe trigger checkout.session.completed

#

does this create a payment session

#

or do i need to just ping that myself?

last frost
#

what do you mean by "ping" that yourself?

tame hatch
#

oh like make a POST request to my endpoint to create a checkout session

last frost
#

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

tame hatch
#

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?

last frost
#

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

tame hatch
#

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

last frost
#

ah i misunderstood

#

then, you should probably trace backwards slowly

#

are you able to retrieve session?

tame hatch
#

yeah

#

all the otehr params i filled in in the request are there

#

except the line items lol

last frost
#

session.LineItems?

#

can you paste the response?

#

oh nvm

tame hatch
#

&{{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

last frost
#

it's alright

tame hatch
#

but it should be 23rd in that json

#

you can see its nil for some reason

#

so i wouldnt be able to expand it

last frost
#

umm i'm not sure we're on the same page here?

#

the line_items parameter wouldn't exist because it's not included

tame hatch
#

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

last frost
#

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

tame hatch
#

but when i do fmt.Println(s.LineItems) its already null

safe basin
#

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.

tame hatch
#

okay so are you saying before i make the session at the very bottom I should add in params.AddExpand("line_items")?

safe basin
#

you can yes

#

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

tame hatch
#

instead of session.get its session.New(params) in my example right

#

because i dont believe im calling session.Get anywhere

safe basin
# tame hatch 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?

tame hatch
#

damn

#

that might be it

#

ty ser you're the goat @safe basin