title: What is the structure of Stripe PHP API method response?
body: <p>I am working on a Stripe integration and I am baffled by the actual responses I get from the PHP API. I started out believing that the API reference was accurate and that the response would be a JSON string as shown for each method. I quickly discovered significant differences. Most often, the id field is missing from the JSON response. Also, the response seems to be a string, an object, and maybe some other structures, all at the same time.</p>
  
  <p>Here is my debug code. I am using the latest Stripe PHP library, version 1.7.15. </p>
  
  <pre><code>function var_dump_ret($mixed=null)
  {
    ob_start();
    var_dump($mixed);
    $content=ob_get_contents();
    ob_end_clean();
    return($content);
  }
  
  $token=$_POST['stripeToken'];
  $customer=Stripe_Customer::create(array(
    "card"=&gt;$token,
    "plan"=&gt;"agency")
  );
  
  $custVarDump=var_dump_ret($customer);
  $cDecoded=json_decode($customer);
  $Debug="Invidual attributes of JSON decoded customer object:"._EOL;
  $Debug.="object:".$cDecoded-&gt;object._EOL;
  $Debug.="created:".$cDecoded-&gt;created._EOL;
  $Debug.="id:".$cDecoded-&gt;id._EOL;
  $Debug.="livemode:".$cDecoded-&gt;livemode._EOL;
  $Debug.="description:".$cDecoded-&gt;description._EOL;
  $Debug.="active_card.object:".$cDecoded-&gt;active_card-&gt;object._EOL;
  $Debug.="active_card.last4:".$cDecoded-&gt;active_card-&gt;last4._EOL;
  $Debug.="active_card.type:".$cDecoded-&gt;active_card-&gt;type._EOL;
  $Debug.="active_card.exp_month:".$cDecoded-&gt;active_card-&gt;exp_month._EOL;
  $Debug.="active_card.exp_year:".$cDecoded-&gt;active_card-&gt;exp_year._EOL;
  $Debug.="active_card.fingerprint:".$cDecoded-&gt;active_card-&gt;fingerprint._EOL;
  $Debug.="active_card.country:".$cDecoded-&gt;active_card-&gt;country._EOL;
  $Debug.="active_card.name:".$cDecoded-&gt;active_card-&gt;name._EOL;
  $Debug.="active_card.address_line1:".$cDecoded-&gt;active_card-&gt;address_line1._EOL;
  $Debug.="active_card.address_line2:".$cDecoded-&gt;active_card-&gt;address_line2._EOL;
  $Debug.="active_card.address_city:".$cDecoded-&gt;active_card-&gt;address_city._EOL;
  $Debug.="active_card.address_state:".$cDecoded-&gt;active_card-&gt;address_state._EOL;
  $Debug.="active_card.address_zip:".$cDecoded-&gt;active_card-&gt;address_zip._EOL;
  $Debug.="active_card.address_country:".$cDecoded-&gt;active_card-&gt;address_country._EOL;
  $Debug.="active_card.cvc_check:".$cDecoded-&gt;active_card-&gt;cvc_check._EOL;
  $Debug.="active_card.address_line1_check:".$cDecoded-&gt;active_card-&gt;address_line1_check._EOL;
  $Debug.="active_card.address_zip_check:".$cDecoded-&gt;active_card-&gt;address_zip_check._EOL;
  $Debug.="email:".$cDecoded-&gt;email._EOL;
  $Debug.="delinquent:".$cDecoded-&gt;delinquent._EOL;
  //$Debug.="subscription:".$cDecoded-&gt;subscription._EOL;
  $Debug.="discount:".$cDecoded-&gt;discount._EOL;
  $Debug.="account_balance:".$cDecoded-&gt;account_balance._EOL;
  $Debug.="unaltered response from Stripe_Customer::create:"._EOL.$customer._EOL.
      "var dump of response:"._EOL.$custVarDump._EOL.
      "print_r of json_decode of response:"._EOL.print_r($cDecoded,true)._EOL;
  
  file_put_contents(_LOGFILE,$Debug,FILE_APPEND);
  </code></pre>
  
  <p>Below are the contents of my debug file for the invidual attributes of the JSON decoded customer object. When executed, the code posted a notice.</p>
  
  <p>Notice: Undefined property: stdClass::$id in stripe/subscription.php on line 51</p>
  
  <p>Also note that I had to comment out the line that added 'subscription' to the debug string due to a fatal error regarding stdClass.</p>
  
  <pre><code>object:customer
  created:1365951909
  id:
  livemode:
  description:
  active_card.object:card
  active_card.last4:4242
  active_card.type:Visa
  active_card.exp_month:7
  active_card.exp_year:2013
  active_card.fingerprint:WTXPLgKDCXyp9xpD
  active_card.country:US
  active_card.name:charlie
  active_card.address_line1:
  active_card.address_line2:
  active_card.address_city:
  active_card.address_state:
  active_card.address_zip:
  active_card.address_country:
  active_card.cvc_check:pass
  active_card.address_line1_check:
  active_card.address_zip_check:
  email:
  delinquent:
  discount:
  account_balance:0
  </code></pre>
  
  <p>Most notably absent is the customer ID. It does not exist in the JSON response. However, as seen in some of the Stripe example programs, it can be accessed using $customer->id. Furthermore, the var_dump output indicates even more atributes are present in a structure I cannot figure out. The entire debug file is at <a href="http://www.helioza.com/stripe/debug.txt" rel="noreferrer">http://www.helioza.com/stripe/debug.txt</a>. I have only shown the customer create method, but I am experiencing similar problems with invoices and cannot find the invoice id anywhere in the Stripe_Invoice::all or Stripe_Invoice::upcoming responses.</p>
  
  <p>Questions</p>
  
  <p>1) How can the value returned by Stripe_Customer::create be both a string and an object at the same time?</p>
  
  <p>2) Where can I find documentation that describes the API method return values, including how to access each attribute?</p>