-
Notifications
You must be signed in to change notification settings - Fork 1
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
[POM-84] feat: 주문 거절 시 결제 취소 #30
Changes from 5 commits
dab4d6d
279e1d4
86b7c0f
4b7bed8
be8260d
7941272
4ebf7d9
3377715
3e253a7
068440b
ea1339e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,7 @@ | ||
package com.ray.pominowner.payment.dto; | ||
|
||
import com.ray.pominowner.payment.domain.PGType; | ||
import com.ray.pominowner.payment.domain.Payment; | ||
import com.ray.pominowner.payment.domain.PaymentStatus; | ||
|
||
public record PaymentCreateRequest(Long id, int amount, PaymentStatus status, PGType provider) { | ||
|
||
public Payment toEntity() { | ||
return new Payment(id, amount, status, provider); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,38 @@ | ||
package com.ray.pominowner.payment.service; | ||
|
||
import com.ray.pominowner.payment.domain.Payment; | ||
import com.ray.pominowner.payment.domain.PaymentStatus; | ||
import com.ray.pominowner.payment.repository.PaymentRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import static com.ray.pominowner.global.util.ExceptionMessage.NO_PAYMENT; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
@Transactional | ||
public class PaymentService { | ||
|
||
private final PaymentRepository paymentRepository; | ||
|
||
@Transactional | ||
public Payment create(Payment payment) { | ||
return paymentRepository.save(payment); | ||
} | ||
|
||
|
||
public Payment canceled(Long paymentId) { | ||
Payment payment = paymentRepository.findById(paymentId) | ||
.orElseThrow(() -> new IllegalArgumentException(NO_PAYMENT.getMessage())); | ||
|
||
Payment canceled = Payment.builder() | ||
.id(paymentId) | ||
.amount(payment.getAmount()) | ||
.provider(payment.getProvider()) | ||
.status(PaymentStatus.CANCELLED) | ||
.build(); | ||
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. |
||
|
||
return paymentRepository.save(canceled); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,10 @@ | |
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.mockito.BDDMockito.given; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
|
@@ -37,4 +40,34 @@ public void successCreatePayment() { | |
assertThat(createdPayment).isEqualTo(payment); | ||
} | ||
|
||
@Test | ||
@DisplayName("Payment 취소에 성공한다.") | ||
public void successCancelPayment() { | ||
// given | ||
Payment saved = new Payment(1L, 1000, PaymentStatus.COMPLETE, PGType.TOSS); | ||
Payment canceled = new Payment(1L, 1000, PaymentStatus.CANCELLED, PGType.TOSS); | ||
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. status의 cancelled 와 변수명 canceled을 통일하면 좋을 것 같아요 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. |
||
|
||
given(paymentRepository.findById(saved.getId())).willReturn(Optional.of(saved)); | ||
given(paymentRepository.save(canceled)).willReturn(canceled); | ||
|
||
// when | ||
Payment payment = paymentService.canceled(saved.getId()); | ||
|
||
// then | ||
assertThat(canceled).isEqualTo(payment); | ||
} | ||
|
||
@Test | ||
@DisplayName("PaymentId가 존재하지 않는 경우 취소에 실패한다.") | ||
public void failCancelPayment() { | ||
// given | ||
Payment saved = new Payment(1L, 1000, PaymentStatus.COMPLETE, PGType.TOSS); | ||
|
||
given(paymentRepository.findById(saved.getId())).willThrow(IllegalArgumentException.class); | ||
|
||
// when, then | ||
assertThatThrownBy(() -> paymentService.canceled(saved.getId())) | ||
.isInstanceOf(IllegalArgumentException.class); | ||
} | ||
|
||
} |
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.
메소드이름이 동사 과거형인게 조금 부자연스러워 보여요. 현재형으로 바꾸거나 목적어를 추가하는 건 어떠신가요?
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.
refactor: 결제 취소 메서드 명 현재형으로 변경