-
Notifications
You must be signed in to change notification settings - Fork 2
feat: STD-47 예금주 조회(계좌인증) #117
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
Open
CTR-iNNate
wants to merge
4
commits into
develop
Choose a base branch
from
feat/cert-account
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/com/tenten/studybadge/account/controller/AccountController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package com.tenten.studybadge.account.controller; | ||
|
|
||
| import com.tenten.studybadge.account.dto.AccountRequest; | ||
| import com.tenten.studybadge.account.service.AccountService; | ||
| import com.tenten.studybadge.common.security.LoginUser; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.Parameter; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class AccountController { | ||
|
|
||
| private final AccountService accountService; | ||
|
|
||
| @Operation(summary = "계좌 인증", description = "회원정보 수정 시 계좌인증(예금주조회)") | ||
| @Parameter(name = "BankCode", description = "은행코드") | ||
| @Parameter(name = "BankNum", description = "계좌번호") | ||
| @PostMapping("/api/cert/account") | ||
| public ResponseEntity<Void> certAccount(@LoginUser Long memberId, | ||
| @RequestBody AccountRequest accountRequest) { | ||
|
|
||
| accountService.certAccount(memberId, accountRequest); | ||
|
|
||
| return ResponseEntity.status(HttpStatus.OK).build(); | ||
| } | ||
|
|
||
| @Operation(summary = "계좌 인증", description = "회원가입 시 계좌인증(예금주조회)") | ||
| @Parameter(name = "bankCode", description = "은행코드") | ||
| @Parameter(name = "bankNum", description = "계좌번호") | ||
| @Parameter(name = "name", description = "회원가입 시 입력하는 이름") | ||
| @GetMapping("/api/cert/sign-up") | ||
| public ResponseEntity<Void> certSignUp(@RequestParam String bankCode, | ||
| @RequestParam String bankNum, | ||
| @RequestParam String name) { | ||
|
|
||
| accountService.certSignUp(bankCode, bankNum, name); | ||
|
|
||
| return ResponseEntity.status(HttpStatus.OK).build(); | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/tenten/studybadge/account/dto/AccountRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.tenten.studybadge.account.dto; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @Builder | ||
| public class AccountRequest { | ||
|
|
||
| private String bankCode; | ||
|
|
||
| private String bankNum; | ||
| } |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/tenten/studybadge/account/dto/AccountResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package com.tenten.studybadge.account.dto; | ||
|
|
||
| import lombok.*; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @Builder | ||
| public class AccountResponse { | ||
|
|
||
| private String accountHolder; | ||
|
|
||
| public static AccountResponse getHolder(String response) { | ||
|
|
||
| return AccountResponse.builder() | ||
| .accountHolder(response) | ||
| .build(); | ||
| } | ||
| } |
113 changes: 113 additions & 0 deletions
113
src/main/java/com/tenten/studybadge/account/service/AccountService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| package com.tenten.studybadge.account.service; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.siot.IamportRestClient.IamportClient; | ||
| import com.tenten.studybadge.account.dto.AccountRequest; | ||
| import com.tenten.studybadge.account.dto.AccountResponse; | ||
| import com.tenten.studybadge.common.exception.account.NotMatchAccountHolder; | ||
| import com.tenten.studybadge.common.exception.member.NotFoundMemberException; | ||
| import com.tenten.studybadge.member.domain.entity.Member; | ||
| import com.tenten.studybadge.member.domain.repository.MemberRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.http.HttpHeaders; | ||
| import org.springframework.http.MediaType; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.web.reactive.function.client.WebClient; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import static com.tenten.studybadge.common.constant.AccountConstant.*; | ||
|
|
||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class AccountService { | ||
|
|
||
| @Value("${portone.api.key}") | ||
| private String impKey; | ||
|
|
||
| @Value("${portone.api.secret}") | ||
| private String impSecret; | ||
| private IamportClient iamportClient; | ||
|
|
||
| private final MemberRepository memberRepository; | ||
| private final ObjectMapper objectMapper; | ||
|
|
||
| public AccountResponse getAccountHolder(String bankCode, String bankNum) { | ||
|
|
||
| iamportClient = new IamportClient(impKey, impSecret); | ||
|
|
||
| WebClient webClient = WebClient.builder() | ||
| .baseUrl(IamportClient.API_URL) | ||
| .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) | ||
| .defaultHeader(HttpHeaders.AUTHORIZATION, issueToken()) | ||
| .build(); | ||
|
|
||
| String response = webClient.get() | ||
| .uri(uriBuilder -> uriBuilder | ||
| .path(PATH) | ||
| .queryParam(BANK_CODE,bankCode) | ||
| .queryParam(BANK_NUM, bankNum) | ||
| .build()) | ||
| .retrieve() | ||
| .bodyToMono(String.class) | ||
| .block(); | ||
|
|
||
| String decode = decodeUnicode(response); | ||
|
|
||
| return AccountResponse.getHolder(decode); | ||
| } | ||
|
|
||
| public void certAccount(Long memberId, AccountRequest accountRequest) { | ||
|
|
||
| Member member = memberRepository.findById(memberId) | ||
| .orElseThrow(NotFoundMemberException::new); | ||
|
|
||
| AccountResponse accountResponse = getAccountHolder | ||
| (accountRequest.getBankCode(), | ||
| accountRequest.getBankNum()); | ||
|
|
||
| if (accountResponse.getAccountHolder().equals(member.getName())) { | ||
|
|
||
| Member updatedMember = member.toBuilder() | ||
| .isAccountCert(true) | ||
| .build(); | ||
|
|
||
| memberRepository.save(updatedMember); | ||
|
|
||
| } else { | ||
|
|
||
| throw new NotMatchAccountHolder(); | ||
| } | ||
| } | ||
|
|
||
| public void certSignUp(String bankCode, String bankNum, String name) { | ||
|
|
||
| AccountResponse accountResponse = getAccountHolder(bankCode, bankNum); | ||
|
|
||
| if ( !accountResponse.getAccountHolder().equals(name)) { | ||
|
|
||
| throw new NotMatchAccountHolder(); | ||
| } | ||
| } | ||
|
|
||
| private String decodeUnicode(String response) { | ||
| try { | ||
| Map<String, Object> responseMap = objectMapper.readValue(response, Map.class); | ||
|
|
||
| Map<String, Object> responseDetails = (Map<String, Object>) responseMap.get(RESPONSE); | ||
|
|
||
| return (String) responseDetails.get(BANK_HOLDER); | ||
|
|
||
| } catch (Exception e) { | ||
| e.printStackTrace(); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| public String issueToken() { | ||
|
|
||
| return iamportClient.getAuth().getResponse().getToken(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/com/tenten/studybadge/common/constant/AccountConstant.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.tenten.studybadge.common.constant; | ||
|
|
||
| public class AccountConstant { | ||
|
|
||
| public static final String RESPONSE = "response"; | ||
| public static final String BANK_HOLDER = "bank_holder"; | ||
|
|
||
| public static final String PATH = "/vbanks/holder"; | ||
|
|
||
| public static final String BANK_CODE = "bank_code"; | ||
| public static final String BANK_NUM = "bank_num"; | ||
| } |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/tenten/studybadge/common/exception/account/BeforeCertAccountException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.tenten.studybadge.common.exception.account; | ||
|
|
||
| import com.tenten.studybadge.common.exception.basic.AbstractException; | ||
| import org.springframework.http.HttpStatus; | ||
|
|
||
| import static org.springframework.http.HttpStatus.BAD_REQUEST; | ||
|
|
||
| public class BeforeCertAccountException extends AbstractException { | ||
|
|
||
| private static final String ERROR_CODE = "BEFORE_CERT_ACCOUNT_EXCEPTION"; | ||
| private static final String ERROR_MESSAGE = "계좌 인증이 완료되지 않았습니다."; | ||
|
|
||
| @Override | ||
| public HttpStatus getHttpStatus() { | ||
| return BAD_REQUEST; | ||
| } | ||
|
|
||
| @Override | ||
| public String getErrorCode() { | ||
| return ERROR_CODE; | ||
| } | ||
|
|
||
| @Override | ||
| public String getMessage() { | ||
| return ERROR_MESSAGE; | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/tenten/studybadge/common/exception/account/NotMatchAccountHolder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.tenten.studybadge.common.exception.account; | ||
|
|
||
| import com.tenten.studybadge.common.exception.basic.AbstractException; | ||
| import org.springframework.http.HttpStatus; | ||
|
|
||
| import static org.springframework.http.HttpStatus.BAD_REQUEST; | ||
|
|
||
| public class NotMatchAccountHolder extends AbstractException { | ||
|
|
||
| private static final String ERROR_CODE = "NOT_MATCH_ACCOUNT_HOLDER"; | ||
| private static final String ERROR_MESSAGE = "예금주와 회원의 이름이 일치하지 않습니다."; | ||
|
|
||
| @Override | ||
| public HttpStatus getHttpStatus() { | ||
| return BAD_REQUEST; | ||
| } | ||
|
|
||
| @Override | ||
| public String getErrorCode() { | ||
| return ERROR_CODE; | ||
| } | ||
|
|
||
| @Override | ||
| public String getMessage() { | ||
| return ERROR_MESSAGE; | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yml파일에 어떤 값을 넣어야하는지 슬랙으로 공유해주시면 감사하겠습니다~