diff --git a/backend/apps/mailer/utils.py b/backend/apps/mailer/utils.py index 11dd275..c0eac84 100644 --- a/backend/apps/mailer/utils.py +++ b/backend/apps/mailer/utils.py @@ -5,7 +5,7 @@ from .tasks import send_mail_with_attachment -def send_purchase_email(email, payment_id): +def send_purchase_email(email, payment_id, ticket_path): order = Order.objects.filter(payment_id=payment_id).first() qr_code_url = order.qr_code.url context = {"order": {"qr_code": {"url": qr_code_url}}} @@ -18,4 +18,4 @@ def send_purchase_email(email, payment_id): "html_message": html_message, } - send_mail_with_attachment([email], mail_data, "Ticket.pdf") + send_mail_with_attachment([email], mail_data, ticket_path) diff --git a/backend/apps/payments/views.py b/backend/apps/payments/views.py index 9e32bde..1f5c03d 100644 --- a/backend/apps/payments/views.py +++ b/backend/apps/payments/views.py @@ -4,7 +4,6 @@ from apps.amo.views import post_orders from apps.booking.models import Booking, Buyer, Cart from apps.booking.serializers import BookingSerializer, Buyer -from apps.mailer.utils import send_purchase_email from apps.tickets.generator import generate_ticket from apps.tickets.utils import get_ticket_info from django.db import transaction @@ -241,7 +240,6 @@ def yookassa_webhook(request): post_orders([order]) if generate_ticket(get_ticket_info(payment_id), payment_id): - send_purchase_email(order.cart.buyer.email, payment_id) return JsonResponse({"status": "success"}, status=200) else: return Response( diff --git a/backend/apps/tickets/generator.py b/backend/apps/tickets/generator.py index b5eef2d..876b22e 100644 --- a/backend/apps/tickets/generator.py +++ b/backend/apps/tickets/generator.py @@ -1,6 +1,7 @@ import os import qrcode +from apps.mailer.utils import send_purchase_email from apps.payments.models import Order from django.core.files import File from reportlab.lib.pagesizes import A4 @@ -32,7 +33,7 @@ def check_page_space(y_position, c, height): return y_position -def generate_ticket(ticket_info, order_id): +def generate_ticket(ticket_info, payment_id): try: output_file = f"{ticket_info['output_file']}.pdf" @@ -64,7 +65,7 @@ def generate_ticket(ticket_info, order_id): y_position -= 60 # Генерация и вставка QR-кода - qr_code_path = f"qrcode_{order_id}.png" + qr_code_path = f"qrcode_{payment_id}.png" generate_qr_code(ticket_info["qr_data"], qr_code_path) c.drawImage(qr_code_path, width - 120, height - 120, width=100, height=100) @@ -107,7 +108,9 @@ def generate_ticket(ticket_info, order_id): c.showPage() c.save() - order = Order.objects.filter(payment_id=order_id).first() + order = Order.objects.filter(payment_id=payment_id).first() + + send_purchase_email(order.cart.buyer.email, payment_id, output_file) with open(output_file, "rb") as f: order.ticket_file.save(output_file, File(f))