feat: send subscription renewal notification emails
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/pr/woodpecker Pipeline failed Details

fix-rm-not-invoice
Hostea dashboard 2022-09-12 16:53:43 +05:30
parent 669a22a004
commit 9f5032bd28
Signed by: realaravinth
GPG Key ID: AD9F0F08E855ED88
2 changed files with 42 additions and 1 deletions

View File

@ -15,6 +15,8 @@
from django.core.management.base import BaseCommand
from django.core.exceptions import ValidationError
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 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 dash.models import Instance
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()
@ -41,5 +43,27 @@ class Command(BaseCommand):
f"Payment not fulfilled for 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:
self.stdout.write("No instances available")

View File

@ -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