Date: Mon, 26 Feb 2024 14:54:57 +0900
Subject: [PATCH 3/6] =?UTF-8?q?Feat:=20=ED=8F=AC=EC=9D=B8=ED=8A=B8=20?=
=?UTF-8?q?=EA=B2=B0=EC=A0=9C=20=EC=97=B0=EA=B2=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/pages/PaymentPage/PaymentPage.jsx | 50 ++++++++++++++++++---------
1 file changed, 34 insertions(+), 16 deletions(-)
diff --git a/src/pages/PaymentPage/PaymentPage.jsx b/src/pages/PaymentPage/PaymentPage.jsx
index 1a1783e..e052ee3 100644
--- a/src/pages/PaymentPage/PaymentPage.jsx
+++ b/src/pages/PaymentPage/PaymentPage.jsx
@@ -1,12 +1,12 @@
import { loadPaymentWidget } from "@tosspayments/payment-widget-sdk";
-import React, { useEffect, useRef } from "react";
+import React, { useEffect, useRef, useState } from "react";
import { Link, useLocation } from "react-router-dom";
import Header from "../../components/views/Header/Header";
+import { IMAGES } from "../../constants/images";
import useFetchCartData from "../../hooks/useFetchCartData";
import useGetPoint from "../../hooks/useGetPoint";
import useRequestPayment from "../../hooks/useRequestPayment";
import "./PaymentPage.css";
-import { IMAGES } from "../../constants/images";
const clientKey = process.env.REACT_APP_TOSS_CLIENT_KEY;
const customerKey = "OSlBWOomTvjxwqJTcNtEB";
@@ -17,17 +17,29 @@ const PaymentPage = () => {
const cartId = params.get("cartId");
const couponId = location.state?.selectedCoupon ?? null;
const salePrice = location.state?.salePrice ?? 0;
+ const [usedPoint, setUsedPoint] = useState(0);
const paymentWidgetRef = useRef(null);
const paymentMethodsWidgetRef = useRef(null);
const { carts, edit, imgUrl, inOut, isOpened, name, storeId, totalPrice } =
useFetchCartData(cartId);
const requestPayment = useRequestPayment();
- const getPoint = useGetPoint();
+ const point = useGetPoint();
const paymentRequest = () => {
const paymentWidget = paymentWidgetRef.current;
requestPayment(cartId, couponId, paymentWidget);
};
-
+ const handleSetPoint = () => {
+ if (usedPoint !== 0) {
+ setUsedPoint(0);
+ return;
+ }
+ const MiddleSumPrice = totalPrice - salePrice;
+ if (MiddleSumPrice <= 0) {
+ setUsedPoint(0);
+ } else {
+ setUsedPoint(Math.min(point, MiddleSumPrice));
+ }
+ };
useEffect(() => {
(async () => {
// ------ 결제위젯 초기화 ------
@@ -41,7 +53,7 @@ const PaymentPage = () => {
// https://docs.tosspayments.com/reference/widget-sdk#renderpaymentmethods선택자-결제-금액-옵션
const paymentMethodsWidget = paymentWidget.renderPaymentMethods(
"#payment-page__payment-widget",
- { value: Math.max(totalPrice - salePrice, 0) },
+ { value: Math.max(totalPrice - salePrice - usedPoint, 0) },
// 렌더링하고 싶은 결제 UI의 variantKey
// 아래 variantKey는 문서용 테스트키와 연동되어 있습니다. 멀티 UI를 직접 만들고 싶다면 계약이 필요해요.
@@ -59,7 +71,7 @@ const PaymentPage = () => {
paymentWidgetRef.current = paymentWidget;
paymentMethodsWidgetRef.current = paymentMethodsWidget;
})();
- }, [totalPrice, salePrice]);
+ }, [totalPrice, salePrice, usedPoint]);
useEffect(() => {
const paymentMethodsWidget = paymentMethodsWidgetRef.current;
@@ -71,8 +83,10 @@ const PaymentPage = () => {
// ------ 금액 업데이트 ------
// 새로운 결제 금액을 넣어주세요.
// https://docs.tosspayments.com/reference/widget-sdk#updateamount결제-금액
- paymentMethodsWidget.updateAmount(Math.max(totalPrice - salePrice, 0));
- }, [totalPrice, salePrice]);
+ paymentMethodsWidget.updateAmount(
+ Math.max(totalPrice - salePrice - usedPoint, 0)
+ );
+ }, [totalPrice, salePrice, usedPoint]);
return (
@@ -195,23 +209,24 @@ const PaymentPage = () => {
통합 포인트
- {salePrice && (
+ {usedPoint && (
- {salePrice.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}원
+ {usedPoint.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}원
)}
{/* 적용취소, 적용 금액 한계 설정 */}
- 적용
+ {usedPoint === 0 ? "적용" : "적용 취소"}
- 보유: {getPoint} P
+ 보유: {point} P
@@ -226,9 +241,12 @@ const PaymentPage = () => {
할인금액
- {salePrice > 0
+ {salePrice + usedPoint > 0
? "(-)" +
- salePrice.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") +
+ // 표시되는 할인 금액 조정
+ Math.min(salePrice + usedPoint, totalPrice)
+ .toString()
+ .replace(/\B(?=(\d{3})+(?!\d))/g, ",") +
"원"
: "0원"}
@@ -240,10 +258,10 @@ const PaymentPage = () => {
총 결제 금액
{totalPrice &&
- Math.max(totalPrice - salePrice, 0)
+ Math.max(totalPrice - salePrice - usedPoint, 0)
.toString()
.replace(/\B(?=(\d{3})+(?!\d))/g, ",") + "원"}
- {console.log(totalPrice, salePrice)}
+ {console.log(totalPrice, salePrice, usedPoint)}
From e79455e4dbd25cebab355bc257af2de7b4ef5f00 Mon Sep 17 00:00:00 2001
From: KKangHHee <137751841+KKangHHee@users.noreply.github.com>
Date: Tue, 27 Feb 2024 14:28:10 +0900
Subject: [PATCH 4/6] =?UTF-8?q?Docs:=20=EB=B6=88=ED=95=84=EC=9A=94?=
=?UTF-8?q?=ED=95=9C=20=ED=9B=85=20=EC=82=AD=EC=A0=9C=5F0=EC=9B=90?=
=?UTF-8?q?=EA=B2=B0=EC=A0=9C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/hooks/useRequestPaymentZeroCost.jsx | 24 ------------------------
1 file changed, 24 deletions(-)
delete mode 100644 src/hooks/useRequestPaymentZeroCost.jsx
diff --git a/src/hooks/useRequestPaymentZeroCost.jsx b/src/hooks/useRequestPaymentZeroCost.jsx
deleted file mode 100644
index 645553a..0000000
--- a/src/hooks/useRequestPaymentZeroCost.jsx
+++ /dev/null
@@ -1,24 +0,0 @@
-const apiHome = process.env.REACT_APP_HOME_URL;
-const apiVer = "api/v1";
-const apiUrlBasic = `${apiHome}/${apiVer}/order/toss/success?`;
-
-const useRequestZoreCostPayment = () => {
- const zoreCostPaymentKey = "coupon";
- const requestZoreCostPayment = async ({ orderId, amount }) => {
- const apiUrl =
- apiUrlBasic +
- `paymentKey=${zoreCostPaymentKey}&` +
- `orderId=${orderId}&` +
- `amount=${amount}`;
- try {
- window.location.href = apiUrl;
- return;
- } catch (error) {
- console.error(error);
- }
- };
-
- return requestZoreCostPayment;
-};
-
-export default useRequestZoreCostPayment;
From fc243bb907d603e1fd558317719a0f1029cc8ef4 Mon Sep 17 00:00:00 2001
From: KKangHHee <137751841+KKangHHee@users.noreply.github.com>
Date: Tue, 27 Feb 2024 14:29:24 +0900
Subject: [PATCH 5/6] =?UTF-8?q?Docs:=20=EA=B2=B0=EC=A0=9C=20=EC=99=84?=
=?UTF-8?q?=EB=A3=8C=20=EB=B0=8F=20=EC=A3=BC=EB=AC=B8=20=EC=82=AC=ED=95=AD?=
=?UTF-8?q?=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EB=86=92=EC=9D=B4=20=EC=88=98?=
=?UTF-8?q?=EC=A0=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../views/PageComponent/OrderProgress.css | 23 +++++++++++++++----
.../views/PageComponent/OrderProgress.jsx | 2 +-
2 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/src/components/views/PageComponent/OrderProgress.css b/src/components/views/PageComponent/OrderProgress.css
index f2bf3b4..ae0574e 100644
--- a/src/components/views/PageComponent/OrderProgress.css
+++ b/src/components/views/PageComponent/OrderProgress.css
@@ -1,7 +1,11 @@
.order_progress {
+ position: fixed;
+ top: 0;
+ left: 0;
width: 100%;
+ height: 100vh;
+ overflow-y: auto;
background: linear-gradient(180deg, #fff 34.11%, #ffe2ed 100%);
- padding-bottom: 5rem;
}
.order_progress__header {
@@ -133,6 +137,10 @@
letter-spacing: -0.01rem;
}
+/* 주문상세 주문 취소 */
+.order_progress__wrapper {
+ position: relative;
+}
.order_progress__detail {
display: flex;
justify-content: center;
@@ -152,9 +160,13 @@
margin-left: auto;
margin-right: auto;
margin-top: 4rem;
+ margin-bottom: 10.25rem;
}
.order_progress__cancel {
+ position: absolute;
+ top: 6.0675rem;
+ width: 100%;
color: #838383;
text-align: center;
font-family: "Pretendard Variable";
@@ -163,11 +175,14 @@
font-weight: 700;
line-height: 130%; /* 0.975rem */
letter-spacing: -0.0075rem;
- margin-top: 4.25rem;
- /* margin-bottom: 3.63rem; */
}
.order_progress__point {
+ position: absolute;
+ /* 수평 가운데 정렬 */
+ left: 50%;
+ transform: translateX(-50%);
+ top: 2.3775rem;
display: flex;
flex-direction: column;
align-items: center;
@@ -176,7 +191,6 @@
background: url(../../../assets/images/bg_earn_point_info.png) no-repeat
center center;
background-size: cover;
- margin: 0.69rem auto 0 auto;
}
.order_progress__point_text {
@@ -188,5 +202,4 @@
line-height: 130%; /* 0.975rem */
letter-spacing: -0.0075rem;
margin-top: 0.96rem;
- margin-bottom: 0.48rem;
}
diff --git a/src/components/views/PageComponent/OrderProgress.jsx b/src/components/views/PageComponent/OrderProgress.jsx
index cd976e0..354dd71 100644
--- a/src/components/views/PageComponent/OrderProgress.jsx
+++ b/src/components/views/PageComponent/OrderProgress.jsx
@@ -178,7 +178,7 @@ const OrderProgress = () => {
: "안내 문구"}
-