Send invoice failed notification to user also

This commit is contained in:
PCoder 2019-06-13 05:20:00 +02:00
parent 690b80a616
commit ad846fabec

View file

@ -9,6 +9,7 @@ from django.views.decorators.http import require_POST
from hosting.models import MonthlyHostingBill, HostingBillLineItem from hosting.models import MonthlyHostingBill, HostingBillLineItem
from membership.models import StripeCustomer from membership.models import StripeCustomer
from utils.mailer import BaseEmail
from utils.tasks import send_plain_email_task from utils.tasks import send_plain_email_task
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -114,6 +115,7 @@ def handle_invoice_webhook(request):
invoice.lines.data.metadata invoice.lines.data.metadata
) )
logger.error(admin_msg_sub) logger.error(admin_msg_sub)
# send email to admin
email_to_admin_data = { email_to_admin_data = {
'subject': admin_msg_sub, 'subject': admin_msg_sub,
'from_email': settings.DCL_SUPPORT_FROM_ADDRESS, 'from_email': settings.DCL_SUPPORT_FROM_ADDRESS,
@ -121,6 +123,26 @@ def handle_invoice_webhook(request):
'body': "\n".join( 'body': "\n".join(
["%s=%s" % (k, v) for (k, v) in invoice.__dict__.items()]), ["%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) send_plain_email_task.delay(email_to_admin_data)
else: else:
logger.error("Unhandled event : " + event.type) logger.error("Unhandled event : " + event.type)