Skip to content

Commit

Permalink
Merge pull request #47 from Spaces-Place/dusqo
Browse files Browse the repository at this point in the history
팝업창후 예약요청 수정중
  • Loading branch information
KangYeonbae authored Dec 4, 2024
2 parents 4f2d796 + 1b3064d commit 2f23f9d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
13 changes: 7 additions & 6 deletions src/pages/PaymentApproval.js
Original file line number Diff line number Diff line change
@@ -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 (
<div className="payment-approval">
Expand Down
21 changes: 14 additions & 7 deletions src/utils/paymentService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '결제 승인 중 오류가 발생했습니다.'
};
}
};
Expand Down

0 comments on commit 2f23f9d

Please sign in to comment.