【问题标题】:Get card id from Stripe API in PHP从 PHP 中的 Stripe API 获取卡片 ID
【发布时间】:2015-06-29 21:09:23
【问题描述】:

根据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

【问题讨论】:

  • var_dump($customer) 而是查看返回的所有内容。

标签: php


【解决方案1】:

一个客户可以拥有多张卡,因此$customer-&gt;sources-&gt;data 是一个数组(您应该能够从该属性值周围的方括号中看出)。因此,您需要对其进行索引。

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

如果客户保存了多张信用卡,您应该遍历它:

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

【讨论】:

  • 我希望我可以将其复制并粘贴到条带文档中。他们只是假设您以某种方式拥有卡 ID。
  • @Ibu 您假设将卡片 ID 保存到您自己的数据库中,然后使用它来检索特定卡片。 stripe.com/docs/api/php#retrieve_card
  • @Michael 这就是我们所做的,但您也可以将客户 ID 保存在您的数据库中,并从 Stripe 检索卡 ID,就像在这个问题中一样。
  • 将近 5 年后,Stripe 文档仍然很烂:/
猜你喜欢
  • 2019-10-28
  • 1970-01-01
  • 1970-01-01
  • 2019-12-25
  • 2018-08-06
  • 2020-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多