I’m working with Stripe in a PHP app. I’ve created a product and set prices for it via code. I added 'lookup_key' => value to each price. That all worked. When I use stripes lookup_keys command to get prices by that key, I do not know how to parse the output returned.
Example price:
$stripe->prices->create([
'product' => $product['id'],
'unit_amount' => 35000,
'currency' => 'usd',
'lookup_key' => 'double'
]);
To get the price for the lookup_key => double, I use:
$double = $stripe->prices->all(['lookup_keys' => ['double'] ]);
var_dump($double );
The output for that is:
Stripe\Collection JSON: {
"object": "list",
"data": [
{
"id": "price_1OeHBECDQQBHRZz868I26QUy",
"object": "price",
"active": true,
"billing_scheme": "per_unit",
"created": 1706620608,
"currency": "usd",
"custom_unit_amount": null,
"livemode": false,
"lookup_key": "double",
"metadata": [],
"nickname": null,
"product": "prod_PTDcNZpXM6NJMd",
"recurring": null,
"tax_behavior": "unspecified",
"tiers_mode": null,
"transform_quantity": null,
"type": "one_time",
"unit_amount": 35000,
"unit_amount_decimal": "35000"
}
],
"has_more": false,
"url": "/v1/prices"
}"
How do I parse this to get the "unit_amount": 35000, or other items? OR, is there an easier way to get a price or prices from a product.
Thanks for any assistance.
>Solution :
$unitAmount = $double->data[0]->unit_amount;