使用 php 和 alllineitems 时,如何访问每个产品的行项目元数据?
$checkout_lineitems = $stripe->checkout->sessions->allLineItems( $_GET['session_id'], [] );
似乎没有明确的文档。
此外,如果我将产品的名称和描述设置如下:
'product_data' => ['name' => 'Item 1','description' => 'My item']
如何检索描述?如果我使用以下行,它将返回名称!
$checkout_lineitems->data[0]->description
谢谢你。
默认情况下,检索结帐会话的行项目将为您返回完整的 Price 对象,但仅返回产品 ID(请参阅 api 参考)。如果您想取回完整的产品对象,您需要像这样 expand
data.price.product
:
$checkout_lineitems = $stripe->checkout->sessions->allLineItems(
$_GET['session_id'], ['expand' => ['data.price.product']] );
进行更改后,您应该能够访问产品说明。
$checkout_lineitems->data[0]->price->product->description;