Print case where CustomUser is not found in the datbase from Stripe customer id

This commit is contained in:
PCoder 2023-12-27 20:36:59 +05:30
parent 94a81fc976
commit 4d3da3387a

View file

@ -90,26 +90,29 @@ class Command(BaseCommand):
vat_rate = subscription.get("tax_percent", "") vat_rate = subscription.get("tax_percent", "")
c_user = CustomUser.objects.get( c_user = CustomUser.objects.get(
id=StripeCustomer.objects.filter(stripe_id=stripe_customer_id)[0].user.id) id=StripeCustomer.objects.filter(stripe_id=stripe_customer_id)[0].user.id)
customer_name = c_user.name.encode('utf-8') if c_user:
customer_email = c_user.email customer_name = c_user.name.encode('utf-8')
items = subscription.get("items", {}).get("data", []) customer_email = c_user.email
for item in items: items = subscription.get("items", {}).get("data", [])
subscription_name = item.get("plan", {}).get("id", "") for item in items:
amount = item.get("plan", {}).get("amount", "") subscription_name = item.get("plan", {}).get("id", "")
amount = item.get("plan", {}).get("amount", "")
# Convert amount to a proper format (e.g., cents to dollars) # Convert amount to a proper format (e.g., cents to dollars)
amount_in_chf = amount / 100 # Adjust this conversion as needed amount_in_chf = amount / 100 # Adjust this conversion as needed
# Writing to CSV # Writing to CSV
writer.writerow({ writer.writerow({
"customer_name": customer_name, "customer_name": customer_name,
"customer_email": customer_email, "customer_email": customer_email,
"stripe_customer_id": stripe_customer_id, "stripe_customer_id": stripe_customer_id,
"subscription_id": subscription_id, "subscription_id": subscription_id,
"subscription_name": subscription_name, "subscription_name": subscription_name,
"amount": amount_in_chf, "amount": amount_in_chf,
"vat_rate": vat_rate # Fill in VAT rate if available "vat_rate": vat_rate # Fill in VAT rate if available
}) })
else:
print("No customuser for %s %s" % (stripe_customer_id, subscription_id))
if MAKE_MODIFS: if MAKE_MODIFS: