Skip to content

Commit

Permalink
Merge pull request #82 from URECA-PODONG/feat/#6
Browse files Browse the repository at this point in the history
Feat/#6 : 결제 완료 수정
  • Loading branch information
Suh-code authored Nov 6, 2024
2 parents c5ee2d4 + 0b528cd commit 24f5401
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/pages/PaymentPage/CancelPay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { useParams, useNavigate } from "react-router-dom";

const CancelPay = () => {
const [userId, setUserId] = useState(null);
const [merchantId, setMerchantId] = useState(null);
const [impUid, setImpUid] = useState(null);
const [payAmount, setPayAmount] = useState(null);
const { orderId } = useParams();
const navigate = useNavigate();


// 페이지가 렌더링되면 userId를 받아옴
useEffect(() => {
Expand All @@ -35,14 +36,12 @@ const CancelPay = () => {
const response = await axios.get(`${import.meta.env.VITE_BASE_URL}/payment/list/${userId}`);
const paymentData = response.data;

// console.log("Fetched Payment Data:", paymentData);
console.log("Fetched Payment Data:", paymentData);

if (paymentData.length > 0 && paymentData[0].impUid) {
setImpUid(paymentData[0].impUid);
setPayAmount(paymentData[0].pay_amount);

// impUid 설정 후 handleCancel 호출
handleCancel(paymentData[0].impUid, paymentData[0].pay_amount);
setMerchantId(paymentData[0].merchantId);
setPayAmount(paymentData[0].payAmount);
} else {
console.error("impUid를 찾을 수 없습니다.");
alert("impUid를 찾을 수 없습니다.");
Expand All @@ -53,6 +52,13 @@ const CancelPay = () => {
}
};

useEffect(() => {
if (impUid && payAmount) {
handleCancel(impUid, payAmount);
}
}, [impUid, payAmount]);


// 결제 취소 요청 핸들링
const handleCancel = async (impUid, payAmount) => {
if (!impUid) return;
Expand Down Expand Up @@ -99,6 +105,14 @@ const CancelPay = () => {
);
console.log("결제 취소 완료:", response.data);
alert("결제가 취소되었습니다.");
console.log(merchantId, impUid);
await axios.get(`${import.meta.env.VITE_BASE_URL}/payment/cancel`, {
params:{
id : merchantId,
iamUid : impUid,
}
});

navigate(`/paymentCancelDone/${orderId}`);

} catch (error) {
Expand Down
4 changes: 4 additions & 0 deletions src/pages/PaymentPage/PaymentCancelDone.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ const PaymentCancelDone = () => {
<PaymentDetailsContainer>
{payment && (
<>
<PaymentDetailRow>
<PaymentDetailTitle>결제 상태 :</PaymentDetailTitle>
<PaymentDetailValue>{payment.payStatus}</PaymentDetailValue>
</PaymentDetailRow>
<PaymentDetailRow>
<PaymentDetailTitle>주문 날짜 :</PaymentDetailTitle>
<PaymentDetailValue>{new Date(payment.createdAt).toLocaleString()}</PaymentDetailValue>
Expand Down

0 comments on commit 24f5401

Please sign in to comment.