Analysis of output from Stripe_Charge Stripe Payments

The following output is the result of a call var_export($charge);

How can I access the output 'paid'=>truefrom $charge? Any ideas would be appreciated.

I tried $charge->_values->paid, $charge->paidetc. I was not lucky.

I also tried $charge['_values']['paid'];

Stripe_Charge::__set_state(array(
   '_apiKey' => 'sk_test_BPZyFpcAM',
   '_values' => 
  array (
    'id' => 'ch_102kMF29T6',
    'object' => 'charge',
    'created' => 1381688,
    'livemode' => false,
    'paid' => true,
    'amount' => 104000,
    'currency' => 'usd',
    'refunded' => false,
    'card' => 
    Stripe_Card::__set_state(array(
       '_apiKey' => 'sk_test_BPZyFpc',
       '_values' => 
      array (
        'id' => 'card_102kMF29T6',
        'object' => 'card',
        'last4' => '4242',
        'type' => 'Visa',
        'exp_month' => 2,
        'exp_year' => 2015,
        'fingerprint' => '7sRY4jiFM',
        'customer' => NULL,
        'country' => 'US',
        'name' => NULL,
        'address_line1' => NULL,
        'address_line2' => NULL,
        'address_city' => NULL,
        'address_state' => NULL,
        'address_zip' => NULL,
        'address_country' => NULL,
        'cvc_check' => 'pass',
        'address_line1_check' => NULL,
        'address_zip_check' => NULL,
      ),
       '_unsavedValues' => 
      Stripe_Util_Set::__set_state(array(
         '_elts' => 
        array (
        ),
      )),
       '_transientValues' => 
      Stripe_Util_Set::__set_state(array(
         '_elts' => 
        array (
        ),
      )),
       '_retrieveOptions' => 
      array (
      ),
    )),
    'captured' => true,
    'refunds' => 
    array (
    ),
    'balance_transaction' => 'txn_102kMF29T6Z',
    'failure_message' => NULL,
    'failure_code' => NULL,
    'amount_refunded' => 0,
    'customer' => NULL,
    'invoice' => NULL,
    'description' => 'admin@fra.org',
    'dispute' => NULL,
    'metadata' => 
    array (
    ),
  ),
   '_unsavedValues' => 
  Stripe_Util_Set::__set_state(array(
     '_elts' => 
    array (
    ),
  )),
   '_transientValues' => 
  Stripe_Util_Set::__set_state(array(
     '_elts' => 
    array (
    ),
  )),
   '_retrieveOptions' => 
  array (
  ),
))
+4
source share
4 answers

You can use the __toArray ($ recursive = false) function to get data in the form of an array.

Example:

$chargeArray = $charge->__toArray(true);
echo $chargeArray['paid'];

I was also able to access object data using an array structure before even converting to an array. For me it $charge['paid']gets meaning.

+12
source

you can use the method __toArray():

$array = $collection->__toArray(true);

+2

, , , json_decode, - php , $ret

$ret = json_decode($ret); 

$ret->paid;
$ret->captured;
$ret->card->id; 
and so on..

, .

+1
echo gettype($charge->paid); //boolean
var_dump($charge->paid); //bool(true)

if($charge->paid==true)echo "==true"; //==true
if($charge->paid===true)echo "===true"; //===true
if($charge->paid==1)echo "==1"; //==1
if($charge->paid===1)echo "===1"; //nada, it a boolean, not numeric

, if($charge->paid===true), , , .

, print_r, , 1.

 [_values:protected] => Array ( [id] => ch_10as29724hknftGBm9TxC [object] => charge [created] => 1384696845 [livemode] => [paid] => 1 [amount] => 1400

, , , , . if($charge->paid){...}

- false, , , (""), 0 false. , , - , .

$val = "false";
if($val){
    echo "true"; //true
}

, intval ($ val), .

if(intval($charge->paid)){...}

0

All Articles