Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.GetMapping;

@Tag(name = "Payment", description = "결제 관련 API")
@RestController
Expand All @@ -35,4 +38,30 @@ public ApiResponse<PaymentResponseDTO.PaymentRequestResultDTO> confirmPayment(
@RequestBody @Valid PaymentConfirmDTO dto) {
return ApiResponse.onSuccess(paymentService.confirmPayment(dto));
}

@Operation(summary = "결제 취소", description = "결제 키를 받아 결제를 취소합니다.")
@PostMapping("/{paymentKey}/cancel")
public ApiResponse<PaymentResponseDTO.CancelPaymentResultDTO> cancelPayment(
@PathVariable String paymentKey,
@RequestBody @Valid PaymentRequestDTO.CancelPaymentDTO dto) {
return ApiResponse.onSuccess(paymentService.cancelPayment(paymentKey, dto));
}

@Operation(summary = "결제 내역 조회", description = "로그인한 사용자의 결제 내역을 조회합니다.")
@GetMapping
public ApiResponse<PaymentResponseDTO.PaymentListResponseDTO> getPaymentList(
@RequestParam(name = "userId", required = false, defaultValue = "1") Long userId,
@RequestParam(name = "page", defaultValue = "1") Integer page,
@RequestParam(name = "limit", defaultValue = "10") Integer limit,
@RequestParam(name = "status", required = false) String status) {
// TODO: userId는 추후 Security Context에서 가져오도록 수정
return ApiResponse.onSuccess(paymentService.getPaymentList(userId, page, limit, status));
}

@Operation(summary = "결제 상세 조회", description = "특정 결제 건의 상세 내역을 조회합니다.")
@GetMapping("/{paymentId}")
public ApiResponse<PaymentResponseDTO.PaymentDetailResultDTO> getPaymentDetail(
@PathVariable Long paymentId) {
return ApiResponse.onSuccess(paymentService.getPaymentDetail(paymentId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

public class PaymentRequestDTO {

public record RequestPaymentDTO(
@NotNull Long bookingId) {
}
public record RequestPaymentDTO(
@NotNull Long bookingId) {
}

public record CancelPaymentDTO(
@NotNull String cancelReason) {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.eatsfine.eatsfine.domain.payment.enums.PaymentStatus;

import java.time.LocalDateTime;
import java.util.List;

public class PaymentResponseDTO {

Expand All @@ -14,4 +15,50 @@ public record PaymentRequestResultDTO(
Integer amount,
LocalDateTime requestedAt) {
}

public record CancelPaymentResultDTO(
Long paymentId,
String orderId,
String paymentKey,
String status,
LocalDateTime canceledAt) {
}

public record PaymentHistoryResultDTO(
Long paymentId,
Long bookingId,
String restaurantName,
Integer amount,
String paymentType,
String paymentMethod,
String paymentProvider,
String status,
LocalDateTime approvedAt) {
}

public record PaymentListResponseDTO(
List<PaymentHistoryResultDTO> payments,
PaginationDTO pagination) {
}

public record PaginationDTO(
Integer currentPage,
Integer totalPages,
Long totalCount) {
}

public record PaymentDetailResultDTO(
Long paymentId,
Long bookingId,
String restaurantName,
String paymentMethod,
String paymentProvider,
Integer amount,
String paymentType,
String status,
LocalDateTime requestedAt,
LocalDateTime approvedAt,
String receiptUrl,
String refundInfo) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ public record TossPaymentResponse(
String lastTransactionKey,
Integer suppliedAmount,
Integer vat,
EasyPay easyPay) {
EasyPay easyPay,
Receipt receipt) {

public record EasyPay(
String provider,
Integer amount,
Integer discountAmount) {
}

public record Receipt(
String url) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,28 @@ public class Payment extends BaseEntity {
@Column(name = "payment_type", nullable = false)
private PaymentType paymentType;

@Column(name = "receipt_url")
private String receiptUrl;

public void setPaymentKey(String paymentKey) {
this.paymentKey = paymentKey;
}

public void completePayment(LocalDateTime approvedAt, PaymentMethod method, String paymentKey,
PaymentProvider provider) {
PaymentProvider provider, String receiptUrl) {
this.paymentStatus = PaymentStatus.COMPLETED;
this.approvedAt = approvedAt;
this.paymentMethod = method;
this.paymentKey = paymentKey;
this.paymentProvider = provider;
this.receiptUrl = receiptUrl;
}

public void failPayment() {
this.paymentStatus = PaymentStatus.FAILED;
}

public void cancelPayment() {
this.paymentStatus = PaymentStatus.REFUNDED;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.eatsfine.eatsfine.domain.payment.exception;

import com.eatsfine.eatsfine.global.apiPayload.code.BaseErrorCode;
import com.eatsfine.eatsfine.global.apiPayload.exception.GeneralException;

public class PaymentException extends GeneralException {

public PaymentException(BaseErrorCode code) {
super(code);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
package com.eatsfine.eatsfine.domain.payment.repository;

import com.eatsfine.eatsfine.domain.payment.entity.Payment;
import com.eatsfine.eatsfine.domain.payment.enums.PaymentStatus;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface PaymentRepository extends JpaRepository<Payment, Long> {
Optional<Payment> findByOrderId(String orderId);

Optional<Payment> findByPaymentKey(String paymentKey);

Page<Payment> findAllByBooking_User_Id(Long userId, Pageable pageable);

Page<Payment> findAllByBooking_User_IdAndPaymentStatus(Long userId, PaymentStatus status, Pageable pageable);
}
Loading