title: Stripe Payments and Codeigniter | Getting return values
body: <p>Okay, So within my codeigniter application, I am using the <a href="https://stripe.com/docs/checkout" rel="nofollow noreferrer">Stripe Checkout</a>. I am using the custom option with the following code: </p>
  
  <pre><code>&lt;script&gt;
    var handler = StripeCheckout.configure({
      key: 'pk_test_qzoaU1JTxL7DHF0i4aq3o3Q8',
      image: 'https://candykingdom.org/assets/img/logo/ck_castle.png',
      token: function(token, args) {
        var token = token.id;
        var cost = $('#prices').html();
        var total = cost.replace('.', '');
        var price = total.replace('$', '');
        var price = $.trim(price);
        dataString = 'token=' + token + '&amp;amount=' + price;
        //alert(dataString); return false;
        $.ajax({
          type: "POST",
          url: "/checkout/doCharge",
          data: dataString,
          success: function(data) {
              alert(data);
          }
        });
      }
    });
  
    document.getElementById('customButton').addEventListener('click', function(e) {
        var price = $('#prices').html();
        var total = price.replace('.', '');
        var price = total.replace('$', '');
        // Open Checkout with further options
        handler.open({
          name: 'Candy Kingdom',
          description: 'On-line Purchase',
          amount: price,
          allowRememberMe: false,
  
        });
        e.preventDefault();
    });
  &lt;/script&gt;
  </code></pre>
  
  <p>That creates the checkout and takes care of all that. </p>
  
  <hr>
  
  <p>Then I have the codeigniter Stripe library installed and in the <code>/checkout/doCharge/</code> I have the following code: </p>
  
  <pre><code>public function doCharge()
  {
      $this-&gt;load-&gt;library('stripe');
  
      $amount = $_POST['amount'];
  
      $card = $_POST['token'];
  
      $desc = 'Candy Kingdom On-line Order';
  
      $response = $this-&gt;stripe-&gt;charge_card($amount, $card, $desc);
  
      echo $response;
  }
  </code></pre>
  
  <p>What I am wanting to know is, In the function above, How do I manage to tell whether or not the card was approved/denied. And if it was denied how do I get the failure message from stripe? </p>
  
  <p>I know that stripe <a href="https://stripe.com/docs/api#charge_object" rel="nofollow noreferrer">returns this when you charge a card</a>, I'm just not sure what variable explains the approve/deny and the failing message and how to properly pull them from the <code>json return from stripe.</code></p>
  
  <p>When I run a test card I receive the following in the echo $response;</p>
  
  <p><img src="https://i.stack.imgur.com/blXhj.png" alt="enter image description here"></p>