(self)
Customers are soft deleted as deleted customers are still accessible by the
        Stripe API and sync for all RelatedModels would fail
Customers are soft deleted as deleted customers are still accessible by the
        Stripe API and sync for all RelatedModels would fail
Customers are soft deleted as deleted customers are still accessible by the Stripe API and sync for all RelatedModels would fail
def purge(self):
        """Customers are soft deleted as deleted customers are still accessible by the
        Stripe API and sync for all RelatedModels would fail"""
        try:
            self._api_delete()
        except InvalidRequestError as exc:
            if "No such customer:" in str(exc):
                # The exception was thrown because the stripe customer was already
                # deleted on the stripe side, ignore the exception
                pass
            else:
                # The exception was raised for another reason, re-raise it
                raise

        # toggle the deleted flag on Customer to indicate it has been
        # deleted upstream in Stripe
        self.deleted = True

        if self.subscriber:
            # Delete the idempotency key used by Customer.create()
            # So re-creating a customer for this subscriber before the key expires
            # doesn't return the older Customer data
            idempotency_key_action = "customer:create:{}".format(self.subscriber.pk)
            IdempotencyKey.objects.filter(action=idempotency_key_action).delete()

        self.subscriber = None

        # Remove sources
        self.default_source = None
        for source in self.legacy_cards.all():
            source.remove()

        for source in self.sources.all():
            source.detach()

        self.date_purged = timezone.now()
        self.save()
def purge ( self ) : try : self . _api_delete ( ) except InvalidRequestError as exc : if "No such customer:" in str ( exc ) : # The exception was thrown because the stripe customer was already # deleted on the stripe side, ignore the exception pass else : # The exception was raised for another reason, re-raise it raise # toggle the deleted flag on Customer to indicate it has been # deleted upstream in Stripe self . deleted = True if self . subscriber : # Delete the idempotency key used by Customer.create() # So re-creating a customer for this subscriber before the key expires # doesn't return the older Customer data idempotency_key_action = "customer:create:{}" . format ( self . subscriber . pk ) IdempotencyKey . objects . filter ( action = idempotency_key_action ) . delete ( ) self . subscriber = None # Remove sources self . default_source = None for source in self . legacy_cards . all ( ) : source . remove ( ) for source in self . sources . all ( ) : source . detach ( ) self . date_purged = timezone . now ( ) self . save ( )