如何从条带中的客户对象获取费用信息

时间:2017-11-08 12:24:17

标签: php api stripe-payments

付款成功后。我打印_r($ customer)获取卡和费用信息。我收到此消息,我只能从Stripe_Customer Object变量获取Stripe_Card Object信息而不是$customer

Stripe_Card Object ([_apiKey:protected] => sk_test_... [_values:protected] 
=> Array ( [id] => card_1BLsOAJ6IzxnlSnmpPloNXUN 
[object] => card [address_city] => lahore 
[address_country] => Pakistan 

只有数组的第一个Stripe_Customer Object才能轻易获得,例如

echo  $customer['id']

我尝试多次使用这些方法获取卡片对象的信息但不适合我

echo $customer->source->card->address_country;
echo $customer->source->address_country;
echo $customer['card'];
echo $customer['address_country'];
echo $customer['card']['address_country'];

1 个答案:

答案 0 :(得分:3)

客户可以同时拥有多个来源。 Customer上的source属性是记录在案的here列表。如果您想访问卡片对象,则需要执行以下操作:

$card = $customer->sources->data[0];
$cardId = $card->id;
$cardLast4 = $card->last4;
// etc.