-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from kakao-tech-campus-2nd-step3/week9
Week9 -> master
- Loading branch information
Showing
54 changed files
with
1,609 additions
and
75 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
23 changes: 23 additions & 0 deletions
23
src/main/java/poomasi/domain/order/_payment/config/IamportConfig.java
This file contains 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,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); | ||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/poomasi/domain/order/_payment/controller/PaymentController.java
This file contains 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,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); | ||
} | ||
|
||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/poomasi/domain/order/_payment/dto/request/PaymentPreRegisterRequest.java
This file contains 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,7 @@ | ||
package poomasi.domain.order._payment.dto.request; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public record PaymentPreRegisterRequest(String merchantUid, BigDecimal amount) { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/poomasi/domain/order/_payment/dto/request/PaymentWebHookRequest.java
This file contains 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,5 @@ | ||
package poomasi.domain.order._payment.dto.request; | ||
|
||
public record PaymentWebHookRequest(String imp_uid, | ||
String merchant_uid) { | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/poomasi/domain/order/_payment/dto/response/PaymentPreRegisterResponse.java
This file contains 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,8 @@ | ||
package poomasi.domain.order._payment.dto.response; | ||
|
||
public record PaymentPreRegisterResponse(String merchantUid) { | ||
|
||
public static PaymentPreRegisterResponse from(String merchantUid){ | ||
return new PaymentPreRegisterResponse(merchantUid); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/poomasi/domain/order/_payment/dto/response/PaymentResponse.java
This file contains 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,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
39
src/main/java/poomasi/domain/order/_payment/entity/Payment.java
This file contains 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,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; | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/poomasi/domain/order/_payment/entity/PaymentMethod.java
This file contains 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,7 @@ | ||
package poomasi.domain.order._payment.entity; | ||
|
||
public enum PaymentMethod { | ||
KAKAO_PAY, | ||
TOSS_PAYMENTS | ||
; | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/poomasi/domain/order/_payment/entity/PaymentState.java
This file contains 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,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(); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/poomasi/domain/order/_payment/repository/PaymentRepository.java
This file contains 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,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); | ||
} |
Oops, something went wrong.