According to the API document of Stripe, I can access the card id
like this:
<?php
\Stripe\Stripe::setApiKey("sk_test_xxxxxxxxxxxxxxxx");
// Get details from card
$customer = \Stripe\Customer::retrieve("cus_xxxxxxxxxxx");
print_r($customer->sources->data->id);
?>
But nothing is echo.
Could you please help me?
I following this documentation : https://stripe.com/docs/api/php#customer_object
A customer can have multiple cards, so $customer->sources->data
is an array (as you should be able to tell from the square brackets around the value of this property). Therefore, you need to index it.
print_r($customer->sources->data[0]->id);
And if a customer has saved multiple credit cards, you should loop over it:
foreach ($customer->sources->data as $card) {
print_r($card->id);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.