def _find_owner_account(cls, data, api_key=None, livemode=None):
        """
        Fetches the Stripe Account (djstripe_owner_account model field)
        linked to the class, cls.
        Tries to retreive using the Stripe_account if given.
        Otherwise uses the api_key.
        """
        from .account import Account

        if livemode is None:
            livemode = djstripe_settings.STRIPE_LIVE_MODE
        api_key = api_key or djstripe_settings.get_default_api_key(livemode)

        # try to fetch by stripe_account. Also takes care of Stripe Connected Accounts
        if data:
            # case of Webhook Event Trigger
            if data.get("object") == "event":
                # if account key exists and has a not null value
                stripe_account_id = get_id_from_stripe_data(data.get("account"))
                if stripe_account_id:
                    return Account._get_or_retrieve(
                        id=stripe_account_id, api_key=api_key
                    )

            else:
                stripe_account = getattr(data, "stripe_account", None)
                stripe_account_id = get_id_from_stripe_data(stripe_account)
                if stripe_account_id:
                    return Account._get_or_retrieve(
                        id=stripe_account_id, api_key=api_key
                    )

        # try to fetch by the given api_key.
        return Account.get_or_retrieve_for_api_key(api_key)

        Fetches the Stripe Account (djstripe_owner_account model field)
        linked to the class, cls.
        Tries to retreive using the Stripe_account if given.
        Otherwise uses the api_key.
        
djstripe/models/base.py