refactor: update payment

This commit is contained in:
Tristan Yang
2023-01-04 11:27:43 +08:00
parent fa4d760ab4
commit 337ea90312
3 changed files with 40 additions and 6 deletions
+12 -2
View File
@@ -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 =
@@ -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<Props> = ({ 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<Props> = ({ closeModal }) => {
>
<StyledRadio
options={LicensePriceList.map(({ title, desc }) => `${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);
+1
View File
@@ -74,6 +74,7 @@ export interface LicenseMetadata {
domain: string | string[];
}
export interface RenewLicense {
mode: "payment" | "subscription",
priceId: string;
metadata: LicenseMetadata;
cancel_url: string;