(event)
Handle updates to customer payment-source objects.

    Docs: https://stripe.com/docs/api/sources
Handle updates to customer payment-source objects.
Handle updates to customer payment - source objects .
def customer_source_webhook_handler(event):
    """Handle updates to customer payment-source objects.

    Docs: https://stripe.com/docs/api/sources
    """
    customer_data = event.data.get("object", {})
    source_type = customer_data.get("object", {})

    # TODO: handle other types of sources
    #  (https://stripe.com/docs/api/sources)
    if source_type == SourceType.card:
        if event.verb.endswith("deleted") and customer_data:
            # On customer.source.deleted, we do not delete the object,
            # we merely unlink it.
            # customer = Customer.objects.get(id=customer_data["id"])
            # NOTE: for now, customer.sources still points to Card
            # Also, https://github.com/dj-stripe/dj-stripe/issues/576
            models.Card.objects.filter(id=customer_data.get("id", "")).delete()
            models.DjstripePaymentMethod.objects.filter(
                id=customer_data.get("id", "")
            ).delete()
        else:
            _handle_crud_like_event(target_cls=models.Card, event=event)
def customer_source_webhook_handler ( event ) : customer_data = event . data . get ( "object" , { } ) source_type = customer_data . get ( "object" , { } ) # TODO: handle other types of sources #  (https://stripe.com/docs/api/sources) if source_type == SourceType . card : if event . verb . endswith ( "deleted" ) and customer_data : # On customer.source.deleted, we do not delete the object, # we merely unlink it. # customer = Customer.objects.get(id=customer_data["id"]) # NOTE: for now, customer.sources still points to Card # Also, https://github.com/dj-stripe/dj-stripe/issues/576 models . Card . objects . filter ( id = customer_data . get ( "id" , "" ) ) . delete ( ) models . DjstripePaymentMethod . objects . filter ( id = customer_data . get ( "id" , "" ) ) . delete ( ) else : _handle_crud_like_event ( target_cls = models . Card , event = event )