Skip to content

Commit

Permalink
pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaniog committed Jun 15, 2024
1 parent 2752885 commit 00496da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 11 additions & 2 deletions backend/apps/amo/dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ class ContactDTO:
phone: str


UNPAY_STATUS = 67507838
PAY_STATUS = 67507834


@dataclasses.dataclass
class DealDTO:
name: str
price: int
bought_tickets: str
created_at: datetime
contact: ContactDTO
status_id: int


@dataclasses.dataclass
Expand Down Expand Up @@ -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}]},
Expand All @@ -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
)


Expand Down
2 changes: 2 additions & 0 deletions backend/apps/payments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 00496da

Please sign in to comment.