Change invoice url

This commit is contained in:
PCoder 2020-02-01 12:13:56 +05:30
parent e6f00abd71
commit 918d2b17e1
2 changed files with 19 additions and 5 deletions

View file

@ -46,7 +46,7 @@
<div class="vm-vmid"> <div class="vm-vmid">
<div class="vm-item-subtitle">{% trans "Current Pricing" %}</div> <div class="vm-item-subtitle">{% trans "Current Pricing" %}</div>
<div class="vm-item-lg">{{order.price|floatformat:2|intcomma}} CHF/{% if order.generic_product %}{% trans order.generic_product.product_subscription_interval %}{% else %}{% trans "Month" %}{% endif %}</div> <div class="vm-item-lg">{{order.price|floatformat:2|intcomma}} CHF/{% if order.generic_product %}{% trans order.generic_product.product_subscription_interval %}{% else %}{% trans "Month" %}{% endif %}</div>
<a class="btn btn-vm-invoice" href="{% url 'hosting:orders' order.pk %}">{% trans "See Invoice" %}</a> <a class="btn btn-vm-invoice" href="{{inv_url}}">{% trans "See Invoice" %}</a>
</div> </div>
</div> </div>
<div class="vm-detail-item"> <div class="vm-detail-item">

View file

@ -1687,13 +1687,27 @@ class VirtualMachineView(LoginRequiredMixin, View):
context = None context = None
try: try:
serializer = VirtualMachineSerializer(vm) serializer = VirtualMachineSerializer(vm)
hosting_order = HostingOrder.objects.get(
vm_id=serializer.data['vm_id']
)
inv_url = None
if hosting_order.subscription_id:
stripe_obj = stripe.Invoice.list(
hosting_order.subscription_id
)
inv_url = stripe_obj[0].data.hosted_invoice_url
elif hosting_order.stripe_charge_id:
stripe_obj = stripe.Charge.retrieve(
hosting_order.stripe_charge_id
)
inv_url = stripe_obj.receipt_url
context = { context = {
'virtual_machine': serializer.data, 'virtual_machine': serializer.data,
'order': HostingOrder.objects.get( 'order': hosting_order,
vm_id=serializer.data['vm_id'] 'keys': UserHostingKey.objects.filter(user=request.user),
), 'inv_url': inv_url
'keys': UserHostingKey.objects.filter(user=request.user)
} }
except Exception as ex: except Exception as ex:
logger.debug("Exception generated {}".format(str(ex))) logger.debug("Exception generated {}".format(str(ex)))
messages.error(self.request, messages.error(self.request,