(event)
Handle updates to customer discount objects.

    Docs: https://stripe.com/docs/api#discounts

    Because there is no concept of a "Discount" model in dj-stripe (due to the
    lack of a stripe id on them), this is a little different to the other
    handlers.
Handle updates to customer discount objects.
Handle updates to customer discount objects .
def customer_discount_webhook_handler(event):
    """Handle updates to customer discount objects.

    Docs: https://stripe.com/docs/api#discounts

    Because there is no concept of a "Discount" model in dj-stripe (due to the
    lack of a stripe id on them), this is a little different to the other
    handlers.
    """

    crud_type = CrudType.determine(event=event)
    discount_data = event.data.get("object", {})
    coupon_data = discount_data.get("coupon", {})
    customer = event.customer

    if crud_type is CrudType.DELETED:
        coupon = None
        coupon_start = None
        coupon_end = None
    else:
        coupon, _ = _handle_crud_like_event(
            target_cls=models.Coupon,
            event=event,
            data=coupon_data,
            id=coupon_data.get("id"),
        )
        coupon_start = discount_data.get("start")
        coupon_end = discount_data.get("end")

    customer.coupon = coupon
    customer.coupon_start = convert_tstamp(coupon_start)
    customer.coupon_end = convert_tstamp(coupon_end)
    customer.save()
def customer_discount_webhook_handler ( event ) : crud_type = CrudType . determine ( event = event ) discount_data = event . data . get ( "object" , { } ) coupon_data = discount_data . get ( "coupon" , { } ) customer = event . customer if crud_type is CrudType . DELETED : coupon = None coupon_start = None coupon_end = None else : coupon , _ = _handle_crud_like_event ( target_cls = models . Coupon , event = event , data = coupon_data , id = coupon_data . get ( "id" ) , ) coupon_start = discount_data . get ( "start" ) coupon_end = discount_data . get ( "end" ) customer . coupon = coupon customer . coupon_start = convert_tstamp ( coupon_start ) customer . coupon_end = convert_tstamp ( coupon_end ) customer . save ( )