From 0f390874e3a16657513df2894ee6798a1f880846 Mon Sep 17 00:00:00 2001 From: jwaminseok <109052897+jms0324@users.noreply.github.com> Date: Fri, 31 May 2024 18:14:55 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]-=20=EA=B2=B0=EC=A0=9CAPI=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20(#111)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: 환경변수 세팅 * chore: aws secret manager 설정 * [chore] CI/CD settings (#13) * chore: common 폴더 구조 변경 * chore: 환경변수 파일 분리 (local/dev) * feat: 서버 profile 확인용 api 추가 * chore: 무중단 배포시 실행할 스크립트 작성 * chore: Github Actions 스크립트 작성 (임시 trigger 설정) * chore: CI/CD trigger 재설정 * chore: 인덴트 오류 수정 * chore: CodeDeploy 옵션 문자열 오류 수정 * chore: Spring Security 및 Redis 임시 주석 처리 * chore: trigger 시점 develop 으로 변경 * chore: profile 조회 엔드포인트 수정 * style: CD 브랜치 trigger 시점 임시 변경 * fix: trigger 시점 develop 으로 원상 복귀 --------- Co-authored-by: Wang HoEun * feat/14-entity develop브랜치에 merge * Feat/#14 entity (#15) * 엔티티 첫 커밋 * diary엔티티에 멤버와의 관계추가 * feat : diary엔티티에 summary추가 * refactor: entity에 감정,조언 분리 * refactor:수정완료 * refactor: feeling클래스 감정추가 * feat: summary엔티티따로생성 후 member와 다대일양방향관계생성 * worried 스펠링수정 * feat: 카카오 로그인 구현+s3서버 세팅 (#31) * feat: 카카오 로그인 구현+s3서버 세팅 * fix: build gradle 수정 --------- Co-authored-by: Wang HoEun * fix: build.gradle 파일 최신화 * Feat/#30 slowtype save api (#32) * diary-content-api구현 및 테스트성공 * json필드 이름변경 * refactor:ApiResponse초기세팅 필드이름변경status * api명세서 변경으로인한 초기세팅 변경 * succes type에서 오타로 인한 커밋 * feat: list-calender api구현 but 테스트는 아직 * api테스트완료 but 시간대 문제발생 * 애플리케이션 timezone을 utc로 설정하여 임시해결 * refactor /#24 json필드명 오류발견후수정 * index on feat/#26-list-calender: b531010 refactor /#24 json필드명 오류발견후수정 * feat-feelinglist 1차구현 * try catch구문 삭제 및 exceptionhandler수정, apiresponse수정 * entity 수정 * feat:apiresponse수정 및 s3설정파일 임시구현 * feat:S3연결제외 api구현 * refactor: imageurl추가에따른 컨텐트 api 살짝수정 * refactor: diarycontent반환값에 title추가 * refactor: s3연결전까지 코든짠것 * success type 추가 * refactor : successtype변경 * develop pull 마무리 * refactor : application.yml이랑 value값맞추기성공 * feat: api구현 및 테스트 완료 * refactor:content,advice길이수정 * fix: bootstarp 파일이 없는 오류 해결 * refactor: 카카오 인가코드 프론트측엫서 받아오는 방식으로 수정 (#36) Co-authored-by: Wang HoEun * [refactor] kakao login 기존 프론트가 토큰 가져오는 방식으로 수정 (#38) * refactor: 카카오 인가코드 프론트측엫서 받아오는 방식으로 수정 * fix: 다시 login 되돌려두기 --------- Co-authored-by: Wang HoEun * Refactor/#40 slow type diary retry (#41) * 수정전 commit * Principal객체사용한 memberId기반 api전체 수정 * refactor : slowtype api principal제외 * Refactor/#40 slow type diary retry (#44) * 수정전 commit * Principal객체사용한 memberId기반 api전체 수정 * refactor : slowtype api principal제외 * refactor:오류수정을 위한 임시파일경로생성 * Update DiaryController.java 오타해결 * refactor 충돌해결 * Refactor/#46 choose diary type api retry (#47) * Develop (#45) * chore: 환경변수 세팅 * chore: aws secret manager 설정 * [chore] CI/CD settings (#13) * chore: common 폴더 구조 변경 * chore: 환경변수 파일 분리 (local/dev) * feat: 서버 profile 확인용 api 추가 * chore: 무중단 배포시 실행할 스크립트 작성 * chore: Github Actions 스크립트 작성 (임시 trigger 설정) * chore: CI/CD trigger 재설정 * chore: 인덴트 오류 수정 * chore: CodeDeploy 옵션 문자열 오류 수정 * chore: Spring Security 및 Redis 임시 주석 처리 * chore: trigger 시점 develop 으로 변경 * chore: profile 조회 엔드포인트 수정 * style: CD 브랜치 trigger 시점 임시 변경 * fix: trigger 시점 develop 으로 원상 복귀 --------- Co-authored-by: Wang HoEun * feat/14-entity develop브랜치에 merge * Feat/#14 entity (#15) * 엔티티 첫 커밋 * diary엔티티에 멤버와의 관계추가 * feat : diary엔티티에 summary추가 * refactor: entity에 감정,조언 분리 * refactor:수정완료 * refactor: feeling클래스 감정추가 * feat: summary엔티티따로생성 후 member와 다대일양방향관계생성 * worried 스펠링수정 * feat: 카카오 로그인 구현+s3서버 세팅 (#31) * feat: 카카오 로그인 구현+s3서버 세팅 * fix: build gradle 수정 --------- Co-authored-by: Wang HoEun * fix: build.gradle 파일 최신화 * Feat/#30 slowtype save api (#32) * diary-content-api구현 및 테스트성공 * json필드 이름변경 * refactor:ApiResponse초기세팅 필드이름변경status * api명세서 변경으로인한 초기세팅 변경 * succes type에서 오타로 인한 커밋 * feat: list-calender api구현 but 테스트는 아직 * api테스트완료 but 시간대 문제발생 * 애플리케이션 timezone을 utc로 설정하여 임시해결 * refactor /#24 json필드명 오류발견후수정 * index on feat/#26-list-calender: b531010 refactor /#24 json필드명 오류발견후수정 * feat-feelinglist 1차구현 * try catch구문 삭제 및 exceptionhandler수정, apiresponse수정 * entity 수정 * feat:apiresponse수정 및 s3설정파일 임시구현 * feat:S3연결제외 api구현 * refactor: imageurl추가에따른 컨텐트 api 살짝수정 * refactor: diarycontent반환값에 title추가 * refactor: s3연결전까지 코든짠것 * success type 추가 * refactor : successtype변경 * develop pull 마무리 * refactor : application.yml이랑 value값맞추기성공 * feat: api구현 및 테스트 완료 * refactor:content,advice길이수정 * fix: bootstarp 파일이 없는 오류 해결 * refactor: 카카오 인가코드 프론트측엫서 받아오는 방식으로 수정 (#36) Co-authored-by: Wang HoEun * [refactor] kakao login 기존 프론트가 토큰 가져오는 방식으로 수정 (#38) * refactor: 카카오 인가코드 프론트측엫서 받아오는 방식으로 수정 * fix: 다시 login 되돌려두기 --------- Co-authored-by: Wang HoEun * Refactor/#40 slow type diary retry (#41) * 수정전 commit * Principal객체사용한 memberId기반 api전체 수정 * refactor : slowtype api principal제외 * Refactor/#40 slow type diary retry (#44) * 수정전 commit * Principal객체사용한 memberId기반 api전체 수정 * refactor : slowtype api principal제외 * refactor:오류수정을 위한 임시파일경로생성 * Update DiaryController.java 오타해결 * refactor 충돌해결 --------- Co-authored-by: Wang HoEun Co-authored-by: Wang Hoeun <38005874+hoeun0723@users.noreply.github.com> * requestHeader를 사용한 코드수정 및 diarytyperequestDto추가 --------- Co-authored-by: Wang HoEun Co-authored-by: Wang Hoeun <38005874+hoeun0723@users.noreply.github.com> * feeling별 diary list조회 api수정 (#50) * refactor:content api코드수정및 responseDto 수정 (#53) * Refactor/#55 list calendar api retry (#56) * refactor: calendar api코드수정 및 diary생성시 writedAt필드 설정코드추가 * refactor:writedAt필드 현재시간값가져오기로 수정 * calendarapi수정 * refactor:content api에서 advice와 feeling값 null값허용 (#59) * Refactor/#58 diary content api exception retry (#61) * refactor:content api에서 advice와 feeling값 null값허용 * diary엔티티 content칼럼 Longtext로수정및 slowtype api 이미지파일없어도가능하게 * FeelingListResponseDto의 imageUrl필드추가 (#64) * CalendarDiaryResponseDto의 ImageUrl필드추가 (#67) * feeling list,slowtype생성 request오류 추가 * refactor:ZonedDatetime추가 (#70) * refactor: imageFile 안줘도 가능하게 코드수정 (#73) * feat: 수정 api구현 (#76) * refactor: logging추가 (#80) * refactor-requestpart대신 modelattribute (#83) * refactor:s3파일중복체크후 업로드하는 로직 추가 (#86) * feat: 일기삭제api구현 및 에러타입추가,slowtypeapi요청값대문자로수정 (#88) * refactor:imageurl LONGTEXT로변경 * refactor:slowtyperesponseDto에 createdDate필드추가 (#92) * refactor:이미지생성api구현 및 중복코드제거 (#95) * feag:카카오톡공유하기api구현 (#98) * refacotr:requestpart로 변경 (#101) * refactor:createdDate추가 (#104) * refactor:프롬프트수정 (#107) * [FEAT]-109 payment (#110) * feat: iampory필요한 환경세팅 * feat:결제검증로직추가 --------- Co-authored-by: Wang HoEun Co-authored-by: Wang Hoeun <38005874+hoeun0723@users.noreply.github.com> --- build.gradle | 3 + .../payment/controller/PaymentController.java | 80 +++++++++++++++++++ .../global/common/dto/enums/ErrorType.java | 1 + src/main/resources/application.yml | 7 +- 4 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/kau/kkoolbeeServer/domain/payment/controller/PaymentController.java diff --git a/build.gradle b/build.gradle index cc446f0..9ae4af8 100644 --- a/build.gradle +++ b/build.gradle @@ -19,6 +19,7 @@ configurations { repositories { mavenCentral() + maven { url 'https://jitpack.io' } // JitPack 저장소 추가 } dependencies { @@ -67,6 +68,8 @@ dependencies { // JSON implementation 'com.googlecode.json-simple:json-simple:1.1.1' + // I'mport REST Client + implementation 'com.github.iamport:iamport-rest-client-java:0.2.21' diff --git a/src/main/java/org/kau/kkoolbeeServer/domain/payment/controller/PaymentController.java b/src/main/java/org/kau/kkoolbeeServer/domain/payment/controller/PaymentController.java new file mode 100644 index 0000000..678a555 --- /dev/null +++ b/src/main/java/org/kau/kkoolbeeServer/domain/payment/controller/PaymentController.java @@ -0,0 +1,80 @@ +package org.kau.kkoolbeeServer.domain.payment.controller; + +import com.siot.IamportRestClient.IamportClient; +import com.siot.IamportRestClient.exception.IamportResponseException; +import com.siot.IamportRestClient.response.IamportResponse; +import com.siot.IamportRestClient.response.Payment; +import jakarta.annotation.PostConstruct; +import org.kau.kkoolbeeServer.global.common.dto.ApiResponse; +import org.kau.kkoolbeeServer.global.common.dto.enums.ErrorType; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +@ComponentScan +@RestController +public class PaymentController { + + @Value("${iamport.key}") + private String restApiKey; + @Value("${iamport.secret}") + private String restApiSecret; + private IamportClient iamportClient; + + @PostConstruct + public void init() { + this.iamportClient = new IamportClient(restApiKey, restApiSecret); + } + + + /* @PostMapping("/verifyIamport/{imp_uid}") + public ResponseEntity> paymentByImpUid(@PathVariable("imp_uid") String imp_uid) throws IamportResponseException, IOException { + IamportResponse response = iamportClient.paymentByImpUid(imp_uid); + Map result = new HashMap<>(); + + if (response.getResponse().getStatus().equals("paid")) { + result.put("status", "paid"); + } else { + result.put("status", "failed"); + } + + return ResponseEntity.ok(result); + + + + + }*/ + + /*@PostMapping("/verifyIamport/{imp_uid}") + public IamportResponse paymentByImpUid(@PathVariable("imp_uid") String imp_uid) throws IamportResponseException, IOException { + return iamportClient.paymentByImpUid(imp_uid); + }*/ + @PostMapping("/verifyIamport/{imp_uid}") + public ResponseEntity verifyPayment(@PathVariable("imp_uid") String impUid) { + try { + IamportResponse response = iamportClient.paymentByImpUid(impUid); + if (response.getResponse() != null) { +// 결제 검증 로직 추가 (예: 결제 금액 검증, 결제자 정보 검증 등) + return ResponseEntity.ok(response.getResponse()); + } else { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ApiResponse.error(ErrorType.NOT_FOUND_PAYMENT)); + } + } catch (IamportResponseException e) { +// 아임포트 서버로부터 오류 응답을 받은 경우 + return ResponseEntity.status(e.getHttpStatusCode()).body(ApiResponse.error(ErrorType.INTERNAL_SERVER_ERROR,e.getMessage())); + } catch (IOException e) { +// 네트워크 오류 등의 IOException 처리 + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ApiResponse.error(ErrorType.INTERNAL_SERVER_ERROR,"서버 오류가 발생했습니다.")); + } + } + + +} diff --git a/src/main/java/org/kau/kkoolbeeServer/global/common/dto/enums/ErrorType.java b/src/main/java/org/kau/kkoolbeeServer/global/common/dto/enums/ErrorType.java index 65551b4..e42eaaf 100644 --- a/src/main/java/org/kau/kkoolbeeServer/global/common/dto/enums/ErrorType.java +++ b/src/main/java/org/kau/kkoolbeeServer/global/common/dto/enums/ErrorType.java @@ -44,6 +44,7 @@ public enum ErrorType { NOT_FOUND_REFRESH_TOKEN_ERROR(HttpStatus.NOT_FOUND, "존재하지 않는 리프레시 토큰입니다."), NOT_YOUR_DIARY(HttpStatus.NOT_FOUND,"해당 Diary에 접근할 수 있는 권한이 없습니다."), NO_DIARY(HttpStatus.NOT_FOUND,"해당 Id에 맞는 Diary가 존재하지 않습니다."), + NOT_FOUND_PAYMENT(HttpStatus.NOT_FOUND,"결제 정보를 찾을 수 없습니다."), /** * 500 INTERNAL SERVER ERROR diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index cc310f3..5dbc782 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -26,4 +26,9 @@ logging: util: EC2MetadataUtils: error openai: - api.key: ${API_KEY} \ No newline at end of file + api.key: ${API_KEY} + + +iamport: + key: ${IAMPORT_KEY} + secret: ${IAMPORT_SECRET}