diff --git a/src/main/java/com/sopterm/makeawish/controller/UserController.java b/src/main/java/com/sopterm/makeawish/controller/UserController.java index 89d6bbf..66e2225 100644 --- a/src/main/java/com/sopterm/makeawish/controller/UserController.java +++ b/src/main/java/com/sopterm/makeawish/controller/UserController.java @@ -16,7 +16,6 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; -import static com.sopterm.makeawish.common.message.ErrorMessage.NOT_VALID_USER_ACCOUNT; import static com.sopterm.makeawish.common.message.ErrorMessage.NO_EXIST_USER_ACCOUNT; import static com.sopterm.makeawish.common.message.SuccessMessage.*; import static java.util.Objects.nonNull; @@ -30,7 +29,7 @@ public class UserController { private final UserService userService; private final AbuseService abuseService; - private static final int VERIFY_ACCOUNT_SUCCESS = 0; + private static final String VERIFY_ACCOUNT_SUCCESS = "100"; @Operation(summary = "유저 계좌 정보 가져오기") @GetMapping("/account") @@ -69,9 +68,9 @@ public ResponseEntity checkAccountInformation( @Parameter(hidden = true) @AuthenticationPrincipal InternalMemberDetails memberDetails, @RequestBody UserAccountVerifyRequestDTO verifyRequestDTO) throws Exception { val response = userService.verifyUserAccount(memberDetails.getId(), verifyRequestDTO); - return response == VERIFY_ACCOUNT_SUCCESS + return response.getResult().equals(VERIFY_ACCOUNT_SUCCESS) ? ResponseEntity.ok(ApiResponse.success(SUCCESS_VERIFY_USER_ACCOUNT.getMessage())) - : ResponseEntity.ok(ApiResponse.fail(NOT_VALID_USER_ACCOUNT.getMessage(), response)); + : ResponseEntity.ok(ApiResponse.fail(response.getResultMessage())); } @Operation(summary = "어뷰징 유저 확인") diff --git a/src/main/java/com/sopterm/makeawish/service/UserService.java b/src/main/java/com/sopterm/makeawish/service/UserService.java index f8c12f2..7b64698 100644 --- a/src/main/java/com/sopterm/makeawish/service/UserService.java +++ b/src/main/java/com/sopterm/makeawish/service/UserService.java @@ -1,5 +1,6 @@ package com.sopterm.makeawish.service; +import com.popbill.api.AccountCheckInfo; import com.popbill.api.AccountCheckService; import com.popbill.api.PopbillException; import com.sopterm.makeawish.domain.abuse.AbuseLog; @@ -18,6 +19,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + import static com.sopterm.makeawish.common.message.ErrorMessage.INVALID_USER; import static com.sopterm.makeawish.common.message.ErrorMessage.NO_EXIST_USER_ACCOUNT; import static java.util.Objects.isNull; @@ -36,7 +39,7 @@ public class UserService { @Value("${popbill.businessNumber}") private String corpNum; - private static final int ABUSE_CAUTION_COUNT = 4; + private static final List USER_FAIL_CODE = List.of("300", "301", "400", "801", "898", "899"); public UserAccountResponseDTO getUserAccount(Long userId) { val wisher = getUser(userId); @@ -69,21 +72,19 @@ private User getUser(Long userId) { } @Transactional - public Integer verifyUserAccount(Long userId, UserAccountVerifyRequestDTO verifyRequestDTO) throws PopbillException { + public AccountCheckInfo verifyUserAccount(Long userId, UserAccountVerifyRequestDTO verifyRequestDTO) throws PopbillException { abuseService.checkAbuseUser(userId); - var response = 0; - try { - val accountInfo = accountCheckService.CheckAccountInfo(corpNum, verifyRequestDTO.BankCode(), verifyRequestDTO.AccountNumber()); - if (!verifyRequestDTO.name().equals(accountInfo.getAccountName())) { - val abuseLog = AbuseLog.builder() - .user(getUser(userId)) - .build(); - abuseService.createAbuseLog(abuseLog); - response = abuseService.countAbuseLogByUser(userId); - } - } catch (PopbillException e) { - throw new PopbillException(e.getCode(), e.getMessage()); + val accountInfo = accountCheckService.CheckAccountInfo(corpNum, verifyRequestDTO.BankCode(), verifyRequestDTO.AccountNumber()); + if (checkIsUserFail(accountInfo.getResult())) { + val abuseLog = AbuseLog.builder() + .user(getUser(userId)) + .build(); + abuseService.createAbuseLog(abuseLog); } - return response; + return accountInfo; + } + + private boolean checkIsUserFail(String result) { + return USER_FAIL_CODE.contains(result); } }