Skip to content

Commit

Permalink
implemented fixes for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Naz-iv committed Dec 18, 2023
1 parent 7f23cc6 commit f2e7f3e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 13 deletions.
2 changes: 2 additions & 0 deletions borrowing_service/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ def notify_new_borrowing(sender, instance, created, **kwargs):
)
except TelegramUser.DoesNotExist:
pass
except Exception as e:
print(str(e))
6 changes: 0 additions & 6 deletions notifications_service/bot_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,3 @@ def user_borrowings(bot, message) -> None:
])

bot.reply_to(message, borrowings_info)


def send_payment_notification(bot, user_id, message) -> None:
chat_id = get_object_or_404(TelegramUser, user_id=user_id)

bot.send_message(chat_id=chat_id, text=message)
7 changes: 3 additions & 4 deletions notifications_service/management/commands/run_telegram_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
welcome_message,
help_information,
user_borrowings,
is_user,
send_payment_notification
is_user
)

bot = telebot.TeleBot(TELEGRAM_BOT_TOKEN)
Expand Down Expand Up @@ -36,8 +35,8 @@ def send_users_borrowings(message: telebot.types.Message) -> None:
user_borrowings(bot, message)


def send_notification(user_id, message):
send_payment_notification(bot, user_id, message)
def send_notification(chat_id, message):
bot.send_message(chat_id, message)


class Command(BaseCommand):
Expand Down
25 changes: 25 additions & 0 deletions payment_service/migrations/0003_alter_payment_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.2.8 on 2023-12-18 18:11

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("payment_service", "0002_alter_payment_session_url"),
]

operations = [
migrations.AlterField(
model_name="payment",
name="status",
field=models.CharField(
choices=[
("PENDING", "pending"),
("PAID", "paid"),
("EXPIRED", "expired"),
],
default="PENDING",
max_length=40,
),
),
]
13 changes: 11 additions & 2 deletions payment_service/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from borrowing_service.models import Borrowing
from core import settings
from notifications_service.management.commands import run_telegram_bot
from notifications_service.management.commands.run_telegram_bot import send_notification
from notifications_service.models import TelegramUser
from payment_service.models import Payment


Expand Down Expand Up @@ -100,5 +102,12 @@ def successful_payment_notification(payment: Payment) -> None:

message = (f"Your payment of {amount_total} dollars "
f"for {book_name} was successful")

run_telegram_bot.send_notification(user.id, message)
try:
send_notification(
TelegramUser.objects.get(user_id=user.id).chat_id,
message
)
except TelegramUser.DoesNotExist:
pass
except Exception as e:
print(str(e))
1 change: 0 additions & 1 deletion payment_service/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def payment_successful(self, request, pk: None):
"""Endpoint for redirection after successful payment"""
payment = self.get_object()
session = stripe.checkout.Session.retrieve(payment.session_id)
dockerize-bot

status = session.status
if status != "complete":
Expand Down

0 comments on commit f2e7f3e

Please sign in to comment.