Reputation: 13
Using Stripe's API with PHP. I'm trying to get the "last4" value from this test object
$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": "[email protected]",
"tokenization_method": null
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/customers/cus_8MfE5OY7uZb8qd/sources"
}
}
I can get all the data up to the sources by using
print $customers->description;
When I get to the data, this obviously returns an array:
print $customers->sources->data;
I've tried a few things to try and get the "last4" value, but no luck. Can someone point me in the right direction please? Thanks!
Upvotes: 1
Views: 467
Reputation: 2345
The $customers->sources->data
is an Array, and its first element is the object that contains the last4
you're looking for.
You should be able to get it with:
print $customers->sources->data[0]->last4;
Upvotes: 1
Reputation: 1
Have you tried pointing to "last4" as it is an another object?
echo $customers->sources->data->last4
Upvotes: 0