Improve import_usercarddetails management command
This commit is contained in:
parent
34ed51a643
commit
33bd2e1760
1 changed files with 29 additions and 23 deletions
|
@ -12,28 +12,34 @@ class Command(BaseCommand):
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
try:
|
try:
|
||||||
stripe_utils = StripeUtils()
|
stripe_utils = StripeUtils()
|
||||||
for user in CustomUser.objects.filter(id__gte=114):
|
for user in CustomUser.objects.all():
|
||||||
if user.stripecustomer:
|
if hasattr(user, 'stripecustomer'):
|
||||||
card_details_resp = stripe_utils.get_card_details(
|
if user.stripecustomer:
|
||||||
user.stripecustomer.stripe_id
|
card_details_resp = stripe_utils.get_card_details(
|
||||||
)
|
user.stripecustomer.stripe_id
|
||||||
card_details = card_details_resp['response_object']
|
|
||||||
if card_details:
|
|
||||||
ucd = UserCardDetail.get_or_create_user_card_detail(
|
|
||||||
stripe_customer=user.stripecustomer,
|
|
||||||
card_details=card_details
|
|
||||||
)
|
)
|
||||||
UserCardDetail.save_default_card_local(
|
card_details = card_details_resp['response_object']
|
||||||
user.stripecustomer.stripe_id,
|
if card_details:
|
||||||
ucd.card_id
|
ucd = UserCardDetail.get_or_create_user_card_detail(
|
||||||
)
|
stripe_customer=user.stripecustomer,
|
||||||
print("Saved user card details for {}".format(
|
card_details=card_details
|
||||||
user.email
|
)
|
||||||
))
|
UserCardDetail.save_default_card_local(
|
||||||
else:
|
user.stripecustomer.stripe_id,
|
||||||
print(" --- Could not get card details for {}".format(
|
ucd.card_id
|
||||||
user.email
|
)
|
||||||
))
|
print("Saved user card details for {}".format(
|
||||||
print("Error: {}".format(card_details_resp['error']))
|
user.email
|
||||||
|
))
|
||||||
|
else:
|
||||||
|
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
|
||||||
|
))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Error occurred. Details {}".format(str(e)))
|
print(" *** Error occurred. Details {}".format(str(e)))
|
||||||
|
|
Loading…
Reference in a new issue