检索条带帐户信息

时间:2017-03-20 16:23:24

标签: php stripe-payments

在PHP中使用Stripe的API。我试图获得" last4"来自此测试对象的值



$customers = \Stripe\Customer::retrieve("cus_8MfE5OY7uZb8qd");

Stripe\Customer JSON: {
  "id": "cus_8MfE5OY7uZb8qd",
  "object": "customer",
  "account_balance": 0,
  "created": 1462014302,
  "currency": "gbp",
  "default_source": "card_185vu8E5mWaZh4R5u4vxBYwJ",
  "delinquent": false,
  "description": null,
  "discount": null,
  "email": null,
  "livemode": false,
  "metadata": {
  },
  "shipping": null,
  "sources": {
    "object": "list",
    "data": [
      {
        "id": "card_185vu8E5mWaZh4R5u4vxBYwJ",
        "object": "card",
        "address_city": null,
        "address_country": null,
        "address_line1": null,
        "address_line1_check": null,
        "address_line2": null,
        "address_state": null,
        "address_zip": null,
        "address_zip_check": null,
        "brand": "Visa",
        "country": "US",
        "customer": "cus_8MfE5OY7uZb8qd",
        "cvc_check": "pass",
        "dynamic_last4": null,
        "exp_month": 2,
        "exp_year": 2020,
        "funding": "credit",
        "last4": "4242",
        "metadata": {
        },
        "name": "stu@blue-caterpillar.co.uk",
        "tokenization_method": null
      }
    ],
    "has_more": false,
    "total_count": 1,
    "url": "/v1/customers/cus_8MfE5OY7uZb8qd/sources"
  }
}




我可以使用

将所有数据传输到源代码
print $customers->description;

当我到达数据时,这显然会返回一个数组:

print $customers->sources->data;

我尝试了一些事情来尝试获得" last4"价值,但没有运气。有人能指出我正确的方向吗?谢谢!

2 个答案:

答案 0 :(得分:1)

$customers->sources->data是一个数组,其第一个元素是包含您正在寻找的last4的对象。

你应该能够得到它:

print $customers->sources->data[0]->last4;

答案 1 :(得分:0)

你有没有试过指向" last4"因为它是另一个对象?

 echo $customers->sources->data->last4