Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] 토스페이 결제 기능 구현 #19

Merged
merged 9 commits into from
Mar 3, 2024
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@

# misc
.DS_Store
.env.local
.env.development.local
.env.production
.env.development
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
Expand Down
117 changes: 112 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
"@material-tailwind/react": "^2.1.9",
"@stomp/stompjs": "^7.0.0",
"@toast-ui/react-editor": "^3.2.3",
"@tosspayments/payment-widget-sdk": "^0.10.2",
"axios": "^1.6.7",
"chart.js": "^4.4.2",
"flowbite": "^2.3.0",
"flowbite-datepicker": "^1.2.6",
"http-proxy-middleware": "^2.0.6",
"nanoid": "^5.0.6",
"react": "^17.0.2",
"react-chartjs-2": "^5.2.0",
"react-dom": "^17.0.2",
Expand Down
27 changes: 27 additions & 0 deletions src/api/communityApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import GetTokenFromLocalStorage from "./Common/token";
import axios from "axios";
import userInstance from "./userBaseApi";

const Token = GetTokenFromLocalStorage('user')
if (Token) {
axios.defaults.headers.common['Authorization'] = `Bearer ${Token}`
}

/**
* @since 2024.03.03
* @author 김유빈
*/
const CommunityApi = {

/**
* 나의 커뮤니티 게시글 리스트 조회
*
* @since 2024.03.03
* @author 김유빈
*/
getMyCommunities: async (pageNo = 0, amount = 5) => {
return await userInstance.get(`/communities?type=me&pageNo=${pageNo}&amount=${amount}`)
},
}

export default CommunityApi;
45 changes: 45 additions & 0 deletions src/api/paymentApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import axios from "axios";
import Token from "./Common/token";
import userInstance from "./userBaseApi";

if (Token) {
axios.defaults.headers.common['Authorization'] = `Bearer ${Token}`
}

/**
* @since 2024.02.29
* @author 김유빈
*/
const PaymentApi = {

/**
* 구매자 정보 조회
*
* @since 2024.03.02
* @author 김유빈
*/
getBuyer: async () => {
return await userInstance.get(`/ad/users`)
},

/**
* 토스페이 결제 승인 요청
*
* @since 2024.02.29
* @author 김유빈
*/
confirmTossPay: async (data, file = null) => {
const formData = new FormData()
formData.append("data", new Blob([JSON.stringify(data)]), {
type: "application/json;charset=UTF-8"
})
formData.append("file", file)
return await userInstance.post(`/payments/toss/confirm`, formData, {
headers: {
"Content-Type": "multipart/form-data",
},
})
},
};

export default PaymentApi;
7 changes: 4 additions & 3 deletions src/api/planApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ const PlanApi = {
* @since 2024.02.27
* @author 김유빈
*/
save: async (data) => {
save: async (data, file = null) => {
const formData = new FormData()
formData.append("data", new Blob([JSON.stringify(data)], {
formData.append("data", new Blob([JSON.stringify(data)]), {
type: "application/json"
}))
})
formData.append("file", file)
return await axios.post(`/api/v1/plans`, formData, {
"Content-Type": `multipart/form-data`,
})
Expand Down
13 changes: 13 additions & 0 deletions src/api/popupApi.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import GetTokenFromLocalStorage from "./Common/token";
import axios from "axios";
import userInstance from "./userBaseApi";

const Token = GetTokenFromLocalStorage('user')
if (Token) {
Expand All @@ -11,6 +12,7 @@ if (Token) {
* @author 이상민
*/
const PopupApi = {

/**
* 나의 사업계획서에 따른 팝업 조회
*
Expand All @@ -20,6 +22,7 @@ const PopupApi = {
findByPlanId: async (planId = 0) => {
return await axios.get(`/api/v1/plans/${planId}/popup`)
},

/**
* 나의 사업계획서에 따른 팝업 조회
*
Expand All @@ -33,6 +36,16 @@ const PopupApi = {
const response = await axios.post(`/api/v1/popups`, formData);
return response.data;
},

/**
* 나의 팝업스토어 게시글 리스트 조회
*
* @since 2024.03.03
* @author 김유빈
*/
getMyPopups: async (pageNo = 0, amount = 5) => {
return await userInstance.get(`/popups?sort=me&pageNo=${pageNo}&amount=${amount}`)
},
}

export default PopupApi;
47 changes: 47 additions & 0 deletions src/components/business/BuyerContentBox/BuyerContentBox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import InputText from "../../common/Input/InputText";
import ContentBox from "../../common/ContentBox/ContentBox";
import React, {useEffect, useState} from "react";
import PaymentApi from "../../../api/paymentApi";

/**
* BuyerContentBox 컴포넌트 제작
*
* @since 2024.03.02
* @author 김유빈
*/
function BuyerContentBox() {
const [buyer, setBuyer] = useState({})
useEffect(() => {
const fetchData = async () => {
try {
const response = await PaymentApi.getBuyer()
const data = response.data.data
const buyer = {
id: data.id,
nickname: data.nickname,
email: data.email,
businessRegistrationNumber: data.businessRegistrationNumber,
connectedNumber: data.connectedNumber,
}
setBuyer(buyer)
} catch (error) {
console.error("주문자 데이터를 가져오는 중 오류 발생: ", error)
}
}
fetchData()
}, [])
return (
<ContentBox
title="주문자 정보"
content={
<>
<InputText title="주문자" value={buyer.nickname} disabled="true"/>
<InputText title="연락처" value={buyer.connectedNumber} disabled="true"/>
<InputText title="이메일" value={buyer.email} disabled="true"/>
<InputText title="사업자 등록번호" value={buyer.businessRegistrationNumber} disabled="true"/>
</>
}/>
)
}

export default BuyerContentBox;
19 changes: 19 additions & 0 deletions src/components/business/SelectedAdPost/SelectedAdPost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import CheckedPostTable from "../../common/Table/CheckedPostTable";
import ContentBox from "../../common/ContentBox/ContentBox";
import React from "react";

/**
* @since 2024.03.03
* @author 김유빈
*/
function SelectedAdPost({posts}) {
return (
<>
<ContentBox
title="게시글 선택"
content={<CheckedPostTable posts={posts}/>}/>
</>
)
}

export default SelectedAdPost;
Loading