Commit 620ebde0 authored by Jiwon Yoon's avatar Jiwon Yoon
Browse files

무통장입금 수정

parent 2ff3fb7c
...@@ -55,7 +55,7 @@ function ListCard(props) { ...@@ -55,7 +55,7 @@ function ListCard(props) {
<Col sm={8} xs={6} className='p-1'><strong>{e.createdAt.substring(0, 10)}</strong></Col> <Col sm={8} xs={6} className='p-1'><strong>{e.createdAt.substring(0, 10)}</strong></Col>
<Col sm={3} xs={5} className='p-1'><li>결제정보 :</li></Col> <Col sm={3} xs={5} className='p-1'><li>결제정보 :</li></Col>
<Col sm={8} xs={6} className='p-1'><strong>{e.paymentWay}</strong>{e.paymentWay == 'Remittance' ? ( <Col sm={8} xs={6} className='p-1'><strong>{e.completeState}</strong>{e.completeState == 'Remittance' ? (
<> <>
<br /><strong>{e.paymentInfo.bank} / ~ {e.paymentInfo.deadline}</strong> <br /><strong>{e.paymentInfo.bank} / ~ {e.paymentInfo.deadline}</strong>
</> </>
......
...@@ -6,6 +6,7 @@ import axios from 'axios'; ...@@ -6,6 +6,7 @@ import axios from 'axios';
import { isAuthenticated } from '../utils/auth'; import { isAuthenticated } from '../utils/auth';
import catchErrors from '../utils/catchErrors'; import catchErrors from '../utils/catchErrors';
import { Container, Row, Col, Button, Form } from 'react-bootstrap'; import { Container, Row, Col, Button, Form } from 'react-bootstrap';
const paymentInfo = {}
function Payment({ match, location }) { function Payment({ match, location }) {
const [cart, setCart] = useState([]) const [cart, setCart] = useState([])
...@@ -20,7 +21,6 @@ function Payment({ match, location }) { ...@@ -20,7 +21,6 @@ function Payment({ match, location }) {
const [completeState, setCompleteState] = useState(false) const [completeState, setCompleteState] = useState(false)
const user = isAuthenticated() const user = isAuthenticated()
let history = useHistory(); let history = useHistory();
const preCart = []
useEffect(() => { useEffect(() => {
getUser() getUser()
...@@ -79,10 +79,18 @@ function Payment({ match, location }) { ...@@ -79,10 +79,18 @@ function Payment({ match, location }) {
function handleReceiverInfo(e) { function handleReceiverInfo(e) {
const { name, value } = e.target const { name, value } = e.target
console.log(name,value) console.log(name, value)
setOrder({ ...order, receiverInfo: { ...order.receiverInfo, [name]: value } }) setOrder({ ...order, receiverInfo: { ...order.receiverInfo, [name]: value } })
} }
function handlepaymentInfo(e) {
const { name, value } = e.target
// console.log(name, value)
paymentInfo[name] = value
console.log(paymentInfo)
// setOrder({ ...order, paymentInfo: { ...order.paymentInfo, [name]: value } })
}
function postClick() { function postClick() {
if (post.length !== 0) { if (post.length !== 0) {
setPost([]) setPost([])
...@@ -122,37 +130,33 @@ function Payment({ match, location }) { ...@@ -122,37 +130,33 @@ function Payment({ match, location }) {
}; };
function handleClick() { function handleClick() {
if (paymentWay.length !== 0) { const bankList = (
setCompleteState(false) <Row className="justify-content-md-center">
setPaymentWay([]) <Col md={6} className="border m-5 p-5">
} else { <Form>
const bankList = ( <Form.Group controlId="bank">
<Row className="justify-content-md-center"> <Form.Label>입금은행</Form.Label>
<Col md={6} className="border m-5 p-5"> <Form.Control as="select" name="bank" onChange={handlepaymentInfo}>
<Form> <option value=''>입금은행을 선택하세요.</option>
<Form.Group controlId="bank"> <option value="농협 / 352-0559-2528-83 / 김수빈">농협 / 352-0559-2528-83 / 김수빈</option>
<Form.Label>입금은행</Form.Label> <option value="우리은행 / 0000-000-000000 / 이재연">우리은행 / 0000-000-000000 / 이재연</option>
<Form.Control as="select" name="bank" onChange={handleReceiverInfo}> <option value="국민은행 / 111111-11-111111 / 윤대기">국민은행 / 111111-11-111111 / 윤대기</option>
<option value=''>입금은행을 선택하세요.</option> </Form.Control>
<option value="농협">농협 / 352-0559-2528-83 / 김수빈</option> </Form.Group>
<option value="우리은행">우리은행 / 0000-000-000000 / 이재연</option> <Form.Group controlId="depositor">
<option value="국민은행">국민은행 / 111111-11-111111 / 윤대기</option> <Form.Label>입금자</Form.Label>
</Form.Control> <Form.Control type="text" name="depositor" onChange={handlepaymentInfo} />
</Form.Group> </Form.Group>
<Form.Group controlId="depositor"> <Form.Group controlId="deadline">
<Form.Label>입금자</Form.Label> <Form.Label>입금예정일</Form.Label>
<Form.Control type="text" name="depositor" onChange={handleReceiverInfo} /> <Form.Control type="date" name="deadline" onChange={handlepaymentInfo} />
</Form.Group> </Form.Group>
<Form.Group controlId="deadline"> </Form>
<Form.Label>입금예정일</Form.Label> </Col>
<Form.Control type="date" name="deadline" onChange={handleReceiverInfo} /> </Row>)
</Form.Group> setCompleteState("Remittance")
</Form> setPaymentWay(bankList)
</Col>
</Row>)
setCompleteState("Remittance")
setPaymentWay(bankList)
}
} }
async function kakaopay() { async function kakaopay() {
...@@ -163,66 +167,91 @@ function Payment({ match, location }) { ...@@ -163,66 +167,91 @@ function Payment({ match, location }) {
<p>주문하기를 눌러 결제를 이어가주세요.</p> <p>주문하기를 눌러 결제를 이어가주세요.</p>
</div> </div>
) )
// setOrder({ ...order, paymentInfo: { bank: "kakaopay" }})
} }
async function paymentCompleted() { async function paymentCompleted() {
console.log(paymentInfo)
console.log(completeState)
const cartIds = [] const cartIds = []
order.products.map((el) => { order.products.map((el) => {
cartIds.push(el._id) cartIds.push(el._id)
}) })
// try { try {
// setError('') setError('')
// const response = await axios.post(`/api/order/addorder`, { if (completeState === "kakaopay") {
// userId: user, let itemNames = ""
// ...order, if (cart.length > 1) {
// paymentWay: completeState, itemNames = cart[0].productId.pro_name + '' + String(cart.length - 1) + ''
// total: finalPrice + 2500 } else {
// }) itemNames = cart[0].productId.pro_name
// const response2 = await axios.post(`/api/cart/deletecart2`, { }
// userId: user, setError('')
// cartId: cartIds const response = await fetch('/api/kakaopay/test/single', {
// }) method: "POST",
// const response3 = await axios.post(`/api/product/pluspurchase`, { headers: {
// products: order.products 'Content-type': 'application/json'
// }) },
// if (completeState === "kakaopay") { body: JSON.stringify({
// let itemNames = "" cid: 'TC0ONETIME',
// if (cart.length > 1) { partner_order_id: 'partner_order_id',
// itemNames = cart[0].productId.pro_name + ' 외 ' + String(cart.length - 1) + '개' partner_user_id: user,
// } else { item_name: itemNames,
// itemNames = cart[0].productId.pro_name quantity: cart.length,
// } total_amount: finalPrice + 2500,
// setError('') vat_amount: 200,
// const response = await fetch('/api/kakaopay/test/single', { tax_free_amount: 0,
// method: "POST", approval_url: 'http://localhost:3000/paymentcompleted',
// headers: { fail_url: 'http://localhost:3000/shoppingcart',
// 'Content-type': 'application/json' cancel_url: 'http://localhost:3000/shoppingcart',
// }, })
// body: JSON.stringify({ })
// cid: 'TC0ONETIME', const data = await response.json()
// partner_order_id: 'partner_order_id', const response1 = await axios.post(`/api/order/addorder`, {
// partner_user_id: user, userId: user,
// item_name: itemNames, ...order,
// quantity: cart.length, completeState,
// total_amount: finalPrice + 2500, total: finalPrice + 2500
// vat_amount: 200, })
// tax_free_amount: 0, const response2 = await axios.post(`/api/cart/deletecart2`, {
// approval_url: 'http://localhost:3000/paymentcompleted', userId: user,
// fail_url: 'http://localhost:3000/shoppingcart', cartId: cartIds
// cancel_url: 'http://localhost:3000/shoppingcart', })
// }) const response3 = await axios.post(`/api/product/pluspurchase`, {
// }) products: order.products
// const data = await response.json() })
// window.location.href = data.redirect_url if (response1 && response2 && response3) {
// } else { window.location.href = data.redirect_url
// alert("주문이 완료되었습니다.") }
// history.push('/paymentcompleted') } else if(completeState === "Remittance"){
// } const response1 = await axios.post(`/api/order/addorder`, {
// } catch (error) { userId: user,
// catchErrors(error, setError) ...order,
// alert("주문에 실패하셨습니다. 다시 확인해주세요.") paymentInfo,
// window.location.reload() completeState,
// } total: finalPrice + 2500
})
const response2 = await axios.post(`/api/cart/deletecart2`, {
userId: user,
cartId: cartIds
})
const response3 = await axios.post(`/api/product/pluspurchase`, {
products: order.products
})
if (response1 && response2 && response3) {
alert("주문이 완료되었습니다.")
history.push('/paymentcompleted')
} else {
alert("주문에 실패하셨습니다. 다시 확인해주세요.")
}
} else {
alert("completeState없음")
}
} catch (error) {
catchErrors(error, setError)
alert("주문에 실패하셨습니다. 정보가 모두 입력되었는지 다시 확인해주세요.")
window.location.reload()
}
} }
if (error) { if (error) {
...@@ -232,7 +261,7 @@ function Payment({ match, location }) { ...@@ -232,7 +261,7 @@ function Payment({ match, location }) {
return ( return (
<Container className="mb-5"> <Container className="mb-5">
{console.log("order=",order)} {console.log("order=", order)}
<h3 className="my-5 font-weight-bold text-center">주문/결제</h3> <h3 className="my-5 font-weight-bold text-center">주문/결제</h3>
<div> <div>
<h5 className="font-weight-bold py-3 border-top border-bottom text-center" style={{ background: '#F7F3F3' }}>주문자 정보</h5> <h5 className="font-weight-bold py-3 border-top border-bottom text-center" style={{ background: '#F7F3F3' }}>주문자 정보</h5>
...@@ -313,9 +342,32 @@ function Payment({ match, location }) { ...@@ -313,9 +342,32 @@ function Payment({ match, location }) {
<div> <div>
<h5 className="font-weight-bold py-3 border-top border-bottom text-center" style={{ background: '#F7F3F3' }}>결제수단</h5> <h5 className="font-weight-bold py-3 border-top border-bottom text-center" style={{ background: '#F7F3F3' }}>결제수단</h5>
<div className="text-center m-3"> <div className="text-center m-3">
<Button className="align-top m-1" variant="success" onClick={handleClick} style={{ height: '42px' }}>무통장입금</Button> <Button className="align-top m-1" variant="success" type="button" onClick={handleClick} style={{ height: '42px' }}>무통장입금</Button>
<Button className="align-top m-1 p-0" style={{ borderColor: "#ffeb00" }} type="button" onClick={kakaopay} alt="카카오페이"><img src="icon/payment_icon_yellow_small2.png" /></Button> <Button className="align-top m-1 p-0" style={{ borderColor: "#ffeb00" }} type="button" onClick={kakaopay} alt="카카오페이"><img src="icon/payment_icon_yellow_small2.png" /></Button>
</div> </div>
{/* <Row className="justify-content-md-center">
<Col md={6} className="border m-5 p-5">
<Form>
<Form.Group controlId="bank">
<Form.Label>입금은행</Form.Label>
<Form.Control as="select" name="bank" onChange={handlepaymentInfo}>
<option value=''>입금은행을 선택하세요.</option>
<option value="농협 / 352-0559-2528-83 / 김수빈">농협 / 352-0559-2528-83 / 김수빈</option>
<option value="우리은행 / 0000-000-000000 / 이재연">우리은행 / 0000-000-000000 / 이재연</option>
<option value="국민은행 / 111111-11-111111 / 윤대기">국민은행 / 111111-11-111111 / 윤대기</option>
</Form.Control>
</Form.Group>
<Form.Group controlId="depositor">
<Form.Label>입금자</Form.Label>
<Form.Control type="text" name="depositor" onChange={handlepaymentInfo} />
</Form.Group>
<Form.Group controlId="deadline">
<Form.Label>입금예정일</Form.Label>
<Form.Control type="date" name="deadline" onChange={handlepaymentInfo} />
</Form.Group>
</Form>
</Col>
</Row> */}
{paymentWay} {paymentWay}
</div> </div>
<div className="text-center"> <div className="text-center">
......
...@@ -4,26 +4,37 @@ import User from "../schemas/User.js"; ...@@ -4,26 +4,37 @@ import User from "../schemas/User.js";
import Product from "../schemas/Product.js"; import Product from "../schemas/Product.js";
const addorder = async (req, res) => { const addorder = async (req, res) => {
const { userId, products, receiverInfo, paymentWay, total } = req.body const { userId, products, receiverInfo, completeState, paymentInfo, total } = req.body
console.log("pay=",paymentWay) console.log("paymentInfo=", paymentInfo)
console.log(receiverInfo.bank , receiverInfo.depositor , receiverInfo.deadline) console.log("receiverInfo=", receiverInfo)
// console.log(receiverInfo.bank, receiverInfo.depositor, receiverInfo.deadline)
try { try {
// if (!/^[0-9]{2,3}-[0-9]{3,4}-[0-9]{4}/.test(receiverInfo.tel)) {
// return res.status(422).send('유효한 휴대전화번호가 아닙니다. 정확히 입력해주세요.')
// } else if (paymentWay) {
// if (paymentWay == 'Remittance') {
// if (!(receiverInfo.bank && receiverInfo.depositor && receiverInfo.deadline)) {
// return res.status(422).send('선택하신 결제 수단에 관한 모든 정보를 입력해주시기 바랍니다.')
// }
// const paymentInfo = { bank: receiverInfo.bank, depositor: receiverInfo.depositor, deadline: receiverInfo.deadline }
// const newOrder = await new Order({ userId, products, receiverInfo, paymentWay, paymentInfo, total }).save()
// res.status(200).send('Order DB에 저장 완료')
// } else {
// const newOrder = await new Order({ userId, products, receiverInfo, paymentWay, total }).save()
// res.status(200).send('Order DB에 저장 완료')
// }
// } else {
// return res.status(422).send('결제수단을 선택해주시기 바랍니다.')
// }
if (!/^[0-9]{2,3}-[0-9]{3,4}-[0-9]{4}/.test(receiverInfo.tel)) { if (!/^[0-9]{2,3}-[0-9]{3,4}-[0-9]{4}/.test(receiverInfo.tel)) {
return res.status(422).send('유효한 휴대전화번호가 아닙니다. 정확히 입력해주세요.') return res.status(422).send('유효한 휴대전화번호가 아닙니다. 정확히 입력해주세요.')
} else if (paymentWay) { } else if (completeState === "kakaopay") {
if (paymentWay == 'Remittance') { const paymentInfo = { bank: "kakaopay", depositor: "none", deadline: "none" }
if (!(receiverInfo.bank && receiverInfo.depositor && receiverInfo.deadline)) { const newOrder = await new Order({ userId, products, completeState, receiverInfo, paymentInfo, total }).save()
return res.status(422).send('선택하신 결제 수단에 관한 모든 정보를 입력해주시기 바랍니다.') res.status(200).send('Order DB에 저장 완료')
}
const paymentInfo = { bank: receiverInfo.bank, depositor: receiverInfo.depositor, deadline: receiverInfo.deadline }
const newOrder = await new Order({ userId, products, receiverInfo, paymentWay, paymentInfo, total }).save()
res.status(200).send('Order DB에 저장 완료')
} else {
const newOrder = await new Order({ userId, products, receiverInfo, paymentWay, total }).save()
res.status(200).send('Order DB에 저장 완료')
}
} else { } else {
return res.status(422).send('결제수단을 선택해주시기 바랍니다.') const newOrder = await new Order({ userId, products,completeState, receiverInfo, paymentInfo, total }).save()
res.status(200).send('Order DB에 저장 완료')
} }
} catch (error) { } catch (error) {
console.log(error) console.log(error)
......
...@@ -53,19 +53,22 @@ const OrderSchema = new mongoose.Schema({ ...@@ -53,19 +53,22 @@ const OrderSchema = new mongoose.Schema({
required: true required: true
} }
}, },
paymentWay: { completeState: {
type: String, type: String,
required: true required: true
}, },
paymentInfo: { paymentInfo: {
bank: { bank: {
type: String type: String,
required: true
}, },
depositor: { depositor: {
type: String type: String,
required: true
}, },
deadline: { deadline: {
type: String type: String,
required: true
} }
}, },
total: { total: {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment