Skip to content

Commit

Permalink
Merge pull request #84 from kakao-tech-campus-2nd-step3/week9
Browse files Browse the repository at this point in the history
Week9 -> master
  • Loading branch information
amm0124 authored Nov 2, 2024
2 parents 1ec731f + 2932cf5 commit 59861bd
Show file tree
Hide file tree
Showing 54 changed files with 1,609 additions and 75 deletions.
10 changes: 8 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ java {

repositories {
mavenCentral()
maven {
url 'https://jitpack.io'
}
}

dependencies {
Expand All @@ -34,8 +37,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-actuator'


// H2 Database
// H2 Database
runtimeOnly 'com.h2database:h2'

// JSON
Expand All @@ -62,9 +64,13 @@ dependencies {
implementation(platform("software.amazon.awssdk:bom:2.27.21"))
implementation("software.amazon.awssdk:s3")

// 아임포트 및 아임포트 웹훅
implementation 'com.github.iamport:iamport-rest-client-java:0.2.23'

}


tasks.named('test') {
useJUnitPlatform()
}

19 changes: 11 additions & 8 deletions src/main/java/poomasi/domain/auth/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,29 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
//기본 로그아웃 해제
http.logout(AbstractHttpConfigurer::disable);

/*

// 기본 경로 및 테스트 경로
http.authorizeHttpRequests((authorize) -> authorize
.requestMatchers(HttpMethod.GET, "/api/farm/**").permitAll()
.requestMatchers(HttpMethod.GET, "/api/product/**").permitAll()
.requestMatchers(HttpMethod.GET, "/api/review/**").permitAll()
.requestMatchers("/api/sign-up", "/api/login", "api/reissue").permitAll()
.requestMatchers("/api/sign-up", "/api/login", "api/reissue", "api/payment/**", "api/order/**").permitAll()
.requestMatchers("/api/need-auth/**").authenticated()
.anyRequest().
authenticated()
);*/

);

/*
http.authorizeHttpRequests((authorize) -> authorize
.requestMatchers("/**").permitAll()
.requestMatchers("/api/auth-test/**", "/api/cart/**").authenticated()
.requestMatchers("/api/auth-test/**",
"/api/cart/**",
"/api/order/**",
"/api/payment/**").authenticated()
.anyRequest()
.authenticated()
);

*/
/*
로그아웃 필터 등록하기
LogoutHandler[] handlers = {
Expand All @@ -114,14 +117,14 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
oauth2 인증은 현재 해제해놨습니다 -> 차후 code를 front에서 어떤 경로로 받을 것인지
아니면 kakao에서 바로 redirect를 백엔드로 할 지 정해지면
processing url 작성하겠습니다
*/
http
.oauth2Login((oauth2) -> oauth2
.userInfoEndpoint((userInfoEndpointConfig) -> userInfoEndpointConfig
.userService(oAuth2UserDetailServiceImpl))
.successHandler(customSuccessHandler)
);
*/

http.oauth2Login(AbstractHttpConfigurer::disable);

CustomUsernamePasswordAuthenticationFilter customUsernameFilter =
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/poomasi/domain/farm/entity/Farm.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import jakarta.annotation.Nullable;
import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.List;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -13,6 +15,7 @@
import poomasi.domain.farm.dto.FarmUpdateRequest;

import java.time.LocalDateTime;
import poomasi.domain.review.entity.Review;

@Entity
@Getter
Expand Down Expand Up @@ -64,6 +67,10 @@ public class Farm {
@UpdateTimestamp
private LocalDateTime updatedAt = LocalDateTime.now();

@OneToMany(cascade = CascadeType.REMOVE, orphanRemoval = true)
@JoinColumn(name = "entityId")
List<Review> reviewList = new ArrayList<>();

@Builder
public Farm(String name, Long ownerId, String address, String addressDetail, Double latitude, Double longitude, String description, Long experiencePrice) {
this.name = name;
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/poomasi/domain/member/entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.SQLDelete;
import poomasi.domain.order.entity.Order;
import poomasi.domain.wishlist.entity.WishList;

import java.time.LocalDateTime;
Expand Down Expand Up @@ -49,6 +50,13 @@ public class Member {

private LocalDateTime deletedAt;

@OneToMany(mappedBy = "member", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Order> orderLists;

@Setter
@Column(nullable = true)
private String farmerTierCode;

public Member(String email, String password, LoginType loginType, Role role) {
this.email = email;
this.password = password;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package poomasi.domain.order._payment.config;


import com.siot.IamportRestClient.IamportClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class IamportConfig {

@Value("${IMP_API_KEY}")
private String apiKey;

@Value("${imp.api.secretKey}")
private String secretKey;

@Bean
public IamportClient iamportClient() {
return new IamportClient(apiKey, secretKey);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package poomasi.domain.order._payment.controller;

import com.siot.IamportRestClient.exception.IamportResponseException;
import jdk.jfr.Description;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*;
import poomasi.domain.order._payment.dto.request.PaymentPreRegisterRequest;
import poomasi.domain.order._payment.dto.request.PaymentWebHookRequest;
import poomasi.domain.order._payment.dto.response.PaymentResponse;
import poomasi.domain.order._payment.service.PaymentService;

import java.io.IOException;

@RestController
@RequestMapping("/api/payment")
@RequiredArgsConstructor
public class PaymentController {

private final PaymentService paymentService;

@Description("사전 결제 api")
@Secured({"ROLE_CUSTOMER", "ROLE_FARMER"})
@PostMapping("/pre-payment")
public void postPrepare(PaymentPreRegisterRequest paymentPreRegisterRequest) throws IamportResponseException, IOException {
paymentService.portonePrePaymentRegister(paymentPreRegisterRequest);
}

@Description("사후 결제(검증 api)")
@PostMapping("/validate")
public void validatePayment(PaymentWebHookRequest paymentWebHookRequest) throws IamportResponseException, IOException {
paymentService.portoneVerifyPostPayment(paymentWebHookRequest);
}

/*
*@Description("포트원 webhook + 동기화")
* */



@GetMapping("/")
@Secured("ROLE_CUSTOMER")
@Description("결제 내역 단건 조회")
public ResponseEntity<?> getPaymentById(Long paymentId){
PaymentResponse paymentResponse = paymentService.getPayment(paymentId);
return ResponseEntity.ok(paymentResponse);
}


@Secured("ROLE_CUSTOMER")
@Description("order에 해당하는 결제 내역 조회")
public ResponseEntity<?> getPaymentByOrderId(@RequestParam Long orderId){
PaymentResponse paymentResponse = paymentService.getPayment(orderId);
return ResponseEntity.ok(paymentResponse);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package poomasi.domain.order._payment.dto.request;

import java.math.BigDecimal;

public record PaymentPreRegisterRequest(String merchantUid, BigDecimal amount) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package poomasi.domain.order._payment.dto.request;

public record PaymentWebHookRequest(String imp_uid,
String merchant_uid) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package poomasi.domain.order._payment.dto.response;

public record PaymentPreRegisterResponse(String merchantUid) {

public static PaymentPreRegisterResponse from(String merchantUid){
return new PaymentPreRegisterResponse(merchantUid);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package poomasi.domain.order._payment.dto.response;

import poomasi.domain.order._payment.entity.Payment;
import poomasi.domain.order._payment.entity.PaymentMethod;

import java.math.BigDecimal;

public record PaymentResponse(Long paymentId,
String merchantUid,
BigDecimal totalPrice,
BigDecimal discountPrice,
BigDecimal finalPrice,
PaymentMethod paymentMethod
) {
public static PaymentResponse fromEntity(Payment payment){
return new PaymentResponse(
payment.getId(),
payment.getMerchantUid(),
payment.getTotalPrice(),
payment.getDiscountPrice(),
payment.getFinalPrice(),
payment.getPaymentMethod()
);
}
}
39 changes: 39 additions & 0 deletions src/main/java/poomasi/domain/order/_payment/entity/Payment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package poomasi.domain.order._payment.entity;


import jakarta.persistence.*;
import jdk.jfr.Description;
import lombok.Getter;
import poomasi.domain.order.entity.Order;

import java.math.BigDecimal;

@Entity
@Getter
public class Payment {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Description("상품 총 가격")
private BigDecimal totalPrice;

@Description("할인 가격")
private BigDecimal discountPrice;

@Description("최종 가격")
private BigDecimal finalPrice;

@Description("결제 방식")
@Enumerated(EnumType.STRING)
private PaymentMethod paymentMethod;

@OneToOne
private Order order;

@Description("포트원에서 결제 식별을 위한 merchant_uid")
@Column(name = "merchant_uid" , updatable = false)
private String merchantUid;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package poomasi.domain.order._payment.entity;

public enum PaymentMethod {
KAKAO_PAY,
TOSS_PAYMENTS
;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package poomasi.domain.order._payment.entity;

public enum PaymentState {
PENDING, // 결제 대기 중
COMPLETED, // 결제 완료
FAILED, // 결제 실패
CANCELLED, // 결제 취소됨
REFUNDED, // 환불 완료
DECLINED; // 결제 거부됨

@Override
public String toString() {
// 사용자 친화적인 문자열로 반환할 수 있도록 오버라이딩
switch (this) {
case PENDING:
return "Payment Pending";
case COMPLETED:
return "Payment Completed";
case FAILED:
return "Payment Failed";
case CANCELLED:
return "Payment Cancelled";
case REFUNDED:
return "Payment Refunded";
case DECLINED:
return "Payment Declined";
default:
return super.toString();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package poomasi.domain.order._payment.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import poomasi.domain.order._payment.entity.Payment;

import java.util.List;

@Repository
public interface PaymentRepository extends JpaRepository<Payment, Long> {
// public Long countByImpuidContainsIgnoreCase(String impuid);
//List<Payment> findByOrderId(Long orderId);
}
Loading

0 comments on commit 59861bd

Please sign in to comment.