Hashaam
Hashaam

Reputation: 125

How do i get charge info from customer object in stripe

After successful payment . i print_r($customer) to get card and charge information .I received this ,i only able to get first Stripe_Customer Object information but not Stripe_Card Object from $customer variable

Stripe_Card Object ([_apiKey:protected] => sk_test_... [_values:protected] 
=> Array ( [id] => card_1BLsOAJ6IzxnlSnmpPloNXUN 
[object] => card [address_city] => lahore 
[address_country] => Pakistan 

only first Stripe_Customer Object of array can easily get e.g

echo  $customer['id']

i try many times to get information of card object using these methods but not work for me

echo $customer->source->card->address_country;
echo $customer->source->address_country;
echo $customer['card'];
echo $customer['address_country'];
echo $customer['card']['address_country'];

Upvotes: 0

Views: 396

Answers (1)

koopajah
koopajah

Reputation: 25552

A customer can have more than one source at the same time. The source property on the Customer is a list as documented here. If you want to access the card object you'd need to do something like this:

$card = $customer->sources->data[0];
$cardId = $card->id;
$cardLast4 = $card->last4;
// etc.

Upvotes: 3

Related Questions