Skip to content

Commit

Permalink
Merge pull request #380 from Kotik112/add-email-gift-card-info
Browse files Browse the repository at this point in the history
[FR-206] Add feature to send email with gift card info
  • Loading branch information
BerglundDaniel authored Dec 12, 2023
2 parents a8a0116 + e33202b commit ad3d99d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions api/src/messages/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class MessageTemplate(enum.Enum):
QUIZ_REMINDER = "quiz_reminder"
MEMBERSHIP_REMINDER = "membership_reminder"
NEW_LOW_INCOME_MEMBER = "new_low_income_member"
GIFT_CARD_PURCHASE = "gift_card_purchase"


class Message(Base):
Expand Down
21 changes: 20 additions & 1 deletion api/src/shop/gift_card_util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from secrets import token_hex
from messages.message import send_message
from messages.models import MessageTemplate


def generate_gift_card_code(length=16):
Expand All @@ -11,4 +13,21 @@ def generate_gift_card_code(length=16):
Returns:
A unique validation code.
"""
return token_hex(length)[:length].upper()
return token_hex(length)[:length].upper()


def send_gift_card_email(gift_card):
"""
Send an email to the recipient of a gift card.
Parameters:
- gift_card: The gift card to send an email for.
"""

send_message(
template=MessageTemplate.GIFT_CARD_PURCHASE,
member=None,
recipient_email=gift_card.email,
gift_card=gift_card,
)

17 changes: 17 additions & 0 deletions api/src/templates/gift_card_purchase.body.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends 'email_body_base.html' %}

{% block swedish %}
<p>Hej!</p>
<p>Tack så mycket för ditt köp av ett presentkort!</p>
<p>Ditt presentkort har skickats till dig och är redo att användas.</p>
{# site url behövs uppdateras med den faktiska urlen #}
<p>Logga in på <a href="{{ site_url_here }}">{{ site_url }}</a> för att se detaljerna och använda ditt presentkort.</p>
{% endblock %}

{% block english %}
<p>Hi!</p>
<p>Thank you so much for your purchase of a gift card!</p>
<p>Your gift card has been sent to you and is ready to use.</p>
{# site url needs to be updated with the actual url #}
<p>Log in to <a href="{{ site_url_here }}">{{ site_url }}</a> to view the details and redeem your gift card.</p>
{% endblock %}
1 change: 1 addition & 0 deletions api/src/templates/gift_card_purchase.subject.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Information about your purchased gift card!

0 comments on commit ad3d99d

Please sign in to comment.