“Invalid Stripe Token” thrown when “Price” not set
-
Stripe Payments is v. 1.5.2 (I did check)
I’ve followed your tutorial in setting up Stripe donations:
https://www.tipsandtricks-hq.com/how-to-accept-donation-via-stripe-from-your-wordpress-site-easily-7811The first example generates a popup as expected when the button is clicked.
The last example was expected to do the same; but it instead redirects to the checkout page inserting an “Invalid Stripe Token” error.
I have replicated both it working successfully with a shortcode of
[accept_stripe_payment price=”10″]And failing with a tag of:
[accept_stripe_payment]This is at my super-secret test page:
https://theveganoption.org/secret-test-template-01/
-
The “name” field parameter is missing from the shortcode. That field needs to be there so the plugin can identify the item.
Are you using the same name for more than one of the short-codes in there? Each shortcode should use a different value for the item name. So they can be distinguished separately.
Once you fix that, you won’t see this issue.
Thank you for taking the time to have a look.
Unfortunately, that doesn’t fix it. Apart from the two stripped-down examples from which I’d removed the name attribute (I’ve now put it back), the other shortcodes all had different names.
So this example from the tutorial (pasted onto my test page) fails:
[accept_stripe_payment name="Test donation for a good cause" button_text="Donate Now"]
I’ve also added name attributes back to my stripped down-examples and the one without a price attribute still fails. Pasting:
This works: [accept_stripe_payment price="10" name="Test 1"] This won't: [accept_stripe_payment name="Test 2"]
Let me check your shortcode on my site and then I will get back to you.
(Just updated to v1.5.3, and that didn’t solve it.)
I just copied and pasted the following shortcode on my site and did a transaction, it worked fine:
[accept_stripe_payment name=”Test 2″]
Something else is going on your site. Do you have any javascript error on your webpage?
Did make sure to empty any cache after you updated the shortcode? If you are viewing a cached page which is rendering the old content then you would still have the same issue.
Yes, the page throws two Javascript errors. One on the Stripe plugin:
Uncaught TypeError: Cannot read property 'data' of undefined at HTMLInputElement.<anonymous> (stripe-handler.js:6) at Function.each (jquery.js:2) at a.fn.init.each (jquery.js:2) at HTMLDocument.<anonymous> (stripe-handler.js:4) at i (jquery.js:2) at Object.fireWith [as resolveWith] (jquery.js:2) at Function.ready (jquery.js:2) at HTMLDocument.K (jquery.js:2)
And one Javascript error on the KnightLab timeline that’s also on the page.
So I removing the KnightLab timeline, and (to avoid client-side caching & cookies – there’s no server-side caching) opening the page in an entirely different browser (Opera) gives me the same behaviour, and the same Javascript error:
stripe-handler.js?ver=1.5.2:6 Uncaught TypeError: Cannot read property 'data' of undefined at HTMLInputElement.<anonymous> (stripe-handler.js?ver=1.5.2:6) at Function.each (jquery.js?ver=1.12.4:2) at a.fn.init.each (jquery.js?ver=1.12.4:2) at HTMLDocument.<anonymous> (stripe-handler.js?ver=1.5.2:4) at i (jquery.js?ver=1.12.4:2) at Object.fireWith [as resolveWith] (jquery.js?ver=1.12.4:2) at Function.ready (jquery.js?ver=1.12.4:2) at HTMLDocument.K (jquery.js?ver=1.12.4:2)
Does that JS error mean anything to you, MRA? Suggest any pointers for what could be going wrong? It looks to me like “stripe-handler.js” isn’t finding the
input type="text"
element. But I’ve changed the source code and it’s there:
<form id='stripe_form_9' action='https://theveganoption.org/stripe-checkout-result/' METHOD='POST'> <p><input style='max-width: 10em;' type='text' id='stripeAmount_9' value='' name='stripeAmount' placeholder='Enter amount' required/><span> GBP</span><span style='display: block;' id='error_explanation_9'></span></p><input type='hidden' id='stripeToken_9' name='stripeToken' /><input type='hidden' id='stripeTokenType_9' name='stripeTokenType' /><input type='hidden' id='stripeEmail_9' name='stripeEmail' /><input type='hidden' data-stripe-button-uid='9' /><input type='hidden' value='Test 2' name='item_name' /><input type = 'hidden' value = '1' name = 'item_quantity' /><input type = 'hidden' value = 'GBP' name = 'currency_code' /><input type = 'hidden' value = '' name = 'item_url' /><input type = 'hidden' value = '' name = 'charge_description' /><input type="hidden" id="_wpnonce" name="_wpnonce" value="ce997f19f7" /><input type="hidden" name="_wp_http_referer" value="/secret-test-template-01/" /><button id='stripe_button_9' type='submit' class='stripe-button-el'><span>Support the show</span></button></form>
Correction: But I’ve
changedchecked the source code and it’s thereokay so those JS errors are coming from another plugin or theme you have on the site. Those JS errors will prevent the Stripe JS code from executing correctly. This is why you are seeing the issue.
You need to figure out the source of the JS error and eliminate it. Then our plugin will start to work correctly. Have a look at the following post which should help you in addressing the JS errors you have on your site:
https://www.tipsandtricks-hq.com/forum/topic/debugging-javascript-errors-on-your-siteI’ve looked at several other web pages on my site (an individual post; a post index; a simple WordPress page with no Stripe shortcodes) and none of them throw Javascript errors.
That, and the fact that the error is thrown by stripe-handler.js, prompt me to ask why you think the error is elsewhere?
I’d also like to ask if you’ve got a Debug setting (or debugging variant of the plugin) that would tell me what the “anonymous” element that has no data actually is. If there *is* a issue caused elsewhere, that might be a quicker clue to it.
So you know my competence level, I’ve done programming work in the past, but my Javascript is rusty.
I don’t seem to see any errors I’ve used both firefox and chrome to to avail
Interesting. Just to double check, DYeung2017, you mean you didn’t get any JavaScript errors after opening up the Developer Tools and loading
https://theveganoption.org/secret-test-template-01/ ?I get those errors just on loading the page.
What happens if you fill in a quantity and press the button? (This only takes you to the modal dialogue asking for CC details – or at least it will if it works.)
THe link you provided shows many errors however none are shown here https://jeanforpremier.ca/donatetest/ when I fill the quantity works perfectly all the way to check out confirmation however the button ammounts still overcharge
I’m sure MRA would never release any code that threw JS errors on most installations. It’s normal for bugs to only emerge in particular situations; so I never meant to suggest everyone could reproduce it. It would still be really useful to find out exactly which element was throwing the JS error.
When you say “threw many errors”, what do you mean other than (i) the Javascript error I have described above, and (ii) the Stripe error when a variable donation button is clicked.
Because if you’re getting more than two errors on https://theveganoption.org/secret-test-template-01/, it’d be good to know what they are.
So I’ve done some digging. The error is thrown by wp_asp_add_stripe_handler, which is trying to find the stripehandlerX variable and read its data.
jQuery(document).ready(function() { jQuery('input[data-stripe-button-uid]').each(function (ind, obj) { uid = jQuery(obj).data('stripeButtonUid'); wp_asp_add_stripe_handler(window['stripehandler' + uid].data); }); });
It’s thrown for these values:
i 5 uid 6
It’s not a shock that uid=6 would break things when you look at the slot where the variables are actually set:
<script type='text/javascript'> /* <![CDATA[ */ var stripehandler = {"strEnterValidAmount":"Please enter a valid amount","strMinAmount":"Minimum amount is 0.5","key":"pk_live_uwHa1TPAG3EEZQ7FCXX36KSZ"}; var stripehandler1 = {"data":{"description":"","image":"","currency":"GBP","name":"Test donation for a good cause","url":"","amount":0,"billingAddress":false,"shippingAddress":false,"uniq_id":1,"variable":true}}; var stripehandler2 = {"data":{"description":"","image":"","currency":"GBP","name":"Support show expenses","url":"","amount":0,"billingAddress":false,"shippingAddress":false,"uniq_id":2,"variable":true}}; var stripehandler4 = {"data":{"description":"","image":"","currency":"GBP","name":"Test 2","url":"","amount":0,"billingAddress":false,"shippingAddress":false,"uniq_id":4,"variable":true}}; /* ]]> */ </script>
I checked the item names against the page, and those are for the three buttons with undefined prices.
That’s the precise opposite of what I was expecting to find; but obviously, you’d expect something to fail.<b>
It looks like you only set theseinput forms without a price set.</b>Then I ran the whole thing with just one variable donation input button, and it still threw the same error. Then I ran it in the debugger, and I think I’ve found the problem.
Break point on line 5 (uid = …), and data dump:
ind 0 obj <input type=?"hidden" data-stripe-button-uid=?"1">?
Break point on line 6:
uid 1
That’s not a surprise. But the next line is looking for stripehandler1.
And the relevant source code is:
/* <![CDATA[ */ var stripehandler = {"strEnterValidAmount":"Please enter a valid amount","strMinAmount":"Minimum amount is 0.5","key":"pk_live_uwHa1TPAG3EEZQ7FCXX36KSZ"}; var stripehandler0 = {"data":{"description":"","image":"","currency":"GBP","name":"Test donation for a good cause","url":"","amount":0,"billingAddress":false,"shippingAddress":false,"uniq_id":0,"variable":true}}; /* ]]> */ </script>
So obviously, it fails.
So I think the real problem is that (for some reason that isn’t reproduced on all platforms) when you have a stripeHandlerX variable, the variables that are coded by the plugin start at an index 0; whereas the Javascript expects them to start at an index of 1; so the Javascript doesn’t find them.
How does that sound to you, MRA?
- The topic ‘“Invalid Stripe Token” thrown when “Price” not set’ is closed to new replies.