Convert Stripe API response to JSON using stripe-php library

前端 未结 7 1732
迷失自我
迷失自我 2021-01-01 21:06

I\'m accessing customer data from the Stripe API, which I\'d like to convert to JSON. Usually I\'d convert an object to an array and use json_encode() but I don

7条回答
  •  粉色の甜心
    2021-01-01 21:40

    The attributes of Stripe_Objects can be accessed like this:

    $customer->attribute;
    

    So to get the customer's card's last4, you can do this:

    $customer->default_card->last4;
    

    However, you'll need to make sure you have the default_card attribute populated. You can retrieve the default_card object at the same time as the rest of the customer by passing the expand argument:

    $customer = Stripe_Customer::retrieve(array(
        "id" => "cus_2dVcTSc6ZtHQcv", 
        "expand" => array("default_card")
    ));
    

提交回复
热议问题