#dalel.eth - Checkout Metadata
1 messages ยท Page 1 of 1 (latest)
Metadata isn't automatically copied between objects in most cases. That metadata will either be on the checkout session itself if you set it via the metadata parameter or the PaymentIntent/SetupIntent/Subscription if you set it via the payment_intent_data, setup_intent_data, or subscription_data parameters
Where would you like this metadata to be set?
If you want it somewhere other than those four objects, we can find the appropriate time and place to copy it on to whichever object you like
Hey @random basin ! Sorry had to step away for a little while there
Hi ๐ I'm taking over for @random basin .
Okay, so the metadata you are showing here is for the Checkout Session. That's the object it will be appended to.
hmm alright
I need to append it to the customer so that it displays inmy customer dashboard
I'm using the customer.created webhook to do this
but it doesn't appear to be working
does this make sense to you @echo ivy ?
Yes I see what you mean
So what part of this isn't working?
I use Django but I've never used DjStripe. To me it looks like you are saving to your local Customer object. Is this supposed to update the Stripe object also?
Hey @echo ivy - yes I'm trying to figure out the best way to update the Stripe object
in the checkout session - I want to provide the metadat during the checkout session so that it saves and I can view on Stripe dashboard
Yes I remember. I'm curious what is happening in the line from your code with customer.save(). I haven't used the DjStripe plugin.
But in my Django integrations that would only save to the local database object.
DjStripe syncs with Stripe
allows me to keep a record of Stripe models / data in my local db
Okay so does it modify the save() method on the local models? What method does it call?
I'm initializing that metadata that I expect in stripe though, in the checkout session
uses webhooks
Right, and that is attached to the Checkout Session object. So you are trying to migrate it to the Customer, correct?
I'm not sure I even need to migrate it to the Customer manually that way - that's just something I was trying out
Webhooks listen for data. You can use them to sync your local DB to Stripe data but not the other way around.
You would need to be calling a stripe.Customer.modify(metadata=metadata) at the time you save the customer
Sorry that was inaccurate. Stripe uses webhooks to provide data to you. Events trigger webhook requests which are sent to the endpoints you set up on your server. However, it's a one way transmission.
gotcha that's what I was thinking ๐
so I can save the customer using that modify() method at the time the checkout session is completed
or customer created maybe? what do you think
only problem with that is that the metadata I need is coming from the request object
To be clear, the modify method is using the Stripe library for Python.
gotcha
As for the webhook event, I would walk through completing a Checkout Session in Test mode and see all the events that fire. You can check them in your dashboard here:
https://dashboard.stripe.com/test/events
"TypeError: modify() missing 1 required positional argument: 'sid'"
so looks like it's working and the function is being called
but is missing something
confirmed that the webhook events are working ๐
but the metadata still not on Stripe with that event
Okay, again the metadata should be appended to the session object you create with the stripe.checkout.Session.create() call.
What do you expect your application to do?
I want the application to create the checkout session and pass the metadata to stripe and append the metadata to the customer object
so passing it into the session object as a parameter as I previously did is the wrong approach?
session.append(metadata=metadata)
or can I do something like the above?
No you want to keep it in the checkout Session create call
okay - so where did I go wrong here?
But you have to do the adding of it to the Customer when the webhook sends the session object back.
ohhh I see
customer = session["customer"]
and then use stripe.Customer.modify(metadata=metadata)
Yup. Then you should see a POST request to Stripe updating your Customer record in Stripe's data.
but how to specify the customer
in this function call?
right - but how to actually write it?
stripe.Customer.modify(metadata=metadata, id=cus_XXXX)
that doesn't seem quite right either ๐ค
ID first, without the named parameter e.g. stripe.Customer.modify(cus_ZZZ, metdata=metadata)
gotcha
hmmm
"customer = session["customer"]
KeyError: 'customer'"
how to access customer from the session object?
are you sure you have something in session right now?
session.customer is the way though
@rose pagoda is this in the webhook handler code you shared earlier?
how do you mean?
it is now!
I've updated it - just a sec I'll share it
Okay this is the customer.created event. That means the object that is coming back is the customer itself.
ah -so there is probably a better webhook event to utilize for this
checkout session completed
Bingo!
And that will have the session.customer attribute with the ID you can use to update your customer. Also it will have the metadata you appended when you created the session
so in theory this should work?
Well. you'll need to use session["customer"] because it's a dict, same with 'customer'
I do think session.customer just works and it shouldn't be an issue
I don't really understand your code right now unfortunately ๐ฆ
You're also mixing multiple things, like is the customer update call even being made?
Step 1 is to manually test things and hardcode values stripe.customer.modify('cus_123', metadata={'order_id': '6735'}) and confirm that works, then do the same in the webhook with clear logs too
okay let's see...
I'm not quite sure how to check...
but going to see if that hardcoding worked
tried this and still no metadata
I'm just trying to figure out how to get the metadata to be set when my customer is created
I'm sorry for being dense, you say "no metadata" but without any info
like are you still hardcoding this straight in a webhook handler that might not be running at all?
Or have your done a one-off python script that creates and then updates a customer to set metadata and familiarize yourself with that part of our API?
I am hardcoding it in a webhook handler but it does appear to be running based on my logs
what's the customer id?
that's what I'm trying to get from the session object
so not sure - I was trying to log that but since I'm unable to access the customer object here I'm not sure
want me to go through the user flow though and send the customer ID that is created? even if there is no metadata?
you must have an id already (or many) since you log it in the picture of the code you shared above
it's failing
"customer = session.customer
AttributeError: 'dict' object has no attribute 'customer'"
failing just before the logs
ah it actually did work with session["customer"]
cus_KwoHXvWk4pVJU4
still no metadata set, though
sure but you can quickly debug this and check the Customer in the Dashboard and confirm you never made that update call
https://dashboard.stripe.com/test/customers/cus_KwoHXvWk4pVJU4 => Event and logs
ahh I see
I'm sorry, I'm flying a bit blind here, you keep saying "doesn't work" but there isn't much to go on
Can you move away from the webhook entirely for a few minutes, work on end to end code that will properly update an existing customer, make that work, and once that work, move that code to your webhook handler (with actionable logs) to confirm it's running. With also proper error handling https://stripe.com/docs/api/errors
Sure I'll try that approach
The problem with the webhook is that sometimes you think you are running the code but you aren't and it's hard to clearly debug since it's all async without a direct console output
yeah it's hard to tell - I assumed the code was running since my logs are working on my server
is email an accessible field on a customer object?
customer.email or customer["email"] - one of these should work?
" stripe.customer.modify(customer.id, metadata={"djstripe_subscriber": "40"})
AttributeError: module 'stripe.api_resources.customer' has no attribute 'modify'"
I'm thinking this might just be because it is a lowercase "c"?
Successfully updated customer metadata ๐
now to get it working with my data...this might be a quick fix now
stripe.error.InvalidRequestError: Request req_IvMyr3NPtbW2mF: Not a valid URL
do you guys recognize this?
getting this now trying to create a checkout session...this is a separate issue so maybe we create a separate thread?
or happy to discuss in here - whatever is best for y'all
jumping in as koopajah had to step away! we can totally continue discussing in this thread
sweet sweet thank you
when you get an error message like what you pasted, a good place to start would be to take a look at what was sent to Stripe in that request. If you login to your Dashboard, you can view what was sent in the POST request in logs : https://dashboard.stripe.com/test/logs/iar_IvMyr3NPtbW2mF
if you take a look at what was sent, it looks like your app has concatenated some other stuff into the success_url, so that's not a valid URL
sorry, i didn't quite understand that, the success_url needs to be a valid URL : https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-success_url. Where are you referring to which mentions that it has 2 parameters?
For the purposes of my application it relies on two parameters - userId and communityId both of which I'm passing from my frontend
so the url should be something like https://myapp.com/1/profile/38
assuming communityId of 1 and userId of 38
so should be a valid URL if I am not mistaken
it is very interesting to look at the logs though - I see what you mean @dense ravine !
looks like the communityId is not being accessed properly and so it is in fact an invalid URL...
@dense ravine here's how the success URL is being interpreted...
activeCommunityId is what I need within params
here's how I'm currently building the success url - do you see anything wrong with this?
this is where community_id comes from
that second one being on the frontend
i would log out every section which you're concatenating there to figure out where's the issue
for example, console.log(FRONTEND_URL), console.log(request.data["community_id"]), etc
Wow - looks like the issue is on my frontend after all
don't think this has anything to do with Stripe so I'll take care of it. thanks for your help though!
you're welcome, feel free to reach out again if you have other questions! ๐