#scott-checkout-customfields-rubysynatx
1 messages ยท Page 1 of 1 (latest)
@viscid plaza let's chat here
Moving these messages from the main thread:
sorry, I meant to edit out comments & compress code
employeenoe is the CORRECT custom_field name btw
require 'stripe'
Stripe.api_key = [SECRET KEY FROM ENV]
def get_enum_from_sessions
sessions_with_enum = []
all_sessions = Stripe::Checkout::Session.list
all_sessions.auto_paging_each do |session|
if session.metadata && session.metadata['employeenoe']
sessions_with_enum << { session.id: session.id, employee_number: session.metadata['employeenoe'] }
end
end
sessions_with_enum
end
Custom fields and metadata are not the same thing
I was going to ask that
Your code is trying to pull metadata from a Session but that will be empty if you're using custom fields instead: https://docs.stripe.com/payments/checkout/custom-fields
Is metadata something you pass INTO the form?
If I may, I believe I set up the checkout page as I want in that I am trying to have the customer enter their employee number in a field I have set up. So I guess my problem is how do I retrive that value?
Will the link you sent address my question?
Yep, that link will help! You can inspect the checkout.session.completed event to look at the custom_fields hash on the Checkout Session
Metadata is not customer facing at all. That's something you add/update/remove via the API
My first glimpse of the link you sent has under 2. Retrieve custom fields. Then it discusses webhooks. I need to retrieve the value with the API.
Yep, got it on the metadata. Thank you. Duh
No worries!
You can retrieve the Checkout Session and look at the custom_fields hash: https://docs.stripe.com/api/checkout/sessions/object#checkout_session_object-custom_fields
ok, sorry to be a pain, but I've read most of your links. I'm still having trouble.
I know that most everyone probably uses webhooks. I do not. I process a response using the Ruby API.
I'm looking for the correct API "terminology"
Stripe::Checkout::Session..........
I tried
Stripe::Checkout::Session.completed
that doesn't work at all
Stripe::Checkout::Session.list does work but I don't see any value from my custom_field listed from any of my customers
I highly recommend you use webhooks with Checkout so you know when a a payment has been completed and you're able to kick off any fulfillment logic
You'll need to retrieve a specific Session so will need to know that Session's ID: Stripe::Checkout::Session.retrieve('cs_ID')
I AM able to get all session ids
But I don't understand why I have to use webhooks???? Let me explain (am I naive??)..
I run my own linux server at home. I assume my IP address changes continually as I do not have a static IP address.
I'm also not thinking I want to keep Sinatra running full time.
Am I being obtuse??
My customers are sporadic. Some on one day, none on others.
All I need to do is use the API within ruby to check for new subscriptions one time a day within my ruby code. The subscription allows them access to a website is all. No 'shipping' of products, etc.
Sorry for the delay. Let's take a step back.
Hi ๐
I"m stepping in as my colleague needs to go. Please give me a minute to catch up
I think I'm getting closer..
I just found one employee number...
all_sessions = Stripe::Checkout::Session.list({status: 'complete'})
all_sessions.each do |session|
puts session.?????
session.custom_fields.numeric.value???
If you are going to provide code can you please write it between three backticks? It'll make it easier to read.
e.g.
all_sessions = Stripe::Checkout::Session.list({status: 'complete'})
all_sessions.each do |session|
puts session.?????
session.custom_fields.numeric.value???
Absolutely!! Sorry!
If you want to get extra fancy you can even specify the language like I did with the three ` followed by the language name ruby.
So are the users entering the data you want to retrieve in the customer fields or are you storing it in metadata?
hmmmmm.... don't see that, but I'll try
The customer is entering their employee number
so metadata is NOT what I'm looking for
I'm drilling it down...
session.custom_fields then I don't know if I should use a dot (.) or hash symbol (:) or just a string ('employeenoe')
Snufkin,
I DO appreciate your help.
When debugging the Stripe object, I don't know the correct way to get the data. Seems like a lot of the JSON data is very recursive.
Okay so we are looking at a syntax issue here.
Yes, now we are
Sorry for the delay, the server is pretty busy
I understand
I AM able to get my data but its bulky syntax now
session.custom_fields[0].values[2].values.last.to_i
Okay that kind of makes sense given the field type "array of hashes"
I'd love to address it directly. Ha
``session.custom_fields[:employeenoe]
session.custom_fields[:employeenoe]
but nooooo
ha
Yes I could see that as desirable. But the array syntax means you cannot refer to the field by name, I think. I'm not a Ruby expert
when child objects are listed as '@..." does that mean I can use a dot (.)?
Do you have an example?
session.custom_fields
@opts = {Hash[2]}
@original_values = {Hash[5]}
@retrieve_params = {Hash[0]}
@transient_values = {Set}
@unsaved_values = {Set}
@values = {Hash[5]}
@@permanent_attributes = {Set}
Hmmm... I'm trying to test some things out but I don't think so. Not all of those are publicly accessible properties
ok... I'll leave you to the others. Again, thank you for your help.
Happy to struggle together in ignorance ๐