What is the structure of the response of the Stripe PHP API method method?

I am working on Stripe integration and I am confused by the actual answers received from the PHP API. I began to think that the API reference is accurate and that the response will be a JSON string, as shown for each method. I quickly discovered significant differences. Most often, the id field is not in the JSON response. In addition, the answer seems to be a string, an object, and possibly some other structures, all at the same time.

Here is my debug code. I am using the latest Stripe PHP library, version 1.7.15.

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"=>$token,
  "plan"=>"agency")
);

$custVarDump=var_dump_ret($customer);
$cDecoded=json_decode($customer);
$Debug="Invidual attributes of JSON decoded customer object:"._EOL;
$Debug.="object:".$cDecoded->object._EOL;
$Debug.="created:".$cDecoded->created._EOL;
$Debug.="id:".$cDecoded->id._EOL;
$Debug.="livemode:".$cDecoded->livemode._EOL;
$Debug.="description:".$cDecoded->description._EOL;
$Debug.="active_card.object:".$cDecoded->active_card->object._EOL;
$Debug.="active_card.last4:".$cDecoded->active_card->last4._EOL;
$Debug.="active_card.type:".$cDecoded->active_card->type._EOL;
$Debug.="active_card.exp_month:".$cDecoded->active_card->exp_month._EOL;
$Debug.="active_card.exp_year:".$cDecoded->active_card->exp_year._EOL;
$Debug.="active_card.fingerprint:".$cDecoded->active_card->fingerprint._EOL;
$Debug.="active_card.country:".$cDecoded->active_card->country._EOL;
$Debug.="active_card.name:".$cDecoded->active_card->name._EOL;
$Debug.="active_card.address_line1:".$cDecoded->active_card->address_line1._EOL;
$Debug.="active_card.address_line2:".$cDecoded->active_card->address_line2._EOL;
$Debug.="active_card.address_city:".$cDecoded->active_card->address_city._EOL;
$Debug.="active_card.address_state:".$cDecoded->active_card->address_state._EOL;
$Debug.="active_card.address_zip:".$cDecoded->active_card->address_zip._EOL;
$Debug.="active_card.address_country:".$cDecoded->active_card->address_country._EOL;
$Debug.="active_card.cvc_check:".$cDecoded->active_card->cvc_check._EOL;
$Debug.="active_card.address_line1_check:".$cDecoded->active_card->address_line1_check._EOL;
$Debug.="active_card.address_zip_check:".$cDecoded->active_card->address_zip_check._EOL;
$Debug.="email:".$cDecoded->email._EOL;
$Debug.="delinquent:".$cDecoded->delinquent._EOL;
//$Debug.="subscription:".$cDecoded->subscription._EOL;
$Debug.="discount:".$cDecoded->discount._EOL;
$Debug.="account_balance:".$cDecoded->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);

Below is the contents of my debug file for the invisible attributes of a decoded client JSON object. When it was executed, the code sent a notification.

Note: Undefined property: stdClass :: $ id in stripe / subscription.php on line 51

, , "" - , stdClass.

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

, . JSON. , Stripe, $customer- > id. , var_dump , , . http://www.helioza.com/stripe/debug.txt. , Stripe_Invoice:: all Stripe_Invoice::.

1) , Stripe_Customer:: create, , ?

2) , API, ?

+5
2

, Stripe API JSON HTTP (.. , ), Stripe PHP JSON PHP.

Stripe_Customer::create json_decode - , , , json_decode , , .

, . $customer->description $customer->active_card->cvc_check. , , .

+6

. , , Stripe PHP, . , JSON .

JSON, , script, JSON PHP, $obj- > arr [index] → obj2, . www.helioza.com/decoders/explain-json.php JSON, , Stripe API, PHP-, .

5/27/2014

, , . , , , , Stripe API.

, PHP-. API.

EXAMPLE RESPONSE
{
  "object": "customer",
  "created": 1401219085,
  "id": "cus_474RjipEtz2ff7",
  "livemode": false,
  "description": "payinguser@example.com",
  "email": null,
  "delinquent": false,
  "metadata": {
  },
  "subscriptions": {
    "object": "list",
    "total_count": 0,
    "has_more": false,
    "url": "/v1/customers/cus_474RjipEtz2ff7/subscriptions",
    "data": [

    ]
  },

, , -API HTTP. - Stripe , POST. , JSON, HTTP. doc JSON - . JSON, , , , . StdClass , PHP .

. , Stripe ? , JSON HTTP. .

, , , , Stripe . . SO .

+2
source

All Articles