feat: send subscription renewal notification emails
parent
7832e9e021
commit
12e8ae37de
|
@ -15,6 +15,8 @@
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.core.mail import send_mail
|
||||||
|
from django.template.loader import render_to_string
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
from oauth2_provider.models import get_application_model
|
from oauth2_provider.models import get_application_model
|
||||||
|
@ -23,7 +25,7 @@ from oauth2_provider.generators import generate_client_id, generate_client_secre
|
||||||
from accounts.utils import gen_secret
|
from accounts.utils import gen_secret
|
||||||
from dash.models import Instance
|
from dash.models import Instance
|
||||||
from infrastructure.models import InstanceCreated
|
from infrastructure.models import InstanceCreated
|
||||||
from billing.utils import generate_invoice, payment_fullfilled
|
from billing.utils import generate_invoice, payment_fullfilled, get_invoice_link
|
||||||
|
|
||||||
Application = get_application_model()
|
Application = get_application_model()
|
||||||
|
|
||||||
|
@ -41,5 +43,27 @@ class Command(BaseCommand):
|
||||||
f"Payment not fulfilled for instance: {paid_instance.instance}"
|
f"Payment not fulfilled for instance: {paid_instance.instance}"
|
||||||
)
|
)
|
||||||
payment = generate_invoice(instance=paid_instance.instance)
|
payment = generate_invoice(instance=paid_instance.instance)
|
||||||
|
owner = paid_instance.instance.owned_by
|
||||||
|
ctx = {
|
||||||
|
"username": owner.username,
|
||||||
|
"payment": payment,
|
||||||
|
"link": get_invoice_link(payment=payment),
|
||||||
|
}
|
||||||
|
|
||||||
|
body = render_to_string(
|
||||||
|
"billing/emails/renew-subscription.txt",
|
||||||
|
context=ctx,
|
||||||
|
)
|
||||||
|
|
||||||
|
email = owner.email
|
||||||
|
sender = settings.DEFAULT_FROM_EMAIL
|
||||||
|
|
||||||
|
send_mail(
|
||||||
|
subject="[Gna!] Payment receipt your Hostea VM",
|
||||||
|
message=body,
|
||||||
|
from_email=f"No reply Gna!<{sender}>", # TODO read from settings.py
|
||||||
|
recipient_list=[email],
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.stdout.write("No instances available")
|
self.stdout.write("No instances available")
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
Hello {{ username }}!
|
||||||
|
|
||||||
|
Your Gna! VM subscription is due for renewal. Please click the link
|
||||||
|
below to renew your subscription:
|
||||||
|
|
||||||
|
{{link}}
|
||||||
|
|
||||||
|
-----------------------------------------------------
|
||||||
|
|
||||||
|
- Instance Name: {{ payment.instance_name }}
|
||||||
|
- Configuration: {{payment.instance_configuration_id.name}}
|
||||||
|
- Total Amount: {{payment.total}} {{payment.currency|upper}}
|
||||||
|
|
||||||
|
We appreciate your business!
|
||||||
|
|
||||||
|
Cheers,
|
||||||
|
Gna! team
|
Loading…
Reference in New Issue