-
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 28 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,36 @@ public class Payment extends BaseTimeEntity { | |
|
||
private String impUid; | ||
|
||
public Payment(Long id, Long amount, String email, String pageName) { | ||
@Column(nullable = false) | ||
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. 굿!! merchantUid는 null이 아니어야 하지 |
||
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 +71,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 +108,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,18 @@ | ||
package com.example.tyfserver.payment.dto; | ||
|
||
import com.example.tyfserver.payment.util.UUID; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class PaymentCancelRequest { | ||
|
||
@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 좋은것 같아!