From fbf5914e5016935f856ddf795d94cb8ccf290221 Mon Sep 17 00:00:00 2001 From: Yoo117 Date: Thu, 10 Oct 2024 11:27:01 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- payments/views.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/payments/views.py b/payments/views.py index 2a32db2..991ed13 100644 --- a/payments/views.py +++ b/payments/views.py @@ -61,11 +61,6 @@ def get(self, request, pk=None): return Response(serializer.data) else: cart, _ = Cart.objects.get_or_create(user=request.user) - if not cart.cart_items.exists(): - return Response( - {"detail": "장바구니가 비어있습니다."}, - status=status.HTTP_200_OK, - ) serializer = CartSerializer(cart) return Response(serializer.data) @@ -154,7 +149,7 @@ def _create_order_from_cart(self, request): status=status.HTTP_400_BAD_REQUEST, ) - if cart.total_price() > 50000: + if cart.get_total_price() > 50000: return Response( {"detail": "상품의 총 가격이 50,000원을 초과할 수 없습니다."}, status=status.HTTP_400_BAD_REQUEST, @@ -168,7 +163,7 @@ def _create_order_from_cart(self, request): "curriculum": item.curriculum.id if item.curriculum else None, "course": item.course.id if item.course else None, "quantity": item.quantity, - "price": item.price(), + "price": item.get_price(), } for item in cart.cart_items.all() ], @@ -340,7 +335,7 @@ def get_queryset(self): def _validate_order(self, order): if order.order_status != "pending": raise ValidationError("결제 가능한 상태의 주문이 아닙니다.") - if order.total_price() > 50000: + if order.get_total_price() > 50000: raise ValidationError("결제 금액이 50,000원을 초과할 수 없습니다.") if hasattr(order, "payment") and order.payment.payment_status == "completed": raise ValidationError("이미 결제가 완료된 주문입니다.") @@ -368,7 +363,7 @@ def post(self, request, order_id): order=order, user=request.user, payment_status="pending", - amount=order.total_price(), + amount=order.get_total_price(), transaction_id=kakao_response["tid"], ) @@ -575,13 +570,13 @@ def get_receipt_detail(self, request, payment_id): "order_info": { "order_id": order.id, "order_status": order.order_status, - "total_items": order.total_items(), - "total_price": order.total_price(), + "total_items": order.get_total_items(), + "total_price": order.get_total_price(), "items": [ { - "name": item.item_name, + "name": item.get_item_name(), "quantity": item.quantity, - "price": item.price, + "price": item.get_price(), } for item in order.order_items.all() ],