diff --git a/src/pages/PaymentApproval.js b/src/pages/PaymentApproval.js
index 80ffc25..1afc126 100644
--- a/src/pages/PaymentApproval.js
+++ b/src/pages/PaymentApproval.js
@@ -1,22 +1,23 @@
// PaymentApproval.js
import { useEffect } from 'react';
-import { useSearchParams } from 'react-router-dom';
+import { useLocation } from 'react-router-dom';
const PaymentApproval = () => {
+ const location = useLocation();
+
useEffect(() => {
- // 부모 창으로 메시지 전송
if (window.opener) {
+ const currentUrl = `${window.location.origin}/api/v1/payments${location.pathname}${location.search}`;
window.opener.postMessage(
{
type: 'KAKAO_PAYMENT_SUCCESS',
- url: window.location.href
+ url: currentUrl
},
- '*'
+ window.location.origin
);
- // 팝업 창 닫기
window.close();
}
- }, []);
+ }, [location]);
return (
diff --git a/src/utils/paymentService.js b/src/utils/paymentService.js
index 36859c5..60fc4cd 100644
--- a/src/utils/paymentService.js
+++ b/src/utils/paymentService.js
@@ -77,27 +77,34 @@ export const handlePaymentApproval = async (orderNumber, pgToken) => {
}
try {
+ // URL 경로 수정
const response = await payment_api.get(
- `/kakao/approval`, {
+ '/kakao/approval', {
params: {
order_number: orderNumber,
pg_token: pgToken
},
headers: {
- 'Authorization': `Bearer ${token}`
+ 'Authorization': `Bearer ${token}`,
+ 'Content-Type': 'application/json'
}
}
);
- return {
- success: true,
- data: response.data
- };
+ // 성공 여부를 명확하게 확인
+ if (response.data) {
+ return {
+ success: true,
+ data: response.data
+ };
+ } else {
+ throw new Error('결제 승인에 실패했습니다.');
+ }
} catch (error) {
console.error('Payment approval error:', error);
return {
success: false,
- error: error.message
+ error: error.message || '결제 승인 중 오류가 발생했습니다.'
};
}
};