Stripe_InvalidRequestError: You cannot use a Stripe token more than once I'm trying to integrate Stripe’s Checkout and PHP into a simple module and I've got the following:

Stripe::setApiKey($stripe['secret_key']);

if (!empty($form_state['input'])) {
  $input = $form_state['input'];
  // Create a Customer
  $customer = Stripe_Customer::create(array(
    "card" =&gt; $input['stripeToken'],
    "email" =&gt; $input['stripeEmail'],
  ));

  // Charge the Customer instead of the card
  $charge = Stripe_Charge::create(array(
    "amount" =&gt; 4900,
    "currency" =&gt; "GBP",
    "customer" =&gt; $customer-&gt;id,
  ));
}
else {
  $data = array(
    "data-key" =&gt; $stripe['publishable_key'],
    "data-name" =&gt; variable_get("site_name", ""),
    "data-amount" =&gt; 4900,
    "data-currency" =&gt; "GBP",
  );

  $form['stripe'] = array(
    '#markup' =&gt; '&lt;script src="https://checkout.stripe.com/checkout.js" class="stripe-button" ' . join(' ', array_map(function($sKey) use ($data) {
      if (is_bool($data[$sKey])) {
        return $data[$sKey] ? $sKey : '';
      }
      return $sKey . '="' . $data[$sKey] . '"';
    }, array_keys($data))) . '&gt;&lt;/script&gt;'
  );
}


Everything is working great so far apart from when I call $charge = Stripe_Charge::create I get an error returned Stripe_InvalidRequestError: You cannot use a Stripe token more than once but I don't understand how my code would be using the token more than once.

Although I get this error, in my dashboard at Stripe the payment is successfully processed, I'm using the Stripe API Client Library for PHP
OK I have figured it out, when the form code is running, it runs multiple times, to stop it I added a variable to $form_state so the top of my code above becomes:

Stripe::setApiKey($stripe['secret_key']);

if (!empty($form_state['input']) &amp;&amp; !isset($form_state['processed'])) {
  $form_state['processed'] = TRUE;