簡體   English   中英

從PHP中的Stripe API獲取卡ID

[英]Get card id from Stripe API in PHP

根據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);
?>

但是沒有什么是回聲。

請你幫助我好嗎?

我遵循此文檔: https : //stripe.com/docs/api/php#customer_object

一個客戶可以擁有多張卡,因此$customer->sources->data是一個數組(正如您應該能夠在此屬性的值周圍的方括號中看出)。 因此,您需要為其編制索引。

print_r($customer->sources->data[0]->id);

並且,如果客戶已保存了多張信用卡,則應遍歷:

foreach ($customer->sources->data as $card) {
    print_r($card->id);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM