Skip to content

Commit

Permalink
Feat: 포인트 결제 및 0원 결제 연동
Browse files Browse the repository at this point in the history
  • Loading branch information
KKangHHee committed Feb 27, 2024
1 parent fc243bb commit 7509003
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions src/hooks/useRequestPayment.jsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import axios from "axios";
import useRequestZoreCostPayment from "./useRequestPaymentZeroCost";

const apiRoot = process.env.REACT_APP_API_ROOT;
const apiVer = "api/v1";
const apiUrl = `${apiRoot}/${apiVer}/order/toss`;

const useRequestPayment = () => {
const requestZoreCostPayment = useRequestZoreCostPayment();
const requestPayment = async (cartId, couponId, paymentWidget) => {
const requestPayment = async (cartId, couponId, paymentWidget, point) => {
try {
const body = { cartId, couponId };
const body = { cartId, couponId, point };
const response = await axios.post(apiUrl, body, {
withCredentials: true,
});

if (response.data.amount <= 0) {
const orderIds = response.data.orderId;
const amounts = response.data.amount;
requestZoreCostPayment({ orderId: orderIds, amount: amounts });
window.location.href =
response.data.successUrl +
`?paymentType=NORMAL&orderId=${response.data.orderId}&paymentKey=membership&amount=${response.data.amount}`;
return;
}
paymentWidget?.requestPayment(response.data);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/PaymentPage/PaymentPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const PaymentPage = () => {
const point = useGetPoint();
const paymentRequest = () => {
const paymentWidget = paymentWidgetRef.current;
requestPayment(cartId, couponId, paymentWidget);
requestPayment(cartId, couponId, paymentWidget, usedPoint);
};
const handleSetPoint = () => {
if (usedPoint !== 0) {
Expand Down

0 comments on commit 7509003

Please sign in to comment.