#Ed.D - Checkout
1 messages · Page 1 of 1 (latest)
thank you very much
its not so much the question, but that answer. i'm processing checkout sessions events using hooks to do various database stuff
Why do you want the Checkout Session ID on the Payment Intent?
well when the checkout session kicks off, i want to create a database record with that checkout session id
and also a user email
but the user email isnt present yet until after they fill out payment info
i'm mostly interested if there is a way to share metadata along different events along the checkout flow
pass metadata from checkout session to payment intent for example
There is not, but there are other ways to approach this.
ok
I'm still not clear why you want the Checkout Session ID on the Payment Intent... is it because you're only listening for Payment Intent events and not stuff like checkout.session.completed?
im using python sdk to create a checkout session using checkoutSession.create() and once this is created i want to create a booking record in my database which is keyed by the checkout session id and set the status of this booking to RESERVED. Once the payment flow is completed or canceled, i'll be setting this record to a status according to what the customer chooses, so either BOOKED or CANCELED etc. i want to store the user's email in this record
i wont be getting the user's email until the payment_intent flow, unless im mistaken...
You'll get the email after the Checkout Session completes, so you should listen for checkout.session.completed to determine when that happens.
right, but at that point the session may have been completed or canceled
i suppose i could update the record at that time, but it would be better to have it at row insert
i mean, it would be better not to have to update records with missing data
right, but at that point the session may have been completed or canceled
This is not correct. If they cancel you will not get that event.
so i was thinking that I could insert the record at the start the payment_intent flow
no no, if they cancel i'll fire a separate function on a hook specific to that event
so checkout_session.created -> insert booking record with reserved status -> checkout.session.completed -> update this record with booked status
i'd like the user's email to be in the record without the need to update it later to avoid missing data
There is no event for Checkout Sessions being created, but that happens on your server so you don't need an event for it. The second part is correct though, yes.
i know. when i use the checkout.Session.create() i will insert
but this wont have the user email
i guess the next event which might have this is the payment_intent.created event
i guess the next event which might have this is the payment_intent.created event
That's not correct in some flows. In payment mode the Payment Intent is created when the Checkout Session is created.
alright maybe not that event, but my point is the email is not on the event which fires creation of a record which should contain email
and right now that event is the creation of the checkout session
i dont want to create a record with missing data, to fill it later on
id rather have one event contain all necessary data to create a record
session_id, customer email, some product data, status
at the moment, i dont have both session id and email in the same event
Sorry, I think I might be misunderstanding something. It sounds like you're creating an entry in your database at the same time you're creating a Checkout Session, and you want the entry to have the email of the Customer. Is that right?
yes
i want to create an entry in my database with the customer info and some identifier to the payment flow through stripe, so that i can locate this record when i update it during further events of the payment flow
the reason i chose checkout_session is because i found it easy to attach metadata to the checkout_session
this record should have some product data needed to create the booking (number of people booked and booking date for example) as well as some sort of stripe identifier that i can retrieve in future stages of the payment
based on these stages, i need to update the record's status
So, hang on, still fuzzy on something. If you're creating the DB record at the same time you're creating the Checkout Session it's not possible to get the email in there at that time because the customer hasn't provided it yet, right?
So how do you expect to get the email to insert it at that point in time? You mentioned not wanting to update it later, but you have to update it later after Checkout is complete, right?
yeah the customer hasn't input that data yet at the time the session is created. i do NOT want to update the record with the customer email later
that could be problematic
i want to create a complete record at some point of the payment flow, and update just the status of the record based on the resolution of the payment flow (either cancel or copmlete)
when i create the checkout session, i have all information i need to create this record except the email
stripe identifier (checkout session id), product data (booking date, and number of people to book and internal product id), status=RESERVED
the only thing missing is the customer email
if there is an easy way to get all of this information at once then great, otherwise i will forgo storing the customer email
You can't get it at the point in time which you create the Checkout Session because the information doesn't exist yet. The Customer provides the email during Checkout, so you would need to wait until the Checkout Session completes to get it.
seems there is no single event with all of this data, which i why i was hoping to be able to attach metadata from checkoutsession flow to payment intent flow or something else so that one any of these events, i will have all necessary data to insert a record
i'll just not store emails
would be nice to be able to pass metadata through separate flows, which is why i wanted to get clarity on what the SO answer meant
did this person give me incorrect information?
The checkout.session.completed event has everything you need, does it not? What's missing?
the checkout session completed event is not guaranteed to fire no?
It will only fire for successful Checkout Sessions, yeah, but that's the only time you're guaranteed to have the customer's email. It's the only event that fits all your requirements.
If the Checkout Session is canceled the email may not be present.
but that event doesnt always fire, so it wont work
Yeah, but you have directly conflicting requirements. You can either guarantee the email will be there or you can guarantee you'll get a record inserted for every Checkout Session, not both.
unless there is a way for me to pass metadata between flows
like this person in the SO answer suggested
You can add metadata on the Checkout Session which can be anything you want: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-metadata