Skip to content

Commit

Permalink
Merge pull request #30 from Spaces-Place/dusqo
Browse files Browse the repository at this point in the history
payment오류 수정중
  • Loading branch information
KangYeonbae authored Dec 2, 2024
2 parents f2a6024 + 3773933 commit 37f5f4e
Showing 1 changed file with 40 additions and 21 deletions.
61 changes: 40 additions & 21 deletions src/utils/paymentService.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,47 @@ if (!PAYMENT_API_URL) {
}

export const initiateKakaoPayment = async (bookingData, totalPrice, spaceId) => {
try {
const response = await axios.post(`${PAYMENT_API_URL}/kakao`, {
space_id: spaceId,
use_date: bookingData.date,
start_time: bookingData.startTime,
end_time: bookingData.endTime
}, {
headers: {
'Authorization': `Bearer ${localStorage.getItem('token')}`,
'Content-Type': 'application/json'
}
});
// API URL 확인을 위한 로깅 추가
const url = `${process.env.REACT_APP_PYMENTS_API}/kakao`;
console.log('Payment API URL:', url);
const token = localStorage.getItem('token');
if (!token) {
throw new Error('로그인이 필요합니다.');
}

try {
const response = await axios.post(url, {
space_id: spaceId,
use_date: bookingData.date,
start_time: bookingData.startTime,
end_time: bookingData.endTime
}, {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
// CORS 이슈 디버깅을 위한 설정
withCredentials: true
});

if (response.data.next_redirect_pc_url) {
window.location.href = response.data.next_redirect_pc_url;
}

return response.data;
} catch (error) {
console.error('Payment initiation failed:', error.response?.data || error.message);
throw error;
}
if (response.data.next_redirect_pc_url) {
window.location.href = response.data.next_redirect_pc_url;
}

return response.data;
} catch (error) {
if (error.response?.status === 401) {
throw new Error('로그인이 만료되었습니다. 다시 로그인해주세요.');
}
// 자세한 에러 정보 로깅
console.error('Payment Error:', {

status: error.response?.status,
data: error.response?.data,
config: error.config
});
throw error;
}
};

export const handlePaymentResult = async (searchParams) => {
Expand Down

0 comments on commit 37f5f4e

Please sign in to comment.