Get All Line Items Checkout Event
Your error is in this bit:
        // @var LineItem $lineItem
        $lineItem = $event-&gt;lineItem;

Looking at the event in question:
https://craftcms.com/docs/commerce/3.x/events.html#beforecapturetransaction
...this shows that you get a Transaction model supplied in this event:
https://docs.craftcms.com/commerce/api/v3/craft-commerce-models-transaction.html#public-properties
...note that model gives you direct access to the related order element:
https://docs.craftcms.com/commerce/api/v3/craft-commerce-elements-order.html
...from which you can then retrieve all the line items (and products etc associated with them), by looping over order.lineItems