[英]Get card id from Stripe API in PHP
According to the API document of Stripe, I can access the card id
like this: 根据Stripe的API文档,我可以这样访问
card id
:
<?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 我遵循此文档: 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). 一个客户可以拥有多张卡,因此
$customer->sources->data
是一个数组(正如您应该能够在此属性的值周围的方括号中看出)。 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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.