我正在尝试通过提供客户ID来检索特定客户的所有卡。根据{{3}},我期待以下回复:
Stripe\Collection JSON: {
"object" => "list",
"url" => "/v1/customers/cu_16jdAj2eZvKYlo2CbrCP4HRs/sources",
"has_more" => false,
"data" => [
[0] => Stripe\Card JSON: {
"id": "card_14bIFkou9GUI42eZvKYlo2Cs",
"object": "card",
"last4": "4242",
"brand": "Visa",
"funding": "credit",
"exp_month": 11,
"exp_year": 2018,
"country": "US",
"name": "callingsudhanshu@gmail.com",
"address_line1": null,
"address_line2": null,
"address_city": null,
"address_state": null,
"address_zip": null,
"address_country": null,
"cvc_check": null,
"address_line1_check": null,
"address_zip_check": null,
"tokenization_method": null,
"dynamic_last4": null,
"metadata": {
},
"customer": "cus_6Nb0wxYHigk2mX"
}
[1] => <Stripe\Card[...] ...>
[2] => <Stripe\Card[...] ...>
]
}
这是我对Stripe的要求。试图从data
中提取$card_list
(即所有卡片组):
\Stripe\Stripe::setApiKey($this->stripe_sk);
$card_list = \Stripe\Customer::retrieve($customer_id)->sources->all(array(
'object' => 'card'
));
// Return a list of all cards.
$card_list = $card_list->data;
return $card_list;
我想知道为什么来自$card_list
的Stripe响应包含其他/意外数据。这就是我实际得到的东西:
array(1) {
[0]=>
object(Stripe\Card)#292 (5) {
["_opts":protected]=>
object(Stripe\Util\RequestOptions)#294 (2) {
["headers"]=>
array(0) {
}
["apiKey"]=>
string(32) "sk_test_d3..."
}
["_values":protected]=>
array(23) {
["id"]=>
string(29) "card_16jLIwLBSNgilYpnoEiPhNhA"
["object"]=>
string(4) "card"
["last4"]=>
string(4) "4242"
["brand"]=>
string(4) "Visa"
["funding"]=>
string(6) "credit"
["exp_month"]=>
int(8)
["exp_year"]=>
int(2016)
["fingerprint"]=>
string(16) "T5RzXLIiXrF0nyqH"
["country"]=>
string(2) "US"
["name"]=>
NULL
["address_line1"]=>
NULL
["address_line2"]=>
NULL
["address_city"]=>
NULL
["address_state"]=>
NULL
["address_zip"]=>
NULL
["address_country"]=>
NULL
["cvc_check"]=>
string(4) "pass"
["address_line1_check"]=>
NULL
["address_zip_check"]=>
NULL
["tokenization_method"]=>
NULL
["dynamic_last4"]=>
NULL
["metadata"]=>
object(Stripe\AttachedObject)#261 (5) {
["_opts":protected]=>
object(Stripe\Util\RequestOptions)#294 (2) {
["headers"]=>
array(0) {
}
["apiKey"]=>
string(32) "sk_test_d..."
}
["_values":protected]=>
array(0) {
}
["_unsavedValues":protected]=>
object(Stripe\Util\Set)#262 (1) {
["_elts":"Stripe\Util\Set":private]=>
array(0) {
}
}
["_transientValues":protected]=>
object(Stripe\Util\Set)#306 (1) {
["_elts":"Stripe\Util\Set":private]=>
array(0) {
}
}
["_retrieveOptions":protected]=>
array(0) {
}
}
["customer"]=>
string(18) "cus_6xCtshHPQiYSdI"
}
["_unsavedValues":protected]=>
object(Stripe\Util\Set)#270 (1) {
["_elts":"Stripe\Util\Set":private]=>
array(0) {
}
}
["_transientValues":protected]=>
object(Stripe\Util\Set)#120 (1) {
["_elts":"Stripe\Util\Set":private]=>
array(0) {
}
}
["_retrieveOptions":protected]=>
array(0) {
}
}
}
希望有人可以解释响应的“扩展”版本,我正在这里。提前谢谢!
答案 0 :(得分:4)
我几天前就陷入了这个问题,我已经设法使用这样的json_encode()
API解决了这个问题(需要将此导出为我的AJAX返回)。
$cards = \Stripe\Customer::retrieve($_SESSION['stripe_customer_id'])->sources->all(array("object" => "card"));
$list = json_encode($cards->data);
echo($list);
希望这有帮助。
BTW:您的回复与var_dump()
输出相似。
答案 1 :(得分:0)
如果要以数组形式规范化数据以轻松获取值,请添加__toArray();
以获取数组中的响应。
例如: $cards->data->__toArray();