php - how to get second level data from Stripe JSON object -
i have function able retrieve level 1 array data, not level 2 in return json string following charge.
else if(!empty($_session['sess_plan_buy_code'])){        $pcharge = \stripe\customer::create(array(        "source" => $_post['stripetoken'],        "plan" => $_session['sess_plan_buy_code'],        "email" => $_session["sess_email"]        ));     echo "my customer id is: " . $pcharge->id;     echo'<br>';     $stuff = json_decode($pcharge->subscriptions);     var_dump($stuff); actual json return string: json
the output above code is:
my customer id is: cus_6cvcqdpdhmqlge null
expected output:
my customer id is: cus_6cvcqdpdhmqlge 1
i have tried:
$stuff = $pcharge->subscriptions[0]; $stuff = $pcharge->subscriptions['total_count']; $stuff = json_decode($pcharge->subscriptions); and  few loops either null or other error indicating programmer doesn't know doing.
how level 2 , level 3 data in stripe json return string?
you don't need call json_decode(), stripe api decoding internally. need access objects , arrays returns.
$pcharge = \stripe\customer::create(array(     "source" => $_post['stripetoken'],     "plan" => $_session['sess_plan_buy_code'],     "email" => $_session["sess_email"] )); echo "my customer id is: " . $pcharge->id; echo'<br>'; $stuff = $pcharge->subscriptions; echo "subscription count is: " . count($stuff->data); // total_count isn't returned default if want access subscriptions, use $stuff->data[$i].
Comments
Post a Comment