-
Notifications
You must be signed in to change notification settings - Fork 8
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
[#199, #198] 환불 API 작성, Payment 도메인 수정 #200
Changes from 23 commits
c55af3b
78efff0
5bc76ae
dd89c27
4f191a1
d0a756b
1f48d36
6e3d048
8b397ce
6611c32
e79a835
fe9121f
8c57263
6c4c108
a3f1bcc
b83ca46
049e8e1
50f6f00
625bb3a
3847a07
2a674e2
155311f
a9ad935
8242c01
2638b42
f31567f
8e94396
05a161b
49fcdac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,14 @@ | |
|
||
import com.example.tyfserver.common.domain.BaseTimeEntity; | ||
import com.example.tyfserver.payment.exception.IllegalPaymentInfoException; | ||
import com.example.tyfserver.payment.exception.PaymentRequestException; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
import java.util.UUID; | ||
|
||
import static com.example.tyfserver.payment.exception.PaymentRequestException.*; | ||
import static com.example.tyfserver.payment.exception.IllegalPaymentInfoException.*; | ||
|
||
@Entity | ||
@Getter | ||
|
@@ -33,15 +33,35 @@ public class Payment extends BaseTimeEntity { | |
|
||
private String impUid; | ||
|
||
public Payment(Long id, Long amount, String email, String pageName) { | ||
private UUID merchantUid; | ||
|
||
@PrePersist | ||
protected void onCreate() { | ||
merchantUid = UUID.randomUUID(); | ||
} | ||
|
||
public Payment(Long id, Long amount, String email, String pageName, UUID merchantUid) { | ||
this.id = id; | ||
this.amount = amount; | ||
this.email = email; | ||
this.pageName = pageName; | ||
this.merchantUid = merchantUid; | ||
} | ||
|
||
public Payment(Long amount, String email, String pageName, UUID merchantUid) { | ||
this(null, amount, email, pageName, merchantUid); | ||
} | ||
|
||
public Payment(Long id, Long amount, String email, String pageName) { | ||
this(id, amount, email, pageName, null); | ||
} | ||
|
||
public Payment(Long amount, String email, String pageName) { | ||
this(null, amount, email, pageName); | ||
this(null, amount, email, pageName, null); | ||
} | ||
|
||
public void updateStatus(PaymentStatus paymentStatus) { | ||
this.status = paymentStatus; | ||
} | ||
|
||
public void complete(PaymentInfo paymentInfo) { | ||
|
@@ -50,21 +70,32 @@ public void complete(PaymentInfo paymentInfo) { | |
this.status = PaymentStatus.PAID; | ||
} | ||
|
||
public void updateStatus(PaymentStatus paymentStatus) { | ||
this.status = paymentStatus; | ||
} | ||
|
||
private void validatePaymentComplete(PaymentInfo paymentInfo) { | ||
if (!PaymentStatus.isPaid(paymentInfo.getStatus())) { | ||
updateStatus(paymentInfo.getStatus()); | ||
throw IllegalPaymentInfoException.from(IllegalPaymentInfoException.ERROR_CODE_NOT_PAID, paymentInfo.getModule()); | ||
throw IllegalPaymentInfoException.from(ERROR_CODE_NOT_PAID, paymentInfo.getModule()); | ||
} | ||
|
||
validatePaymentInfo(paymentInfo); | ||
} | ||
|
||
public void cancel(PaymentInfo paymentInfo) { | ||
validatePaymentCancel(paymentInfo); | ||
this.impUid = paymentInfo.getImpUid(); | ||
this.status = PaymentStatus.CANCELLED; | ||
} | ||
Comment on lines
+83
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cancel 메서드 내부에서 호출되는 private 메서드 관련자료: 클린코드5 형식 맞추기 - 종속 함수 부분 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 엥 이미 하단인데? 혹시 커밋별로 보느라 옛날걸 보고있어서 그런건가! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아 이부분은 내가 이전껄 봤나봐 👀 |
||
|
||
private void validatePaymentCancel(PaymentInfo paymentInfo) { | ||
if (!PaymentStatus.isCancelled(paymentInfo.getStatus())) { | ||
updateStatus(paymentInfo.getStatus()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cancel이 아니라면 그냥 그대로 결제된 상태일테지만 확실히 하기위해서 update 해주는거야? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 맞아 혹시몰라서 다시 동기화를 시켜주려고 |
||
throw IllegalPaymentInfoException.from(ERROR_CODE_NOT_CANCELLED, paymentInfo.getModule()); | ||
} | ||
|
||
validatePaymentInfo(paymentInfo); | ||
} | ||
|
||
private void validatePaymentInfo(PaymentInfo paymentInfo) { | ||
if (!id.equals(paymentInfo.getMerchantId())) { | ||
if (!merchantUid.equals(paymentInfo.getMerchantUid())) { | ||
updateStatus(PaymentStatus.INVALID); | ||
throw IllegalPaymentInfoException.from(ERROR_CODE_INVALID_MERCHANT_ID, paymentInfo.getModule()); | ||
} | ||
|
@@ -76,7 +107,7 @@ private void validatePaymentInfo(PaymentInfo paymentInfo) { | |
|
||
if (!pageName.equals(paymentInfo.getPageName())) { | ||
updateStatus(PaymentStatus.INVALID); | ||
throw IllegalPaymentInfoException.from(ERROR_INVALID_CREATOR, paymentInfo.getModule()); | ||
throw IllegalPaymentInfoException.from(ERROR_CODE_INVALID_CREATOR, paymentInfo.getModule()); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
package com.example.tyfserver.payment.domain; | ||
|
||
import com.example.tyfserver.payment.dto.PaymentRequest; | ||
import java.util.UUID; | ||
|
||
public interface PaymentServiceConnector { | ||
PaymentInfo requestPaymentInfo(PaymentRequest paymentRequest); | ||
|
||
PaymentInfo requestPaymentInfo(UUID merchantUid); | ||
|
||
PaymentInfo requestPaymentCancel(UUID merchantUid); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.example.tyfserver.payment.dto; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.validation.constraints.NotBlank; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class PaymentCancelRequest { | ||
|
||
@NotBlank | ||
@JsonDeserialize | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이거 어떤 이슈가 있어서 붙여진건지 궁금~! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 샤워하면서 생각하면서 이해했다! 기존에 나는 어 String을 왜 다시 UUID로 바꿨지 String이 더 낫지 않나 했는데 String으로 할 경우에 Request타입에서 UUID인지 확인하기가 힘들다는 거구나!! String으로 하면 장점이 음.. @JsonDeserialize 를 안해줘도 된다? 정도 ..?? 그리고 아마 UUID를 했는데 String으로 들어왔을 경우에 던져지는 Error는 우리가 어노테이션으로 걸어준 valid에 대한 에러가 아니어서 UUID로 받아오는 것이 좋아보이긴 한데 내 우려는 프론트가 이거 String으로 던질 것 같단 말이야?? 아마도 높은확률로?? UUID 형식과 똑같은 String으로 던졌을 때에 저 Request가 잘 받아오냐 이게 관건인 것 같은데 이 부분에 대한 테스트가 없어서 아직 확인이 불가능하긴하네. 그리고 아직 환불에 대한 정확한 틀이 안짜여져있긴한데, 영수증에는 imp_uid가 적혀져있어서 merchant_uid가 아닌 imp_uid로 찾는 경우로 변경될 수도 있다는 점! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imp_uid도 결국엔 String이고 UUID는 아닐 것 같은데, 우리가 기본적으로 이 RequestDto에 대해서 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 나중에 지금상태에서 UUID가 아닌 형식으로 오면 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 응 어차피 DB 조회에서는 UUID 써야하니깐 dto로 String으로 미리받고(imp_uid, merchant_uid 둘 다 받을 수 있으니) UUID가 필요한 곳에서
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 굿굿 String으로 바꾸고 커스텀 Validator 붙일게! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 나는 requestDto에 대한 필드가 UUID일 경우의 프론트 이슈를 말한거였어!! 지금 |
||
private String merchantUid; | ||
|
||
public PaymentCancelRequest(String merchantUid) { | ||
this.merchantUid = merchantUid; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기 UUID로 다시 바꾸었구나! UUID를 사용할때, UUID아닌 형식이 오면 org.springframework.http.converter.HttpMessageNotReadableException 이렇게 와서 우리가 커스텀 예외로 처리가 불가능 하니 String 으로 변경해서 Validator를 만든다는 거지?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 근데 프론트에서 String으로 보낼 것 같은뒤 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그러게... 프론트에서는 String라고 생각하고 보낼거 같은데 🤔 (아임포트에 String으로 명시돼 있었으니까..?) |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.example.tyfserver.payment.dto; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.UUID; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class PaymentCancelResponse { | ||
|
||
private UUID merchantUid; | ||
|
||
public PaymentCancelResponse(UUID merchantUid) { | ||
this.merchantUid = merchantUid; | ||
} | ||
} |
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.
PayementStatus에 Pending 상태로 저장되니까
PayemntPendingRequest 좋은것 같아!