Skip to content

Commit 0cd03a3

Browse files
committed
payment failed api 추가
1 parent 7b964eb commit 0cd03a3

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

payment/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
path("portone/webhook/", PortoneWebhookApi.as_view(), name="portone-webhook"),
88
path("key/", post__generate_payment_key, name="get-payment-key"),
99
path("success/", PaymentSuccessApi.as_view(), name="payment-success"),
10+
path("failed/", PaymentSuccessApi.as_view(), name="payment-success"),
1011
path("cancel/", post__cancel_payment, name="cancel-payment"),
1112
]

payment/views.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,32 @@ def post(self, request):
7979
return Response(dto)
8080

8181

82+
class PaymentFailedApi(APIView):
83+
def post(self, request):
84+
if not request.is_authenticated:
85+
return Response({"msg": "not logged in user"}, status=400)
86+
87+
payment_key = request.data["merchant_uid"]
88+
89+
payment = Payment.objects.get(payment_key=payment_key)
90+
payment.status = enum.PaymentStatus.PAYMENT_FAILED.value
91+
payment.save()
92+
93+
payment_history = PaymentHistory(
94+
payment_key=payment_key,
95+
status=enum.PaymentStatus.PAYMENT_FAILED.value,
96+
is_webhook=False
97+
)
98+
payment_history.save()
99+
100+
dto = {
101+
"msg": "ok",
102+
"merchant_uid": request.data["merchant_uid"]
103+
}
104+
105+
return Response(dto)
106+
107+
82108
@api_view(["POST"])
83109
def post__generate_payment_key(request):
84110

0 commit comments

Comments
 (0)