(
        cls,
        field,
        manipulated_data,
        current_ids=None,
        pending_relations=None,
        stripe_account=None,
    )
return field_data, skip, is_nulled
This converts a stripe API field to the dj stripe object it references,
        so that foreign keys can be connected up automatically.

        :param field:
        :type field: models.ForeignKey
        :param manipulated_data:
        :type manipulated_data: dict
        :param current_ids: stripe ids of objects that are currently being processed
        :type current_ids: set
        :param pending_relations: list of tuples of relations to be attached post-save
        :type pending_relations: list
        :param stripe_account: The optional connected account \
            for which this request is being made.
        :type stripe_account: string
        :return:
This converts a stripe API field to the dj stripe object it references,
        so that foreign keys can be connected up automatically.
This converts a stripe API field to the dj stripe object it references so that foreign keys can be connected up automatically .
def _stripe_object_field_to_foreign_key(
        cls,
        field,
        manipulated_data,
        current_ids=None,
        pending_relations=None,
        stripe_account=None,
    ):
        """
        This converts a stripe API field to the dj stripe object it references,
        so that foreign keys can be connected up automatically.

        :param field:
        :type field: models.ForeignKey
        :param manipulated_data:
        :type manipulated_data: dict
        :param current_ids: stripe ids of objects that are currently being processed
        :type current_ids: set
        :param pending_relations: list of tuples of relations to be attached post-save
        :type pending_relations: list
        :param stripe_account: The optional connected account \
            for which this request is being made.
        :type stripe_account: string
        :return:
        """
        from djstripe.models import DjstripePaymentMethod

        field_data = None
        field_name = field.name
        refetch = False
        skip = False
        # a flag to indicate if the given field is null upstream on Stripe
        is_nulled = False

        if issubclass(field.related_model, StripeModel) or issubclass(
            field.related_model, DjstripePaymentMethod
        ):

            if field_name in manipulated_data:
                raw_field_data = manipulated_data.get(field_name)

                # field's value is None. Skip syncing but set as None.
                # Otherwise nulled FKs sync gets skipped.
                if not raw_field_data:
                    is_nulled = True
                    skip = True

            else:
                # field does not exist in manipulated_data dict. Skip Syncing
                skip = True
                raw_field_data = None

            id_ = get_id_from_stripe_data(raw_field_data)

            if id_ == raw_field_data:
                # A field like {"subscription": "sub_6lsC8pt7IcFpjA", ...}
                refetch = True
            else:
                # A field like {"subscription": {"id": sub_6lsC8pt7IcFpjA", ...}}
                pass

            if id_ in current_ids:
                # this object is currently being fetched, don't try to fetch again,
                # to avoid recursion instead, record the relation that should be
                # created once "object_id" object exists
                if pending_relations is not None:
                    object_id = manipulated_data["id"]
                    pending_relations.append((object_id, field, id_))
                skip = True

            # sync only if field exists and is not null
            if not skip and not is_nulled:
                # add the id of the current object to the list
                # of ids being processed.
                # This will avoid infinite recursive syncs in case a relatedmodel
                # requests the same object
                current_ids.add(id_)

                field_data, _ = field.related_model._get_or_create_from_stripe_object(
                    manipulated_data,
                    field_name,
                    refetch=refetch,
                    current_ids=current_ids,
                    pending_relations=pending_relations,
                    stripe_account=stripe_account,
                )

                # Remove the id of the current object from the list
                # after it has been created or retrieved
                current_ids.remove(id_)

        else:
            # eg PaymentMethod, handled in hooks
            skip = True

        return field_data, skip, is_nulled
def _stripe_object_field_to_foreign_key ( cls , field , manipulated_data , current_ids = None , pending_relations = None , stripe_account = None , ) : from djstripe . models import DjstripePaymentMethod field_data = None field_name = field . name refetch = False skip = False # a flag to indicate if the given field is null upstream on Stripe is_nulled = False if issubclass ( field . related_model , StripeModel ) or issubclass ( field . related_model , DjstripePaymentMethod ) : if field_name in manipulated_data : raw_field_data = manipulated_data . get ( field_name ) # field's value is None. Skip syncing but set as None. # Otherwise nulled FKs sync gets skipped. if not raw_field_data : is_nulled = True skip = True else : # field does not exist in manipulated_data dict. Skip Syncing skip = True raw_field_data = None id_ = get_id_from_stripe_data ( raw_field_data ) if id_ == raw_field_data : # A field like {"subscription": "sub_6lsC8pt7IcFpjA", ...} refetch = True else : # A field like {"subscription": {"id": sub_6lsC8pt7IcFpjA", ...}} pass if id_ in current_ids : # this object is currently being fetched, don't try to fetch again, # to avoid recursion instead, record the relation that should be # created once "object_id" object exists if pending_relations is not None : object_id = manipulated_data [ "id" ] pending_relations . append ( ( object_id , field , id_ ) ) skip = True # sync only if field exists and is not null if not skip and not is_nulled : # add the id of the current object to the list # of ids being processed. # This will avoid infinite recursive syncs in case a relatedmodel # requests the same object current_ids . add ( id_ ) field_data , _ = field . related_model . _get_or_create_from_stripe_object ( manipulated_data , field_name , refetch = refetch , current_ids = current_ids , pending_relations = pending_relations , stripe_account = stripe_account , ) # Remove the id of the current object from the list # after it has been created or retrieved current_ids . remove ( id_ ) else : # eg PaymentMethod, handled in hooks skip = True return field_data , skip , is_nulled