diff --git a/src/main/java/com/example/sinitto/auth/service/KakaoApiService.java b/src/main/java/com/example/sinitto/auth/service/KakaoApiService.java index 71fbe33a..7ee01e8c 100644 --- a/src/main/java/com/example/sinitto/auth/service/KakaoApiService.java +++ b/src/main/java/com/example/sinitto/auth/service/KakaoApiService.java @@ -20,7 +20,6 @@ public class KakaoApiService { private static final String KAKAO_AUTH_BASE_URL = "https://kauth.kakao.com/oauth"; private static final String KAKAO_API_BASE_URL = "https://kapi.kakao.com/v2/user"; private static final String LOCALHOST_URL = "localhost:5173"; - private static final String FRONT_URL = "dc9u22hnkwb24.cloudfront.net"; private final RestTemplate restTemplate; private final KakaoProperties kakaoProperties; @@ -39,7 +38,7 @@ public String getAuthorizationUrl(HttpServletRequest httpServletRequest) { if (requestUrl.contains(LOCALHOST_URL)) { redirectUri = kakaoProperties.devRedirectUri(); - } else if (requestUrl.contains(FRONT_URL)) { + } else if (requestUrl.contains(kakaoProperties.frontUriWithoutHttps())) { redirectUri = kakaoProperties.redirectUri(); } else { throw new BadRequestException("해당 도메인에서는 카카오 로그인이 불가합니다. requestUrl : " + requestUrl); @@ -62,7 +61,7 @@ public KakaoTokenResponse getAccessToken(String authorizationCode, HttpServletRe if (requestUrl.contains(LOCALHOST_URL)) { redirectUri = kakaoProperties.devRedirectUri(); - } else if (requestUrl.contains(FRONT_URL)) { + } else if (requestUrl.contains(kakaoProperties.frontUriWithoutHttps())) { redirectUri = kakaoProperties.redirectUri(); } else { throw new BadRequestException("해당 도메인에서는 카카오 로그인이 불가합니다. requestUrl : " + requestUrl); diff --git a/src/main/java/com/example/sinitto/common/properties/KakaoProperties.java b/src/main/java/com/example/sinitto/common/properties/KakaoProperties.java index 49ade0ad..2600627b 100644 --- a/src/main/java/com/example/sinitto/common/properties/KakaoProperties.java +++ b/src/main/java/com/example/sinitto/common/properties/KakaoProperties.java @@ -7,6 +7,10 @@ public record KakaoProperties( String clientId, String redirectUri, String devRedirectUri, - String frontUri + String frontUri, + String bankName, + String accountNumber, + String name, + String frontUriWithoutHttps ) { } diff --git a/src/main/java/com/example/sinitto/common/service/KakaoMessageService.java b/src/main/java/com/example/sinitto/common/service/KakaoMessageService.java index 1331e529..31ce0e89 100644 --- a/src/main/java/com/example/sinitto/common/service/KakaoMessageService.java +++ b/src/main/java/com/example/sinitto/common/service/KakaoMessageService.java @@ -29,7 +29,7 @@ public KakaoMessageService(KakaoTokenService kakaoTokenService, RestTemplate res this.kakaoProperties = kakaoProperties; } - public void sendPointChargeRequestReceivedMessage(String email, int point, String name) { + public void sendPointChargeRequestReceivedMessage(String email, int point, String name, String depositMessage) { String accessToken = kakaoTokenService.getValidAccessTokenInServer(email); if (accessToken == null) { @@ -45,7 +45,7 @@ public void sendPointChargeRequestReceivedMessage(String email, int point, Strin "\"object_type\": \"feed\"," + "\"content\": {" + "\"title\": \"%s님의 포인트 충전 요청 접수\"," + - "\"description\": \"입금 금액을 입금해주시기 바랍니다.\"," + + "\"description\": \"입금자명 변경하여 입금해주시기 바랍니다.\"," + "\"image_url\": \"%s\"," + "\"image_width\": 640," + "\"image_height\": 640," + @@ -58,9 +58,10 @@ public void sendPointChargeRequestReceivedMessage(String email, int point, Strin "\"items\": [" + "{\"item\": \"충전 요청\", \"item_op\": \"%d points\"}," + "{\"item\": \"입금 금액\", \"item_op\": \"%d 원\"}," + - "{\"item\": \"은행\", \"item_op\": \"시니또 은행\"}," + - "{\"item\": \"계좌번호\", \"item_op\": \"3333-11-225533\"}," + - "{\"item\": \"성명\", \"item_op\": \"시니또 매니저\"}" + + "{\"item\": \"입금자명\", \"item_op\": \"%s\"}," + + "{\"item\": \"은행\", \"item_op\": \"%s\"}," + + "{\"item\": \"계좌번호\", \"item_op\": \"%s\"}," + + "{\"item\": \"성명\", \"item_op\": \"%s\"}" + "]" + "}," + "\"buttons\": [" + @@ -73,8 +74,8 @@ public void sendPointChargeRequestReceivedMessage(String email, int point, Strin "}" + "]" + "}", - name, SINITTO_IMAGE_URL, kakaoProperties.frontUri(), kakaoProperties.frontUri(), point, point, - kakaoProperties.frontUri(), kakaoProperties.frontUri() + name, SINITTO_IMAGE_URL, kakaoProperties.frontUri(), kakaoProperties.frontUri(), point, point, depositMessage, + kakaoProperties.bankName(), kakaoProperties.accountNumber(), kakaoProperties.name(), kakaoProperties.frontUri(), kakaoProperties.frontUri() ); diff --git a/src/main/java/com/example/sinitto/point/service/PointService.java b/src/main/java/com/example/sinitto/point/service/PointService.java index 15ed05b4..0794bdc3 100644 --- a/src/main/java/com/example/sinitto/point/service/PointService.java +++ b/src/main/java/com/example/sinitto/point/service/PointService.java @@ -72,7 +72,7 @@ public PointChargeResponse savePointChargeRequest(Long memberId, int price) { pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), member, price, PointLog.Status.CHARGE_REQUEST)); - kakaoMessageService.sendPointChargeRequestReceivedMessage(member.getEmail(), price, member.getName()); + kakaoMessageService.sendPointChargeRequestReceivedMessage(member.getEmail(), price, member.getName(), member.getDepositMessage()); return new PointChargeResponse(member.getDepositMessage()); } diff --git a/src/test/java/com/example/sinitto/auth/service/KakaoApiServiceTest.java b/src/test/java/com/example/sinitto/auth/service/KakaoApiServiceTest.java index 0ff276cb..a46820eb 100644 --- a/src/test/java/com/example/sinitto/auth/service/KakaoApiServiceTest.java +++ b/src/test/java/com/example/sinitto/auth/service/KakaoApiServiceTest.java @@ -8,7 +8,6 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoSettings; -import org.springframework.beans.factory.annotation.Value; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -22,15 +21,16 @@ public class KakaoApiServiceTest { private HttpServletRequest httpServletRequest; @Mock private KakaoProperties kakaoProperties; - @Value("kakao.clientId") - private String clientId; - @Value("kakao.devRedirectUri") - private String devRedirectUri; - @Value("kakao.redirectUri") - private String redirectUri; + private String clientId = "testClientId"; + + private String devRedirectUri = "testDevUri"; + + private String redirectUri = "https://testRedirectUri"; + + private String frontUriWithoutHttps = "testRedirectUri"; @Test - @DisplayName("getAuthorizationUrl 메소드 테스트 - devUri 포홤 시") + @DisplayName("getAuthorizationUrl 메소드 테스트 - devUri 포함 시") void getAuthorizationUrlTestWithDevUri() { //given when(httpServletRequest.getHeader("Referer")).thenReturn("http://localhost:5173"); @@ -49,10 +49,11 @@ void getAuthorizationUrlTestWithDevUri() { } @Test - @DisplayName("getAuthorizationUrl 메소드 테스트 - 배포 uri 포홤 시") + @DisplayName("getAuthorizationUrl 메소드 테스트 - 배포 uri 포함 시") void getAuthorizationUrlTestWithAwsUri() { //given - when(httpServletRequest.getHeader("Referer")).thenReturn("https://dc9u22hnkwb24.cloudfront.net"); + when(kakaoProperties.frontUriWithoutHttps()).thenReturn(frontUriWithoutHttps); + when(httpServletRequest.getHeader("Referer")).thenReturn("https://testRedirectUri"); when(kakaoProperties.redirectUri()).thenReturn(redirectUri); when(kakaoProperties.clientId()).thenReturn(clientId); @@ -72,6 +73,7 @@ void getAuthorizationUrlTestWithAwsUri() { void getAuthorizationUrlTestWithAnotherUri() { //given when(httpServletRequest.getHeader("Referer")).thenReturn("http://test-uri.com"); + when(kakaoProperties.frontUriWithoutHttps()).thenReturn(frontUriWithoutHttps); //when, then assertThrows(BadRequestException.class, () -> kakaoApiService.getAuthorizationUrl(httpServletRequest));