diff --git a/backend/apps/amo/dto.py b/backend/apps/amo/dto.py index e5f81c5..33c3662 100644 --- a/backend/apps/amo/dto.py +++ b/backend/apps/amo/dto.py @@ -13,6 +13,10 @@ class ContactDTO: phone: str +UNPAY_STATUS = 67507838 +PAY_STATUS = 67507834 + + @dataclasses.dataclass class DealDTO: name: str @@ -20,6 +24,7 @@ class DealDTO: bought_tickets: str created_at: datetime contact: ContactDTO + status_id: int @dataclasses.dataclass @@ -54,6 +59,7 @@ def deal_to_json(deal: DealDTO) -> {}: return { "name": deal.name, "price": deal.price, + "pipeline_id": deal.price, "created_at": int(deal.created_at.astimezone().timestamp()), "custom_fields_values": [ {"field_id": d_f_id[DEAL_BOUGHT_TICKETS], "values": [{"value": deal.bought_tickets}]}, @@ -75,17 +81,20 @@ def deal_to_json(deal: DealDTO) -> {}: def order_to_deal(order) -> DealDTO: bookings = group_bookings_by_place_event_time(order) + status = PAY_STATUS if (order.payment_status == "succeeded") else UNPAY_STATUS + return DealDTO( order.cart.buyer.first_name + " " + order.cart.buyer.last_name + " " + datetime.now().strftime("%d.%m"), int(order.total), "\n\n".join(list(map(booking_to_string, bookings))), datetime.now(), - contact=ContactDTO( + ContactDTO( first_name=order.cart.buyer.first_name, last_name=order.cart.buyer.last_name, email=order.cart.buyer.email, phone=order.cart.buyer.phone, - ) + ), + status ) diff --git a/backend/apps/payments/views.py b/backend/apps/payments/views.py index 9ff1571..7e706e2 100644 --- a/backend/apps/payments/views.py +++ b/backend/apps/payments/views.py @@ -16,6 +16,7 @@ from .models import Order from .serializers import PaymentProcessingSerializer, PaymentStatusSerializer from .services import YooKassaService +from apps.amo.views import post_orders @api_view(["POST"]) @@ -165,6 +166,7 @@ def yookassa_webhook(request): order = Order.objects.filter(payment_id=payment_id).first() order.payment_status = status order.save() + post_orders([order]) if generate_ticket(get_ticket_info(payment_id), payment_id): send_purchase_email(order.cart.buyer.email, payment_id)