generated from pricelees/issue-pr-template
refactor: payment 패키지 내 DTO 코틀린 마이그레이션 및 클래스 통합
This commit is contained in:
parent
2734290661
commit
571f6b2e11
@ -13,10 +13,8 @@ import roomescape.payment.infrastructure.persistence.CanceledPayment;
|
|||||||
import roomescape.payment.infrastructure.persistence.CanceledPaymentRepository;
|
import roomescape.payment.infrastructure.persistence.CanceledPaymentRepository;
|
||||||
import roomescape.payment.infrastructure.persistence.Payment;
|
import roomescape.payment.infrastructure.persistence.Payment;
|
||||||
import roomescape.payment.infrastructure.persistence.PaymentRepository;
|
import roomescape.payment.infrastructure.persistence.PaymentRepository;
|
||||||
import roomescape.payment.web.dto.request.PaymentCancelRequest;
|
import roomescape.payment.web.PaymentCancel;
|
||||||
import roomescape.payment.web.dto.response.PaymentCancelResponse;
|
import roomescape.payment.web.ReservationPaymentResponse;
|
||||||
import roomescape.payment.web.dto.response.PaymentResponse;
|
|
||||||
import roomescape.payment.web.dto.response.ReservationPaymentResponse;
|
|
||||||
import roomescape.reservation.domain.Reservation;
|
import roomescape.reservation.domain.Reservation;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@ -31,9 +29,10 @@ public class PaymentService {
|
|||||||
this.canceledPaymentRepository = canceledPaymentRepository;
|
this.canceledPaymentRepository = canceledPaymentRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReservationPaymentResponse savePayment(PaymentResponse paymentResponse, Reservation reservation) {
|
public ReservationPaymentResponse savePayment(roomescape.payment.web.PaymentApprove.Response paymentResponse,
|
||||||
Payment payment = new Payment(paymentResponse.orderId(), paymentResponse.paymentKey(),
|
Reservation reservation) {
|
||||||
paymentResponse.totalAmount(), reservation, paymentResponse.approvedAt());
|
Payment payment = new Payment(paymentResponse.orderId, paymentResponse.paymentKey,
|
||||||
|
paymentResponse.totalAmount, reservation, paymentResponse.approvedAt);
|
||||||
Payment saved = paymentRepository.save(payment);
|
Payment saved = paymentRepository.save(payment);
|
||||||
return ReservationPaymentResponse.from(saved);
|
return ReservationPaymentResponse.from(saved);
|
||||||
}
|
}
|
||||||
@ -43,12 +42,12 @@ public class PaymentService {
|
|||||||
return paymentRepository.findByReservationId(reservationId);
|
return paymentRepository.findByReservationId(reservationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveCanceledPayment(PaymentCancelResponse cancelInfo, OffsetDateTime approvedAt, String paymentKey) {
|
public void saveCanceledPayment(PaymentCancel.Response cancelInfo, OffsetDateTime approvedAt, String paymentKey) {
|
||||||
canceledPaymentRepository.save(new CanceledPayment(
|
canceledPaymentRepository.save(new CanceledPayment(
|
||||||
paymentKey, cancelInfo.cancelReason(), cancelInfo.cancelAmount(), approvedAt, cancelInfo.canceledAt()));
|
paymentKey, cancelInfo.cancelReason, cancelInfo.cancelAmount, approvedAt, cancelInfo.canceledAt));
|
||||||
}
|
}
|
||||||
|
|
||||||
public PaymentCancelRequest cancelPaymentByAdmin(Long reservationId) {
|
public PaymentCancel.Request cancelPaymentByAdmin(Long reservationId) {
|
||||||
String paymentKey = findPaymentByReservationId(reservationId)
|
String paymentKey = findPaymentByReservationId(reservationId)
|
||||||
.orElseThrow(() -> new RoomescapeException(ErrorType.PAYMENT_NOT_POUND,
|
.orElseThrow(() -> new RoomescapeException(ErrorType.PAYMENT_NOT_POUND,
|
||||||
String.format("[reservationId: %d]", reservationId), HttpStatus.NOT_FOUND))
|
String.format("[reservationId: %d]", reservationId), HttpStatus.NOT_FOUND))
|
||||||
@ -56,7 +55,7 @@ public class PaymentService {
|
|||||||
// 취소 시간은 현재 시간으로 일단 생성한 뒤, 결제 취소 완료 후 해당 시간으로 변경합니다.
|
// 취소 시간은 현재 시간으로 일단 생성한 뒤, 결제 취소 완료 후 해당 시간으로 변경합니다.
|
||||||
CanceledPayment canceled = cancelPayment(paymentKey, "고객 요청", OffsetDateTime.now());
|
CanceledPayment canceled = cancelPayment(paymentKey, "고객 요청", OffsetDateTime.now());
|
||||||
|
|
||||||
return new PaymentCancelRequest(paymentKey, canceled.getCancelAmount(), canceled.getCancelReason());
|
return new PaymentCancel.Request(paymentKey, canceled.getCancelAmount(), canceled.getCancelReason());
|
||||||
}
|
}
|
||||||
|
|
||||||
private CanceledPayment cancelPayment(String paymentKey, String cancelReason, OffsetDateTime canceledAt) {
|
private CanceledPayment cancelPayment(String paymentKey, String cancelReason, OffsetDateTime canceledAt) {
|
||||||
|
|||||||
69
src/main/java/roomescape/payment/web/PaymentDTO.kt
Normal file
69
src/main/java/roomescape/payment/web/PaymentDTO.kt
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
package roomescape.payment.web
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
|
||||||
|
import roomescape.payment.web.support.PaymentCancelResponseDeserializer
|
||||||
|
import roomescape.reservation.dto.response.ReservationResponse
|
||||||
|
import java.time.OffsetDateTime
|
||||||
|
|
||||||
|
class PaymentApprove {
|
||||||
|
@JvmRecord
|
||||||
|
data class Request(
|
||||||
|
@JvmField val paymentKey: String,
|
||||||
|
@JvmField val orderId: String,
|
||||||
|
@JvmField val amount: Long,
|
||||||
|
@JvmField val paymentType: String
|
||||||
|
)
|
||||||
|
|
||||||
|
@JvmRecord
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
data class Response(
|
||||||
|
@JvmField val paymentKey: String,
|
||||||
|
@JvmField val orderId: String,
|
||||||
|
@JvmField val approvedAt: OffsetDateTime,
|
||||||
|
@JvmField val totalAmount: Long
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
class PaymentCancel {
|
||||||
|
@JvmRecord
|
||||||
|
data class Request(
|
||||||
|
@JvmField val paymentKey: String,
|
||||||
|
@JvmField val amount: Long,
|
||||||
|
@JvmField val cancelReason: String
|
||||||
|
)
|
||||||
|
|
||||||
|
@JvmRecord
|
||||||
|
@JsonDeserialize(using = PaymentCancelResponseDeserializer::class)
|
||||||
|
data class Response(
|
||||||
|
@JvmField val cancelStatus: String,
|
||||||
|
@JvmField val cancelReason: String,
|
||||||
|
@JvmField val cancelAmount: Long,
|
||||||
|
@JvmField val canceledAt: OffsetDateTime
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@JvmRecord
|
||||||
|
data class ReservationPaymentResponse(
|
||||||
|
val id: Long,
|
||||||
|
val orderId: String,
|
||||||
|
val paymentKey: String,
|
||||||
|
val totalAmount: Long,
|
||||||
|
val reservation: ReservationResponse,
|
||||||
|
val approvedAt: OffsetDateTime
|
||||||
|
) {
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
fun from(saved: roomescape.payment.infrastructure.persistence.Payment): ReservationPaymentResponse {
|
||||||
|
return ReservationPaymentResponse(
|
||||||
|
saved.id,
|
||||||
|
saved.orderId,
|
||||||
|
saved.paymentKey,
|
||||||
|
saved.totalAmount,
|
||||||
|
ReservationResponse.from(saved.reservation),
|
||||||
|
saved.approvedAt
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +0,0 @@
|
|||||||
package roomescape.payment.web.dto.request;
|
|
||||||
|
|
||||||
public record PaymentCancelRequest(String paymentKey, Long amount, String cancelReason) {
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
package roomescape.payment.web.dto.request;
|
|
||||||
|
|
||||||
public record PaymentRequest(String paymentKey, String orderId, Long amount, String paymentType) {
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
package roomescape.payment.web.dto.response;
|
|
||||||
|
|
||||||
import java.time.OffsetDateTime;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
|
||||||
|
|
||||||
import roomescape.payment.web.support.PaymentCancelResponseDeserializer;
|
|
||||||
|
|
||||||
@JsonDeserialize(using = PaymentCancelResponseDeserializer.class)
|
|
||||||
public record PaymentCancelResponse(
|
|
||||||
String cancelStatus,
|
|
||||||
String cancelReason,
|
|
||||||
Long cancelAmount,
|
|
||||||
OffsetDateTime canceledAt
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
package roomescape.payment.web.dto.response;
|
|
||||||
|
|
||||||
import java.time.OffsetDateTime;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|
||||||
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
||||||
public record PaymentResponse(
|
|
||||||
String paymentKey,
|
|
||||||
String orderId,
|
|
||||||
OffsetDateTime approvedAt,
|
|
||||||
Long totalAmount
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
package roomescape.payment.web.dto.response;
|
|
||||||
|
|
||||||
import java.time.OffsetDateTime;
|
|
||||||
|
|
||||||
import roomescape.payment.infrastructure.persistence.Payment;
|
|
||||||
import roomescape.reservation.dto.response.ReservationResponse;
|
|
||||||
|
|
||||||
public record ReservationPaymentResponse(Long id, String orderId, String paymentKey, Long totalAmount,
|
|
||||||
ReservationResponse reservation, OffsetDateTime approvedAt) {
|
|
||||||
|
|
||||||
public static ReservationPaymentResponse from(Payment saved) {
|
|
||||||
return new ReservationPaymentResponse(saved.getId(), saved.getOrderId(), saved.getPaymentKey(),
|
|
||||||
saved.getTotalAmount(), ReservationResponse.from(saved.getReservation()), saved.getApprovedAt());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
package roomescape.payment.web.dto.response;
|
|
||||||
|
|
||||||
public record TossPaymentErrorResponse(String code, String message) {
|
|
||||||
}
|
|
||||||
@ -5,24 +5,23 @@ import com.fasterxml.jackson.core.TreeNode
|
|||||||
import com.fasterxml.jackson.databind.DeserializationContext
|
import com.fasterxml.jackson.databind.DeserializationContext
|
||||||
import com.fasterxml.jackson.databind.JsonNode
|
import com.fasterxml.jackson.databind.JsonNode
|
||||||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer
|
import com.fasterxml.jackson.databind.deser.std.StdDeserializer
|
||||||
import roomescape.payment.web.dto.response.PaymentCancelResponse
|
import roomescape.payment.web.PaymentCancel
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.time.OffsetDateTime
|
import java.time.OffsetDateTime
|
||||||
|
|
||||||
class PaymentCancelResponseDeserializer(
|
class PaymentCancelResponseDeserializer(
|
||||||
vc: Class<PaymentCancelResponse?>? = null
|
vc: Class<PaymentCancel.Response>? = null
|
||||||
) : StdDeserializer<PaymentCancelResponse?>(vc) {
|
) : StdDeserializer<PaymentCancel.Response>(vc) {
|
||||||
|
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
override fun deserialize(
|
override fun deserialize(
|
||||||
jsonParser: JsonParser,
|
jsonParser: JsonParser,
|
||||||
deserializationContext: DeserializationContext?
|
deserializationContext: DeserializationContext?
|
||||||
): PaymentCancelResponse {
|
): PaymentCancel.Response {
|
||||||
val cancels: JsonNode = jsonParser.codec.readTree<TreeNode>(jsonParser)
|
val cancels: JsonNode = jsonParser.codec.readTree<TreeNode>(jsonParser)
|
||||||
.get("cancels")
|
.get("cancels")
|
||||||
.get(0) as JsonNode
|
.get(0) as JsonNode
|
||||||
|
|
||||||
return PaymentCancelResponse(
|
return PaymentCancel.Response(
|
||||||
cancels.get("cancelStatus").asText(),
|
cancels.get("cancelStatus").asText(),
|
||||||
cancels.get("cancelReason").asText(),
|
cancels.get("cancelReason").asText(),
|
||||||
cancels.get("cancelAmount").asLong(),
|
cancels.get("cancelAmount").asLong(),
|
||||||
|
|||||||
@ -31,10 +31,8 @@ import roomescape.common.dto.response.RoomescapeApiResponse;
|
|||||||
import roomescape.common.dto.response.RoomescapeErrorResponse;
|
import roomescape.common.dto.response.RoomescapeErrorResponse;
|
||||||
import roomescape.common.exception.RoomescapeException;
|
import roomescape.common.exception.RoomescapeException;
|
||||||
import roomescape.payment.infrastructure.client.TossPaymentClient;
|
import roomescape.payment.infrastructure.client.TossPaymentClient;
|
||||||
import roomescape.payment.web.dto.request.PaymentCancelRequest;
|
import roomescape.payment.web.PaymentApprove;
|
||||||
import roomescape.payment.web.dto.request.PaymentRequest;
|
import roomescape.payment.web.PaymentCancel;
|
||||||
import roomescape.payment.web.dto.response.PaymentCancelResponse;
|
|
||||||
import roomescape.payment.web.dto.response.PaymentResponse;
|
|
||||||
import roomescape.reservation.dto.request.AdminReservationRequest;
|
import roomescape.reservation.dto.request.AdminReservationRequest;
|
||||||
import roomescape.reservation.dto.request.ReservationRequest;
|
import roomescape.reservation.dto.request.ReservationRequest;
|
||||||
import roomescape.reservation.dto.request.WaitingRequest;
|
import roomescape.reservation.dto.request.WaitingRequest;
|
||||||
@ -120,13 +118,13 @@ public class ReservationController {
|
|||||||
return RoomescapeApiResponse.success();
|
return RoomescapeApiResponse.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
PaymentCancelRequest paymentCancelRequest = reservationWithPaymentService.removeReservationWithPayment(
|
PaymentCancel.Request paymentCancelRequest = reservationWithPaymentService.removeReservationWithPayment(
|
||||||
reservationId, memberId);
|
reservationId, memberId);
|
||||||
|
|
||||||
PaymentCancelResponse paymentCancelResponse = paymentClient.cancelPayment(paymentCancelRequest);
|
PaymentCancel.Response paymentCancelResponse = paymentClient.cancelPayment(paymentCancelRequest);
|
||||||
|
|
||||||
reservationWithPaymentService.updateCanceledTime(paymentCancelRequest.paymentKey(),
|
reservationWithPaymentService.updateCanceledTime(paymentCancelRequest.paymentKey,
|
||||||
paymentCancelResponse.canceledAt());
|
paymentCancelResponse.canceledAt);
|
||||||
|
|
||||||
return RoomescapeApiResponse.success();
|
return RoomescapeApiResponse.success();
|
||||||
}
|
}
|
||||||
@ -144,21 +142,21 @@ public class ReservationController {
|
|||||||
@MemberId @Parameter(hidden = true) Long memberId,
|
@MemberId @Parameter(hidden = true) Long memberId,
|
||||||
HttpServletResponse response
|
HttpServletResponse response
|
||||||
) {
|
) {
|
||||||
PaymentRequest paymentRequest = reservationRequest.getPaymentRequest();
|
PaymentApprove.Request paymentRequest = reservationRequest.getPaymentRequest();
|
||||||
PaymentResponse paymentResponse = paymentClient.confirmPayment(paymentRequest);
|
PaymentApprove.Response paymentResponse = paymentClient.confirmPayment(paymentRequest);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ReservationResponse reservationResponse = reservationWithPaymentService.addReservationWithPayment(
|
ReservationResponse reservationResponse = reservationWithPaymentService.addReservationWithPayment(
|
||||||
reservationRequest, paymentResponse, memberId);
|
reservationRequest, paymentResponse, memberId);
|
||||||
return getCreatedReservationResponse(reservationResponse, response);
|
return getCreatedReservationResponse(reservationResponse, response);
|
||||||
} catch (RoomescapeException e) {
|
} catch (RoomescapeException e) {
|
||||||
PaymentCancelRequest cancelRequest = new PaymentCancelRequest(paymentRequest.paymentKey(),
|
PaymentCancel.Request cancelRequest = new PaymentCancel.Request(paymentRequest.paymentKey,
|
||||||
paymentRequest.amount(), e.getMessage());
|
paymentRequest.amount, e.getMessage());
|
||||||
|
|
||||||
PaymentCancelResponse paymentCancelResponse = paymentClient.cancelPayment(cancelRequest);
|
PaymentCancel.Response paymentCancelResponse = paymentClient.cancelPayment(cancelRequest);
|
||||||
|
|
||||||
reservationWithPaymentService.saveCanceledPayment(paymentCancelResponse, paymentResponse.approvedAt(),
|
reservationWithPaymentService.saveCanceledPayment(paymentCancelResponse, paymentResponse.approvedAt,
|
||||||
paymentRequest.paymentKey());
|
paymentRequest.paymentKey);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
|||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import roomescape.payment.web.dto.request.PaymentRequest;
|
import roomescape.payment.web.PaymentApprove;
|
||||||
|
|
||||||
@Schema(name = "회원의 예약 저장 요청", description = "회원의 예약 요청시 사용됩니다.")
|
@Schema(name = "회원의 예약 저장 요청", description = "회원의 예약 요청시 사용됩니다.")
|
||||||
public record ReservationRequest(
|
public record ReservationRequest(
|
||||||
@ -30,7 +30,7 @@ public record ReservationRequest(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public PaymentRequest getPaymentRequest() {
|
public PaymentApprove.Request getPaymentRequest() {
|
||||||
return new PaymentRequest(paymentKey, orderId, amount, paymentType);
|
return new PaymentApprove.Request(paymentKey, orderId, amount, paymentType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,10 +6,9 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import roomescape.payment.business.PaymentService;
|
import roomescape.payment.business.PaymentService;
|
||||||
import roomescape.payment.web.dto.request.PaymentCancelRequest;
|
import roomescape.payment.web.PaymentApprove;
|
||||||
import roomescape.payment.web.dto.response.PaymentCancelResponse;
|
import roomescape.payment.web.PaymentCancel;
|
||||||
import roomescape.payment.web.dto.response.PaymentResponse;
|
import roomescape.payment.web.ReservationPaymentResponse;
|
||||||
import roomescape.payment.web.dto.response.ReservationPaymentResponse;
|
|
||||||
import roomescape.reservation.domain.Reservation;
|
import roomescape.reservation.domain.Reservation;
|
||||||
import roomescape.reservation.dto.request.ReservationRequest;
|
import roomescape.reservation.dto.request.ReservationRequest;
|
||||||
import roomescape.reservation.dto.response.ReservationResponse;
|
import roomescape.reservation.dto.response.ReservationResponse;
|
||||||
@ -27,7 +26,8 @@ public class ReservationWithPaymentService {
|
|||||||
this.paymentService = paymentService;
|
this.paymentService = paymentService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReservationResponse addReservationWithPayment(ReservationRequest request, PaymentResponse paymentInfo,
|
public ReservationResponse addReservationWithPayment(ReservationRequest request,
|
||||||
|
PaymentApprove.Response paymentInfo,
|
||||||
Long memberId) {
|
Long memberId) {
|
||||||
Reservation reservation = reservationService.addReservation(request, memberId);
|
Reservation reservation = reservationService.addReservation(request, memberId);
|
||||||
ReservationPaymentResponse reservationPaymentResponse = paymentService.savePayment(paymentInfo, reservation);
|
ReservationPaymentResponse reservationPaymentResponse = paymentService.savePayment(paymentInfo, reservation);
|
||||||
@ -35,12 +35,12 @@ public class ReservationWithPaymentService {
|
|||||||
return reservationPaymentResponse.reservation();
|
return reservationPaymentResponse.reservation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveCanceledPayment(PaymentCancelResponse cancelInfo, OffsetDateTime approvedAt, String paymentKey) {
|
public void saveCanceledPayment(PaymentCancel.Response cancelInfo, OffsetDateTime approvedAt, String paymentKey) {
|
||||||
paymentService.saveCanceledPayment(cancelInfo, approvedAt, paymentKey);
|
paymentService.saveCanceledPayment(cancelInfo, approvedAt, paymentKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PaymentCancelRequest removeReservationWithPayment(Long reservationId, Long memberId) {
|
public PaymentCancel.Request removeReservationWithPayment(Long reservationId, Long memberId) {
|
||||||
PaymentCancelRequest paymentCancelRequest = paymentService.cancelPaymentByAdmin(reservationId);
|
PaymentCancel.Request paymentCancelRequest = paymentService.cancelPaymentByAdmin(reservationId);
|
||||||
reservationService.removeReservationById(reservationId, memberId);
|
reservationService.removeReservationById(reservationId, memberId);
|
||||||
return paymentCancelRequest;
|
return paymentCancelRequest;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
package roomescape.payment
|
package roomescape.payment
|
||||||
|
|
||||||
import roomescape.payment.SampleTossPaymentConst.amount
|
import roomescape.payment.SampleTossPaymentConst.amount
|
||||||
import roomescape.payment.web.dto.request.PaymentCancelRequest
|
import roomescape.payment.web.PaymentApprove
|
||||||
import roomescape.payment.web.dto.request.PaymentRequest
|
import roomescape.payment.web.PaymentCancel
|
||||||
import kotlin.math.roundToLong
|
import kotlin.math.roundToLong
|
||||||
|
|
||||||
object SampleTossPaymentConst {
|
object SampleTossPaymentConst {
|
||||||
@ -22,7 +22,7 @@ object SampleTossPaymentConst {
|
|||||||
val cancelReason: String = "테스트 결제 취소"
|
val cancelReason: String = "테스트 결제 취소"
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
val paymentRequest: PaymentRequest = PaymentRequest(
|
val paymentRequest: PaymentApprove.Request = PaymentApprove.Request(
|
||||||
paymentKey,
|
paymentKey,
|
||||||
orderId,
|
orderId,
|
||||||
amount,
|
amount,
|
||||||
@ -40,7 +40,7 @@ object SampleTossPaymentConst {
|
|||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
val cancelRequest: PaymentCancelRequest = PaymentCancelRequest(
|
val cancelRequest: PaymentCancel.Request = PaymentCancel.Request(
|
||||||
paymentKey,
|
paymentKey,
|
||||||
amount,
|
amount,
|
||||||
cancelReason
|
cancelReason
|
||||||
@ -125,7 +125,6 @@ object SampleTossPaymentConst {
|
|||||||
"method": "$paymentType",
|
"method": "$paymentType",
|
||||||
"version": "2022-11-16"
|
"version": "2022-11-16"
|
||||||
}
|
}
|
||||||
|
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
@ -205,7 +204,6 @@ object SampleTossPaymentConst {
|
|||||||
"method": "$paymentType",
|
"method": "$paymentType",
|
||||||
"version": "2022-11-16"
|
"version": "2022-11-16"
|
||||||
}
|
}
|
||||||
|
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,9 +18,9 @@ import roomescape.member.infrastructure.persistence.Member;
|
|||||||
import roomescape.member.infrastructure.persistence.MemberRepository;
|
import roomescape.member.infrastructure.persistence.MemberRepository;
|
||||||
import roomescape.member.infrastructure.persistence.Role;
|
import roomescape.member.infrastructure.persistence.Role;
|
||||||
import roomescape.payment.infrastructure.persistence.CanceledPaymentRepository;
|
import roomescape.payment.infrastructure.persistence.CanceledPaymentRepository;
|
||||||
import roomescape.payment.web.dto.request.PaymentCancelRequest;
|
import roomescape.payment.web.PaymentApprove;
|
||||||
import roomescape.payment.web.dto.response.PaymentResponse;
|
import roomescape.payment.web.PaymentCancel;
|
||||||
import roomescape.payment.web.dto.response.ReservationPaymentResponse;
|
import roomescape.payment.web.ReservationPaymentResponse;
|
||||||
import roomescape.reservation.domain.Reservation;
|
import roomescape.reservation.domain.Reservation;
|
||||||
import roomescape.reservation.domain.ReservationStatus;
|
import roomescape.reservation.domain.ReservationStatus;
|
||||||
import roomescape.reservation.domain.ReservationTime;
|
import roomescape.reservation.domain.ReservationTime;
|
||||||
@ -50,7 +50,8 @@ class PaymentServiceTest {
|
|||||||
@DisplayName("결제 정보를 저장한다.")
|
@DisplayName("결제 정보를 저장한다.")
|
||||||
void savePayment() {
|
void savePayment() {
|
||||||
// given
|
// given
|
||||||
PaymentResponse paymentInfo = new PaymentResponse("payment-key", "order-id", OffsetDateTime.now(), 10000L);
|
PaymentApprove.Response paymentInfo = new PaymentApprove.Response("payment-key", "order-id",
|
||||||
|
OffsetDateTime.now(), 10000L);
|
||||||
LocalDateTime localDateTime = LocalDateTime.now().plusHours(1L);
|
LocalDateTime localDateTime = LocalDateTime.now().plusHours(1L);
|
||||||
LocalDate date = localDateTime.toLocalDate();
|
LocalDate date = localDateTime.toLocalDate();
|
||||||
ReservationTime time = reservationTimeRepository.save(new ReservationTime(localDateTime.toLocalTime()));
|
ReservationTime time = reservationTimeRepository.save(new ReservationTime(localDateTime.toLocalTime()));
|
||||||
@ -64,14 +65,15 @@ class PaymentServiceTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(reservationPaymentResponse.reservation().id()).isEqualTo(reservation.getId());
|
assertThat(reservationPaymentResponse.reservation().id()).isEqualTo(reservation.getId());
|
||||||
assertThat(reservationPaymentResponse.paymentKey()).isEqualTo(paymentInfo.paymentKey());
|
assertThat(reservationPaymentResponse.paymentKey()).isEqualTo(paymentInfo.paymentKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("예약 ID로 결제 정보를 제거하고, 결제 취소 테이블에 취소 정보를 저장한다.")
|
@DisplayName("예약 ID로 결제 정보를 제거하고, 결제 취소 테이블에 취소 정보를 저장한다.")
|
||||||
void cancelPaymentByAdmin() {
|
void cancelPaymentByAdmin() {
|
||||||
// given
|
// given
|
||||||
PaymentResponse paymentInfo = new PaymentResponse("payment-key", "order-id", OffsetDateTime.now(), 10000L);
|
PaymentApprove.Response paymentInfo = new PaymentApprove.Response("payment-key", "order-id",
|
||||||
|
OffsetDateTime.now(), 10000L);
|
||||||
LocalDateTime localDateTime = LocalDateTime.now().plusHours(1L);
|
LocalDateTime localDateTime = LocalDateTime.now().plusHours(1L);
|
||||||
LocalDate date = localDateTime.toLocalDate();
|
LocalDate date = localDateTime.toLocalDate();
|
||||||
ReservationTime time = reservationTimeRepository.save(new ReservationTime(localDateTime.toLocalTime()));
|
ReservationTime time = reservationTimeRepository.save(new ReservationTime(localDateTime.toLocalTime()));
|
||||||
@ -83,13 +85,13 @@ class PaymentServiceTest {
|
|||||||
paymentService.savePayment(paymentInfo, reservation);
|
paymentService.savePayment(paymentInfo, reservation);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
PaymentCancelRequest paymentCancelRequest = paymentService.cancelPaymentByAdmin(reservation.getId());
|
PaymentCancel.Request paymentCancelRequest = paymentService.cancelPaymentByAdmin(reservation.getId());
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(canceledPaymentRepository.findByPaymentKey("payment-key")).isNotEmpty();
|
assertThat(canceledPaymentRepository.findByPaymentKey("payment-key")).isNotEmpty();
|
||||||
assertThat(paymentCancelRequest.paymentKey()).isEqualTo(paymentInfo.paymentKey());
|
assertThat(paymentCancelRequest.paymentKey).isEqualTo(paymentInfo.paymentKey);
|
||||||
assertThat(paymentCancelRequest.cancelReason()).isEqualTo("고객 요청");
|
assertThat(paymentCancelRequest.cancelReason).isEqualTo("고객 요청");
|
||||||
assertThat(paymentCancelRequest.amount()).isEqualTo(10000L);
|
assertThat(paymentCancelRequest.amount).isEqualTo(10000L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -107,7 +109,8 @@ class PaymentServiceTest {
|
|||||||
@DisplayName("결제 취소 정보에 있는 취소 시간을 업데이트한다.")
|
@DisplayName("결제 취소 정보에 있는 취소 시간을 업데이트한다.")
|
||||||
void updateCanceledTime() {
|
void updateCanceledTime() {
|
||||||
// given
|
// given
|
||||||
PaymentResponse paymentInfo = new PaymentResponse("payment-key", "order-id", OffsetDateTime.now(), 10000L);
|
PaymentApprove.Response paymentInfo = new PaymentApprove.Response("payment-key", "order-id",
|
||||||
|
OffsetDateTime.now(), 10000L);
|
||||||
LocalDateTime localDateTime = LocalDateTime.now().plusHours(1L);
|
LocalDateTime localDateTime = LocalDateTime.now().plusHours(1L);
|
||||||
LocalDate date = localDateTime.toLocalDate();
|
LocalDate date = localDateTime.toLocalDate();
|
||||||
ReservationTime time = reservationTimeRepository.save(new ReservationTime(localDateTime.toLocalTime()));
|
ReservationTime time = reservationTimeRepository.save(new ReservationTime(localDateTime.toLocalTime()));
|
||||||
@ -121,10 +124,10 @@ class PaymentServiceTest {
|
|||||||
|
|
||||||
// when
|
// when
|
||||||
OffsetDateTime canceledAt = OffsetDateTime.now().plusHours(2L);
|
OffsetDateTime canceledAt = OffsetDateTime.now().plusHours(2L);
|
||||||
paymentService.updateCanceledTime(paymentInfo.paymentKey(), canceledAt);
|
paymentService.updateCanceledTime(paymentInfo.paymentKey, canceledAt);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
canceledPaymentRepository.findByPaymentKey(paymentInfo.paymentKey())
|
canceledPaymentRepository.findByPaymentKey(paymentInfo.paymentKey)
|
||||||
.ifPresent(canceledPayment -> assertThat(canceledPayment.getCanceledAt()).isEqualTo(canceledAt));
|
.ifPresent(canceledPayment -> assertThat(canceledPayment.getCanceledAt()).isEqualTo(canceledAt));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,22 +7,22 @@ import io.kotest.assertions.assertSoftly
|
|||||||
import io.kotest.core.spec.style.StringSpec
|
import io.kotest.core.spec.style.StringSpec
|
||||||
import io.kotest.matchers.shouldBe
|
import io.kotest.matchers.shouldBe
|
||||||
import roomescape.payment.SampleTossPaymentConst
|
import roomescape.payment.SampleTossPaymentConst
|
||||||
import roomescape.payment.web.dto.response.PaymentCancelResponse
|
import roomescape.payment.web.PaymentCancel
|
||||||
|
|
||||||
class PaymentCancelResponseDeserializerTest : StringSpec({
|
class PaymentCancelResponseDeserializerTest : StringSpec({
|
||||||
|
|
||||||
val objectMapper: ObjectMapper = jacksonObjectMapper().registerModule(
|
val objectMapper: ObjectMapper = jacksonObjectMapper().registerModule(
|
||||||
SimpleModule().addDeserializer(
|
SimpleModule().addDeserializer(
|
||||||
PaymentCancelResponse::class.java,
|
PaymentCancel.Response::class.java,
|
||||||
PaymentCancelResponseDeserializer()
|
PaymentCancelResponseDeserializer()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
"결제 취소 응답을 역직렬화하여 PaymentCancelResponse 객체를 생성한다" {
|
"결제 취소 응답을 역직렬화하여 PaymentCancelResponse 객체를 생성한다" {
|
||||||
val cancelResponseJson: String = SampleTossPaymentConst.cancelJson
|
val cancelResponseJson: String = SampleTossPaymentConst.cancelJson
|
||||||
val cancelResponse: PaymentCancelResponse = objectMapper.readValue(
|
val cancelResponse: PaymentCancel.Response = objectMapper.readValue(
|
||||||
cancelResponseJson,
|
cancelResponseJson,
|
||||||
PaymentCancelResponse::class.java
|
PaymentCancel.Response::class.java
|
||||||
)
|
)
|
||||||
|
|
||||||
assertSoftly(cancelResponse) {
|
assertSoftly(cancelResponse) {
|
||||||
|
|||||||
@ -41,10 +41,8 @@ import roomescape.payment.infrastructure.persistence.CanceledPayment;
|
|||||||
import roomescape.payment.infrastructure.persistence.CanceledPaymentRepository;
|
import roomescape.payment.infrastructure.persistence.CanceledPaymentRepository;
|
||||||
import roomescape.payment.infrastructure.persistence.Payment;
|
import roomescape.payment.infrastructure.persistence.Payment;
|
||||||
import roomescape.payment.infrastructure.persistence.PaymentRepository;
|
import roomescape.payment.infrastructure.persistence.PaymentRepository;
|
||||||
import roomescape.payment.web.dto.request.PaymentCancelRequest;
|
import roomescape.payment.web.PaymentApprove;
|
||||||
import roomescape.payment.web.dto.request.PaymentRequest;
|
import roomescape.payment.web.PaymentCancel;
|
||||||
import roomescape.payment.web.dto.response.PaymentCancelResponse;
|
|
||||||
import roomescape.payment.web.dto.response.PaymentResponse;
|
|
||||||
import roomescape.reservation.domain.Reservation;
|
import roomescape.reservation.domain.Reservation;
|
||||||
import roomescape.reservation.domain.ReservationStatus;
|
import roomescape.reservation.domain.ReservationStatus;
|
||||||
import roomescape.reservation.domain.ReservationTime;
|
import roomescape.reservation.domain.ReservationTime;
|
||||||
@ -105,8 +103,8 @@ public class ReservationControllerTest {
|
|||||||
"paymentType", "DEFAULT"
|
"paymentType", "DEFAULT"
|
||||||
);
|
);
|
||||||
|
|
||||||
when(paymentClient.confirmPayment(any(PaymentRequest.class))).thenReturn(
|
when(paymentClient.confirmPayment(any(PaymentApprove.Request.class))).thenReturn(
|
||||||
new PaymentResponse("pk", "oi", OffsetDateTime.of(date, time, ZoneOffset.ofHours(9)), 1000L));
|
new PaymentApprove.Response("pk", "oi", OffsetDateTime.of(date, time, ZoneOffset.ofHours(9)), 1000L));
|
||||||
|
|
||||||
RestAssured.given().log().all()
|
RestAssured.given().log().all()
|
||||||
.contentType(ContentType.JSON)
|
.contentType(ContentType.JSON)
|
||||||
@ -404,8 +402,8 @@ public class ReservationControllerTest {
|
|||||||
new Payment("pk", "oi", 1000L, saved, OffsetDateTime.now().minusHours(1L)));
|
new Payment("pk", "oi", 1000L, saved, OffsetDateTime.now().minusHours(1L)));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
when(paymentClient.cancelPayment(any(PaymentCancelRequest.class)))
|
when(paymentClient.cancelPayment(any(PaymentCancel.Request.class)))
|
||||||
.thenReturn(new PaymentCancelResponse("pk", "고객 요청", savedPayment.getTotalAmount(),
|
.thenReturn(new PaymentCancel.Response("pk", "고객 요청", savedPayment.getTotalAmount(),
|
||||||
OffsetDateTime.now()));
|
OffsetDateTime.now()));
|
||||||
|
|
||||||
// then
|
// then
|
||||||
@ -433,11 +431,11 @@ public class ReservationControllerTest {
|
|||||||
String paymentKey = "pk";
|
String paymentKey = "pk";
|
||||||
OffsetDateTime canceledAt = OffsetDateTime.now().plusHours(1L).withNano(0);
|
OffsetDateTime canceledAt = OffsetDateTime.now().plusHours(1L).withNano(0);
|
||||||
OffsetDateTime approvedAt = OffsetDateTime.of(localDateTime, ZoneOffset.ofHours(9));
|
OffsetDateTime approvedAt = OffsetDateTime.of(localDateTime, ZoneOffset.ofHours(9));
|
||||||
when(paymentClient.confirmPayment(any(PaymentRequest.class)))
|
when(paymentClient.confirmPayment(any(PaymentApprove.Request.class)))
|
||||||
.thenReturn(new PaymentResponse(paymentKey, "oi", approvedAt, 1000L));
|
.thenReturn(new PaymentApprove.Response(paymentKey, "oi", approvedAt, 1000L));
|
||||||
|
|
||||||
when(paymentClient.cancelPayment(any(PaymentCancelRequest.class)))
|
when(paymentClient.cancelPayment(any(PaymentCancel.Request.class)))
|
||||||
.thenReturn(new PaymentCancelResponse(paymentKey, "고객 요청", 1000L, canceledAt));
|
.thenReturn(new PaymentCancel.Response(paymentKey, "고객 요청", 1000L, canceledAt));
|
||||||
|
|
||||||
RestAssured.given().log().all()
|
RestAssured.given().log().all()
|
||||||
.contentType(ContentType.JSON)
|
.contentType(ContentType.JSON)
|
||||||
|
|||||||
@ -18,8 +18,8 @@ import roomescape.member.infrastructure.persistence.MemberRepository;
|
|||||||
import roomescape.member.infrastructure.persistence.Role;
|
import roomescape.member.infrastructure.persistence.Role;
|
||||||
import roomescape.payment.infrastructure.persistence.CanceledPaymentRepository;
|
import roomescape.payment.infrastructure.persistence.CanceledPaymentRepository;
|
||||||
import roomescape.payment.infrastructure.persistence.PaymentRepository;
|
import roomescape.payment.infrastructure.persistence.PaymentRepository;
|
||||||
import roomescape.payment.web.dto.request.PaymentCancelRequest;
|
import roomescape.payment.web.PaymentApprove;
|
||||||
import roomescape.payment.web.dto.response.PaymentResponse;
|
import roomescape.payment.web.PaymentCancel;
|
||||||
import roomescape.reservation.domain.Reservation;
|
import roomescape.reservation.domain.Reservation;
|
||||||
import roomescape.reservation.domain.ReservationStatus;
|
import roomescape.reservation.domain.ReservationStatus;
|
||||||
import roomescape.reservation.domain.ReservationTime;
|
import roomescape.reservation.domain.ReservationTime;
|
||||||
@ -53,7 +53,8 @@ class ReservationWithPaymentServiceTest {
|
|||||||
@DisplayName("예약과 결제 정보를 추가한다.")
|
@DisplayName("예약과 결제 정보를 추가한다.")
|
||||||
void addReservationWithPayment() {
|
void addReservationWithPayment() {
|
||||||
// given
|
// given
|
||||||
PaymentResponse paymentInfo = new PaymentResponse("payment-key", "order-id", OffsetDateTime.now(), 10000L);
|
PaymentApprove.Response paymentInfo = new PaymentApprove.Response("payment-key", "order-id",
|
||||||
|
OffsetDateTime.now(), 10000L);
|
||||||
LocalDateTime localDateTime = LocalDateTime.now().plusDays(1L).withNano(0);
|
LocalDateTime localDateTime = LocalDateTime.now().plusDays(1L).withNano(0);
|
||||||
LocalDate date = localDateTime.toLocalDate();
|
LocalDate date = localDateTime.toLocalDate();
|
||||||
ReservationTime time = reservationTimeRepository.save(new ReservationTime(localDateTime.toLocalTime()));
|
ReservationTime time = reservationTimeRepository.save(new ReservationTime(localDateTime.toLocalTime()));
|
||||||
@ -88,7 +89,8 @@ class ReservationWithPaymentServiceTest {
|
|||||||
@DisplayName("예약 ID를 이용하여 예약과 결제 정보를 제거하고, 결제 취소 정보를 저장한다.")
|
@DisplayName("예약 ID를 이용하여 예약과 결제 정보를 제거하고, 결제 취소 정보를 저장한다.")
|
||||||
void removeReservationWithPayment() {
|
void removeReservationWithPayment() {
|
||||||
// given
|
// given
|
||||||
PaymentResponse paymentInfo = new PaymentResponse("payment-key", "order-id", OffsetDateTime.now(), 10000L);
|
PaymentApprove.Response paymentInfo = new PaymentApprove.Response("payment-key", "order-id",
|
||||||
|
OffsetDateTime.now(), 10000L);
|
||||||
LocalDateTime localDateTime = LocalDateTime.now().plusDays(1L).withNano(0);
|
LocalDateTime localDateTime = LocalDateTime.now().plusDays(1L).withNano(0);
|
||||||
LocalDate date = localDateTime.toLocalDate();
|
LocalDate date = localDateTime.toLocalDate();
|
||||||
ReservationTime time = reservationTimeRepository.save(new ReservationTime(localDateTime.toLocalTime()));
|
ReservationTime time = reservationTimeRepository.save(new ReservationTime(localDateTime.toLocalTime()));
|
||||||
@ -101,11 +103,11 @@ class ReservationWithPaymentServiceTest {
|
|||||||
reservationRequest, paymentInfo, member.getId());
|
reservationRequest, paymentInfo, member.getId());
|
||||||
|
|
||||||
// when
|
// when
|
||||||
PaymentCancelRequest paymentCancelRequest = reservationWithPaymentService.removeReservationWithPayment(
|
PaymentCancel.Request paymentCancelRequest = reservationWithPaymentService.removeReservationWithPayment(
|
||||||
reservationResponse.id(), member.getId());
|
reservationResponse.id(), member.getId());
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(paymentCancelRequest.cancelReason()).isEqualTo("고객 요청");
|
assertThat(paymentCancelRequest.cancelReason).isEqualTo("고객 요청");
|
||||||
assertThat(reservationRepository.findById(reservationResponse.id())).isEmpty();
|
assertThat(reservationRepository.findById(reservationResponse.id())).isEmpty();
|
||||||
assertThat(paymentRepository.findByPaymentKey("payment-key")).isEmpty();
|
assertThat(paymentRepository.findByPaymentKey("payment-key")).isEmpty();
|
||||||
assertThat(canceledPaymentRepository.findByPaymentKey("payment-key")).isNotEmpty();
|
assertThat(canceledPaymentRepository.findByPaymentKey("payment-key")).isNotEmpty();
|
||||||
@ -115,7 +117,8 @@ class ReservationWithPaymentServiceTest {
|
|||||||
@DisplayName("결제 정보가 없으면 True를 반환한다.")
|
@DisplayName("결제 정보가 없으면 True를 반환한다.")
|
||||||
void isNotPaidReservation() {
|
void isNotPaidReservation() {
|
||||||
// given
|
// given
|
||||||
PaymentResponse paymentInfo = new PaymentResponse("payment-key", "order-id", OffsetDateTime.now(), 10000L);
|
PaymentApprove.Response paymentInfo = new PaymentApprove.Response("payment-key", "order-id",
|
||||||
|
OffsetDateTime.now(), 10000L);
|
||||||
LocalDateTime localDateTime = LocalDateTime.now().plusHours(1L);
|
LocalDateTime localDateTime = LocalDateTime.now().plusHours(1L);
|
||||||
LocalDate date = localDateTime.toLocalDate();
|
LocalDate date = localDateTime.toLocalDate();
|
||||||
ReservationTime time = reservationTimeRepository.save(new ReservationTime(localDateTime.toLocalTime()));
|
ReservationTime time = reservationTimeRepository.save(new ReservationTime(localDateTime.toLocalTime()));
|
||||||
@ -136,7 +139,8 @@ class ReservationWithPaymentServiceTest {
|
|||||||
@DisplayName("결제 정보가 있으면 False를 반환한다.")
|
@DisplayName("결제 정보가 있으면 False를 반환한다.")
|
||||||
void isPaidReservation() {
|
void isPaidReservation() {
|
||||||
// given
|
// given
|
||||||
PaymentResponse paymentInfo = new PaymentResponse("payment-key", "order-id", OffsetDateTime.now(), 10000L);
|
PaymentApprove.Response paymentInfo = new PaymentApprove.Response("payment-key", "order-id",
|
||||||
|
OffsetDateTime.now(), 10000L);
|
||||||
LocalDateTime localDateTime = LocalDateTime.now().plusDays(1L).withNano(0);
|
LocalDateTime localDateTime = LocalDateTime.now().plusDays(1L).withNano(0);
|
||||||
LocalDate date = localDateTime.toLocalDate();
|
LocalDate date = localDateTime.toLocalDate();
|
||||||
ReservationTime time = reservationTimeRepository.save(new ReservationTime(localDateTime.toLocalTime()));
|
ReservationTime time = reservationTimeRepository.save(new ReservationTime(localDateTime.toLocalTime()));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user