def _stripe_object_to_line_items(
        cls, target_cls, data, invoice, api_key=djstripe_settings.STRIPE_SECRET_KEY
    ):
        """
        Retrieves LineItems for an invoice.

        If the line item doesn't exist already then it is created.

        If the invoice is an upcoming invoice that doesn't persist to the
        database (i.e. ephemeral) then the line items are also not saved.

        :param target_cls: The target class to instantiate per line item.
        :type target_cls:  Type[djstripe.models.LineItem]
        :param data: The data dictionary received from the Stripe API.
        :type data: dict
        :param invoice: The invoice object that should hold the line items.
        :type invoice: ``djstripe.models.Invoice``
        """
        lines = data.get("lines")
        if not lines:
            return []

        lineitems = []
        for line in lines.auto_paging_iter():
            if invoice.id:
                save = True
                line.setdefault("invoice", invoice.id)

            else:
                # Don't save invoice items for ephemeral invoices
                save = False

            line.setdefault("customer", invoice.customer.id)
            line.setdefault("date", int(dateformat.format(invoice.created, "U")))

            item, _ = target_cls._get_or_create_from_stripe_object(
                line, refetch=False, save=save, api_key=api_key
            )
            lineitems.append(item)

        return lineitems

        Retrieves LineItems for an invoice.

        If the line item doesn't exist already then it is created.

        If the invoice is an upcoming invoice that doesn't persist to the
        database (i.e. ephemeral) then the line items are also not saved.

        :param target_cls: The target class to instantiate per line item.
        :type target_cls:  Type[djstripe.models.LineItem]
        :param data: The data dictionary received from the Stripe API.
        :type data: dict
        :param invoice: The invoice object that should hold the line items.
        :type invoice: ``djstripe.models.Invoice``
        
djstripe/models/base.py