Skip to content
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

SAPHY-140 refactor: 결제 기능 리펙토링 #89

Merged
merged 1 commit into from
Oct 2, 2024

Conversation

Muokok
Copy link
Collaborator

@Muokok Muokok commented Oct 2, 2024

📄 Summary

  • refactor: Pay 엔티티 필드 수정, * feat: 결제 준비, 결제 완료 DTO 생성

🕰️ Actual Time of Completion

🙋🏻 More

* refactor: Pay 엔티티 필드 수정

* feat: 결제 준비, 결제 완료 DTO 생성
@Muokok Muokok added ✨ Feature 새로운 기능 ♻️ Refactor 코드 리팩토링 labels Oct 2, 2024
@Muokok Muokok self-assigned this Oct 2, 2024
Copy link
Member

@gyuseon25 gyuseon25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다!
Prepare로 검증하고 Complete로 실제 결제를 진행하는 구조군요!


// 물품 금액과 결제 금액이 같은지 검증
if (!iamportPayment.getAmount().equals(item.getPrice())) {
BigDecimal calculatedAmount = item.getPrice().multiply(BigDecimal.valueOf(request.getQuantity()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 BigDecimal이라 직접 안곱하고 multiply를 쓰는거군요
하나 배워갑니다 👏

Copy link
Contributor

@holyPigeon holyPigeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이륙 허가요 슈우우우우우우우우우우ㅜ우ㅜㅜㅜㅜㅜㅜ우우웅~

@@ -34,56 +37,54 @@ public class PayService {
private final IamportClient iamportClient;
Copy link
Contributor

@holyPigeon holyPigeon Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기서 ItemRepository -> ItemRepository<Item> 으로 바꾸면 밑에 로직에서 Optional을 안 써도 될 것 같습니다!

Comment on lines +47 to +49
if (item.getStock() < request.getQuantity()) {
throw SaphyException.from(ITEM_OUT_OF_STOCK);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어 이거 제가 1시간 전에 PR 올린 거에 들어있는 거긴 한데
item 엔티티 안에 재고에 따라 주문할 수 있는지 없는지 boolean canOrder() 메서드로 구현해놔서 나중에 바꿔도 될 것 같습니다!

try {
// PortOne 결제 확인
iamportResponse = iamportClient.paymentByImpUid(request.getImpUid());
if (payResponse.getResponse().getAmount().equals(pay.getAmount())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기 if문 조건은 뭔가 private 메서드로 뽑을 수 있으면 훨씬 깔끔할 것 같습니다!

Copy link
Member

@MinSang22Kim MinSang22Kim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다~!

.orElseThrow(() -> SaphyException.from(PAY_NOT_FOUND));
return new PayResponse(pay.getId(), pay.getTransactionId(), pay.getStatus());
private String generateMerchantUid() {
return "ORD-" + UUID.randomUUID();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UUID 앞에 ORD를 붙여서 직관적이라 좋은 거 같아요! 예전에 재우님 코드 리뷰에 있었던 내용을 반영한 건가요~?

Comment on lines +47 to 54
if (item.getStock() < request.getQuantity()) {
throw SaphyException.from(ITEM_OUT_OF_STOCK);
}

// 물품 금액과 결제 금액이 같은지 검증
if (!iamportPayment.getAmount().equals(item.getPrice())) {
BigDecimal calculatedAmount = item.getPrice().multiply(BigDecimal.valueOf(request.getQuantity()));
if (!calculatedAmount.equals(request.getAmount())) {
throw SaphyException.from(PAY_PRICE_MISMATCH);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

나중에 이런 조건문들은 private 메서드로 따로 빼서 리팩토링 하면 더 코드가 깔끔해질 거 같아요!

@MinSang22Kim MinSang22Kim merged commit 45e5baf into develop Oct 2, 2024
1 check passed
@holyPigeon holyPigeon deleted the feat/SAPHY-140-buy-device branch October 4, 2024 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Feature 새로운 기능 ♻️ Refactor 코드 리팩토링
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants