From ed6059feaa3f2f7a94f501ccefeff16030877edb Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 13 Apr 2019 14:34:32 +0200 Subject: [PATCH] Set unit amount to 0 if not available in Stripe response --- hosting/models.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hosting/models.py b/hosting/models.py index 4476615a..ea776389 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -342,7 +342,12 @@ class MonthlyHostingBill(AssignPermissionsMixin, models.Model): period_start=datetime.utcfromtimestamp(item.period.start).replace(tzinfo=pytz.utc), period_end=datetime.utcfromtimestamp(item.period.end).replace(tzinfo=pytz.utc), proration=item.proration, quantity=item.quantity, - unit_amount=item.unit_amount + # Strange that line item does not have unit_amount but api + # states that it is present + # https://stripe.com/docs/api/invoiceitems/object#invoiceitem_object-unit_amount + # So, for the time being I set the unit_amount to 0 if not + # found in the line item + unit_amount=item.unit_amount if hasattr(item, "unit_amount") else 0 ) line_item_instance.assign_permission(instance.customer.user) instance.assign_permissions(instance.customer.user)