#mshell - elements not defined

1 messages ยท Page 1 of 1 (latest)

pallid thorn
#

Can you share your code for the checkout page? Need to see how you define elements

#

Try using var for elements. And make sure initialize() is called

sinful kelp
#

I tried changing the const to var for the line var elements = stripe.elements({clientSecret, appearance});, but that did not have any effect.

#

The image shows other errors that I am seeing in the console, but I do not know if they are related.

proper echo
#

๐Ÿ‘‹ I'm hopping in since @pallid thorn has to head out soon - give me a few minutes to catch up

#

It's because you initialized elements in your initialize() function - so it's limited in scope and can't be used in your handleSubmit function. You need to change the way you initialize elements so it can be referenced outside of the initialize() function

sinful kelp
proper echo
#

Yours is slightly different though - you have const elements = stripe.elements({, so elements can only be used within the initialize() function. Our example uses elements = stripe.elements({ clientSecret }); and has let elements; outside of the initialize() function

sinful kelp
#

Now I remember... I clicked the "Download full app" and that was the sample config I was using as a starting point. There are quite a few differences between the two.

#

I think I have made so many changes at this point, I might need to go back to the starting point, because I can't undo every change I have made.

proper echo
#

Well for this particular error, if you just change how you're initializing elements then that should get you past the error you're getting now

sinful kelp
#

I'm sorry, I know enough about JS to write the code I"ve written so far, but I'm really not an expert. I don't know what you mean when you say "change how you're initializing..."

proper echo
#

Just remove the const you have in front of elements, and then add let elements; right before the line that has initialize();

sinful kelp
#

when I remove the const elements from async function initialize() and put it below const appearance and before initialize();, I get this error in the console: checkout.php:332 Uncaught ReferenceError: clientSecret is not defined

#

And I changed const to let

proper echo
#

Did you change the one in front of elements or did you accidentally change the one in front of clientSecret as well?

sinful kelp
#

clientSecret is still defined within async function initialize() with a const.

proper echo
#

Gotcha - then there must be a bug later in your code, not that you've gotten rid of the elements one, now you have to find and fix the next one

sinful kelp
#

Also, when I moved the initialization of elements outside the function and I refreshed the webpage, then the input fields for card number, expiration date, CVV, etc. no longer display.

proper echo
#

I'd really recommend taking a step back and going through all the errors one by one until you eliminate them all

sinful kelp
#

I keep getting "Each dictionary in the list "icons" should contain a non-empty UTF8 string field "type"." Are you familiar with that error?