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
|
||||
vm_id = -1
|
||||
plan_name = ""
|
||||
invoice_total = 0
|
||||
invoice_hosted_url = ""
|
||||
for line_data in invoice["lines"]["data"]:
|
||||
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:
|
||||
try:
|
||||
if is_first:
|
||||
plan_name = line_data.plan.name
|
||||
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
|
||||
|
||||
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
|
||||
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:
|
||||
vm_id = int(vm_id)
|
||||
except ValueError as ve:
|
||||
|
@ -144,8 +165,8 @@ def get_line_item_from_stripe_invoice(invoice):
|
|||
period=mark_safe("%s — %s" % (
|
||||
datetime.datetime.fromtimestamp(start_date).strftime('%Y-%m-%d'),
|
||||
datetime.datetime.fromtimestamp(end_date).strftime('%Y-%m-%d'))),
|
||||
total='%.2f' % (invoice.total/100),
|
||||
stripe_invoice_url=invoice.hosted_invoice_url,
|
||||
total=invoice_total,
|
||||
stripe_invoice_url=invoice_hosted_url,
|
||||
see_invoice_text=_("See Invoice")
|
||||
))
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue