From ad846fabec075fccf4781e4aa8772d4d805f6308 Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 13 Jun 2019 05:20:00 +0200 Subject: [PATCH] Send invoice failed notification to user also --- webhook/views.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/webhook/views.py b/webhook/views.py index f768e55d..7eed6141 100644 --- a/webhook/views.py +++ b/webhook/views.py @@ -9,6 +9,7 @@ from django.views.decorators.http import require_POST from hosting.models import MonthlyHostingBill, HostingBillLineItem from membership.models import StripeCustomer +from utils.mailer import BaseEmail from utils.tasks import send_plain_email_task logger = logging.getLogger(__name__) @@ -114,6 +115,7 @@ def handle_invoice_webhook(request): invoice.lines.data.metadata ) logger.error(admin_msg_sub) + # send email to admin email_to_admin_data = { 'subject': admin_msg_sub, 'from_email': settings.DCL_SUPPORT_FROM_ADDRESS, @@ -121,6 +123,26 @@ def handle_invoice_webhook(request): 'body': "\n".join( ["%s=%s" % (k, v) for (k, v) in invoice.__dict__.items()]), } + # send email to user + context = { + 'base_url': "{0}://{1}".format(request.scheme, + request.get_host()), + 'dcl_text': settings.DCL_TEXT, + } + email_data = { + 'subject': 'IMPORTANT: The payment for VM {VM_ID} at {dcl_text} failed'.format( + dcl_text=settings.DCL_TEXT, + VM_ID=invoice.lines.data.metadata + ), + 'to': stripe_customer.user.email, + 'context': context, + 'template_name': 'invoice_failed', + 'template_path': 'datacenterlight/emails/', + 'from_address': settings.DCL_SUPPORT_FROM_ADDRESS + } + email = BaseEmail(**email_data) + email.send() + send_plain_email_task.delay(email_to_admin_data) else: logger.error("Unhandled event : " + event.type)