diff --git a/backend/accounts/utils.py b/backend/accounts/utils.py index 6ed5ff0..a6bbefd 100644 --- a/backend/accounts/utils.py +++ b/backend/accounts/utils.py @@ -4,6 +4,8 @@ from .models import EmailConfirmation import uuid from django.conf import settings from django.utils.timezone import now +from backend.core.models import Document, Organization + def send_confirmation_email(email): @@ -21,4 +23,28 @@ def send_confirmation_email(email): message=f"Please click on the link to confirm your e-mail address: {confirmation_link}", from_email= settings.EMAIL_HOST_USER, recipient_list=[email] - ) \ No newline at end of file + ) + +def send_payment_email(email): + organization = Organization.objects.get(email=email) + document = Document.objects.get(organization=organization) + + payment_link = f"http://127.0.0.1:8000{reverse('core:payment_page')}?email={email}" + + send_mail( + subject="Complete your payment", + message=f"Click the link to proceed with payment: {payment_link}", + from_email=settings.EMAIL_HOST_USER, + recipient_list=[email], + fail_silently=False, + ) + +def send_document_email(email, document_link): + send_mail( + subject="Your Document is Ready", + message=f"You can access your document at any time here: {document_link}", + from_email=settings.EMAIL_HOST_USER, + recipient_list=[email], + fail_silently=False, + ) + diff --git a/backend/accounts/views.py b/backend/accounts/views.py index c644ca5..1757f37 100644 --- a/backend/accounts/views.py +++ b/backend/accounts/views.py @@ -4,7 +4,7 @@ from backend.accounts.forms import SignupForm from .models import EmailConfirmation from django.shortcuts import get_object_or_404, render from django.http import HttpResponse -from backend.accounts.utils import send_confirmation_email +from backend.accounts.utils import send_confirmation_email, send_payment_email from .tasks import create_document_for_organization class SignUpView(CreateView): @@ -20,7 +20,7 @@ def confirm_email(request, uuid): return render(request, 'confirmation_expired.html', {'email': confirmation.email}) task = create_document_for_organization.delay(confirmation.email) - print(f"Task ID: {task.id}") + send_payment_email(confirmation.email) return HttpResponse("Email is confirmed") diff --git a/backend/core/templates/payment.html b/backend/core/templates/payment.html new file mode 100644 index 0000000..22bd6c6 --- /dev/null +++ b/backend/core/templates/payment.html @@ -0,0 +1,11 @@ +{% extends 'base.html' %} + +{% block content %} +
Click the button below to pay and access your document.
+ + +{% endblock %} \ No newline at end of file diff --git a/backend/core/urls.py b/backend/core/urls.py index 1b67d6c..9b5d2ea 100644 --- a/backend/core/urls.py +++ b/backend/core/urls.py @@ -11,4 +11,6 @@ urlpatterns = [ # url document/ recieves a parameter named 'uuid' and passes it to the view path('document/