Improve import_usercarddetails management command

This commit is contained in:
PCoder 2018-07-07 02:15:38 +02:00
parent 34ed51a643
commit 33bd2e1760
1 changed files with 29 additions and 23 deletions

View File

@ -12,7 +12,8 @@ class Command(BaseCommand):
def handle(self, *args, **options):
try:
stripe_utils = StripeUtils()
for user in CustomUser.objects.filter(id__gte=114):
for user in CustomUser.objects.all():
if hasattr(user, 'stripecustomer'):
if user.stripecustomer:
card_details_resp = stripe_utils.get_card_details(
user.stripecustomer.stripe_id
@ -31,9 +32,14 @@ class Command(BaseCommand):
user.email
))
else:
print(" --- Could not get card details for {}".format(
print(" --- Could not get card details for "
"{}".format(user.email))
print(" --- Error: {}".format(
card_details_resp['error']
))
else:
print(" === {} does not have a StripeCustomer object".format(
user.email
))
print("Error: {}".format(card_details_resp['error']))
except Exception as e:
print("Error occurred. Details {}".format(str(e)))
print(" *** Error occurred. Details {}".format(str(e)))