diff --git a/src/api/auth.ts b/src/api/auth.ts index 460f28c..d50f151 100644 --- a/src/api/auth.ts +++ b/src/api/auth.ts @@ -10,6 +10,8 @@ export type Me = { address: string; phone_no: string; customer_code: string; + can_pay_by_creditcard: boolean; + can_apply_to_change_payment_method_creditcard: boolean; }; type MeResponse = { diff --git a/src/api/customer.ts b/src/api/customer.ts index 30afd27..fa9bdcd 100644 --- a/src/api/customer.ts +++ b/src/api/customer.ts @@ -51,7 +51,7 @@ export const orderCustomerInfoUpdate = async ( return res; }; -// -------利用者情報変更申請--------------- +// -------口座振替登録用パラメータ取得--------------- export type GetRegisterBankAccountStartParamResponse = { data: { url: string; @@ -65,3 +65,12 @@ export const getRegisterBankAccountStartParam = async () => { }); return res; }; + +// -------クレジットカード利用申請--------------- +export const orderChangePaymentMetodCreditcard = async (param: {}) => { + const res = await request({ + url: getUrl(ApiId.CUSTOMER_CHANGE_PAYMENT_METHOD_CREDITCARD_ORDER), + method: HttpMethod.POST, + }); + return res; +}; diff --git a/src/api/index.ts b/src/api/index.ts index 26ab5f1..39b3b83 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -53,6 +53,10 @@ export const ApiId = { VERIFY_CHANGE_EMAIL: id++, CUSTOMER_UPDATE_INFO_ORDER: id++, CUSTOMER_REGISTER_BANK_ACCOUNT_START_PARAM: id++, + CUSTOMER_CHANGE_PAYMENT_METHOD_CREDITCARD_ORDER: id++, + + // ロボットペイメント関連 + ROBOT_PAYMENT_CREDITCARD_TOKEN_CHECK: id++, } as const; export type ApiId = (typeof ApiId)[keyof typeof ApiId]; diff --git a/src/api/robot-payment.ts b/src/api/robot-payment.ts new file mode 100644 index 0000000..75aad05 --- /dev/null +++ b/src/api/robot-payment.ts @@ -0,0 +1,35 @@ +import { APICommonResponse, ApiId, HttpMethod, makeParam, request } from "api"; +import { getUrl } from "./url"; + +// -------領収証一覧取得--------------- +export type CheckTokenRequest = { + token: string; +}; +export type CheckTokenResponse = { + data: { + url: string; + shop_code: string; + customer_code: string; + token: string; + payment_type: string; + job_type: string; + tax: string; + send_fee: string; + amount: string; + interval: string; + payment_day: string; + auto_amount: string; + target_date: string; + email: string; + phone_number: string; + order_no: string; + }; +} & APICommonResponse; +export const checkToken = async (data: CheckTokenRequest) => { + const res = await request({ + url: getUrl(ApiId.ROBOT_PAYMENT_CREDITCARD_TOKEN_CHECK), + method: HttpMethod.POST, + data: makeParam(data), + }); + return res; +}; diff --git a/src/api/url.ts b/src/api/url.ts index 391aa3f..0bd08b7 100644 --- a/src/api/url.ts +++ b/src/api/url.ts @@ -50,8 +50,12 @@ const urls = { [A.START_CHANGE_EMAIL]: "email/change/start", [A.VERIFY_CHANGE_EMAIL]: "email/change/verify", [A.CUSTOMER_UPDATE_INFO_ORDER]: "customer/update-info-order", + [A.CUSTOMER_CHANGE_PAYMENT_METHOD_CREDITCARD_ORDER]: + "customer/change-payment-method-creditcard-order", [A.CUSTOMER_REGISTER_BANK_ACCOUNT_START_PARAM]: "customer/bank-account-register/start", + [A.ROBOT_PAYMENT_CREDITCARD_TOKEN_CHECK]: + "robot-payment/creditcard/token/check", }; const prefixs = { diff --git a/src/pages/dashboard/robot-payment/creditcard/register.tsx b/src/pages/dashboard/robot-payment/creditcard/register.tsx new file mode 100644 index 0000000..78092d3 --- /dev/null +++ b/src/pages/dashboard/robot-payment/creditcard/register.tsx @@ -0,0 +1,83 @@ +import { Typography } from "@mui/material"; +import { CheckTokenResponse, checkToken } from "api/robot-payment"; +import useAPICall from "hooks/useAPICall"; +import useDashboard from "hooks/useDashBoard"; +import { PageID, TabID } from "pages"; +import { useEffect, useRef, useState } from "react"; +import { useParams } from "react-router-dom"; + +export default function Register() { + const { setHeaderTitle, setTabs } = useDashboard( + PageID.DASHBOARD_ROBOT_PAYMENT_CREDITCARD_REGISTER, + TabID.NONE + ); + const { token: paramToken } = useParams(); + + const [result, setResult] = useState(null); + const [res, setRes] = useState(null); + + const form = useRef(null); + + const { callAPI: callCheckToken } = useAPICall({ + apiMethod: checkToken, + backDrop: true, + onSuccess: (response) => { + setResult(true); + setRes(response); + }, + onFailed: () => { + setResult(false); + }, + }); + + useEffect(() => { + if (paramToken) { + callCheckToken({ token: paramToken }); + } else { + setResult(false); + } + }, [paramToken]); + + useEffect(() => { + if (form.current && res) { + form.current.submit(); + } + }, [form, res]); + + useEffect(() => { + setHeaderTitle("クレジットカード登録"); + setTabs(null); + }, [setHeaderTitle, setTabs]); + + if (result === null) { + return null; + } + if (result === false) { + return 無効なURLです; + } + if (res === null) { + return null; + } + + const { data } = res; + return ( +
+

遷移中...

+ + + + + + + + + + + + + + + +
+ ); +} diff --git a/src/pages/dashboard/user/change-payment-method-creditcard-order.tsx b/src/pages/dashboard/user/change-payment-method-creditcard-order.tsx new file mode 100644 index 0000000..0c41077 --- /dev/null +++ b/src/pages/dashboard/user/change-payment-method-creditcard-order.tsx @@ -0,0 +1,128 @@ +import { + Box, + Button, + Stack, + Table, + TableBody, + TableCell, + TableRow, + Typography, +} from "@mui/material"; +import { HasChildren } from "@types"; +import { + orderChangePaymentMetodCreditcard, + orderCustomerInfoUpdate, + startChangeEmail, +} from "api/customer"; +import RequireChip from "components/chip/RequireChip"; +import InputAlert from "components/form/InputAlert"; +import TextFieldEx from "components/form/TextFieldEx"; +import { FormProvider, RHFTextField } from "components/hook-form"; +import StackRow from "components/stack/StackRow"; +import useAPICall from "hooks/useAPICall"; +import useAuth from "hooks/useAuth"; +import useDashboard from "hooks/useDashBoard"; +import useNavigateCustom from "hooks/useNavigateCustom"; +import useSnackbarCustom from "hooks/useSnackbarCustom"; +import { PageID, TabID } from "pages"; +import { useEffect, useState } from "react"; +import { useForm } from "react-hook-form"; +import { getPath } from "routes/path"; + +type AreaBoxProps = { + label: string; + require?: boolean; +} & HasChildren; +function AreaBox({ label, children, require }: AreaBoxProps) { + return ( + + + 〇{label} + + + {children} + + ); +} + +type FormProps = { + name: string; + name_kana: string; + zip_code: string; + address: string; + phone_no: string; + memo: string; +}; + +export default function ChangePaymentMethodCreditcardOrder() { + const { setHeaderTitle, setTabs } = useDashboard( + PageID.DASHBOARD_USER_CHANGE_PAYMENT_METHOD_CREDITCARD_ORDER, + TabID.NONE + ); + + const { navigateWhenChanged } = useNavigateCustom(); + + const { user } = useAuth(); + + const [mode, setMode] = useState<"confirm" | "done">("confirm"); + + const { error } = useSnackbarCustom(); + + const { callAPI: callOrderChangePaymentMetodCreditcard } = useAPICall({ + apiMethod: orderChangePaymentMetodCreditcard, + backDrop: true, + onSuccess: () => { + setMode("done"); + }, + onFailed: () => { + error("失敗しました"); + }, + }); + + const send = () => { + callOrderChangePaymentMetodCreditcard({}); + }; + + useEffect(() => { + setHeaderTitle("利用者情報変更申請"); + setTabs(null); + }, []); + + useEffect(() => { + if (user && user.can_pay_by_creditcard === false) { + navigateWhenChanged(getPath(PageID.DASHBOARD_OVERVIEW)); + } + }, [user]); + + if (user?.can_pay_by_creditcard !== true) { + return null; + } + + if (mode === "done") { + return ( + + 申請を行いました。受理をお待ちください。 + + ); + } + + return ( + + + + クレジットカードの登録申請を行います。 + 申請受理後に、登録用のURLをメール送信します。 + + メール送信までに数営業日を要する場合がございます。 + + + + + + + + + ); +} diff --git a/src/pages/dashboard/user/detail.tsx b/src/pages/dashboard/user/detail.tsx index ac74196..0388218 100644 --- a/src/pages/dashboard/user/detail.tsx +++ b/src/pages/dashboard/user/detail.tsx @@ -1,4 +1,5 @@ import { Box, Button, Paper, Stack, Typography } from "@mui/material"; +import useAuth from "hooks/useAuth"; import useDashboard from "hooks/useDashBoard"; import useNavigateCustom from "hooks/useNavigateCustom"; import { PageID, TabID } from "pages"; @@ -13,6 +14,8 @@ export default function UserDetail() { const { navigateWhenChanged } = useNavigateCustom(); + const { user } = useAuth(); + useEffect(() => { setHeaderTitle("利用者情報"); setTabs(null); @@ -56,6 +59,22 @@ export default function UserDetail() { 口座情報変更 + {user?.can_apply_to_change_payment_method_creditcard && ( + + + + )} ); diff --git a/src/pages/index.ts b/src/pages/index.ts index a70487d..1ec9529 100644 --- a/src/pages/index.ts +++ b/src/pages/index.ts @@ -31,6 +31,9 @@ export const PageID = { DASHBOARD_USER_CHANGE_EMAIL_START: id++, DASHBOARD_USER_UPDATE_USER_INFO: id++, DASHBOARD_USER_BANK_REGISTER: id++, + DASHBOARD_USER_CHANGE_PAYMENT_METHOD_CREDITCARD_ORDER: id++, + + DASHBOARD_ROBOT_PAYMENT_CREDITCARD_REGISTER: id++, SEASON_TICKET_CONTRACT_SELECTION_ENTRY: id++, SEASON_TICKET_CONTRACT_ENTRY_CANCEL: id++, diff --git a/src/routes/path.ts b/src/routes/path.ts index cb7dc40..b5ccd43 100644 --- a/src/routes/path.ts +++ b/src/routes/path.ts @@ -68,6 +68,10 @@ const PATHS_DASHBOARD = { "/dashboard/update/user/info", [makePathKey(PageID.DASHBOARD_USER_BANK_REGISTER)]: "/dashboard/update/user/back-register", + [makePathKey(PageID.DASHBOARD_USER_CHANGE_PAYMENT_METHOD_CREDITCARD_ORDER)]: + "/dashboard/order/user/payment-method/creditcard", + [makePathKey(PageID.DASHBOARD_ROBOT_PAYMENT_CREDITCARD_REGISTER)]: + "/dashboard/robot-payment/creditcard/register/:token", }; const PATHS = { diff --git a/src/routes/sub/dashboard.tsx b/src/routes/sub/dashboard.tsx index 07027d2..8683752 100644 --- a/src/routes/sub/dashboard.tsx +++ b/src/routes/sub/dashboard.tsx @@ -31,6 +31,15 @@ export default function DashboardRoutes(): RouteObject[] { const BankRegister = Loadable( lazy(() => import("pages/dashboard/user/bank-register")) ); + const ChangePaymentMethodCreditcardOrder = Loadable( + lazy( + () => + import("pages/dashboard/user/change-payment-method-creditcard-order") + ) + ); + const RobotPaymentCreditcardRegister = Loadable( + lazy(() => import("pages/dashboard/robot-payment/creditcard/register")) + ); const allChildren = [ { @@ -66,6 +75,14 @@ export default function DashboardRoutes(): RouteObject[] { pageId: PageID.DASHBOARD_USER_BANK_REGISTER, element: , }, + { + pageId: PageID.DASHBOARD_USER_CHANGE_PAYMENT_METHOD_CREDITCARD_ORDER, + element: , + }, + { + pageId: PageID.DASHBOARD_ROBOT_PAYMENT_CREDITCARD_REGISTER, + element: , + }, ]; return allChildren.map(({ pageId, ...others }) => ({ ...others,