diff --git a/server/src/main/java/kr/or/kosa/cmsplusmain/domain/base/error/ErrorRes.java b/server/src/main/java/kr/or/kosa/cmsplusmain/domain/base/error/ErrorRes.java index eb2915c6..6262a9d1 100644 --- a/server/src/main/java/kr/or/kosa/cmsplusmain/domain/base/error/ErrorRes.java +++ b/server/src/main/java/kr/or/kosa/cmsplusmain/domain/base/error/ErrorRes.java @@ -39,6 +39,13 @@ private ErrorRes(final ErrorCode code) { this.errors = new ArrayList<>(); } + private ErrorRes(final ErrorCode code, final String message) { + this.message = message; + this.status = code.getStatus(); + this.code = code.getCode(); + this.errors = new ArrayList<>(); + } + public static ErrorRes of(final ErrorCode code, final BindingResult bindingResult) { return new ErrorRes(code, FieldError.of(bindingResult)); @@ -48,6 +55,10 @@ public static ErrorRes of(final ErrorCode code) { return new ErrorRes(code); } + public static ErrorRes of(final ErrorCode code, final String message) { + return new ErrorRes(code, message); + } + public static ErrorRes of(final ErrorCode code, final List errors) { return new ErrorRes(code, errors); } diff --git a/server/src/main/java/kr/or/kosa/cmsplusmain/domain/base/error/GlobalExceptionHandler.java b/server/src/main/java/kr/or/kosa/cmsplusmain/domain/base/error/GlobalExceptionHandler.java index 6b04c01e..e1b2311c 100644 --- a/server/src/main/java/kr/or/kosa/cmsplusmain/domain/base/error/GlobalExceptionHandler.java +++ b/server/src/main/java/kr/or/kosa/cmsplusmain/domain/base/error/GlobalExceptionHandler.java @@ -12,6 +12,7 @@ import kr.or.kosa.cmsplusmain.domain.base.error.exception.BusinessException; import kr.or.kosa.cmsplusmain.domain.base.error.exception.EntityNotFoundException; +import kr.or.kosa.cmsplusmain.domain.billing.exception.InvalidBillingStatusException; import lombok.extern.slf4j.Slf4j; @ControllerAdvice @@ -80,6 +81,14 @@ protected ResponseEntity handleAccessDeniedException(AccessDeniedExcep return new ResponseEntity<>(response, HttpStatus.valueOf(ErrorCode.HANDLE_ACCESS_DENIED.getStatus())); } + @ExceptionHandler(InvalidBillingStatusException.class) + protected ResponseEntity handleInvalidBillingStatusException(final InvalidBillingStatusException e) { + log.error("handleInvalidBillingStatusException", e); + final ErrorCode errorCode = e.getErrorCode(); + final ErrorRes response = ErrorRes.of(errorCode, e.getMessage()); + return new ResponseEntity<>(response, HttpStatus.valueOf(errorCode.getStatus())); + } + @ExceptionHandler(BusinessException.class) protected ResponseEntity handleBusinessException(final BusinessException e) { log.error("handleBusinessException", e); @@ -88,7 +97,6 @@ protected ResponseEntity handleBusinessException(final BusinessExcepti return new ResponseEntity<>(response, HttpStatus.valueOf(errorCode.getStatus())); } - @ExceptionHandler(Exception.class) protected ResponseEntity handleException(Exception e) { log.error("handleUnknownException", e); diff --git a/server/src/main/java/kr/or/kosa/cmsplusmain/domain/billing/controller/BillingController.java b/server/src/main/java/kr/or/kosa/cmsplusmain/domain/billing/controller/BillingController.java index 4ae59edc..4b7effda 100644 --- a/server/src/main/java/kr/or/kosa/cmsplusmain/domain/billing/controller/BillingController.java +++ b/server/src/main/java/kr/or/kosa/cmsplusmain/domain/billing/controller/BillingController.java @@ -60,7 +60,7 @@ public void cancelInvoice(@VendorId Long vendorId, @PathVariable Long billingId) * */ @GetMapping("payment/{billingId}") public void payRealtimeBilling(@VendorId Long vendorId, @PathVariable Long billingId) { - billingService.payBilling(vendorId, billingId); + billingService.payRealTimeBilling(vendorId, billingId); } /* diff --git a/server/src/main/java/kr/or/kosa/cmsplusmain/domain/billing/service/BillingService.java b/server/src/main/java/kr/or/kosa/cmsplusmain/domain/billing/service/BillingService.java index f9a2469e..450acb43 100644 --- a/server/src/main/java/kr/or/kosa/cmsplusmain/domain/billing/service/BillingService.java +++ b/server/src/main/java/kr/or/kosa/cmsplusmain/domain/billing/service/BillingService.java @@ -114,9 +114,6 @@ public void cancelInvoice(Long vendorId, Long billingId) { billing.setInvoiceCancelled(); } - /* - * 청구 실시간 결제 - * */ @Transactional public void payBilling(Long vendorId, Long billingId) { Billing billing = validateAndGetBilling(vendorId, billingId); @@ -127,6 +124,19 @@ public void payBilling(Long vendorId, Long billingId) { billing.setPaid(); } + /* + * 청구 실시간 결제 + * */ + @Transactional + public void payRealTimeBilling(Long vendorId, Long billingId) { + Billing billing = validateAndGetBilling(vendorId, billingId); + BillingState.Field.PAY_REALTIME.validateState(billing); + + // TODO: 결제 프로세스 구현 + + billing.setPaid(); + } + /* * 청구 실시간 결제 취소 * */