Handle if the invoice is not an stripe's invoice object
This commit is contained in:
parent
73cb003353
commit
e136eb93c0
1 changed files with 36 additions and 15 deletions
|
@ -108,22 +108,43 @@ def get_line_item_from_stripe_invoice(invoice):
|
||||||
is_first = True
|
is_first = True
|
||||||
vm_id = -1
|
vm_id = -1
|
||||||
plan_name = ""
|
plan_name = ""
|
||||||
|
invoice_total = 0
|
||||||
|
invoice_hosted_url = ""
|
||||||
for line_data in invoice["lines"]["data"]:
|
for line_data in invoice["lines"]["data"]:
|
||||||
if is_first:
|
try:
|
||||||
plan_name = line_data.plan.name
|
if is_first:
|
||||||
start_date = line_data.period.start
|
plan_name = line_data.plan.name
|
||||||
end_date = line_data.period.end
|
|
||||||
is_first = False
|
|
||||||
if hasattr(line_data.metadata, "VM_ID"):
|
|
||||||
vm_id = line_data.metadata.VM_ID
|
|
||||||
else:
|
|
||||||
if line_data.period.start < start_date:
|
|
||||||
start_date = line_data.period.start
|
start_date = line_data.period.start
|
||||||
if line_data.period.end > end_date:
|
|
||||||
end_date = line_data.period.end
|
end_date = line_data.period.end
|
||||||
if hasattr(line_data.metadata, "VM_ID"):
|
is_first = False
|
||||||
vm_id = line_data.metadata.VM_ID
|
if hasattr(line_data.metadata, "VM_ID"):
|
||||||
|
vm_id = line_data.metadata.VM_ID
|
||||||
|
else:
|
||||||
|
if line_data.period.start < start_date:
|
||||||
|
start_date = line_data.period.start
|
||||||
|
if line_data.period.end > end_date:
|
||||||
|
end_date = line_data.period.end
|
||||||
|
if hasattr(line_data.metadata, "VM_ID"):
|
||||||
|
vm_id = line_data.metadata.VM_ID
|
||||||
|
invoice_total = '%.2f' % (invoice.total/100)
|
||||||
|
invoice_hosted_url = invoice.hosted_invoice_url
|
||||||
|
except AttributeError as e:
|
||||||
|
if is_first:
|
||||||
|
plan_name = line_data["plan"]["name"]
|
||||||
|
start_date = line_data["period"]["start"]
|
||||||
|
end_date = line_data["period"]["end"]
|
||||||
|
is_first = False
|
||||||
|
if hasattr(line_data["metadata"], "VM_ID"):
|
||||||
|
vm_id = line_data["metadata"]["VM_ID"]
|
||||||
|
else:
|
||||||
|
if line_data["period"]["start"] < start_date:
|
||||||
|
start_date = line_data["period"]["start"]
|
||||||
|
if line_data["period"]["end"] > end_date:
|
||||||
|
end_date = line_data["period"]["end"]
|
||||||
|
if hasattr(line_data["metadata"], "VM_ID"):
|
||||||
|
vm_id = line_data["metadata"]["VM_ID"]
|
||||||
|
invoice_total = '%.2f' % (invoice["total"]/100)
|
||||||
|
invoice_hosted_url = invoice["hosted_invoice_url"]
|
||||||
try:
|
try:
|
||||||
vm_id = int(vm_id)
|
vm_id = int(vm_id)
|
||||||
except ValueError as ve:
|
except ValueError as ve:
|
||||||
|
@ -144,8 +165,8 @@ def get_line_item_from_stripe_invoice(invoice):
|
||||||
period=mark_safe("%s — %s" % (
|
period=mark_safe("%s — %s" % (
|
||||||
datetime.datetime.fromtimestamp(start_date).strftime('%Y-%m-%d'),
|
datetime.datetime.fromtimestamp(start_date).strftime('%Y-%m-%d'),
|
||||||
datetime.datetime.fromtimestamp(end_date).strftime('%Y-%m-%d'))),
|
datetime.datetime.fromtimestamp(end_date).strftime('%Y-%m-%d'))),
|
||||||
total='%.2f' % (invoice.total/100),
|
total=invoice_total,
|
||||||
stripe_invoice_url=invoice.hosted_invoice_url,
|
stripe_invoice_url=invoice_hosted_url,
|
||||||
see_invoice_text=_("See Invoice")
|
see_invoice_text=_("See Invoice")
|
||||||
))
|
))
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue