diff --git a/src/app/config.ts b/src/app/config.ts index cdb47731..2d4c0627 100644 --- a/src/app/config.ts +++ b/src/app/config.ts @@ -5,9 +5,11 @@ const BASE_URL = process.env.REACT_APP_RELEASE : `https://dev.voce.chat/api`; let prices = [ { + mode: "subscription", + sub_type: "year", //day month year title: "VoceChat Pro", limit: 100, - pid: "price_1LkICIGGoUDRyc3jqrdPEnkY", + pid: "price_1MMMWAGGoUDRyc3jIsMay5Rs", desc: "User Limit: 100" }, { @@ -26,7 +28,15 @@ export const LicensePriceList = limit: 99999, pid: "price_1LkQGpGGoUDRyc3jGTh3GYHw", desc: "test price" - } + }, + { + title: "VoceChat Pro", + limit: 100, + pid: "price_1MMNNCGGoUDRyc3jSIGIsb3C", + desc: "test subscription price", + mode: "subscription", + sub_type: "year", //day month year + }, ] : prices; export const PAYMENT_URL_PREFIX = diff --git a/src/routes/setting/License/LicensePriceListModal.tsx b/src/routes/setting/License/LicensePriceListModal.tsx index 957d9a49..c0e81cc4 100644 --- a/src/routes/setting/License/LicensePriceListModal.tsx +++ b/src/routes/setting/License/LicensePriceListModal.tsx @@ -8,27 +8,50 @@ import StyledRadio from "../../../common/component/styled/Radio"; import { useGetLicensePaymentUrlMutation } from "../../../app/services/server"; import { LicensePriceList } from "../../../app/config"; import { useTranslation } from "react-i18next"; +import dayjs from "dayjs"; // import { LicenseMetadata, RenewLicense } from "../../types/server"; interface Props { closeModal: () => void; // domain: string; } +type Mode = "subscription" | "payment"; +type SubType = "month" | "quarter" | "year"; +const getExpireDay = (sub_type: SubType) => { + const currDate = dayjs(); + // 默认10年 + let res = currDate; + switch (sub_type) { + case "year": + res = currDate.add(1, "year"); + break; + case "month": + res = currDate.add(1, "month"); + break; + case "quarter": + res = currDate.add(3, "month"); + break; + default: + break; + }; + return res.format("YYYY-MM-DD"); +}; const LicensePriceListModal: FC = ({ closeModal }) => { const { t } = useTranslation("setting"); const { t: ct } = useTranslation(); const [getUrl, { isLoading, isSuccess }] = useGetLicensePaymentUrlMutation(); const [selectPrice, setSelectPrice] = useState( - `${LicensePriceList[0].pid}|${LicensePriceList[0].limit}` + `${LicensePriceList[0].pid}|${LicensePriceList[0].limit}|${LicensePriceList[0].mode || "payment"}|${LicensePriceList[0].sub_type || ""}` ); const handleRenew = async () => { - const [priceId, user_limit] = selectPrice.split("|"); + const [priceId, user_limit, mode, sub_type = "month"] = selectPrice.split("|") as [string, string, Mode, SubType]; const resp = await getUrl({ + mode: mode, priceId, metadata: { user_limit: Number(user_limit), - expire: "2035-01-01", + expire: mode == "subscription" ? getExpireDay(sub_type) : "2035-01-01", // 本地,则*通配符 domain: location.hostname.startsWith("localhost") ? "*" : location.hostname }, @@ -64,7 +87,7 @@ const LicensePriceListModal: FC = ({ closeModal }) => { > `${title} [${desc}]`)} - values={LicensePriceList.map(({ pid, limit }) => `${pid}|${limit}`)} + values={LicensePriceList.map(({ pid, limit, mode = "payment", sub_type = "month" }) => `${pid}|${limit}|${mode}|${sub_type}`)} value={selectPrice} onChange={(v) => { console.log("wtff", v); diff --git a/src/types/server.ts b/src/types/server.ts index cfdfc1b3..8bfb72ec 100644 --- a/src/types/server.ts +++ b/src/types/server.ts @@ -74,6 +74,7 @@ export interface LicenseMetadata { domain: string | string[]; } export interface RenewLicense { + mode: "payment" | "subscription", priceId: string; metadata: LicenseMetadata; cancel_url: string;