Skip to content

Commit 0dae291

Browse files
feat: Add all invoice emails in system (#7296)
1 parent 11d9058 commit 0dae291

File tree

8 files changed

+96
-131
lines changed

8 files changed

+96
-131
lines changed

app/api/helpers/mail.py

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
EVENT_ROLE,
2020
MONTHLY_PAYMENT_EMAIL,
2121
MONTHLY_PAYMENT_FOLLOWUP_EMAIL,
22+
MONTHLY_PAYMENT_POST_DUE_EMAIL,
23+
MONTHLY_PAYMENT_PRE_DUE_EMAIL,
2224
NEW_SESSION,
2325
SESSION_STATE_CHANGE,
2426
TEST_MAIL,
@@ -251,37 +253,25 @@ def send_email_after_event(email, event_name, frontend_url):
251253

252254

253255
def send_email_for_monthly_fee_payment(
254-
email, event_name, previous_month, amount, app_name, link
256+
user, event_name, previous_month, amount, app_name, link, follow_up=False
255257
):
256258
"""email for monthly fee payment"""
259+
options = {
260+
False: MONTHLY_PAYMENT_EMAIL,
261+
True: MONTHLY_PAYMENT_FOLLOWUP_EMAIL,
262+
'pre_due': MONTHLY_PAYMENT_PRE_DUE_EMAIL,
263+
'post_due': MONTHLY_PAYMENT_POST_DUE_EMAIL,
264+
}
265+
key = options[follow_up]
266+
email = user.email
257267
send_email(
258268
to=email,
259-
action=MONTHLY_PAYMENT_EMAIL,
260-
subject=MAILS[MONTHLY_PAYMENT_EMAIL]['subject'].format(
261-
date=previous_month, event_name=event_name
262-
),
263-
html=MAILS[MONTHLY_PAYMENT_EMAIL]['message'].format(
264-
email=email,
265-
event_name=event_name,
266-
date=previous_month,
267-
amount=amount,
268-
app_name=app_name,
269-
payment_url=link,
270-
),
271-
)
272-
273-
274-
def send_followup_email_for_monthly_fee_payment(
275-
email, event_name, previous_month, amount, app_name, link
276-
):
277-
"""followup email for monthly fee payment"""
278-
send_email(
279-
to=email,
280-
action=MONTHLY_PAYMENT_FOLLOWUP_EMAIL,
281-
subject=MAILS[MONTHLY_PAYMENT_FOLLOWUP_EMAIL]['subject'].format(
282-
date=previous_month, event_name=event_name
269+
action=key,
270+
subject=MAILS[key]['subject'].format(
271+
date=previous_month, event_name=event_name, app_name=app_name
283272
),
284-
html=MAILS[MONTHLY_PAYMENT_FOLLOWUP_EMAIL]['message'].format(
273+
html=MAILS[key]['message'].format(
274+
name=user.full_name,
285275
email=email,
286276
event_name=event_name,
287277
date=previous_month,

app/api/helpers/notification.py

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
get_event_exported_actions,
99
get_event_imported_actions,
1010
get_event_role_notification_actions,
11-
get_monthly_payment_follow_up_notification_actions,
1211
get_monthly_payment_notification_actions,
1312
get_new_session_notification_actions,
1413
get_session_state_change_notification_actions,
@@ -142,7 +141,7 @@ def send_notif_after_export(user, event_name, download_url=None, error_text=None
142141

143142

144143
def send_notif_monthly_fee_payment(
145-
user, event_name, previous_month, amount, app_name, link, event_id
144+
user, event_name, previous_month, amount, app_name, link, event_id, follow_up=False
146145
):
147146
"""
148147
Send notification about monthly fee payments.
@@ -155,12 +154,11 @@ def send_notif_monthly_fee_payment(
155154
:param event_id:
156155
:return:
157156
"""
158-
message_settings = MessageSettings.query.filter_by(
159-
action=SESSION_STATE_CHANGE
160-
).first()
157+
key = MONTHLY_PAYMENT_FOLLOWUP_NOTIF if follow_up else MONTHLY_PAYMENT_NOTIF
158+
message_settings = MessageSettings.query.filter_by(action=key).first()
161159
if not message_settings or message_settings.notification_status == 1:
162160
actions = get_monthly_payment_notification_actions(event_id, link)
163-
notification = NOTIFS[MONTHLY_PAYMENT_NOTIF]
161+
notification = NOTIFS[key]
164162
title = notification['subject'].format(date=previous_month, event_name=event_name)
165163
message = notification['message'].format(
166164
event_name=event_name, date=previous_month, amount=amount, app_name=app_name,
@@ -169,34 +167,6 @@ def send_notif_monthly_fee_payment(
169167
send_notification(user, title, message, actions)
170168

171169

172-
def send_followup_notif_monthly_fee_payment(
173-
user, event_name, previous_month, amount, app_name, link, event_id
174-
):
175-
"""
176-
Send follow up notifications for monthly fee payment.
177-
:param user:
178-
:param event_name:
179-
:param previous_month:
180-
:param amount:
181-
:param app_name:
182-
:param link:
183-
:param event_id:
184-
:return:
185-
"""
186-
message_settings = MessageSettings.query.filter_by(
187-
action=SESSION_STATE_CHANGE
188-
).first()
189-
if not message_settings or message_settings.notification_status == 1:
190-
actions = get_monthly_payment_follow_up_notification_actions(event_id, link)
191-
notification = NOTIFS[MONTHLY_PAYMENT_FOLLOWUP_NOTIF]
192-
title = notification['subject'].format(date=previous_month, event_name=event_name)
193-
message = notification['message'].format(
194-
event_name=event_name, date=previous_month, amount=amount, app_name=app_name
195-
)
196-
197-
send_notification(user, title, message, actions)
198-
199-
200170
def send_notif_event_role(user, role_name, event_name, link, event_id):
201171
"""
202172
Send notification to a user about an event role invite.

app/api/helpers/system_mails.py

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
MAIL_TO_EXPIRED_ORDERS,
1515
MONTHLY_PAYMENT_EMAIL,
1616
MONTHLY_PAYMENT_FOLLOWUP_EMAIL,
17+
MONTHLY_PAYMENT_POST_DUE_EMAIL,
18+
MONTHLY_PAYMENT_PRE_DUE_EMAIL,
1719
NEW_SESSION,
1820
NEXT_EVENT,
1921
PASSWORD_CHANGE,
@@ -301,27 +303,67 @@
301303
),
302304
},
303305
MONTHLY_PAYMENT_EMAIL: {
304-
'recipient': 'Owner, Organizer',
305-
'subject': u'{date} - Monthly service fee invoice for {event_name}',
306+
'recipient': 'Owner',
307+
'subject': u'Your invoice for {event_name} for {date} is available on {app_name}',
306308
'message': (
307-
u"The total service fee for the ticket sales of {event_name} in the month of {date} is {amount}."
308-
+ u"<br/> That payment for the same has to be made in 30 days. <a href='{payment_url}'>Click here</a> to "
309-
u"view your invoice and complete the payment."
310-
u"<br><br><em>Thank you for using {app_name}.</em>"
309+
u"Hello {name},<br><br>"
310+
u"The invoice for your event {event_name} on eventyay.com for {date} is now available. Your invoice payment is due within 30 days.<br><br>"
311+
u"Amount Due: {amount}<br><br>"
312+
u"Please pay within 30 days.<br><br>"
313+
u"Pay Now at: <a href='{payment_url}'>{payment_url}</a><br><br>"
314+
u"A detailed invoice is available in <a href='https://eventyay.com/account/billing/invoices/'>the billing area</a> of your account. If you have any questions about invoices, please find more information on our FAQ at https://support.eventyay.com.<br><br>"
315+
u"<em>Thank you for using {app_name}!</em><br><br>"
316+
u"{app_name} Team"
311317
),
312318
'sent_at': '1st day of the month',
313319
},
314320
MONTHLY_PAYMENT_FOLLOWUP_EMAIL: {
315-
'recipient': 'Owner, Organizer',
316-
'subject': u'Past Due: {date} - Monthly service fee invoice for {event_name}',
321+
'recipient': 'Owner',
322+
'subject': u'Reminder: Your invoice for {event_name} for {date} is available on {app_name}',
317323
'message': (
318-
u"The total service fee for the ticket sales of {event_name} in the month of {date} is {amount}."
319-
+ u"<br/> That payment for the same is past the due date. <a href='{payment_url}'>Click here</a> to "
320-
u"view your invoice and complete the payment to prevent loss of functionality."
321-
u"<br><br><em>Thank you for using {app_name}.</em>"
324+
u"Hello {name},<br><br>"
325+
u"Just a friendly reminder that we haven't received your payment for your invoice for {event_name} for {date}. Payment is fast and simple using your credit card or PayPal account.<br><br>"
326+
u"Amount Due: {amount}<br><br>"
327+
u"Please pay within 15 days.<br><br>"
328+
u"Pay Now at: <a href='{payment_url}'>{payment_url}</a><br><br>"
329+
u"A detailed invoice is available in <a href='https://eventyay.com/account/billing/invoices/'>the billing area</a> of your account. If you have any questions about invoices, please find more information on our FAQ at https://support.eventyay.com.<br><br>"
330+
u"<em>Thank you for using {app_name}!</em><br><br>"
331+
u"{app_name} Team"
322332
),
323333
'sent_at': '15th day of the month',
324334
},
335+
MONTHLY_PAYMENT_PRE_DUE_EMAIL: {
336+
'recipient': 'Owner',
337+
'subject': u'Reminder: Your invoice for {event_name} for {date} is available on {app_name}',
338+
'message': (
339+
u"Hello {name},<br><br>"
340+
u"This is a reminder that we haven't received your payment for your invoice for {event_name} for {date}. Payment is fast and simple using your credit card or PayPal account.<br><br>"
341+
u"Amount Due: {amount}<br><br>"
342+
u"Please pay within 2 days.<br><br>"
343+
u"Pay Now: <a href='{payment_url}'>{payment_url}</a><br><br>"
344+
u"Late payments can be subject to a 5% finance fee.<br><br>"
345+
u"A detailed invoice is available in <a href='https://eventyay.com/account/billing/invoices/'>the billing area</a> of your account. If you have any questions about invoices, please find more information on our FAQ at https://support.eventyay.com.<br><br>"
346+
u"<em>Thank you for using {app_name}!</em><br><br>"
347+
u"{app_name} Team"
348+
),
349+
'sent_at': '27th day of the month',
350+
},
351+
MONTHLY_PAYMENT_POST_DUE_EMAIL: {
352+
'recipient': 'Owner',
353+
'subject': u'Please pay your overdue invoice for {event_name} for {date} on {app_name}',
354+
'message': (
355+
u"Hello {name},<br><br>"
356+
u"Your payment is now past due.<br>Please pay this invoice immediately to avoid your account being suspended.<br><br>"
357+
u"Amount Due: {amount}<br><br>"
358+
u"Please pay immediately at: <a href='{payment_url}'>{payment_url}</a><br><br>"
359+
u"Late payments can be subject to a 5% finance fee.<br><br>"
360+
u"A detailed invoice is available in <a href='https://eventyay.com/account/billing/invoices/'>the billing area</a> of your account. If you have any questions about invoices, please find more information on our FAQ at https://support.eventyay.com.<br><br>"
361+
u"If you feel this invoice is incorrect or have any questions, you can contact our support team for assistance.<br><br>"
362+
u"<em>Thank you for using {app_name}!</em><br><br>"
363+
u"{app_name} Team"
364+
),
365+
'sent_at': '30th day of the month',
366+
},
325367
EVENT_IMPORTED: {
326368
'recipient': 'User',
327369
'subject': u'Event {event_name} has been imported',

app/api/helpers/system_notifications.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,6 @@ def get_monthly_payment_notification_actions(event_id, payment_url):
6666
:param payment_url: url to view invoice.
6767
:return: actions
6868
"""
69-
view_invoice_action = NotificationAction(
70-
subject='event', link=payment_url, subject_id=event_id, action_type='view'
71-
)
72-
save_to_db(view_invoice_action)
73-
return [view_invoice_action]
74-
75-
76-
def get_monthly_payment_follow_up_notification_actions(event_id, payment_url):
77-
"""
78-
Get the actions associated with a follow up notification of monthly payments.
79-
:param event_id: id of the event.
80-
:param payment_url: url to view invoice.
81-
:return: actions
82-
"""
8369
view_invoice_action = NotificationAction(
8470
subject='invoice', link=payment_url, subject_id=event_id, action_type='view'
8571
)

app/models/event_invoice.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,8 @@
66

77
from app.api.helpers.db import get_new_identifier
88
from app.api.helpers.files import create_save_pdf
9-
from app.api.helpers.mail import (
10-
send_email_for_monthly_fee_payment,
11-
send_followup_email_for_monthly_fee_payment,
12-
)
13-
from app.api.helpers.notification import (
14-
send_followup_notif_monthly_fee_payment,
15-
send_notif_monthly_fee_payment,
16-
)
9+
from app.api.helpers.mail import send_email_for_monthly_fee_payment
10+
from app.api.helpers.notification import send_notif_monthly_fee_payment
1711
from app.api.helpers.storage import UPLOAD_PATHS
1812
from app.api.helpers.utilities import monthdelta, round_money
1913
from app.models import db
@@ -160,20 +154,25 @@ def send_notification(self, follow_up=False):
160154
app_name = get_settings()['app_name']
161155
frontend_url = get_settings()['frontend_url']
162156
link = '{}/event-invoice/{}/review'.format(frontend_url, self.identifier)
163-
email_function = send_email_for_monthly_fee_payment
164-
notification_function = send_notif_monthly_fee_payment
165-
if follow_up:
166-
email_function = send_followup_email_for_monthly_fee_payment
167-
notification_function = send_followup_notif_monthly_fee_payment
168-
email_function(
169-
self.user.email, self.event.name, prev_month, self.amount, app_name, link,
170-
)
171-
notification_function(
157+
currency = self.event.payment_currency
158+
amount = f"{currency} {self.amount}"
159+
send_email_for_monthly_fee_payment(
172160
self.user,
173161
self.event.name,
174162
prev_month,
175-
self.amount,
163+
amount,
176164
app_name,
177165
link,
178-
self.event_id,
166+
follow_up=follow_up,
179167
)
168+
if isinstance(follow_up, bool):
169+
send_notif_monthly_fee_payment(
170+
self.user,
171+
self.event.name,
172+
prev_month,
173+
amount,
174+
app_name,
175+
link,
176+
self.event_id,
177+
follow_up=follow_up,
178+
)

app/models/mail.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
MAIL_TO_EXPIRED_ORDERS = 'Mail Expired Orders'
2828
MONTHLY_PAYMENT_EMAIL = 'Monthly Payment Email'
2929
MONTHLY_PAYMENT_FOLLOWUP_EMAIL = 'Monthly Payment Follow Up Email'
30+
MONTHLY_PAYMENT_PRE_DUE_EMAIL = 'Monthly Payment Pre Due Email'
31+
MONTHLY_PAYMENT_POST_DUE_EMAIL = 'Monthly Payment Post Due Email'
3032
EVENT_IMPORTED = 'Event Imported'
3133
EVENT_IMPORT_FAIL = 'Event Import Failed'
3234
TEST_MAIL = 'Test Mail'

tests/all/integration/api/helpers/test_notification.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22

33
from app.api.helpers.notification import (
4-
send_followup_notif_monthly_fee_payment,
54
send_notif_after_event,
65
send_notif_after_export,
76
send_notif_after_import,
@@ -92,8 +91,8 @@ def test_send_notif_monthly_fee_payment(user):
9291

9392

9493
def test_send_followup_notif_monthly_fee_payment(user):
95-
send_followup_notif_monthly_fee_payment(
96-
user, 'Champagne Showers', 'November', 4532.99, 'RedFoo', link, 1,
94+
send_notif_monthly_fee_payment(
95+
user, 'Champagne Showers', 'November', 4532.99, 'RedFoo', link, 1, follow_up=True
9796
)
9897
notification = Notification.query.first()
9998
assert (

tests/all/integration/api/helpers/test_systemnotifications.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
get_event_published_notification_actions,
77
get_event_role_notification_actions,
88
get_invite_papers_notification_actions,
9-
get_monthly_payment_follow_up_notification_actions,
109
get_monthly_payment_notification_actions,
1110
get_new_session_notification_actions,
1211
get_next_event_notification_actions,
@@ -67,28 +66,6 @@ def test_monthly_payment_notification(self):
6766
response = get_monthly_payment_notification_actions(
6867
request_event_id, request_url
6968
)
70-
expected_action = NotificationAction(
71-
subject='event',
72-
link=request_url,
73-
subject_id=request_event_id,
74-
action_type='view',
75-
)
76-
expected_action = [expected_action]
77-
expected_length = len(expected_action)
78-
response_length = len(response)
79-
self.assertIsInstance(response, list)
80-
self.assertEqual(expected_action[0].subject, response[0].subject)
81-
self.assertEqual(expected_length, response_length)
82-
83-
def test_monthly_pay_followup_notification(self):
84-
"""Method to test the actions associated with a follow up notification of monthly payments."""
85-
86-
with self.app.test_request_context():
87-
request_url = 'https://localhost/e/345525/payment'
88-
request_event_id = 1
89-
response = get_monthly_payment_follow_up_notification_actions(
90-
request_event_id, request_url
91-
)
9269
expected_action = NotificationAction(
9370
subject='invoice',
9471
link=request_url,

0 commit comments

Comments
 (0)