def update_customer_helper(metadata, customer_id, subscriber_key):
    """
    A helper function that updates customer's subscriber and metadata fields
    """

    # only update customer.subscriber if both the customer and subscriber already exist
    subscriber_id = metadata.get(subscriber_key, "")
    if subscriber_key not in ("", None) and subscriber_id and customer_id:
        subscriber_model = djstripe_settings.get_subscriber_model()

        try:
            subscriber = subscriber_model.objects.get(id=subscriber_id)
            customer = models.Customer.objects.get(id=customer_id)
        except ObjectDoesNotExist:
            pass
        else:
            customer.subscriber = subscriber
            customer.metadata = metadata
            customer.save()

    A helper function that updates customer's subscriber and metadata fields
    
djstripe/event_handlers.py