Coverage for events/services.py: 24%
17 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-05-15 13:29 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-05-15 13:29 -0600
1from django.conf import settings
2from sentry_sdk import capture_exception
3from app.sendgrid import SendgridClient
6def send_ticket_purchase_confirmation(email, product_purchase, payment_intent, tickets, charge):
7 try:
8 sendgrid = SendgridClient(to=email)
9 sendgrid.send_dynamic_email(
10 template_id=settings.SENDGRID_TICKET_PURCHASE_CONFIRMATION_TEMPLATE,
11 dynamic_template_data={
12 "stripe_pi_id": payment_intent.stripe_pi_id,
13 "quantity": product_purchase.quantity,
14 "ticket_name": product_purchase.product.name,
15 "concept": payment_intent.concept,
16 "payment_amount": f"${payment_intent.amount:,}",
17 "participants": [
18 {
19 "first_name": ticket.first_name,
20 "last_name": ticket.last_name,
21 "phone": ticket.phone.as_national,
22 "email": ticket.email,
23 }
24 for ticket in tickets
25 ],
26 "url": f"{settings.FRONTEND_DOMAIN_INVOICES}{charge.random_slug}",
27 "event_name": product_purchase.product.event.name,
28 },
29 )
30 except Exception as e:
31 capture_exception(e)
34def send_ticket_to_participants(request, tickets, product_purchase):
35 for ticket in tickets:
36 try:
37 event = product_purchase.product.event
38 sendgrid = SendgridClient(to=ticket.email)
39 sendgrid.send_dynamic_email(
40 template_id=settings.SENDGRID_TICKET_TEMPLATE,
41 dynamic_template_data={
42 "uuid": f"{ticket.uuid}",
43 "first_name": ticket.first_name,
44 "last_name": ticket.last_name,
45 "event_name": event.name,
46 "ticket_name": product_purchase.product.name,
47 "qr_code": f"{request.build_absolute_uri(ticket.qr_code)}".replace("http", "https"),
48 "date": event.date.strftime("%Y-%m-%d"),
49 "hour": event.hour.strftime("%H:%M"),
50 "main_image": f"{request.build_absolute_uri(event.main_image)}".replace("http", "https"),
51 },
52 )
53 except Exception as e:
54 capture_exception(e)