Skip to content

Commit 55cf46c

Browse files
committed
Разбор уведомления об оплате
1 parent 649e125 commit 55cf46c

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

events/exceptions.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11

22

3+
class ParticipantNotFoundError(Exception):
4+
def __init__(self, *args, **kwargs):
5+
super().__init__(*args)
6+
7+
def __str__(self):
8+
return "Участник не найден."
9+
10+
311
class DuplicateParticipantError(Exception):
412
def __init__(self, *args, **kwargs):
513
super().__init__(*args)

events/pay_views.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from config import settings
1111
from events.models import Event, Participant
12+
from events.exceptions import ParticipantNotFoundError
1213

1314
logger = logging.getLogger(settings.LOGGER)
1415

@@ -20,20 +21,25 @@ def dispatch(self, *args, **kwargs):
2021

2122
@staticmethod
2223
def get(request):
23-
logger.info(f'Pay Notify -> post: {dict(request.POST.items())}')
24-
logger.info(f'Pay Notify -> get: {dict(request.GET.items())}')
25-
logger.info(f'Pay Notify -> get meta: {dict(request.META.items())}')
26-
logger.info(f'Pay Notify -> body: {dict(request.BODY.items())}')
27-
logger.info(f'Pay Notify -> data: {dict(request.DATA.items())}')
2824
return HttpResponse(status=200)
2925

3026
@staticmethod
3127
def post(request):
32-
logger.warning(f'Pay Notify -> post: {dict(request.POST.items())}')
33-
logger.warning(f'Pay Notify -> get: {dict(request.GET.items())}')
34-
logger.warning(f'Pay Notify -> body: {dict(request.BODY.items())}')
35-
logger.warning(f'Pay Notify -> data: {dict(request.DATA.items())}')
36-
logger.warning(f'Pay Notify -> get meta: {dict(request.META.items())}')
28+
if True or 'label' in request.POST:
29+
label = request.POST['label']
30+
label = label.split('_')
31+
for part in label:
32+
if part.startswith('e'):
33+
event_id = int(part[1:])
34+
if part.startswith('p'):
35+
participant_id = int(part[1:])
36+
try:
37+
event = Event.objects.get(id=event_id)
38+
participant = Participant.objects.get(id=participant_id, event=event)
39+
participant.paid = True
40+
participant.save()
41+
except ParticipantNotFoundError as e:
42+
logger.error(e)
3743
return HttpResponse(status=200)
3844

3945

@@ -45,7 +51,7 @@ def get(request, event_id, p_id):
4551
if participant.paid:
4652
return redirect('pay_ok', event_id)
4753
amount = event.price
48-
order_id = f"e{event_id}_p{p_id}_{participant.last_name}_{participant.first_name}"
54+
order_id = f"e{event_id}_p{p_id}"
4955
success_uri = request.build_absolute_uri(reverse('pay_ok', args=(event_id,)))
5056
return render(
5157
request=request,

0 commit comments

Comments
 (0)