title: Stripe 400 Error "Invalid Positive Integer"
body: <p>I have a real bugger of a question.  I am trying to build a donations page for a nonprofit which charges people through Stripe.  Every charge I try to make gives me an error which reads :</p>
  
  <p><em>Parsed Request Post Body</em></p>
  
  <pre><code>{
      "card"        : "TOKEN WAS HERE",
      "description" : "Donation by   ()",
      "amount"      : "0",
      "currency"    : "usd"
  }
  </code></pre>
  
  <p>Response Body:</p>
  
  <pre><code>{
      "error" :
      {
          "type"    : "invalid_request_error",
          "message" : "Invalid positive integer",
          "param"   : "amount"
      }
  }
  </code></pre>
  
  <p>I <em>think</em> there is an issue with the amount I am passing to Stripe (clearly Stripe thinks it is receiving an amount of <code>0</code> - I am just not sure if it ACTUALLY is) - but I absolutely CANNOT figure out what it is.  Here is the full extent of the code on my page :</p>
  
  <pre><code>&lt;?php
      require( 'Stripe/init.php' );
  
      // Load configuration settings
      $config = require( 'config.php' );
  
      // Force https
      if ( $config[ 'test-mode' ] &amp;&amp;
           $_SERVER[ 'HTTPS' ] != 'on' )
      {
          header( 'HTTP/1.1 301 Moved Permanently' );
          header( 'Location: https://' .
                      $_SERVER[ "SERVER_NAME" ] .
                      $_SERVER[ "REQUEST_URI" ] );
          exit;
      }
  
      if ( $_POST )
      {
          \Stripe\Stripe::setApiKey( $config[ 'secret-key' ] );
  
          // POSTed Variables
          $token      = $_POST[ 'stripeToken' ];
          $first_name = $_POST[ 'first-name' ];
          $last_name  = $_POST[ 'last-name' ];
          $name       = $first_name .
                            ' ' .
                            $last_name;
          $address    = $_POST[ 'address' ] .
                            "\n" .
                            $_POST[ 'city' ] .
                            ', ' .
                            $_POST[ 'state' ] .
                            ' ' .
                            $_POST[ 'zip' ];
          $email      = $_POST[ 'email' ];
          $phone      = $_POST[ 'phone' ];
          $amount     = (float) $_POST[ 'amount' ];
  
          try
          {
              if ( ! isset( $_POST[ 'stripeToken' ] ) )
              {
                  throw new Exception( "The Stripe Token was not generated correctly" );
              }
  
              // Charge the card
              $donation = \Stripe\Charge::create( array( 'card'        =&gt; $token,
                                                         'description' =&gt; 'Donation by ' .
                                                                              $name .
                                                                              ' (' .
                                                                              $email .
                                                                              ')',
                                                                          'amount' =&gt; $amount * 100,
                                                                          'currency' =&gt; 'usd' ) );
  
              // Build and send the email
              $headers = 'From: ' .
                             $config[ 'email-from' ];
  
              $headers .= "\r\nBcc: " .
                              $config[ 'email-bcc' ] .
                              "\r\n\r\n";
  
              // Find and replace values
              $find    = array( '%name%',
                                '%amount%' );
  
              $replace = array( $name,
                                '$' .
                                    $amount );
  
              $message = str_replace( $find,
                                      $replace,
                                      $config[ 'email-message' ] ) .
                                          "\n\n";
              $message .= 'Amount: $' .
                              $amount .
                              "\n";
  
              $message .= 'Address: ' .
                              $address .
                              "\n";
  
              $message .= 'Phone: ' .
                              $phone .
                              "\n";
  
              $message .= 'Email: ' .
                              $email .
                              "\n";
  
              $message .= 'Date: ' .
                              date( 'M j, Y, g:ia',
                                    $donation[ 'created' ] ) .
                                    "\n";
  
              $message .= 'Transaction ID: ' .
                              $donation['id'] .
                              "\n\n\n";
  
              $subject = $config[ 'email-subject' ];
  
              // Send it
              if ( !$config[ 'test-mode' ] )
              {
                  mail( $email,
                        $subject,
                        $message,
                        $headers );
              }
  
              // Forward to "Thank You" page
              header( 'Location: ' .
                      $config[ 'thank-you' ] );
              exit;
          }
          catch ( Exception $e )
          {
              $error = $e-&gt;getMessage();
          }
      }
  ?&gt;
  
  &lt;!DOCTYPE html&gt;
  
  &lt;html lang="en"&gt;
      &lt;head&gt;
          &lt;meta charset="UTF-8"&gt;
  
          &lt;title&gt;Title&lt;/title&gt;
  
          &lt;link rel="stylesheet" type="text/css" href="style.css" media="all"&gt;
          &lt;link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"&gt;
          &lt;link rel="icon" href="/favicon.ico" type="image/x-icon"&gt;
  
          &lt;script src  = "https://js.stripe.com/v2"
                  type = "text/javascript"&gt;
          &lt;/script&gt;
  
          &lt;script src  = "https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"
                  type = "text/javascript"&gt;
          &lt;/script&gt;
  
          &lt;script type = "text/javascript"&gt;
              Stripe.setPublishableKey( '&lt;?php echo $config[ 'publishable-key' ] ?&gt;' );
          &lt;/script&gt;
  
          &lt;script src  = "script.js"
                  type = "text/javascript" &gt;
          &lt;/script&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
          &lt;div class = "wrapper"&gt;
              &lt;div class = "messages"&gt;
                  &lt;!-- Error messages go here go here --&gt;
              &lt;/div&gt;
  
              &lt;form action = "#"
                    class  = "donation-form"
                    id     = "donor"
                    method = "POST"&gt;
                  &lt;fieldset&gt;
                      &lt;legend&gt;
                          Contact Information
                      &lt;/legend&gt;
  
                      &lt;div class = "form-row form-first-name"&gt;
                          &lt;label&gt;
                              First Name
                          &lt;/label&gt;
  
                          &lt;input class = "first-name text"
                                 name  = "first-name"
                                 type  = "text"&gt;
                      &lt;/div&gt;
  
                      &lt;div class = "form-row form-last-name"&gt;
                          &lt;label&gt;
                              Last Name
                          &lt;/label&gt;
  
                          &lt;input class = "last-name text"
                                 name  = "last-name"
                                 type  = "text"&gt;
                      &lt;/div&gt;
  
                      &lt;div class = "form-row form-email"&gt;
                          &lt;label&gt;
                              Email
                          &lt;/label&gt;
  
                          &lt;input class = "email text"
                                 name  = "email"
                                 type  = "text"&gt;
                      &lt;/div&gt;
  
                      &lt;div class = "form-row form-phone"&gt;
                          &lt;label&gt;
                              Phone
                          &lt;/label&gt;
  
                          &lt;input class = "phone text"
                                 name  = "phone"
                                 type  = "text"&gt;
                      &lt;/div&gt;
  
                      &lt;div class = "form-row form-address"&gt;
                          &lt;label&gt;
                              Address
                          &lt;/label&gt;
  
                          &lt;textarea class = "address text"
                                    name  = "address"
                                    cols  = "30"
                                    rows  = "2"&gt;
                          &lt;/textarea&gt;
                      &lt;/div&gt;
  
                      &lt;div class = "form-row form-city"&gt;
                          &lt;label&gt;
                              City
                          &lt;/label&gt;
  
                          &lt;input class = "city text"
                                 name  = "city"
                                 type  = "text"&gt;
                      &lt;/div&gt;
  
                      &lt;div class = "form-row form-state"&gt;
                          &lt;label&gt;
                              State
                          &lt;/label&gt;
  
                          &lt;select name = "state" class="state text"&gt;
                              &lt;option value = "AL"&gt;
                                  AL
                              &lt;/option&gt;
  
                              &lt;option value = "AK"&gt;
                                  AK
                              &lt;/option&gt;
  
                              &lt;option value = "AZ"&gt;
                                  AZ
                              &lt;/option&gt;
  
                              &lt;option value = "AR"&gt;
                                  AR
                              &lt;/option&gt;
  
                              &lt;option value = "CA"&gt;
                                  CA
                              &lt;/option&gt;
  
                              &lt;option value = "CO"&gt;
                                  CO
                              &lt;/option&gt;
  
                              &lt;option value = "CT"&gt;
                                  CT
                              &lt;/option&gt;
  
                              &lt;option value = "DE"&gt;
                                  DE
                              &lt;/option&gt;
  
                              &lt;option value = "DC"&gt;
                                  DC
                              &lt;/option&gt;
  
                              &lt;option value = "FL"&gt;
                                  FL
                              &lt;/option&gt;
  
                              &lt;option value = "GA"&gt;
                                  GA
                              &lt;/option&gt;
  
                              &lt;option value = "HI"&gt;
                                  HI
                              &lt;/option&gt;
  
                              &lt;option value = "ID"&gt;
                                  ID
                              &lt;/option&gt;
  
                              &lt;option value = "IL"&gt;
                                  IL
                              &lt;/option&gt;
  
                              &lt;option value = "IN"&gt;
                                  IN
                              &lt;/option&gt;
  
                              &lt;option value = "IA"&gt;
                                  IA
                              &lt;/option&gt;
  
                              &lt;option value = "KS"&gt;
                                  KS
                              &lt;/option&gt;
  
                              &lt;option value = "KY"&gt;
                                  KY
                              &lt;/option&gt;
  
                              &lt;option value = "LA"&gt;
                                  LA
                              &lt;/option&gt;
  
                              &lt;option value = "ME"&gt;
                                  ME
                              &lt;/option&gt;
  
                              &lt;option value = "MD"&gt;
                                  MD
                              &lt;/option&gt;
  
                              &lt;option value = "MA"&gt;
                                  MA
                              &lt;/option&gt;
  
                              &lt;option value = "MI"&gt;
                                  MI
                              &lt;/option&gt;
  
                              &lt;option value = "MN"&gt;
                                  MN
                              &lt;/option&gt;
  
                              &lt;option value = "MS"&gt;
                                  MS
                              &lt;/option&gt;
  
                              &lt;option value = "MO"&gt;
                                  MO
                              &lt;/option&gt;
  
                              &lt;option value = "MT"&gt;
                                  MT
                              &lt;/option&gt;
  
                              &lt;option value = "NE"&gt;
                                  NE
                              &lt;/option&gt;
  
                              &lt;option value = "NV"&gt;
                                  NV
                              &lt;/option&gt;
  
                              &lt;option value = "NH"&gt;
                                  NH
                              &lt;/option&gt;
  
                              &lt;option value = "NJ"&gt;
                                  NJ
                              &lt;/option&gt;
  
                              &lt;option value = "NM"&gt;
                                  NM
                              &lt;/option&gt;
  
                              &lt;option value = "NY"&gt;
                                  NY
                              &lt;/option&gt;
  
                              &lt;option value = "NC"&gt;
                                  NC
                              &lt;/option&gt;
  
                              &lt;option value = "ND"&gt;
                                  ND
                              &lt;/option&gt;
  
                              &lt;option value = "OH"&gt;
                                  OH
                              &lt;/option&gt;
  
                              &lt;option value = "OK"&gt;
                                  OK
                              &lt;/option&gt;
  
                              &lt;option value = "OR"&gt;
                                  OR
                              &lt;/option&gt;
  
                              &lt;option value = "PA"&gt;
                                  PA
                              &lt;/option&gt;
  
                              &lt;option value = "RI"&gt;
                                  RI
                              &lt;/option&gt;
  
                              &lt;option value = "SC"&gt;
                                  SC
                              &lt;/option&gt;
  
                              &lt;option value = "SD"&gt;
                                  SD
                              &lt;/option&gt;
  
                              &lt;option value = "TN"&gt;
                                  TN
                              &lt;/option&gt;
  
                              &lt;option value = "TX"&gt;
                                  TX
                              &lt;/option&gt;
  
                              &lt;option value = "UT"&gt;
                                  UT
                              &lt;/option&gt;
  
                              &lt;option value = "VT"&gt;
                                  VT
                              &lt;/option&gt;
  
                              &lt;option value = "VA"&gt;
                                  VA
                              &lt;/option&gt;
  
                              &lt;option value = "WA"&gt;
                                  WA
                              &lt;/option&gt;
  
                              &lt;option value = "WV"&gt;
                                  WV
                              &lt;/option&gt;
  
                              &lt;option value = "WI"&gt;
                                  WI
                              &lt;/option&gt;
  
                              &lt;option value = "WY"&gt;
                                  WY
                              &lt;/option&gt;
                          &lt;/select&gt;
                      &lt;/div&gt;
  
                      &lt;div class = "form-row form-zip"&gt;
                          &lt;label&gt;
                              Zip
                          &lt;/label&gt;
  
                          &lt;input class = "zip text"
                                 name  = "zip"
                                 type  = "text"&gt;
                      &lt;/div&gt;
                  &lt;/fieldset&gt;
  
                  &lt;fieldset&gt;
                      &lt;legend&gt;
                          Your Generous Donation
                      &lt;/legend&gt;
  
                      &lt;div class = "form-row form-amount"&gt;
                          &lt;label&gt;
                              &lt;input class = "set-amount"
                                     name  = "amount"
                                     type  = "radio"
                                     value = "10"&gt;
                                  $10
                          &lt;/label&gt;
  
                          &lt;label&gt;
                              &lt;input class = "set-amount"
                                     name  = "amount"
                                     type  = "radio"
                                     value = "27"&gt;
                                  $27
                          &lt;/label&gt;
  
                          &lt;label&gt;
                              &lt;input class = "set-amount"
                                     name  = "amount"
                                     type  = "radio"
                                     value = "50"&gt;
                                  $50
                          &lt;/label&gt;
  
                          &lt;label&gt;
                              &lt;input class = "set-amount"
                                     name  = "amount"
                                     type  = "radio"
                                     value = "100"&gt;
                                  $100
                          &lt;/label&gt;
  
                          &lt;label&gt;
                              &lt;input class = "other-amount"
                                     name  = "amount"
                                     type  = "radio"
                                     value = "0"&gt;
                                  Other:
                          &lt;/label&gt;
  
                          &lt;input type="text" class="amount text" /&gt;
                      &lt;/div&gt;
  
                      &lt;div class="form-row form-number"&gt;
                          &lt;label&gt;
                              Card Number
                          &lt;/label&gt;
  
                          &lt;input class        = "card-number text"
                                 autocomplete = "off"
                                 type         = "text"
                                 value        = ""&gt;
                      &lt;/div&gt;
  
                      &lt;div class="form-row form-cvc"&gt;
                          &lt;label&gt;
                              CVC
                          &lt;/label&gt;
  
                          &lt;input class        = "card-cvc text"
                                 autocomplete = "off"
                                 type         = "text"
                                 value        = ""&gt;
                      &lt;/div&gt;
  
                      &lt;div class = "form-row form-expiry"&gt;
                          &lt;label&gt;
                              Expiration Date
                          &lt;/label&gt;
  
                          &lt;select class="card-expiry-month text"&gt;
                              &lt;option selected
                                      value = "01"&gt;
                                  January
                              &lt;/option&gt;
  
                              &lt;option value = "02"&gt;
                                  February
                              &lt;/option&gt;
  
                              &lt;option value = "03"&gt;
                                  March
                              &lt;/option&gt;
  
                              &lt;option value = "04"&gt;
                                  April
                              &lt;/option&gt;
  
                              &lt;option value = "05"&gt;
                                  May
                              &lt;/option&gt;
  
                              &lt;option value = "06"&gt;
                                  June
                              &lt;/option&gt;
  
                              &lt;option value = "07"&gt;
                                  July
                              &lt;/option&gt;
  
                              &lt;option value = "08"&gt;
                                  August
                              &lt;/option&gt;
  
                              &lt;option value = "09"&gt;
                                  September
                              &lt;/option&gt;
  
                              &lt;option value = "10"&gt;
                                  October
                              &lt;/option&gt;
  
                              &lt;option value = "11"&gt;
                                  November
                              &lt;/option&gt;
  
                              &lt;option value = "12"&gt;
                                  December
                              &lt;/option&gt;
                          &lt;/select&gt;
  
                          &lt;select class = "card-expiry-year text"&gt;
                              &lt;option selected
                                      value = "2017"&gt;
                                  2017
                              &lt;/option&gt;
  
                              &lt;option value = "2018"&gt;
                                  2018
                              &lt;/option&gt;
  
                              &lt;option value = "2019"&gt;
                                  2019
                              &lt;/option&gt;
  
                              &lt;option value = "2020"&gt;
                                  2020
                              &lt;/option&gt;
  
                              &lt;option value = "2021"&gt;
                                  2021
                              &lt;/option&gt;
  
                              &lt;option value = "2022"&gt;
                                  2022
                              &lt;/option&gt;
  
                              &lt;option value = "2023"&gt;
                                  2023
                              &lt;/option&gt;
  
                              &lt;option value = "2024"&gt;
                                  2024
                              &lt;/option&gt;
  
                              &lt;option value = "2025"&gt;
                                  2025
                              &lt;/option&gt;
  
                              &lt;option value = "2026"&gt;
                                  2026
                              &lt;/option&gt;
                          &lt;/select&gt;
                      &lt;/div&gt;
  
                      &lt;div class = "form-row form-submit"&gt;
                          &lt;input class = "submit-button"
                                 type  = "submit"
                                 value = "Submit Donation"&gt;
                      &lt;/div&gt;
                  &lt;/fieldset&gt;
              &lt;/form&gt;
          &lt;/div&gt;
  
          &lt;script&gt;
              if ( window.Stripe ) $('.donation-form').show()
          &lt;/script&gt;
  
          &lt;noscript&gt;
              &lt;p&gt;
                  JavaScript is required for the donation form.
              &lt;/p&gt;
          &lt;/noscript&gt;
      &lt;/body&gt;
  
      &lt;script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"&gt;
      &lt;/script&gt;
  
      &lt;script src = 'google-sheet.js'&gt;
      &lt;/script&gt;
  &lt;/html&gt;
  </code></pre>