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

@ -5,7 +5,8 @@ from api.notifications import send_sms
import os import os
import logging import logging
from django.utils import timezone from django.utils import timezone
from api.notifications import send_clean_telegram_markdown
# from api.notifications import send_clean_telegram_markdown
from api.omada import Omada from api.omada import Omada
from apibase.env import env, BASE_DIR from apibase.env import env, BASE_DIR
from procrastinate.contrib.django import app from procrastinate.contrib.django import app

View File

@ -13,9 +13,9 @@ class PaymentAdmin(admin.ModelAdmin):
"paid", "paid",
"paid_at", "paid_at",
"method", "method",
"is_expired",
"expires_at",
"created_at", "created_at",
"expires_at",
"is_expired",
"updated_at", "updated_at",
) )

View File

@ -6,6 +6,7 @@ from procrastinate.contrib.django import app
from api.notifications import send_sms from api.notifications import send_sms
from billing.models import Topup from billing.models import Topup
from django.utils.timezone import localtime from django.utils.timezone import localtime
from datetime import datetime
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -56,8 +57,15 @@ def update_expired_topups(timestamp: int):
def send_sms_task( def send_sms_task(
user: str, mobile: str, amount: float, topup_id: str, created_at: str 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 = ( 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" "Please make a new topup to update your wallet. \n\n- SAR Link"
) )
send_sms(mobile, message) send_sms(mobile, message)