Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] 계좌번호 이름 확인 구현 #149

Merged
merged 10 commits into from
Dec 11, 2023
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ dependencies {

// caffiene cache
implementation "com.github.ben-manes.caffeine:caffeine:3.1.8"

// popbill
implementation 'kr.co.linkhub:popbill-spring-boot-starter:1.9.2'
}

test {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/sopterm/makeawish/common/ErrorHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.time.format.DateTimeParseException;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.popbill.api.PopbillException;
import com.popbill.api.Response;
import com.sopterm.makeawish.exception.WrongAccessTokenException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -74,4 +76,10 @@ public ResponseEntity<ApiResponse> illegalStateException(IllegalStateException e
val response = ApiResponse.fail(exception.getMessage());
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(PopbillException.class)
public ResponseEntity<ApiResponse> popbillException(PopbillException exception){
val response = ApiResponse.fail(exception.getMessage());
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public enum ErrorMessage {
INVALID_USER("인증되지 않은 회원입니다."),
NULL_PRINCIPAL("principal 이 null 일 수 없습니다."),
NO_EXIST_USER_ACCOUNT("유저의 계좌정보가 없습니다."),
NOT_VALID_USER_ACCOUNT("유저의 계좌번호가 아닙니다."),

/** cake **/
INVALID_CAKE("존재하지 않는 케이크입니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum SuccessMessage {
SUCCESS_GET_USER_ACCOUNT_INFO("유저 계좌정보 가져오기 성공"),
SUCCESS_UPDATE_USER_ACCOUNT_INFO("유저 계좌정보 수정 성공"),
SUCCESS_DELETE_USER("회원 탈퇴 성공"),
SUCCESS_VERIFY_USER_ACCOUNT("유저 계좌정보 인증 성공"),

/** wish **/
SUCCESS_CREATE_WISH("소원 링크 생성 성공"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.sopterm.makeawish.controller;

import com.popbill.api.PopbillException;
import com.sopterm.makeawish.common.ApiResponse;
import com.sopterm.makeawish.domain.user.InternalMemberDetails;
import com.sopterm.makeawish.dto.user.UserAccountRequestDTO;
import com.sopterm.makeawish.service.UserService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
Expand Down Expand Up @@ -58,4 +58,12 @@ public ResponseEntity<ApiResponse> deleteUser(
userService.deleteUser(memberDetails.getId());
return ResponseEntity.ok(ApiResponse.success(SUCCESS_DELETE_USER.getMessage()));
}

@Operation(summary = "계좌 실명 조회")
@GetMapping("/verify-account")
public ResponseEntity<ApiResponse> checkAccountInformation(
@RequestParam String name, @RequestParam String BankCode, @RequestParam String AccountNumber) throws Exception {
userService.verifyUserAccount(name, BankCode, AccountNumber);
return ResponseEntity.ok(ApiResponse.success(SUCCESS_VERIFY_USER_ACCOUNT.getMessage()));
}
}
38 changes: 28 additions & 10 deletions src/main/java/com/sopterm/makeawish/service/UserService.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package com.sopterm.makeawish.service;

import static com.sopterm.makeawish.common.message.ErrorMessage.*;
import static java.util.Objects.*;

import com.sopterm.makeawish.repository.PresentRepository;
import com.sopterm.makeawish.repository.wish.WishRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.popbill.api.AccountCheckInfo;
import com.popbill.api.AccountCheckService;
import com.popbill.api.PopbillException;
import com.sopterm.makeawish.domain.user.User;
import com.sopterm.makeawish.dto.user.UserAccountResponseDTO;
import com.sopterm.makeawish.dto.user.UserAccountRequestDTO;
import com.sopterm.makeawish.dto.user.UserAccountResponseDTO;
import com.sopterm.makeawish.repository.PresentRepository;
import com.sopterm.makeawish.repository.UserRepository;

import com.sopterm.makeawish.repository.wish.WishRepository;
import jakarta.persistence.EntityNotFoundException;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import static com.sopterm.makeawish.common.message.ErrorMessage.*;
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;

@Service
@RequiredArgsConstructor
Expand All @@ -25,6 +28,10 @@ public class UserService {
private final UserRepository userRepository;
private final WishRepository wishRepository;
private final PresentRepository presentRepository;
private final AccountCheckService accountCheckService;

@Value("${popbill.businessNumber}")
private String corpNum;

public UserAccountResponseDTO getUserAccount(Long userId) {
val wisher = getUser(userId);
Expand Down Expand Up @@ -59,4 +66,15 @@ private User getUser(Long userId) {
return userRepository.findById(userId)
.orElseThrow(() -> new EntityNotFoundException(INVALID_USER.getMessage()));
}

public void verifyUserAccount(String name, String BankCode, String AccountNumber) throws PopbillException {
try {
val accountInfo = accountCheckService.CheckAccountInfo(corpNum, BankCode, AccountNumber);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 메소드만 코드컨벤션과 다른 것 같습니다!
checkAccountInfo

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분은 해당 API에서 제공하는 함수여서 컨벤션이 다릅니다!


if(!name.equals(accountInfo.getAccountName()))
throw new IllegalArgumentException(NOT_VALID_USER_ACCOUNT.getMessage());
} catch (PopbillException e) {
throw new PopbillException(e.getCode(), e.getMessage());
}
}
}
38 changes: 38 additions & 0 deletions src/test/java/com/sopterm/makeawish/service/UserServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.sopterm.makeawish.service;

import com.popbill.api.AccountCheckInfo;
import com.popbill.api.AccountCheckService;
import com.popbill.api.PopbillException;
import org.checkerframework.checker.units.qual.A;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;

import static org.assertj.core.api.Assertions.assertThatThrownBy;


@SpringBootTest
@Transactional
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class UserServiceTest {
@Autowired
UserService userService;

@Autowired
AccountCheckService accountCheckService;

@Test
@DisplayName("유효하지 않은 기관코드인 경우 예외 발생")
void 계좌_연동_실패(){
// given
String BankCode = "0000";
String AccountNumber = "1234567890";

// when - then
assertThatThrownBy(() -> userService.verifyUserAccount("홍길동",BankCode, AccountNumber))
.isInstanceOf(PopbillException.class);
}
}