Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7658833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:15:11+00:00 2026-05-31T13:15:11+00:00

I’m testing a simple checkout form using stripe for payments. I followed tutorial examples

  • 0

I’m testing a simple checkout form using stripe for payments. I followed tutorial examples ( https://stripe.com/docs/tutorials/forms ) and everything works except the declined card error. As per the api, use 4000000000000002 to simulate a declined card. It just crashes my charge.php file. Here is the code from the html form and charge.php file.

live version here: http://www.getwebshark.com/trial/step3

form.html –

<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
  <meta name="generator" content=
  "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org" />
  <meta http-equiv="Content-type" content="text/html; charset=us-ascii" />

  <title>Stripe Getting Started Form</title>
  <script type="text/javascript" src="https://js.stripe.com/v1/">
</script><!-- jQuery is used only for this example; it isn't required to use Stripe -->

  <script type="text/javascript" src=
  "https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">
</script>
  <script type="text/javascript">
//<![CDATA[
                                // this identifies your website in the createToken call below
                                Stripe.setPublishableKey('ihidthis');

                                function stripeResponseHandler(status, response) {
                                        if (response.error) {
                                                // re-enable the submit button
                                                $('.submit-button').removeAttr("disabled");
                                                // show the errors on the form
                                                $(".payment-errors").html(response.error.message);
                                        } else {
                                                var form$ = $("#payment-form");
                                                // token contains id, last4, and card type
                                                var token = response['id'];
                                                // insert the token into the form so it gets submitted to the server
                                                form$.append("<input type='hidden' name='stripeToken' value='" + token + "' />");
                                                // and submit
                                                form$.get(0).submit();
                                        }
                                }

                                $(document).ready(function() {
                                        $("#payment-form").submit(function(event) {
                                                // disable the submit button to prevent repeated clicks
                                                $('.submit-button').attr("disabled", "disabled");
                                                // createToken returns immediately - the supplied callback submits the form if there are no errors
                                                Stripe.createToken({
                                                name: $('.card-name').val(),
                                                number: $('.card-number').val(),
                                                cvc: $('.card-cvc').val(),
                                                exp_month: $('.card-expiry-month').val(),
                                                exp_year: $('.card-expiry-year').val()
                                                }, stripeResponseHandler);
                                                return false; // submit from callback
                                        });
                                });

                                if (window.location.protocol === 'file:') {
                                        alert("stripe.js does not work when included in pages served over file:// URLs. Try serving this page over a webserver. Contact support@stripe.com if you need assistance.");
                                }
  //]]>
  </script>
</head>

<body>
  <h1>Trial $4.99 with recurring $74.98 after 18 days</h1>
  <!-- to display errors returned by createToken -->

  <form action="charge.php" method="post" id="payment-form" name="payment-form">
    <div class="form-row">
      <label>Name on Card</label> <input type="text" size="20" autocomplete="off" class=
      "card-name" />
    </div>

    <div class="form-row">
      <label>Email</label> <input type="text" size="20" autocomplete="off" name=
      "email" />
    </div>

    <div class="form-row">
      <label>Card Number</label> <input type="text" size="20" autocomplete="off" class=
      "card-number" />
    </div>

    <div class="form-row">
      <label>CVC</label> <input type="text" size="4" autocomplete="off" class=
      "card-cvc" />
    </div>

    <div class="form-row">
      <label>Expiration (MM/YYYY)</label> <input type="text" size="2" class=
      "card-expiry-month" /> <span>/</span> <input type="text" size="4" class=
      "card-expiry-year" />
    </div>

    <div class="form-row">
      <label>Shipping address</label> <input type="text" size="20" autocomplete="off"
      name="address" />
    </div>

    <div class="form-row">
      <label>City</label> <input type="text" size="20" autocomplete="off" name="city" />
    </div>

    <div class="form-row">
      <label>State</label> <input type="text" size="20" autocomplete="off" name=
      "state" />
    </div>

    <div class="form-row">
      <label>Zip Code</label> <input type="text" size="20" autocomplete="off" name=
      "zip" />
    </div><button type="submit" class="submit-button">Submit Payment</button>
  </form>
</body>
</html>

charge.php –

<?php

require_once('stripe-php/lib/Stripe.php');

Stripe::setApiKey("ihidthis");

// get the single use token from the form submitted by stripeResponseHandler
// set your secret key: remember to change this to your live secret key in production
// see your keys here https://manage.stripe.com/account

// get the credit card details submitted by the form
$token = $_POST['stripeToken'];
$email = $_POST['email'];

//combine these variables and post them all to stripe's customer description
$address = $_POST['address'];
$city    = $_POST['city'];
$state   = $_POST['state'];
$zip     = $_POST['zip'];

$description = $address . " " . $city . " " . $state . " " . $zip;


$customer = Stripe_Customer::create(array(
    "card" => $token,
    "plan" => "001",
    "description" => $description,
    "email" => $email
));

Stripe_Charge::create(array(
    "amount" => 499, # amount in cents, again
    "currency" => "usd",
    "customer" => $customer->id
));



echo '<h1>Thank you for your business!</h1>';
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:15:12+00:00Added an answer on May 31, 2026 at 1:15 pm

    Nicolas was correct below but since I was using a one time charge and signing the customer up for a recurring plan, I needed to include both the customer and the charge in the try catch block.

    try {
    
    $customer = Stripe_Customer::create(array(
        "card" => $token,
        "plan" => "001",
        "description" => $description,
        "email" => $email)
    );
    Stripe_Charge::create(array(
        "amount" => 499,
        "currency" => "usd",
        "customer" => $customer->id)
    );
    $success = 'Your payment was successful.';
    } catch (Exception $e) {    
    $error = $e->getMessage();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.