Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing Output from Stripe_Charge Stripe Payments

Tags:

php

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

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

I have tried $charge->_values->paid, $charge->paid, etc.. I haven't had any luck.

I have 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' => '[email protected]',
    'dispute' => NULL,
    'metadata' => 
    array (
    ),
  ),
   '_unsavedValues' => 
  Stripe_Util_Set::__set_state(array(
     '_elts' => 
    array (
    ),
  )),
   '_transientValues' => 
  Stripe_Util_Set::__set_state(array(
     '_elts' => 
    array (
    ),
  )),
   '_retrieveOptions' => 
  array (
  ),
))
like image 398
user2355051 Avatar asked Oct 13 '13 16:10

user2355051


3 Answers

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

Example:

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

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

like image 178
Andre Sugai Avatar answered Oct 28 '22 17:10

Andre Sugai


you can use __toArray() method:

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

This will work for this case

like image 22
Dharmender Tuli Avatar answered Oct 28 '22 15:10

Dharmender Tuli


whatever returns please parse it with json_decode and you will get a assoc array in php i.e suppose return array is $ret

$ret = json_decode($ret); 

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

Hope it will help you.

like image 25
Banty Roy Avatar answered Oct 28 '22 17:10

Banty Roy