title: Handling Variable Amount (Donation) With Stripe & PHP
body: <p>I need to allow users to enter custom amounts using Stripe. They enter what they want to pay in a input. Then I have a script that collects the amount below the default stripe checkout button. But how am I supposed to handle the charge server-side on <code>charge.php</code>?</p>
  
  <p><strong>donation.php</strong></p>
  
  <pre><code>    //user enter custom amount
      &lt;input type="number" class='form-control' 
      id="custom-donation-amount" 
      placeholder="$50.00" min="0" step="10.00 " /&gt;
  
      //default stripe checkout button
        &lt;script
          src="https://checkout.stripe.com/checkout.js" class="stripe-button"
          data-key="pk_test_XXXXXXXXXXXXXXX"
          data-amount="0"
          data-name="ORGANIZATION"
          data-description="Saving Penguins"
          data-image="logo.png"
          data-locale="auto"
          data-zip-code="true"
          data-billing-address="true"
          data-label="DONATE"
          data-currency="usd"&gt;
        &lt;/script&gt;
  
  //script to collect variable amount
    &lt;script type="text/javascript"&gt;
      $(function() {
          $('.donate-button').click(function(event) {
              var amount = $('#custom-donation-amount').val();        
              $('.stripe-button').attr('data-amount', amount)
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>charge.php</strong></p>
  
  <pre><code>&lt;?php require_once('./config.php');
  
    $token  = $_POST['stripeToken'];
    $email  = $_POST['stripeEmail'];
  
    $customer = \Stripe\Customer::create(array(
        'source'  =&gt; $token,
        'email' =&gt; $email)
    );
  
    $charge = \Stripe\Charge::create(array(
        'customer' =&gt; $customer-&gt;id,
        'amount'   =&gt; $amount,
        'currency' =&gt; 'usd'
    ));
  
     header("Location: confirmation.php");
  die();
  
  
  ?&gt;
  </code></pre>