Skip to content

Commit 1fe372c

Browse files
authored
Merge pull request #101 from golony6449/feature/golony/payment
payment failed api 추가
2 parents fc9035c + 0cd03a3 commit 1fe372c

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
@@ -92,6 +92,32 @@ def post(self, request):
9292
return Response(dto)
9393

9494

95+
class PaymentFailedApi(APIView):
96+
def post(self, request):
97+
if not request.is_authenticated:
98+
return Response({"msg": "not logged in user"}, status=400)
99+
100+
payment_key = request.data["merchant_uid"]
101+
102+
payment = Payment.objects.get(payment_key=payment_key)
103+
payment.status = enum.PaymentStatus.PAYMENT_FAILED.value
104+
payment.save()
105+
106+
payment_history = PaymentHistory(
107+
payment_key=payment_key,
108+
status=enum.PaymentStatus.PAYMENT_FAILED.value,
109+
is_webhook=False
110+
)
111+
payment_history.save()
112+
113+
dto = {
114+
"msg": "ok",
115+
"merchant_uid": request.data["merchant_uid"]
116+
}
117+
118+
return Response(dto)
119+
120+
95121
@api_view(["POST"])
96122
def post__generate_payment_key(request):
97123

0 commit comments

Comments
 (0)