another_noob Posted October 5, 2013 Share Posted October 5, 2013 I am working through Larry's Stripe tutorial and have run into what seems like a simple issue, but is giving me fits. The problem is I keep getting a duplicate submission error. I am using the code verbatim from the tutorial download with just the addition of my added diagnostic conditionals. The conditional comparing the $_SESSION['token'] == $token always returns true even when it shouldn't. Here is the output from my conditionals: token = tok_102hNa23Z1ryxpC0EVh3z6aLSESSION[token] before comparing = tok_102hNU23Z1ryxpC0Vw4f922TSESSION[token] after comparing = tok_102hNa23Z1ryxpC0EVh3z6aL Here is the relevant code snippet: // Check for a form submission: if ($_SERVER['REQUEST_METHOD'] == 'POST') { //Just for developmental diagnostic purposes if(isset($_POST['stripeToken'])): echo 'token = ' . $_POST['stripeToken']; endif; //Just for developmental diagnostic purposes if(isset($_SESSION['token'])): echo '<br />SESSION[token] before comparing = ' . $_SESSION['token']; endif; // Stores errors: $errors = array(); // Need a payment token: if (isset($_POST['stripeToken'])) { $token = $_POST['stripeToken']; // Check for a duplicate submission, just in case: // Uses sessions, you could use a cookie instead. if (isset($_SESSION['token']) && ($_SESSION['token'] == $token)) { $errors['token'] = 'You have apparently resubmitted the form. Please do not do that.'; } else { // New submission. $_SESSION['token'] = $token; } } else { $errors['token'] = 'The order cannot be processed. Please make sure you have JavaScript enabled and try again.'; } //Just for developmental diagnostic purposes if(isset($_SESSION['token'])): echo '<br />SESSION[token] after comparing = ' . $_SESSION['token']; endif; I must be overlooking something very simple. I don't see where anybody else has had a problem with this code. Thanks for looking at it. Link to comment Share on other sites More sharing options...
another_noob Posted October 7, 2013 Author Share Posted October 7, 2013 Well, after struggling with this issue far too long, I commented out the lines of code giving me the duplicate submission: // Check for a duplicate submission, just in case: // Uses sessions, you could use a cookie instead. if (isset($_SESSION['token']) && ($_SESSION['token'] == $token)) { $errors['token'] = 'You have apparently resubmitted the form. Please do not do that.'; } else { // New submission. $_SESSION['token'] = $token; } My thinking on this decision is that this script relies on javascript entirely to process the payment. With that in mind there isn't an easy progressive enhancement technique that is going to be worth my time to figure out. Javascript disables the submit button immediately after the user clicks it anyway, so a dual submission seems impossible. As the tutorial is written, if the user has javascript disabled a dual submission is not possible...either is a single submission. It still bugs me that I could not get those simple lines of code to work as expected though. I gained a lot of Stripe knowledge the last few days. My cart system is coming along awesome. Great tutorial Larry, thanks. Link to comment Share on other sites More sharing options...
Larry Posted October 7, 2013 Share Posted October 7, 2013 Thanks for the nice words. Sorry you couldn't get that figured out. Just so you know, "progressive enhancement" doesn't really apply here as JavaScript is mandatory. Link to comment Share on other sites More sharing options...
aminulsumon Posted August 2, 2014 Share Posted August 2, 2014 i have downloaded the source code from http://www.larryullman.com/downloads/Stripe-Larry-Ullman.zip. and after extract i have set private and public key properly. furthermore, i have downloaded stripe lib and include that in test script. BUT i am getting the following error: The order cannot be processed. Please make sure you have JavaScript enabled and try again. i am looking forward for a quick reply or any sample code which works accurately. Link to comment Share on other sites More sharing options...
Larry Posted August 2, 2014 Share Posted August 2, 2014 What debugging steps have you tried and what were the results? Keep in mind that to use my code, you must be competent with PHP. That code is just the fundamental concept; you'll need to modify it to work for your situation. Link to comment Share on other sites More sharing options...
Recommended Posts