def post(self, request, *args, **kwargs): existing_order = billing_orders.get_order_by_id_and_owner( order_id=kwargs.get('order_id'), owner=request.user, log_action='execute' ) billing_orders.cancel_single_order(existing_order) messages.success(request, f'Order of {existing_order.description} is cancelled.') return shortcuts.redirect('billing_orders')
def dispatch(self, request, *args, **kwargs): order_id = kwargs.get('order_id') if order_id: try: orders.get_order_by_id_and_owner( order_id=order_id, owner=request.user, log_action="download a receipt for") except SuspiciousOperation: messages.warning(request, "You can't download this receipt.") return shortcuts.redirect('billing_orders') pdf_info = orders.build_receipt( owner=request.user, order_id=order_id, ) response = HttpResponse(pdf_info['body'], content_type='application/pdf') response[ 'Content-Disposition'] = f'attachment; filename={pdf_info["filename"]}' return response
def post(self, request, *args, **kwargs): existing_order = billing_orders.get_order_by_id_and_owner( order_id=kwargs.get('order_id'), owner=request.user, log_action='execute' ) if existing_order.total_price > existing_order.owner.balance: messages.error(request, self.error_message_balance) return shortcuts.redirect('billing_new_payment') if billing_orders.execute_single_order(existing_order): messages.success(request, self.success_message) else: messages.error(request, self.error_message_technical) return shortcuts.redirect('billing_orders')
def post(self, request, *args, **kwargs): existing_order = orders.get_order_by_id_and_owner( order_id=kwargs.get('order_id'), owner=request.user, log_action='execute') for order_item in existing_order.items.all(): if order_item.type == 'domain_register': domain = zdomains.domain_find(domain_name=order_item.name) if domain and domain.status == 'inactive' and not domain.epp_id: zdomains.domain_delete(domain_name=order_item.name) orders.cancel_and_remove_order(existing_order) messages.success( request, f'Order of {existing_order.description} is cancelled.') return shortcuts.redirect('billing_orders')
def post(self, request, *args, **kwargs): existing_order = orders.get_order_by_id_and_owner( order_id=kwargs.get('order_id'), owner=request.user, log_action='execute') if existing_order.total_price > existing_order.owner.balance: messages.error(request, self.error_message_balance) return HttpResponseRedirect( shortcuts.resolve_url('billing_new_payment') + "?amount={}".format( int(existing_order.total_price - existing_order.owner.balance))) new_status = orders.execute_order(existing_order) if new_status == 'processed': messages.success(request, self.success_message) elif new_status == 'processing': messages.success(request, self.processing_message) else: messages.error(request, self.error_message_technical) return shortcuts.redirect('account_domains')
def get_object(self, queryset=None): return billing_orders.get_order_by_id_and_owner( order_id=self.kwargs.get('order_id'), owner=self.request.user, log_action='check')