#scott-checkout-customfields-rubysynatx

1 messages ยท Page 1 of 1 (latest)

covert phoenixBOT
wraith oak
#

@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

viscid plaza
#

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

wraith oak
#

Custom fields and metadata are not the same thing

viscid plaza
#

I was going to ask that

wraith oak
viscid plaza
#

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?

wraith oak
#

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

viscid plaza
#

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

wraith oak
#

No worries!

viscid plaza
#

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

wraith oak
#

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')

viscid plaza
#

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.

covert phoenixBOT
wraith oak
#

Sorry for the delay. Let's take a step back.

warped gate
#

Hi ๐Ÿ‘‹
I"m stepping in as my colleague needs to go. Please give me a minute to catch up

viscid plaza
#

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

warped gate
#

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???
viscid plaza
#

Absolutely!! Sorry!

warped gate
#

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?

viscid plaza
#

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.

warped gate
#

Okay so we are looking at a syntax issue here.

viscid plaza
#

Yes, now we are

warped gate
#

Sorry for the delay, the server is pretty busy

viscid plaza
#

I understand

#

I AM able to get my data but its bulky syntax now

#

session.custom_fields[0].values[2].values.last.to_i

warped gate
#

Okay that kind of makes sense given the field type "array of hashes"

viscid plaza
#

I'd love to address it directly. Ha

#

``session.custom_fields[:employeenoe]

#

session.custom_fields[:employeenoe]

#

but nooooo

#

ha

warped gate
#

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

viscid plaza
#

when child objects are listed as '@..." does that mean I can use a dot (.)?

warped gate
#

Do you have an example?

viscid plaza
#
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}
warped gate
#

Hmmm... I'm trying to test some things out but I don't think so. Not all of those are publicly accessible properties

viscid plaza
#

ok... I'll leave you to the others. Again, thank you for your help.

warped gate
#

Happy to struggle together in ignorance ๐Ÿ˜