title: STRIPE Payment integration with PHP
body: <p>Have the below code - works fine.. BUT...  As the DB is updated to PAID before the charge, and if the charge is declined, the DB is still updated to PAID.</p>
  
  <p>Want to achieve - </p>
  
  <p>If charge successful and not declined, charge customer THEN update DB to PAID..</p>
  
  <p>NOT</p>
  
  <p>Update DB to PAID, then charge customer...</p>
  
  <hr>
  
  <pre><code>// Create connection
  $conn = mysqli_connect($hostname, $username,$password, $database);
  
  // Check connection
      if (!$conn) {
      die("Connection failed: " . mysqli_connect_error());
      }
  
  $sql = "UPDATE details SET PaymentStatus='PAID' WHERE MembershipNo ='12345'";
  
  if (mysqli_query($conn, $sql)) {
  // starting the session
  
    require_once('config.php');
  
    $token  = $_POST['stripeToken'];
  
    $email = $_POST['stripeEmail'];
  
    $SOSamount = ($_SESSION['price']*100);
    $FirstName = ($_SESSION['FirstName']);
    $LastName = ($_SESSION['LastName']);
  
    $customer = \Stripe\Customer::create(array(
            'email' =&gt; $email,
            'source'  =&gt; $token,
            'description'  =&gt; "$FirstName $LastName - Membership"
            ));
  
  $charge = \Stripe\Charge::create(array(
      'customer' =&gt; $customer-&gt;id,
      'amount'   =&gt; $amount,
      'currency' =&gt; 'aud',
      'description' =&gt; "Membership - $FirstName $LastName"
        ));
  
       mysqli_close($conn);
  </code></pre>