Skip to content

Commit

Permalink
Fix bugs account management (#72)
Browse files Browse the repository at this point in the history
* Fix bug on create and modify Payment Account

* Improve notification on account expiration
  • Loading branch information
eloravpn authored Jan 6, 2025
1 parent 90c99ba commit 06fd651
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
14 changes: 10 additions & 4 deletions src/commerce/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
transaction_router = APIRouter()
payment_account_router = APIRouter()


logger = logging.getLogger("uvicorn.error")


# Order Routes


Expand Down Expand Up @@ -186,7 +186,6 @@ def add_service(
db: Session = Depends(get_db),
admin: Admin = Depends(Admin.get_current),
):

try:
db_service = commerce_service.create_service(db=db, service=service)
except IntegrityError as error:
Expand Down Expand Up @@ -550,12 +549,19 @@ def get_transactions(
"/payment-accounts/", tags=["PaymentAccount"], response_model=PaymentAccountResponse
)
def add_payment_account(
account: PaymentAccountCreate,
payment_account: PaymentAccountCreate,
db: Session = Depends(get_db),
admin: Admin = Depends(Admin.get_current),
):
db_user = user_service.get_user(db, payment_account.user_id)

if not db_user:
raise HTTPException(status_code=404, detail="User not found")

try:
db_account = commerce_service.create_payment_account(db=db, account=account)
db_account = commerce_service.create_payment_account(
db=db, account=payment_account, db_user=db_user
)
except IntegrityError:
raise HTTPException(status_code=409, detail="Payment account already exists")

Expand Down
6 changes: 4 additions & 2 deletions src/commerce/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,11 +739,13 @@ def _get_query_result(limit, offset, query, return_with_count, sort):
return query.all()


def create_payment_account(db: Session, account: PaymentAccountCreate):
def create_payment_account(db: Session, account: PaymentAccountCreate, db_user: User):
db_account = PaymentAccount(
user_id=account.user_id,
user_id=db_user.id,
card_number=account.card_number,
account_number=account.account_number,
bank_name=account.bank_name,
shaba=account.shaba,
owner_name=account.owner_name,
owner_family=account.owner_family,
enable=account.enable,
Expand Down
2 changes: 2 additions & 0 deletions src/jobs/account_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ def review_accounts():
db_user=account.user,
message=messages.USER_NOTIFICATION_ACCOUNT_EXPIRED.format(
id=account.email,
service_title=account.service_title,
due=captions.EXPIRE_TIME,
),
type_=NotificationType.account,
Expand All @@ -642,6 +643,7 @@ def review_accounts():
db_user=account.user,
message=messages.USER_NOTIFICATION_ACCOUNT_EXPIRED.format(
id=account.email,
service_title=account.service_title,
due=captions.EXCEEDED_DATA_LIMIT,
),
type_=NotificationType.account,
Expand Down
2 changes: 2 additions & 0 deletions src/jobs/notification_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def percent_used_traffic_notification_job(min_percent: int, max_percent: int):
message=messages.USED_TRAFFIC_NOTIFICATION.format(
admin_id=config.TELEGRAM_ADMIN_USER_NAME,
account_email=account.email,
service_title=account.service_title,
used_traffic_percent=min_percent,
),
level=level.value,
Expand Down Expand Up @@ -118,6 +119,7 @@ def days_to_expire_notification_job(min_days: int, max_days: int):
notification=NotificationCreate(
user_id=account.user.id,
message=messages.EXPIRE_TIME_NOTIFICATION.format(
service_title=account.service_title,
account_email=account.email,
days=max_days,
),
Expand Down
6 changes: 3 additions & 3 deletions src/telegram/user/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
"""

USER_NOTIFICATION_ACCOUNT_EXPIRED = """
سرویس شما با شناسه {id} بدلیل {due} منقضی شد.
سرویس {service_title} شما با شناسه {id} بدلیل {due} منقضی شد.
✴️ جهت شارژ مجدد سرویس می توانید از طریق منوی<b> 🛍 خرید سرویس</b> اقدام نمایید.
"""
Expand All @@ -286,7 +286,7 @@
"""

USED_TRAFFIC_NOTIFICATION = """
⚠️ شما تا این لحظه بیش از {used_traffic_percent} درصد از ترافیک سرویس یا شناسه {account_email} را مصرف نموده اید.
⚠️ شما تا این لحظه بیش از {used_traffic_percent} درصد از ترافیک سرویس {service_title} یا شناسه {account_email} را مصرف نموده اید.
✳️ جهت مشاهده میزان ترافیک مصرفی و همچنین تاریخ انقضا سرویس، به منوی <b>💎 سرویس های من</b> مراجعه نمایید.
Expand All @@ -296,7 +296,7 @@
"""

EXPIRE_TIME_NOTIFICATION = """
⚠️ کمتر از {days} روز دیگر زمان اعتبار سرویس شما با شناسه {account_email} به پایان می رسد.
⚠️ کمتر از {days} روز دیگر زمان اعتبار سرویس {service_title} شما با شناسه {account_email} به پایان می رسد.
✳️ جهت مشاهده میزان ترافیک مصرفی و همچنین تاریخ انقضا سرویس، به منوی <b>💎 سرویس های من</b> مراجعه نمایید.
Expand Down

0 comments on commit 06fd651

Please sign in to comment.