refactor(billing): enhance SMS message formatting for expired topups with improved date handling

This commit is contained in:
2025-07-08 20:52:42 +05:00
parent d0a8408121
commit 39da7607f6
3 changed files with 13 additions and 4 deletions

View File

@ -6,6 +6,7 @@ from procrastinate.contrib.django import app
from api.notifications import send_sms
from billing.models import Topup
from django.utils.timezone import localtime
from datetime import datetime
logger = logging.getLogger(__name__)
@ -56,8 +57,15 @@ def update_expired_topups(timestamp: int):
def send_sms_task(
user: str, mobile: str, amount: float, topup_id: str, created_at: str
):
# Parse the ISO formatted date string
try:
dt = datetime.fromisoformat(created_at)
formatted_date = dt.strftime("%d %b %Y, %I:%M %p")
except Exception:
formatted_date = created_at # fallback to original if parsing fails
message = (
f"Dear {user}, \n\nYour topup of {amount} MVR [created at {created_at}] has expired. "
f"Dear {user}, \n\nYour topup of {amount} MVR [created at {formatted_date}] has expired. "
"Please make a new topup to update your wallet. \n\n- SAR Link"
)
send_sms(mobile, message)