import axios from 'axios'; import React, { useState, useEffect, useRef } from 'react'; import DaumPostcode from "react-daum-postcode"; import { Container, Card, Row, Col, Button, Form, FormGroup } from 'react-bootstrap'; import { Redirect } from 'react-router-dom'; import PaymentCard from '../Components/PaymentCard'; import { isAuthenticated } from '../utils/auth'; import catchErrors from '../utils/catchErrors'; function Payment({ match, location }) { const [cart, setCart] = useState(location.state) const [order, setOrder] = useState({products: location.state}) const [userData, setUserData] = useState({}) const [error, setError] = useState() const [paymentWay, setPaymentWay] = useState([]) // const [isAddress, setIsAddress] = useState(""); // const [isZoneCode, setIsZoneCode] = useState(); // const [isPostOpen, setIsPostOpen] = useState(); const [post, setPost] = useState([]) const [redirect, setRedirect] = useState(null) const [address, setAddress] = useState("") const [finalPrice, setFinalPrice] = useState(0) const [num, setNum] = useState(0) const user = isAuthenticated() useEffect(() => { getUser() let price = 0 cart.map((el) => { price = Number(el.count) * Number(el.productId.price) + price }) setFinalPrice(price) }, [user]) async function getUser() { try { const response = await axios.get(`/api/users/getuser/${user}`) console.log(response.data) setUserData(response.data) } catch (error) { catchErrors(error, setError) } } function handleReceiverInfo(e) { const { name, value } = e.target console.log(name,value) setOrder({ ...order, receiverInfo: {...order.receiverInfo, [name]: value } }) } function postClick() { if (post.length !== 0) { setPost([]) } else { setPost(
) } } const handleComplete = (data) => { let fullAddress = data.address; let extraAddress = ""; console.log(data) if (data.addressType === "R") { if (data.bname !== "") { extraAddress += data.bname; console.log(extraAddress) } if (data.buildingName !== "") { extraAddress += extraAddress !== "" ? `, ${data.buildingName}` : data.buildingName; } fullAddress += extraAddress !== "" ? ` (${extraAddress})` : ""; } setAddress({ full: fullAddress, code: data.zonecode }); setOrder({ ...order, receiverInfo: {...order.receiverInfo, address: fullAddress, postalCode: data.zonecode } }) console.log(fullAddress); } const postCodeStyle = { // display: "block", position: "absolute", width: "400px", height: "500px", padding: "7px", zIndex: "1000" }; function handleClick() { if (paymentWay.length !== 0) { setPaymentWay([]) } else { const a = (
입금은행 입금자 입금예정일
) setPaymentWay(a) } } async function kakaopay() { const response = await fetch('/api/kakaopay/test/single', { method: "POST", headers: { 'Content-type': 'application/json' }, body: JSON.stringify({ cid: 'TC0ONETIME', partner_order_id: 'partner_order_id', partner_user_id: 'partner_user_id', item_name: '앙고라 반목 폴라 베이직 모헤어 니트 (T)', quantity: 1, total_amount: 22000, vat_amount: 200, tax_free_amount: 0, approval_url: 'http://localhost:3000/account', fail_url: 'http://localhost:3000/shoppingcart', cancel_url: 'http://localhost:3000/kakaopay/payment', }) }) const data = await response.json() console.log(data) window.location.href = data.redirect_url // setRedirect(data.redirect_url) } async function paymentCompleted(){ console.log(user) console.log(order) console.log(finalPrice) try { const response = await axios.post(`/api/order/addorder`, { userId : user, ...order, total : finalPrice+2500 }) console.log(response.data) } catch (error) { catchErrors(error, setError) } } if (redirect) { console.log(redirect) return } return (
{/* {console.log(order)} */}

주문/결제

주문자 정보
이름 휴대전화 이메일
받는사람 정보
이름 휴대전화 주소 {post} 상세 주소를 입력하세요.
주문상품정보
  • 총 상품금액 {finalPrice}원
  • 배송비 2500원
결제금액{finalPrice + 2500}원
결제수단
{paymentWay}
) } export default Payment