Send invoice failed notification to user also
This commit is contained in:
parent
690b80a616
commit
ad846fabec
1 changed files with 22 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue