Change invoice url
This commit is contained in:
parent
e6f00abd71
commit
918d2b17e1
2 changed files with 19 additions and 5 deletions
|
@ -46,7 +46,7 @@
|
|||
<div class="vm-vmid">
|
||||
<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>
|
||||
<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 class="vm-detail-item">
|
||||
|
|
|
@ -1687,13 +1687,27 @@ class VirtualMachineView(LoginRequiredMixin, View):
|
|||
context = None
|
||||
try:
|
||||
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 = {
|
||||
'virtual_machine': serializer.data,
|
||||
'order': HostingOrder.objects.get(
|
||||
vm_id=serializer.data['vm_id']
|
||||
),
|
||||
'keys': UserHostingKey.objects.filter(user=request.user)
|
||||
'order': hosting_order,
|
||||
'keys': UserHostingKey.objects.filter(user=request.user),
|
||||
'inv_url': inv_url
|
||||
}
|
||||
|
||||
except Exception as ex:
|
||||
logger.debug("Exception generated {}".format(str(ex)))
|
||||
messages.error(self.request,
|
||||
|
|
Loading…
Reference in a new issue