diff --git a/src/api/errorMessage.ts b/src/api/errorMessage.ts index 8749aeb..688a33d 100644 --- a/src/api/errorMessage.ts +++ b/src/api/errorMessage.ts @@ -45,12 +45,6 @@ const specificMessages: Record< 409: "이미 완료되었거나 처리할 수 없는 상태의 결제입니다.", }, }, - "/payments/status": { - GET: { - 404: "사용자 정보를 찾을 수 없습니다.", - }, - }, - // --- 쿠폰 (Coupons) --- "/coupons/code": { POST: { diff --git a/src/pages/Payment/Payment.Api.ts b/src/pages/Payment/Payment.Api.ts index 7c8d651..8720986 100644 --- a/src/pages/Payment/Payment.Api.ts +++ b/src/pages/Payment/Payment.Api.ts @@ -21,7 +21,7 @@ export const makePayment = async (selectedCoupons: number[]) => { }; interface PaymentPollingResult { - status: string; + status: "NOT_CREATED" | "PENDING" | "COMPLETED"; finalPrice: number; } diff --git a/src/pages/Payment/usePaymentPolling.ts b/src/pages/Payment/usePaymentPolling.ts index a1eb12f..233c70d 100644 --- a/src/pages/Payment/usePaymentPolling.ts +++ b/src/pages/Payment/usePaymentPolling.ts @@ -88,11 +88,23 @@ export const usePaymentPolling = () => { // 결제 생성 및 폴링 시작 로직 const initializePayment = async () => { try { - await makePayment([]); + const paymentStatus = await pollPaymentStatus(); + setFinalPrice(paymentStatus.finalPrice); + + if (paymentStatus.status === "COMPLETED") { + setStatus("success"); + return; + } + if (paymentStatus.status === "PENDING") { + startPolling(); + return; + } + + await makePayment([]); startPolling(); } catch (error) { - // 409 에러는 이미 결제가 생성된 경우이므로, 정상적으로 폴링을 시작합니다. + // 409 에러는 상태 조회 이후 동시 요청으로 이미 결제가 생성된 경우이므로 정상적으로 폴링을 시작합니다. if (error instanceof ServerError && error.status === 409) { startPolling(); } else {