From 761b8aaefbf9936ab270749a765e78f03763775e Mon Sep 17 00:00:00 2001 From: choyoungseo20 Date: Tue, 17 Jun 2025 16:40:55 +0900 Subject: [PATCH] =?UTF-8?q?key=EB=A5=BC=20=EC=9D=B4=EC=9A=A9=ED=95=9C=20?= =?UTF-8?q?=EA=B2=B0=EC=A0=9C=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../payment/controller/PaymentController.java | 67 ++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/silverbridgeX_user/payment/controller/PaymentController.java b/src/main/java/com/example/silverbridgeX_user/payment/controller/PaymentController.java index 7f01d76..f6ae878 100644 --- a/src/main/java/com/example/silverbridgeX_user/payment/controller/PaymentController.java +++ b/src/main/java/com/example/silverbridgeX_user/payment/controller/PaymentController.java @@ -38,7 +38,7 @@ public ApiResponse readyToKakaoPay(@Authenticatio @PostMapping("/ready/key") @Operation(summary = "카카오페이 URL 생성 API", description = "key를 이용하여 카카오페이 URL을 생성하는 API 입니다.") - public ApiResponse readyToKakaoPay(@RequestParam("pg_token") String key) { + public ApiResponse readyToKakaoPay(@RequestParam("id") String key) { PaymentDto.KakaoReadyResponse kakaoReadyResponse = paymentService.kakaoPayReady(); User user = userService.findByUserName(key); @@ -81,6 +81,21 @@ public ApiResponse refund(@AuthenticationPrincip return ApiResponse.onSuccess(SuccessCode.PAYMENT_CANCEL_SUCCESS, kakaoCancelResponse); } + @GetMapping("/cancel/key") + public ApiResponse refund(@RequestParam("id") String key) { + + User user = userService.findByUserName(key); + Long userId = user.getId(); + + Payment kakaoPay = paymentService.getKakaoPayInfo(userId); + + PaymentDto.KakaoCancelResponse kakaoCancelResponse = paymentService.cancelResponse(kakaoPay.getTid()); + + paymentService.cancelPay(userId); + + return ApiResponse.onSuccess(SuccessCode.PAYMENT_CANCEL_SUCCESS, kakaoCancelResponse); + } + @PostMapping("/subscribe") public ApiResponse subscribePayRequest(@AuthenticationPrincipal CustomUserDetails customUserDetails) { User user = userService.findByUserName(customUserDetails.getUsername()); @@ -95,6 +110,20 @@ public ApiResponse subscribePayRequest(@Authent return ApiResponse.onSuccess(SuccessCode.PAYMENT_SUBSCRIBE_SUCCESS, kakaoApproveResponse); } + @PostMapping("/subscribe/key") + public ApiResponse subscribePayRequest(@RequestParam("id") String key) { + User user = userService.findByUserName(key); + Long userId = user.getId(); + + Payment kakaoPay = paymentService.getKakaoPayInfo(userId); + + PaymentDto.KakaoApproveResponse kakaoApproveResponse = paymentService.approveSubscribeResponse(kakaoPay.getSid()); + + paymentService.savePayInfo(userId, kakaoApproveResponse); + + return ApiResponse.onSuccess(SuccessCode.PAYMENT_SUBSCRIBE_SUCCESS, kakaoApproveResponse); + } + @PostMapping("/subscribe/cancel") @Operation(summary = "카카오페이 구독 취소 API", description = "카카오페이 구독을 취소하는 API 입니다.") public ApiResponse subscribeCancelRequest(@AuthenticationPrincipal CustomUserDetails customUserDetails) { @@ -108,6 +137,19 @@ public ApiResponse subscribeCancelReque return ApiResponse.onSuccess(SuccessCode.PAYMENT_URL_CREATE_SUCCESS, kakaoSubscribeCancelResponse); } + @PostMapping("/subscribe/cancel/key") + @Operation(summary = "카카오페이 구독 취소 API", description = "key를 이용하여 카카오페이 구독을 취소하는 API 입니다.") + public ApiResponse subscribeCancelRequest(@RequestParam("id") String key) { + User user = userService.findByUserName(key); + Long userId = user.getId(); + + Payment kakaoPay = paymentService.getKakaoPayInfo(userId); + + PaymentDto.KakaoSubscribeCancelResponse kakaoSubscribeCancelResponse = paymentService.subscribeCancelResponse(kakaoPay.getSid()); + + return ApiResponse.onSuccess(SuccessCode.PAYMENT_URL_CREATE_SUCCESS, kakaoSubscribeCancelResponse); + } + @GetMapping("/subscribe/status") @Operation(summary = "카카오페이 구독 상태 확인 API", description = "카카오페이 구독 상태를 확인하는 API 입니다.") public ApiResponse subscribeStatusRequest(@AuthenticationPrincipal CustomUserDetails customUserDetails) { @@ -130,4 +172,27 @@ public ApiResponse subscribeStatusRequest(@Authentica return ApiResponse.onSuccess(SuccessCode.PAYMENT_VIEW_SUBSCRIBE_STATUS_SUCCESS, PaymentConverter.toKakaoPayStatus(isLogExist, kakaoSubscribeStatusResponse)); } + + @GetMapping("/subscribe/status/key") + @Operation(summary = "카카오페이 구독 상태 확인 API", description = "key를 이용하여 카카오페이 구독 상태를 확인하는 API 입니다.") + public ApiResponse subscribeStatusRequest(@RequestParam("id") String key) { + User user = userService.findByUserName(key); + Long userId = user.getId(); + + PaymentDto.KakaoSubscribeStatusResponse kakaoSubscribeStatusResponse = new PaymentDto.KakaoSubscribeStatusResponse(); + + boolean isLogExist = false; + if (paymentService.getKakaoPayLog(userId)) { + Payment kakaoPay = paymentService.getKakaoPayInfo(userId); + + if (kakaoPay.getSid() == null || kakaoPay.getSid().isEmpty()) {} + else { + isLogExist = true; + + kakaoSubscribeStatusResponse = paymentService.subscribeStatusResponse(kakaoPay.getSid()); + } + } + + return ApiResponse.onSuccess(SuccessCode.PAYMENT_VIEW_SUBSCRIBE_STATUS_SUCCESS, PaymentConverter.toKakaoPayStatus(isLogExist, kakaoSubscribeStatusResponse)); + } }