Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useEffect, useState, useRef } from 'react';
|
||||
import { Button, Form, Spin } from '@douyinfe/semi-ui';
|
||||
import {
|
||||
API,
|
||||
removeTrailingSlash,
|
||||
showError,
|
||||
showSuccess,
|
||||
} from '../../../helpers';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
export default function SettingsGeneralPayment(props) {
|
||||
const { t } = useTranslation();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [inputs, setInputs] = useState({
|
||||
ServerAddress: '',
|
||||
ShowDefaultPayMethods: true,
|
||||
HideWechatPay: false,
|
||||
HideAlipayPay: false,
|
||||
HidePayPal: false,
|
||||
});
|
||||
const formApiRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (props.options && formApiRef.current) {
|
||||
const disabledPayMethods = Array.isArray(props.options.DisabledPayMethods)
|
||||
? props.options.DisabledPayMethods
|
||||
: [];
|
||||
const currentInputs = {
|
||||
ServerAddress: props.options.ServerAddress || '',
|
||||
ShowDefaultPayMethods:
|
||||
props.options.ShowDefaultPayMethods !== undefined
|
||||
? props.options.ShowDefaultPayMethods
|
||||
: true,
|
||||
HideWechatPay: disabledPayMethods.includes('wxpay'),
|
||||
HideAlipayPay: disabledPayMethods.includes('alipay'),
|
||||
HidePayPal: disabledPayMethods.includes('paypal'),
|
||||
};
|
||||
setInputs(currentInputs);
|
||||
formApiRef.current.setValues(currentInputs);
|
||||
}
|
||||
}, [props.options]);
|
||||
|
||||
const handleFormChange = (values) => {
|
||||
setInputs(values);
|
||||
};
|
||||
|
||||
const submitServerAddress = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
let ServerAddress = removeTrailingSlash(inputs.ServerAddress);
|
||||
const res = await API.put('/api/option/', {
|
||||
key: 'ServerAddress',
|
||||
value: ServerAddress,
|
||||
});
|
||||
if (res.data.success) {
|
||||
showSuccess(t('更新成功'));
|
||||
props.refresh && props.refresh();
|
||||
} else {
|
||||
showError(res.data.message);
|
||||
}
|
||||
} catch (error) {
|
||||
showError(t('更新失败'));
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
const submitShowDefaultPayMethods = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await API.put('/api/option/', {
|
||||
key: 'payment_setting.show_default_pay_methods',
|
||||
value: String(inputs.ShowDefaultPayMethods),
|
||||
});
|
||||
if (res.data.success) {
|
||||
showSuccess(t('更新成功'));
|
||||
props.refresh && props.refresh();
|
||||
} else {
|
||||
showError(res.data.message);
|
||||
}
|
||||
} catch (error) {
|
||||
showError(t('更新失败'));
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
const submitDisabledPayMethods = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
// 保留 UI 未管理的其他类型(如 stripe),仅覆写当前表单管理的开关状态
|
||||
const others = (
|
||||
Array.isArray(props.options?.DisabledPayMethods)
|
||||
? props.options.DisabledPayMethods
|
||||
: []
|
||||
).filter((m) => m !== 'wxpay' && m !== 'alipay' && m !== 'paypal');
|
||||
const disabled = [...others];
|
||||
if (inputs.HideWechatPay) disabled.push('wxpay');
|
||||
if (inputs.HideAlipayPay) disabled.push('alipay');
|
||||
if (inputs.HidePayPal) disabled.push('paypal');
|
||||
const res = await API.put('/api/option/', {
|
||||
key: 'payment_setting.disabled_pay_methods',
|
||||
value: JSON.stringify(disabled),
|
||||
});
|
||||
if (res.data.success) {
|
||||
showSuccess(t('更新成功'));
|
||||
props.refresh && props.refresh();
|
||||
} else {
|
||||
showError(res.data.message);
|
||||
}
|
||||
} catch (error) {
|
||||
showError(t('更新失败'));
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<Spin spinning={loading}>
|
||||
<Form
|
||||
initValues={inputs}
|
||||
onValueChange={handleFormChange}
|
||||
getFormApi={(api) => (formApiRef.current = api)}
|
||||
>
|
||||
<Form.Section text={t('通用设置')}>
|
||||
<Form.Input
|
||||
field='ServerAddress'
|
||||
label={t('服务器地址')}
|
||||
placeholder={'https://yourdomain.com'}
|
||||
style={{ width: '100%' }}
|
||||
extraText={t(
|
||||
'该服务器地址将影响支付回调地址以及默认首页展示的地址,请确保正确配置',
|
||||
)}
|
||||
/>
|
||||
<Button onClick={submitServerAddress}>{t('更新服务器地址')}</Button>
|
||||
</Form.Section>
|
||||
|
||||
<Form.Section text={t('支付方式显示设置')}>
|
||||
<Form.Switch
|
||||
field='ShowDefaultPayMethods'
|
||||
label={t('显示默认支付方式')}
|
||||
extraText={t(
|
||||
'启用后,即使未配置支付信息(支付地址、易支付ID、易支付密钥),也会在充值页面显示支付宝和微信的支付选项',
|
||||
)}
|
||||
/>
|
||||
<Button onClick={submitShowDefaultPayMethods}>
|
||||
{t('更新显示设置')}
|
||||
</Button>
|
||||
</Form.Section>
|
||||
|
||||
<Form.Section text={t('支付渠道开关')}>
|
||||
<Form.Switch
|
||||
field='HideWechatPay'
|
||||
label={t('隐藏微信支付')}
|
||||
extraText={t(
|
||||
'开启后,充值页面将不再显示微信支付按钮,且拒绝微信支付下单(不影响已发起订单的回调入账)',
|
||||
)}
|
||||
/>
|
||||
<Form.Switch
|
||||
field='HideAlipayPay'
|
||||
label={t('隐藏支付宝支付')}
|
||||
extraText={t(
|
||||
'开启后,充值页面将不再显示支付宝支付按钮,且拒绝支付宝下单(不影响已发起订单的回调入账)',
|
||||
)}
|
||||
/>
|
||||
<Form.Switch
|
||||
field='HidePayPal'
|
||||
label={t('隐藏 PayPal 支付')}
|
||||
extraText={t(
|
||||
'开启后拒绝 PayPal 新订单,但仍处理已发起订单的回跳、Webhook 和主动对账',
|
||||
)}
|
||||
/>
|
||||
<Button onClick={submitDisabledPayMethods}>
|
||||
{t('更新支付渠道开关')}
|
||||
</Button>
|
||||
</Form.Section>
|
||||
</Form>
|
||||
</Spin>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,581 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Switch,
|
||||
InputNumber,
|
||||
Input,
|
||||
Table,
|
||||
Modal,
|
||||
Tag,
|
||||
Typography,
|
||||
Spin,
|
||||
Space,
|
||||
Select,
|
||||
Popconfirm,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import {
|
||||
IconPlus,
|
||||
IconDelete,
|
||||
IconEdit,
|
||||
IconRefresh,
|
||||
} from '@douyinfe/semi-icons';
|
||||
import { Crown, Sparkles, Zap } from 'lucide-react';
|
||||
import { API, showError, showSuccess, renderQuota } from '../../../helpers';
|
||||
import QuotaInput from '../../../components/common/ui/QuotaInput';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
const planTypeOptions = [
|
||||
{ value: 'weekly', label: '周卡' },
|
||||
{ value: 'monthly', label: '月卡' },
|
||||
{ value: 'quarterly', label: '季卡' },
|
||||
];
|
||||
|
||||
const tierOptions = [
|
||||
{ value: 'lite', label: '轻度版' },
|
||||
{ value: 'pro', label: '重度版' },
|
||||
];
|
||||
|
||||
export default function SettingsMembership() {
|
||||
const { t } = useTranslation();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [plans, setPlans] = useState([]);
|
||||
const [setting, setSetting] = useState({
|
||||
membership_enabled: false,
|
||||
daily_grant_hour: 0,
|
||||
membership_title: '会员订阅',
|
||||
membership_description: '开通会员,每天自动到账额度,用完再扣账户余额',
|
||||
expiry_notify_days: 3,
|
||||
expiry_notify_enabled: true,
|
||||
});
|
||||
const [settingLoading, setSettingLoading] = useState(false);
|
||||
|
||||
// 编辑方案弹窗
|
||||
const [editModalVisible, setEditModalVisible] = useState(false);
|
||||
const [editingPlan, setEditingPlan] = useState(null);
|
||||
const [editLoading, setEditLoading] = useState(false);
|
||||
|
||||
// 获取方案列表
|
||||
const fetchPlans = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await API.get('/api/user/membership/manage/plans');
|
||||
const { success, data } = res.data;
|
||||
if (success) {
|
||||
setPlans(data || []);
|
||||
}
|
||||
} catch (err) {
|
||||
showError(t('获取会员方案失败'));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 获取配置
|
||||
const fetchSetting = async () => {
|
||||
try {
|
||||
const res = await API.get('/api/user/membership/manage/setting');
|
||||
const { success, data } = res.data;
|
||||
if (success) {
|
||||
setSetting(data);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
};
|
||||
|
||||
// 保存配置
|
||||
const saveSetting = async () => {
|
||||
setSettingLoading(true);
|
||||
try {
|
||||
const res = await API.put('/api/user/membership/manage/setting', setting);
|
||||
const { success, message } = res.data;
|
||||
if (success) {
|
||||
showSuccess(t('配置已保存'));
|
||||
} else {
|
||||
showError(message);
|
||||
}
|
||||
} catch (err) {
|
||||
showError(t('保存配置失败'));
|
||||
} finally {
|
||||
setSettingLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 保存方案
|
||||
const savePlan = async (plan) => {
|
||||
if (!plan?.daily_quota || plan.daily_quota <= 0) {
|
||||
showError(t('请填写每日到账额度(金额需大于 0)'));
|
||||
return;
|
||||
}
|
||||
setEditLoading(true);
|
||||
try {
|
||||
let res;
|
||||
if (plan.id) {
|
||||
res = await API.put('/api/user/membership/manage/plans', plan);
|
||||
} else {
|
||||
res = await API.post('/api/user/membership/manage/plans', plan);
|
||||
}
|
||||
const { success, message } = res.data;
|
||||
if (success) {
|
||||
showSuccess(plan.id ? '更新成功' : '创建成功');
|
||||
setEditModalVisible(false);
|
||||
setEditingPlan(null);
|
||||
fetchPlans();
|
||||
} else {
|
||||
showError(message);
|
||||
}
|
||||
} catch (err) {
|
||||
showError(t('保存失败'));
|
||||
} finally {
|
||||
setEditLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 删除方案
|
||||
const deletePlan = async (id) => {
|
||||
try {
|
||||
const res = await API.delete(`/api/user/membership/manage/plans/${id}`);
|
||||
const { success, message } = res.data;
|
||||
if (success) {
|
||||
showSuccess(t('删除成功'));
|
||||
fetchPlans();
|
||||
} else {
|
||||
showError(message);
|
||||
}
|
||||
} catch (err) {
|
||||
showError(t('删除失败'));
|
||||
}
|
||||
};
|
||||
|
||||
// 手动发放
|
||||
const manualGrant = async () => {
|
||||
try {
|
||||
const res = await API.post('/api/user/membership/manage/grant');
|
||||
const { success, message } = res.data;
|
||||
if (success) {
|
||||
showSuccess(message);
|
||||
} else {
|
||||
showError(message);
|
||||
}
|
||||
} catch (err) {
|
||||
showError(t('发放失败'));
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchPlans();
|
||||
fetchSetting();
|
||||
}, []);
|
||||
|
||||
// 表格列定义
|
||||
const columns = [
|
||||
{
|
||||
title: '方案名称',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
render: (text, record) => (
|
||||
<div className='flex items-center gap-2'>
|
||||
<Zap size={16} className='text-blue-500' />
|
||||
<Text strong>{text}</Text>
|
||||
{record.badge && (
|
||||
<Tag size='small' color='blue'>
|
||||
{record.badge}
|
||||
</Tag>
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '类型',
|
||||
dataIndex: 'plan_type',
|
||||
key: 'plan_type',
|
||||
render: (v) => {
|
||||
const map = { weekly: '周卡', monthly: '月卡', quarterly: '季卡' };
|
||||
return <Tag>{map[v] || v}</Tag>;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '档位',
|
||||
dataIndex: 'tier',
|
||||
key: 'tier',
|
||||
render: (v) => {
|
||||
const map = { lite: '轻度', pro: '重度' };
|
||||
const color = v === 'pro' ? 'red' : 'blue';
|
||||
return <Tag color={color}>{map[v] || v}</Tag>;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '天数',
|
||||
dataIndex: 'duration_days',
|
||||
key: 'duration_days',
|
||||
render: (v) => `${v} 天`,
|
||||
},
|
||||
{
|
||||
title: '价格',
|
||||
dataIndex: 'price',
|
||||
key: 'price',
|
||||
render: (v) => <Text strong>¥{v}</Text>,
|
||||
},
|
||||
{
|
||||
title: '每日额度',
|
||||
dataIndex: 'daily_quota',
|
||||
key: 'daily_quota',
|
||||
render: (v) => <Text type='success'>{renderQuota(v)}</Text>,
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'is_enabled',
|
||||
key: 'is_enabled',
|
||||
render: (v) => (
|
||||
<Tag color={v ? 'green' : 'grey'}>{v ? '启用' : '禁用'}</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '排序',
|
||||
dataIndex: 'sort',
|
||||
key: 'sort',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
render: (_, record) => (
|
||||
<Space>
|
||||
<Button
|
||||
icon={<IconEdit />}
|
||||
size='small'
|
||||
onClick={() => {
|
||||
setEditingPlan({ ...record });
|
||||
setEditModalVisible(true);
|
||||
}}
|
||||
/>
|
||||
<Popconfirm
|
||||
title={t('确定删除此方案?')}
|
||||
onConfirm={() => deletePlan(record.id)}
|
||||
>
|
||||
<Button icon={<IconDelete />} size='small' type='danger' />
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div className='space-y-6'>
|
||||
{/* 功能配置 */}
|
||||
<Card
|
||||
title={
|
||||
<div className='flex items-center gap-2'>
|
||||
<Crown size={20} className='text-amber-500' />
|
||||
<span>{t('会员功能配置')}</span>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div className='space-y-4'>
|
||||
<div className='flex items-center justify-between'>
|
||||
<div>
|
||||
<Text strong>{t('启用会员功能')}</Text>
|
||||
<Text className='text-gray-400 block text-sm'>
|
||||
{t('开启后用户可以在充值页面订阅会员')}
|
||||
</Text>
|
||||
</div>
|
||||
<Switch
|
||||
checked={setting.membership_enabled}
|
||||
onChange={(v) =>
|
||||
setSetting({ ...setting, membership_enabled: v })
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className='grid grid-cols-2 gap-4'>
|
||||
<div>
|
||||
<Text className='block mb-1 text-sm'>
|
||||
{t('每日额度发放时间(0-23点)')}
|
||||
</Text>
|
||||
<InputNumber
|
||||
value={setting.daily_grant_hour}
|
||||
min={0}
|
||||
max={23}
|
||||
onChange={(v) =>
|
||||
setSetting({ ...setting, daily_grant_hour: v })
|
||||
}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Text className='block mb-1 text-sm'>{t('到期提醒天数')}</Text>
|
||||
<InputNumber
|
||||
value={setting.expiry_notify_days}
|
||||
min={1}
|
||||
max={30}
|
||||
onChange={(v) =>
|
||||
setSetting({ ...setting, expiry_notify_days: v })
|
||||
}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Text className='block mb-1 text-sm'>{t('会员页面标题')}</Text>
|
||||
<Input
|
||||
value={setting.membership_title}
|
||||
onChange={(v) => setSetting({ ...setting, membership_title: v })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Text className='block mb-1 text-sm'>{t('会员页面描述')}</Text>
|
||||
<Input
|
||||
value={setting.membership_description}
|
||||
onChange={(v) =>
|
||||
setSetting({ ...setting, membership_description: v })
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className='flex items-center gap-2'>
|
||||
<Button
|
||||
theme='solid'
|
||||
onClick={saveSetting}
|
||||
loading={settingLoading}
|
||||
>
|
||||
{t('保存配置')}
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title={t('确认手动发放今日会员额度?')}
|
||||
onConfirm={manualGrant}
|
||||
>
|
||||
<Button icon={<IconRefresh />}>{t('手动发放今日额度')}</Button>
|
||||
</Popconfirm>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{/* 方案管理 */}
|
||||
<Card
|
||||
title={
|
||||
<div className='flex items-center justify-between w-full'>
|
||||
<div className='flex items-center gap-2'>
|
||||
<Sparkles size={20} className='text-brand' />
|
||||
<span>{t('会员方案管理')}</span>
|
||||
</div>
|
||||
<Button
|
||||
icon={<IconPlus />}
|
||||
theme='solid'
|
||||
size='small'
|
||||
onClick={() => {
|
||||
setEditingPlan({
|
||||
name: '',
|
||||
plan_type: 'monthly',
|
||||
tier: 'lite',
|
||||
duration_days: 30,
|
||||
price: 59.9,
|
||||
daily_quota: 500000,
|
||||
description: '',
|
||||
badge: '',
|
||||
badge_color: '',
|
||||
is_recommend: false,
|
||||
is_enabled: true,
|
||||
sort: 0,
|
||||
});
|
||||
setEditModalVisible(true);
|
||||
}}
|
||||
>
|
||||
{t('新增方案')}
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
{loading ? (
|
||||
<Spin />
|
||||
) : (
|
||||
<Table
|
||||
// 列宽合计远超窄屏视口;没有 scroll 时表格会压缩到 min-content 硬塞进去,
|
||||
// 末尾的操作列落在视口外,且 iOS 上滚动条不可见、毫无可拖动提示
|
||||
scroll={{ x: 'max-content' }}
|
||||
columns={columns}
|
||||
dataSource={plans}
|
||||
rowKey='id'
|
||||
pagination={false}
|
||||
size='small'
|
||||
/>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
{/* 编辑方案弹窗 */}
|
||||
<Modal
|
||||
title={editingPlan?.id ? t('编辑方案') : t('新增方案')}
|
||||
visible={editModalVisible}
|
||||
onOk={() => savePlan(editingPlan)}
|
||||
onCancel={() => {
|
||||
setEditModalVisible(false);
|
||||
setEditingPlan(null);
|
||||
}}
|
||||
confirmLoading={editLoading}
|
||||
width={600}
|
||||
centered
|
||||
>
|
||||
{editingPlan && (
|
||||
<div className='space-y-4 py-2'>
|
||||
<div className='grid grid-cols-2 gap-4'>
|
||||
<div>
|
||||
<Text className='block mb-1 text-sm'>{t('方案名称')}</Text>
|
||||
<Input
|
||||
value={editingPlan.name}
|
||||
onChange={(v) => setEditingPlan({ ...editingPlan, name: v })}
|
||||
placeholder={t('如:月卡·轻度')}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Text className='block mb-1 text-sm'>{t('方案类型')}</Text>
|
||||
<Select
|
||||
value={editingPlan.plan_type}
|
||||
onChange={(v) =>
|
||||
setEditingPlan({ ...editingPlan, plan_type: v })
|
||||
}
|
||||
optionList={planTypeOptions}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className='grid grid-cols-2 gap-4'>
|
||||
<div>
|
||||
<Text className='block mb-1 text-sm'>{t('档位')}</Text>
|
||||
<Select
|
||||
value={editingPlan.tier}
|
||||
onChange={(v) => setEditingPlan({ ...editingPlan, tier: v })}
|
||||
optionList={tierOptions}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Text className='block mb-1 text-sm'>{t('有效天数')}</Text>
|
||||
<InputNumber
|
||||
value={editingPlan.duration_days}
|
||||
min={1}
|
||||
onChange={(v) =>
|
||||
setEditingPlan({ ...editingPlan, duration_days: v })
|
||||
}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className='grid grid-cols-2 gap-4'>
|
||||
<div>
|
||||
<Text className='block mb-1 text-sm'>{t('价格(元)')}</Text>
|
||||
<InputNumber
|
||||
value={editingPlan.price}
|
||||
min={0.01}
|
||||
precision={2}
|
||||
onChange={(v) => setEditingPlan({ ...editingPlan, price: v })}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Text className='block mb-1 text-sm'>{t('每日到账额度')}</Text>
|
||||
<QuotaInput
|
||||
value={editingPlan.daily_quota}
|
||||
minQuota={1}
|
||||
onChange={(v) =>
|
||||
setEditingPlan({ ...editingPlan, daily_quota: v })
|
||||
}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Text className='block mb-1 text-sm'>{t('方案描述')}</Text>
|
||||
<Input
|
||||
value={editingPlan.description}
|
||||
onChange={(v) =>
|
||||
setEditingPlan({ ...editingPlan, description: v })
|
||||
}
|
||||
placeholder={t('方案简要描述')}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className='grid grid-cols-2 gap-4'>
|
||||
<div>
|
||||
<Text className='block mb-1 text-sm'>{t('角标文字')}</Text>
|
||||
<Input
|
||||
value={editingPlan.badge}
|
||||
onChange={(v) => setEditingPlan({ ...editingPlan, badge: v })}
|
||||
placeholder={t('如:推荐、热门')}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Text className='block mb-1 text-sm'>{t('角标颜色')}</Text>
|
||||
<Input
|
||||
value={editingPlan.badge_color}
|
||||
onChange={(v) =>
|
||||
setEditingPlan({ ...editingPlan, badge_color: v })
|
||||
}
|
||||
placeholder='#1890ff'
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className='grid grid-cols-2 gap-4'>
|
||||
<div>
|
||||
<Text className='block mb-1 text-sm'>{t('排序权重')}</Text>
|
||||
<InputNumber
|
||||
value={editingPlan.sort}
|
||||
min={0}
|
||||
onChange={(v) => setEditingPlan({ ...editingPlan, sort: v })}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</div>
|
||||
<div className='flex items-center gap-4 pt-6'>
|
||||
<div className='flex items-center gap-2'>
|
||||
<Switch
|
||||
checked={editingPlan.is_enabled}
|
||||
onChange={(v) =>
|
||||
setEditingPlan({ ...editingPlan, is_enabled: v })
|
||||
}
|
||||
size='small'
|
||||
/>
|
||||
<Text className='text-sm'>{t('启用')}</Text>
|
||||
</div>
|
||||
<div className='flex items-center gap-2'>
|
||||
<Switch
|
||||
checked={editingPlan.is_recommend}
|
||||
onChange={(v) =>
|
||||
setEditingPlan({ ...editingPlan, is_recommend: v })
|
||||
}
|
||||
size='small'
|
||||
/>
|
||||
<Text className='text-sm'>{t('推荐')}</Text>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,310 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React, { useEffect, useState, useRef } from 'react';
|
||||
import {
|
||||
Banner,
|
||||
Button,
|
||||
Form,
|
||||
Row,
|
||||
Col,
|
||||
Typography,
|
||||
Spin,
|
||||
} from '@douyinfe/semi-ui';
|
||||
const { Text } = Typography;
|
||||
import { API, showError, showSuccess, toBoolean } from '../../../helpers';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
export default function SettingsNuonuoInvoice(props) {
|
||||
const { t } = useTranslation();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [inputs, setInputs] = useState({
|
||||
NuonuoEnabled: false,
|
||||
NuonuoAppKey: '',
|
||||
NuonuoAppSecret: '',
|
||||
NuonuoApiUrl: 'https://sdk.nuonuo.com/open/v1/services',
|
||||
NuonuoCallbackUrl: '',
|
||||
NuonuoTaxNum: '',
|
||||
NuonuoSalerName: '',
|
||||
NuonuoSalerAddress: '',
|
||||
NuonuoSalerTel: '',
|
||||
NuonuoSalerBank: '',
|
||||
NuonuoClerk: '',
|
||||
NuonuoExtensionNum: '',
|
||||
NuonuoItemName: '信息技术服务*信息技术服务费',
|
||||
NuonuoTaxRate: '0.06',
|
||||
NuonuoMinAmount: 200,
|
||||
NuonuoMonthlyLimit: 5,
|
||||
});
|
||||
const formApiRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (props.options && formApiRef.current) {
|
||||
const currentInputs = {
|
||||
NuonuoEnabled: toBoolean(props.options.NuonuoEnabled),
|
||||
NuonuoAppKey: props.options.NuonuoAppKey || '',
|
||||
NuonuoAppSecret: props.options.NuonuoAppSecret || '',
|
||||
NuonuoApiUrl:
|
||||
props.options.NuonuoApiUrl ||
|
||||
'https://sdk.nuonuo.com/open/v1/services',
|
||||
NuonuoCallbackUrl: props.options.NuonuoCallbackUrl || '',
|
||||
NuonuoTaxNum: props.options.NuonuoTaxNum || '',
|
||||
NuonuoSalerName: props.options.NuonuoSalerName || '',
|
||||
NuonuoSalerAddress: props.options.NuonuoSalerAddress || '',
|
||||
NuonuoSalerTel: props.options.NuonuoSalerTel || '',
|
||||
NuonuoSalerBank: props.options.NuonuoSalerBank || '',
|
||||
NuonuoClerk: props.options.NuonuoClerk || '',
|
||||
NuonuoExtensionNum: props.options.NuonuoExtensionNum || '',
|
||||
NuonuoItemName:
|
||||
props.options.NuonuoItemName || '信息技术服务*信息技术服务费',
|
||||
NuonuoTaxRate: props.options.NuonuoTaxRate || '0.06',
|
||||
NuonuoMinAmount: parseFloat(props.options.NuonuoMinAmount) || 200,
|
||||
NuonuoMonthlyLimit: parseInt(props.options.NuonuoMonthlyLimit) || 5,
|
||||
};
|
||||
setInputs(currentInputs);
|
||||
formApiRef.current.setValues(currentInputs);
|
||||
}
|
||||
}, [props.options]);
|
||||
|
||||
const handleFormChange = (values) => {
|
||||
setInputs(values);
|
||||
};
|
||||
|
||||
// key 映射:前端字段名 → 后端 option key
|
||||
const keyMap = {
|
||||
NuonuoEnabled: 'nuonuo_setting.enabled',
|
||||
NuonuoAppKey: 'nuonuo_setting.app_key',
|
||||
NuonuoAppSecret: 'nuonuo_setting.app_secret',
|
||||
NuonuoApiUrl: 'nuonuo_setting.api_url',
|
||||
NuonuoCallbackUrl: 'nuonuo_setting.callback_url',
|
||||
NuonuoTaxNum: 'nuonuo_setting.tax_num',
|
||||
NuonuoSalerName: 'nuonuo_setting.saler_name',
|
||||
NuonuoSalerAddress: 'nuonuo_setting.saler_address',
|
||||
NuonuoSalerTel: 'nuonuo_setting.saler_tel',
|
||||
NuonuoSalerBank: 'nuonuo_setting.saler_bank',
|
||||
NuonuoClerk: 'nuonuo_setting.clerk',
|
||||
NuonuoExtensionNum: 'nuonuo_setting.extension_num',
|
||||
NuonuoItemName: 'nuonuo_setting.item_name',
|
||||
NuonuoTaxRate: 'nuonuo_setting.tax_rate',
|
||||
NuonuoMinAmount: 'nuonuo_setting.min_amount',
|
||||
NuonuoMonthlyLimit: 'nuonuo_setting.monthly_limit',
|
||||
};
|
||||
|
||||
const submitConfig = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const options = Object.entries(keyMap).map(([frontKey, backKey]) => {
|
||||
let value = inputs[frontKey];
|
||||
if (typeof value === 'boolean') value = value ? 'true' : 'false';
|
||||
else value = String(value ?? '');
|
||||
return { key: backKey, value };
|
||||
});
|
||||
|
||||
const results = await Promise.all(
|
||||
options.map((opt) => API.put('/api/option/', opt)),
|
||||
);
|
||||
|
||||
const errors = results.filter((res) => !res.data.success);
|
||||
if (errors.length > 0) {
|
||||
errors.forEach((res) => showError(res.data.message));
|
||||
} else {
|
||||
showSuccess(t('保存成功'));
|
||||
props.refresh?.();
|
||||
}
|
||||
} catch (error) {
|
||||
showError(t('保存失败'));
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Banner
|
||||
type='info'
|
||||
description={t(
|
||||
'配置诺诺发票开放平台参数,启用后用户可在线申请开具电子发票。需先在诺诺开放平台(open.nuonuo.com)注册应用并获取 AppKey/AppSecret。',
|
||||
)}
|
||||
style={{ marginBottom: 16 }}
|
||||
/>
|
||||
<Spin spinning={loading}>
|
||||
<Form
|
||||
getFormApi={(api) => (formApiRef.current = api)}
|
||||
onValueChange={handleFormChange}
|
||||
labelPosition='left'
|
||||
labelWidth='160px'
|
||||
>
|
||||
<Row gutter={16}>
|
||||
<Col span={24}>
|
||||
<Form.Switch field='NuonuoEnabled' label={t('启用发票功能')} />
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Text strong style={{ display: 'block', margin: '16px 0 8px' }}>
|
||||
{t('API 凭证')}
|
||||
</Text>
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Input
|
||||
field='NuonuoAppKey'
|
||||
label='AppKey'
|
||||
placeholder={t('诺诺应用 AppKey')}
|
||||
/>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Input
|
||||
field='NuonuoAppSecret'
|
||||
label='AppSecret'
|
||||
placeholder={t('诺诺应用 AppSecret')}
|
||||
mode='password'
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Input
|
||||
field='NuonuoApiUrl'
|
||||
label={t('API 地址')}
|
||||
placeholder='https://sdk.nuonuo.com/open/v1/services'
|
||||
/>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Input
|
||||
field='NuonuoCallbackUrl'
|
||||
label={t('回调地址')}
|
||||
placeholder={t('https://your-domain.com/api/nuonuo/callback')}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Text strong style={{ display: 'block', margin: '16px 0 8px' }}>
|
||||
{t('销方信息')}
|
||||
</Text>
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Input
|
||||
field='NuonuoTaxNum'
|
||||
label={t('销方税号')}
|
||||
placeholder={t('统一社会信用代码')}
|
||||
/>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Input
|
||||
field='NuonuoSalerName'
|
||||
label={t('销方名称')}
|
||||
placeholder={t('公司全称')}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Input
|
||||
field='NuonuoSalerAddress'
|
||||
label={t('销方地址')}
|
||||
placeholder={t('公司注册地址')}
|
||||
/>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Input
|
||||
field='NuonuoSalerTel'
|
||||
label={t('销方电话')}
|
||||
placeholder={t('公司电话')}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row gutter={16}>
|
||||
<Col span={24}>
|
||||
<Form.Input
|
||||
field='NuonuoSalerBank'
|
||||
label={t('开户行及账号')}
|
||||
placeholder={t('销方开户行及银行账号')}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Text strong style={{ display: 'block', margin: '16px 0 8px' }}>
|
||||
{t('开票信息')}
|
||||
</Text>
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Input
|
||||
field='NuonuoClerk'
|
||||
label={t('开票员')}
|
||||
placeholder={t('开票人姓名')}
|
||||
/>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Input
|
||||
field='NuonuoExtensionNum'
|
||||
label={t('分机号')}
|
||||
placeholder={t('全电发票分机号(非全电可留空)')}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Input
|
||||
field='NuonuoItemName'
|
||||
label={t('商品名称')}
|
||||
placeholder={t('信息技术服务*信息技术服务费')}
|
||||
/>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Input
|
||||
field='NuonuoTaxRate'
|
||||
label={t('税率')}
|
||||
placeholder={t('如 0.06 表示 6%')}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Text strong style={{ display: 'block', margin: '16px 0 8px' }}>
|
||||
{t('业务规则')}
|
||||
</Text>
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.InputNumber
|
||||
field='NuonuoMinAmount'
|
||||
label={t('最低开票金额(元)')}
|
||||
min={0}
|
||||
step={10}
|
||||
/>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.InputNumber
|
||||
field='NuonuoMonthlyLimit'
|
||||
label={t('每月申请上限(次)')}
|
||||
min={1}
|
||||
step={1}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Button
|
||||
type='primary'
|
||||
theme='solid'
|
||||
onClick={submitConfig}
|
||||
loading={loading}
|
||||
style={{ marginTop: 16 }}
|
||||
>
|
||||
{t('保存诺诺发票配置')}
|
||||
</Button>
|
||||
</Form>
|
||||
</Spin>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
Form,
|
||||
Button,
|
||||
Typography,
|
||||
Space,
|
||||
Divider,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import { API, showError, showSuccess } from '../../../helpers';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
const { Title, Text } = Typography;
|
||||
|
||||
const SettingsPaymentAlipay = ({ options, refresh }) => {
|
||||
const { t } = useTranslation();
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const onSubmit = async (values) => {
|
||||
try {
|
||||
setLoading(true);
|
||||
|
||||
// 保存支付宝配置
|
||||
const configs = [
|
||||
{ key: 'AlipayAppId', value: values.AlipayAppId || '' },
|
||||
// 如果私钥/公钥未修改(仍然是空或占位符),则使用占位符让后端跳过更新
|
||||
{
|
||||
key: 'AlipayPrivateKey',
|
||||
value:
|
||||
values.AlipayPrivateKey && values.AlipayPrivateKey.trim() !== ''
|
||||
? values.AlipayPrivateKey
|
||||
: '***ALREADY_SET***',
|
||||
},
|
||||
{
|
||||
key: 'AlipayPublicKey',
|
||||
value:
|
||||
values.AlipayPublicKey && values.AlipayPublicKey.trim() !== ''
|
||||
? values.AlipayPublicKey
|
||||
: '***ALREADY_SET***',
|
||||
},
|
||||
{
|
||||
key: 'AlipayPCEnabled',
|
||||
value: values.AlipayPCEnabled ? 'true' : 'false',
|
||||
},
|
||||
{
|
||||
key: 'AlipayWAPEnabled',
|
||||
value: values.AlipayWAPEnabled ? 'true' : 'false',
|
||||
},
|
||||
{
|
||||
key: 'AlipayQREnabled',
|
||||
value: values.AlipayQREnabled ? 'true' : 'false',
|
||||
},
|
||||
{
|
||||
key: 'AlipayIsSandbox',
|
||||
value: values.AlipayIsSandbox ? 'true' : 'false',
|
||||
},
|
||||
{ key: 'AlipayNotifyUrl', value: values.AlipayNotifyUrl || '' },
|
||||
{ key: 'AlipayReturnUrl', value: values.AlipayReturnUrl || '' },
|
||||
{ key: 'AlipaySubject', value: values.AlipaySubject || '平台充值' },
|
||||
{
|
||||
key: 'AlipayExpireMinutes',
|
||||
value: String(values.AlipayExpireMinutes || 30),
|
||||
},
|
||||
];
|
||||
|
||||
for (const config of configs) {
|
||||
const res = await API.put('/api/option/', config);
|
||||
if (!res.data.success) {
|
||||
throw new Error(`保存 ${config.key} 失败: ${res.data.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
showSuccess(t('支付宝配置保存成功'));
|
||||
if (refresh) refresh();
|
||||
} catch (error) {
|
||||
showError(error.message || t('保存失败'));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Title heading={5}>{t('支付宝配置')}</Title>
|
||||
<Text type='tertiary'>
|
||||
{t('配置支付宝电脑网站支付、手机网站支付和当面付扫码支付。请前往')}{' '}
|
||||
<a
|
||||
href='https://open.alipay.com'
|
||||
target='_blank'
|
||||
rel='noopener noreferrer'
|
||||
>{t('支付宝开放平台')}</a>{' '}
|
||||
{t('获取相关配置信息。')}
|
||||
</Text>
|
||||
|
||||
<Divider margin='12px' />
|
||||
|
||||
<Form
|
||||
labelPosition='left'
|
||||
labelAlign='right'
|
||||
labelWidth={180}
|
||||
onSubmit={onSubmit}
|
||||
initValues={{
|
||||
AlipayAppId: options.AlipayAppId || '',
|
||||
AlipayPrivateKey:
|
||||
options.AlipayPrivateKey &&
|
||||
options.AlipayPrivateKey !== '***ALREADY_SET***'
|
||||
? options.AlipayPrivateKey
|
||||
: '',
|
||||
AlipayPublicKey:
|
||||
options.AlipayPublicKey &&
|
||||
options.AlipayPublicKey !== '***ALREADY_SET***'
|
||||
? options.AlipayPublicKey
|
||||
: '',
|
||||
AlipayPCEnabled: options.AlipayPCEnabled || false,
|
||||
AlipayWAPEnabled: options.AlipayWAPEnabled || false,
|
||||
AlipayQREnabled: options.AlipayQREnabled || false,
|
||||
AlipayIsSandbox: options.AlipayIsSandbox || false,
|
||||
AlipayNotifyUrl: options.AlipayNotifyUrl || '',
|
||||
AlipayReturnUrl: options.AlipayReturnUrl || '',
|
||||
AlipaySubject: options.AlipaySubject || '平台充值',
|
||||
AlipayExpireMinutes: options.AlipayExpireMinutes || 30,
|
||||
}}
|
||||
>
|
||||
<Form.Input
|
||||
field='AlipayAppId'
|
||||
label={t('应用 ID (App ID)')}
|
||||
placeholder={t('请输入支付宝应用 ID')}
|
||||
rules={[{ required: true, message: t('请输入应用 ID') }]}
|
||||
/>
|
||||
|
||||
<Form.TextArea
|
||||
field='AlipayPrivateKey'
|
||||
label={t('应用私钥')}
|
||||
placeholder={
|
||||
options.AlipayPrivateKey === '***ALREADY_SET***'
|
||||
? t('已设置(留空不修改,填写新内容则更新)')
|
||||
: t('请粘贴完整的 RSA2 私钥内容(包含 -----BEGIN PRIVATE KEY----- 等)')
|
||||
}
|
||||
rows={6}
|
||||
extraText={
|
||||
options.AlipayPrivateKey === '***ALREADY_SET***'
|
||||
? t('✓ 已配置应用私钥(留空则保持不变)')
|
||||
: t('应用私钥,用于生成签名')
|
||||
}
|
||||
/>
|
||||
|
||||
<Form.TextArea
|
||||
field='AlipayPublicKey'
|
||||
label={t('支付宝公钥')}
|
||||
placeholder={
|
||||
options.AlipayPublicKey === '***ALREADY_SET***'
|
||||
? t('已设置(留空不修改,填写新内容则更新)')
|
||||
: t('请粘贴支付宝公钥内容(包含 -----BEGIN PUBLIC KEY----- 等)')
|
||||
}
|
||||
rows={6}
|
||||
extraText={
|
||||
options.AlipayPublicKey === '***ALREADY_SET***'
|
||||
? t('✓ 已配置支付宝公钥(留空则保持不变)')
|
||||
: t('支付宝公钥(非应用公钥),用于验证签名')
|
||||
}
|
||||
/>
|
||||
|
||||
<Divider margin='12px' />
|
||||
|
||||
<Form.Switch
|
||||
field='AlipayPCEnabled'
|
||||
label={t('启用电脑网站支付')}
|
||||
extraText={t('PC 端网页支付,跳转到支付宝页面')}
|
||||
/>
|
||||
|
||||
<Form.Switch
|
||||
field='AlipayWAPEnabled'
|
||||
label={t('启用手机网站支付')}
|
||||
extraText={t('手机浏览器唤起支付宝 APP 支付')}
|
||||
/>
|
||||
|
||||
<Form.Switch
|
||||
field='AlipayQREnabled'
|
||||
label={t('启用当面付扫码支付')}
|
||||
extraText={t('生成二维码,用户扫码支付')}
|
||||
/>
|
||||
|
||||
<Form.Switch
|
||||
field='AlipayIsSandbox'
|
||||
label={t('沙箱模式')}
|
||||
extraText={t('测试环境,使用支付宝沙箱进行调试')}
|
||||
/>
|
||||
|
||||
<Divider margin='12px' />
|
||||
|
||||
<Form.Input
|
||||
field='AlipayNotifyUrl'
|
||||
label={t('异步通知 URL')}
|
||||
placeholder={t('留空则使用默认地址')}
|
||||
extraText={t('默认: {服务器地址}/api/alipay/notify')}
|
||||
/>
|
||||
|
||||
<Form.Input
|
||||
field='AlipayReturnUrl'
|
||||
label={t('同步返回 URL')}
|
||||
placeholder={t('留空则使用默认地址')}
|
||||
extraText={t('默认: {服务器地址}/recharge')}
|
||||
/>
|
||||
|
||||
<Form.Input
|
||||
field='AlipaySubject'
|
||||
label={t('商品标题')}
|
||||
placeholder={t('平台充值')}
|
||||
extraText={t('显示在支付宝支付界面的商品标题')}
|
||||
/>
|
||||
|
||||
<Form.InputNumber
|
||||
field='AlipayExpireMinutes'
|
||||
label={t('订单过期时间(分钟)')}
|
||||
min={1}
|
||||
max={1440}
|
||||
extraText={t('订单未支付的有效时间,默认 30 分钟')}
|
||||
/>
|
||||
|
||||
<Space style={{ marginTop: 20 }}>
|
||||
<Button type='primary' htmlType='submit' loading={loading}>{t('保存配置')}</Button>
|
||||
</Space>
|
||||
</Form>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default SettingsPaymentAlipay;
|
||||
@@ -0,0 +1,332 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useEffect, useState, useRef } from 'react';
|
||||
import { Button, Form, Row, Col, Typography, Spin } from '@douyinfe/semi-ui';
|
||||
const { Text } = Typography;
|
||||
import {
|
||||
API,
|
||||
removeTrailingSlash,
|
||||
showError,
|
||||
showSuccess,
|
||||
verifyJSON,
|
||||
} from '../../../helpers';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
export default function SettingsPaymentGateway(props) {
|
||||
const { t } = useTranslation();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [inputs, setInputs] = useState({
|
||||
PayAddress: '',
|
||||
EpayId: '',
|
||||
EpayKey: '',
|
||||
Price: 7.3,
|
||||
MinTopUp: 1,
|
||||
TopupGroupRatio: '',
|
||||
CustomCallbackAddress: '',
|
||||
PayMethods: '',
|
||||
AmountOptions: '',
|
||||
AmountDiscount: '',
|
||||
});
|
||||
const [originInputs, setOriginInputs] = useState({});
|
||||
const formApiRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (props.options && formApiRef.current) {
|
||||
const currentInputs = {
|
||||
PayAddress: props.options.PayAddress || '',
|
||||
EpayId: props.options.EpayId || '',
|
||||
EpayKey: props.options.EpayKey || '',
|
||||
Price:
|
||||
props.options.Price !== undefined
|
||||
? parseFloat(props.options.Price)
|
||||
: 7.3,
|
||||
MinTopUp:
|
||||
props.options.MinTopUp !== undefined
|
||||
? parseFloat(props.options.MinTopUp)
|
||||
: 1,
|
||||
TopupGroupRatio: props.options.TopupGroupRatio || '',
|
||||
CustomCallbackAddress: props.options.CustomCallbackAddress || '',
|
||||
PayMethods: props.options.PayMethods || '',
|
||||
AmountOptions: props.options.AmountOptions || '',
|
||||
AmountDiscount: props.options.AmountDiscount || '',
|
||||
};
|
||||
|
||||
// 美化 JSON 展示
|
||||
try {
|
||||
if (currentInputs.AmountOptions) {
|
||||
currentInputs.AmountOptions = JSON.stringify(
|
||||
JSON.parse(currentInputs.AmountOptions),
|
||||
null,
|
||||
2,
|
||||
);
|
||||
}
|
||||
} catch {}
|
||||
try {
|
||||
if (currentInputs.AmountDiscount) {
|
||||
currentInputs.AmountDiscount = JSON.stringify(
|
||||
JSON.parse(currentInputs.AmountDiscount),
|
||||
null,
|
||||
2,
|
||||
);
|
||||
}
|
||||
} catch {}
|
||||
|
||||
setInputs(currentInputs);
|
||||
setOriginInputs({ ...currentInputs });
|
||||
formApiRef.current.setValues(currentInputs);
|
||||
}
|
||||
}, [props.options]);
|
||||
|
||||
const handleFormChange = (values) => {
|
||||
setInputs(values);
|
||||
};
|
||||
|
||||
const submitPayAddress = async () => {
|
||||
if (props.options.ServerAddress === '') {
|
||||
showError(t('请先填写服务器地址'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (originInputs['TopupGroupRatio'] !== inputs.TopupGroupRatio) {
|
||||
if (!verifyJSON(inputs.TopupGroupRatio)) {
|
||||
showError(t('充值分组倍率不是合法的 JSON 字符串'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (originInputs['PayMethods'] !== inputs.PayMethods) {
|
||||
if (!verifyJSON(inputs.PayMethods)) {
|
||||
showError(t('充值方式设置不是合法的 JSON 字符串'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
originInputs['AmountOptions'] !== inputs.AmountOptions &&
|
||||
inputs.AmountOptions.trim() !== ''
|
||||
) {
|
||||
if (!verifyJSON(inputs.AmountOptions)) {
|
||||
showError(t('自定义充值数量选项不是合法的 JSON 数组'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
originInputs['AmountDiscount'] !== inputs.AmountDiscount &&
|
||||
inputs.AmountDiscount.trim() !== ''
|
||||
) {
|
||||
if (!verifyJSON(inputs.AmountDiscount)) {
|
||||
showError(t('充值金额折扣配置不是合法的 JSON 对象'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
const options = [
|
||||
{ key: 'PayAddress', value: removeTrailingSlash(inputs.PayAddress) },
|
||||
];
|
||||
|
||||
if (inputs.EpayId !== '') {
|
||||
options.push({ key: 'EpayId', value: inputs.EpayId });
|
||||
}
|
||||
if (inputs.EpayKey !== undefined && inputs.EpayKey !== '') {
|
||||
options.push({ key: 'EpayKey', value: inputs.EpayKey });
|
||||
}
|
||||
if (inputs.Price !== '') {
|
||||
options.push({ key: 'Price', value: inputs.Price.toString() });
|
||||
}
|
||||
if (inputs.MinTopUp !== '') {
|
||||
options.push({ key: 'MinTopUp', value: inputs.MinTopUp.toString() });
|
||||
}
|
||||
if (inputs.CustomCallbackAddress !== '') {
|
||||
options.push({
|
||||
key: 'CustomCallbackAddress',
|
||||
value: inputs.CustomCallbackAddress,
|
||||
});
|
||||
}
|
||||
if (originInputs['TopupGroupRatio'] !== inputs.TopupGroupRatio) {
|
||||
options.push({ key: 'TopupGroupRatio', value: inputs.TopupGroupRatio });
|
||||
}
|
||||
if (originInputs['PayMethods'] !== inputs.PayMethods) {
|
||||
options.push({ key: 'PayMethods', value: inputs.PayMethods });
|
||||
}
|
||||
if (originInputs['AmountOptions'] !== inputs.AmountOptions) {
|
||||
options.push({
|
||||
key: 'payment_setting.amount_options',
|
||||
value: inputs.AmountOptions,
|
||||
});
|
||||
}
|
||||
if (originInputs['AmountDiscount'] !== inputs.AmountDiscount) {
|
||||
options.push({
|
||||
key: 'payment_setting.amount_discount',
|
||||
value: inputs.AmountDiscount,
|
||||
});
|
||||
}
|
||||
|
||||
// 发送请求
|
||||
const requestQueue = options.map((opt) =>
|
||||
API.put('/api/option/', {
|
||||
key: opt.key,
|
||||
value: opt.value,
|
||||
}),
|
||||
);
|
||||
|
||||
const results = await Promise.all(requestQueue);
|
||||
|
||||
// 检查所有请求是否成功
|
||||
const errorResults = results.filter((res) => !res.data.success);
|
||||
if (errorResults.length > 0) {
|
||||
errorResults.forEach((res) => {
|
||||
showError(res.data.message);
|
||||
});
|
||||
} else {
|
||||
showSuccess(t('更新成功'));
|
||||
// 更新本地存储的原始值
|
||||
setOriginInputs({ ...inputs });
|
||||
props.refresh && props.refresh();
|
||||
}
|
||||
} catch (error) {
|
||||
showError(t('更新失败'));
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<Spin spinning={loading}>
|
||||
<Form
|
||||
initValues={inputs}
|
||||
onValueChange={handleFormChange}
|
||||
getFormApi={(api) => (formApiRef.current = api)}
|
||||
>
|
||||
<Form.Section text={t('支付设置')}>
|
||||
<Text>
|
||||
{t(
|
||||
'(当前仅支持易支付接口,默认使用上方服务器地址作为回调地址!)',
|
||||
)}
|
||||
</Text>
|
||||
<Row gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}>
|
||||
<Col xs={24} sm={24} md={8} lg={8} xl={8}>
|
||||
<Form.Input
|
||||
field='PayAddress'
|
||||
label={t('支付地址')}
|
||||
placeholder={t('例如:https://yourdomain.com')}
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={24} sm={24} md={8} lg={8} xl={8}>
|
||||
<Form.Input
|
||||
field='EpayId'
|
||||
label={t('易支付商户ID')}
|
||||
placeholder={t('例如:0001')}
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={24} sm={24} md={8} lg={8} xl={8}>
|
||||
<Form.Input
|
||||
field='EpayKey'
|
||||
label={t('易支付商户密钥')}
|
||||
placeholder={t('敏感信息不会发送到前端显示')}
|
||||
type='password'
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row
|
||||
gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
|
||||
style={{ marginTop: 16 }}
|
||||
>
|
||||
<Col xs={24} sm={24} md={8} lg={8} xl={8}>
|
||||
<Form.Input
|
||||
field='CustomCallbackAddress'
|
||||
label={t('回调地址')}
|
||||
placeholder={t('例如:https://yourdomain.com')}
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={24} sm={24} md={8} lg={8} xl={8}>
|
||||
<Form.InputNumber
|
||||
field='Price'
|
||||
precision={2}
|
||||
label={t('充值价格(x元/美金)')}
|
||||
placeholder={t('例如:7,就是7元/美金')}
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={24} sm={24} md={8} lg={8} xl={8}>
|
||||
<Form.InputNumber
|
||||
field='MinTopUp'
|
||||
label={t('最低充值美元数量')}
|
||||
placeholder={t('例如:2,就是最低充值2$')}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
<Form.TextArea
|
||||
field='TopupGroupRatio'
|
||||
label={t('充值分组倍率')}
|
||||
placeholder={t('为一个 JSON 文本,键为组名称,值为倍率')}
|
||||
autosize
|
||||
/>
|
||||
<Form.TextArea
|
||||
field='PayMethods'
|
||||
label={t('充值方式设置')}
|
||||
placeholder={t('为一个 JSON 文本')}
|
||||
autosize
|
||||
/>
|
||||
|
||||
<Row
|
||||
gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
|
||||
style={{ marginTop: 16 }}
|
||||
>
|
||||
<Col span={24}>
|
||||
<Form.TextArea
|
||||
field='AmountOptions'
|
||||
label={t('自定义充值数量选项')}
|
||||
placeholder={t(
|
||||
'为一个 JSON 数组,例如:[10, 20, 50, 100, 200, 500]',
|
||||
)}
|
||||
autosize
|
||||
extraText={t(
|
||||
'设置用户可选择的充值数量选项,例如:[10, 20, 50, 100, 200, 500]',
|
||||
)}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Row
|
||||
gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
|
||||
style={{ marginTop: 16 }}
|
||||
>
|
||||
<Col span={24}>
|
||||
<Form.TextArea
|
||||
field='AmountDiscount'
|
||||
label={t('充值金额折扣配置')}
|
||||
placeholder={t(
|
||||
'为一个 JSON 对象,例如:{"100": 0.95, "200": 0.9, "500": 0.85}',
|
||||
)}
|
||||
autosize
|
||||
extraText={t(
|
||||
'设置不同充值金额对应的折扣,键为充值金额,值为折扣率,例如:{"100": 0.95, "200": 0.9, "500": 0.85}',
|
||||
)}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Button onClick={submitPayAddress}>{t('更新支付设置')}</Button>
|
||||
</Form.Section>
|
||||
</Form>
|
||||
</Spin>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,422 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React, { useEffect, useState, useRef } from 'react';
|
||||
import {
|
||||
Banner,
|
||||
Button,
|
||||
Form,
|
||||
Row,
|
||||
Col,
|
||||
Typography,
|
||||
Spin,
|
||||
Table,
|
||||
Modal,
|
||||
Input,
|
||||
InputNumber,
|
||||
Select,
|
||||
} from '@douyinfe/semi-ui';
|
||||
const { Text } = Typography;
|
||||
import { API, showError, showSuccess } from '../../../helpers';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Plus, Trash2 } from 'lucide-react';
|
||||
|
||||
export default function SettingsPaymentGatewayCreem(props) {
|
||||
const { t } = useTranslation();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [inputs, setInputs] = useState({
|
||||
CreemApiKey: '',
|
||||
CreemWebhookSecret: '',
|
||||
CreemProducts: '[]',
|
||||
CreemTestMode: false,
|
||||
});
|
||||
const [, setOriginInputs] = useState({});
|
||||
const [products, setProducts] = useState([]);
|
||||
const [showProductModal, setShowProductModal] = useState(false);
|
||||
const [editingProduct, setEditingProduct] = useState(null);
|
||||
const [productForm, setProductForm] = useState({
|
||||
name: '',
|
||||
productId: '',
|
||||
price: 0,
|
||||
quota: 0,
|
||||
currency: 'USD',
|
||||
});
|
||||
const formApiRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (props.options && formApiRef.current) {
|
||||
const currentInputs = {
|
||||
CreemApiKey: props.options.CreemApiKey || '',
|
||||
CreemWebhookSecret: props.options.CreemWebhookSecret || '',
|
||||
CreemProducts: props.options.CreemProducts || '[]',
|
||||
CreemTestMode: props.options.CreemTestMode === 'true',
|
||||
};
|
||||
setInputs(currentInputs);
|
||||
setOriginInputs({ ...currentInputs });
|
||||
formApiRef.current.setValues(currentInputs);
|
||||
|
||||
// Parse products
|
||||
try {
|
||||
const parsedProducts = JSON.parse(currentInputs.CreemProducts);
|
||||
setProducts(parsedProducts);
|
||||
} catch (e) {
|
||||
setProducts([]);
|
||||
}
|
||||
}
|
||||
}, [props.options]);
|
||||
|
||||
const handleFormChange = (values) => {
|
||||
setInputs(values);
|
||||
};
|
||||
|
||||
const submitCreemSetting = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const options = [];
|
||||
|
||||
if (inputs.CreemApiKey && inputs.CreemApiKey !== '') {
|
||||
options.push({ key: 'CreemApiKey', value: inputs.CreemApiKey });
|
||||
}
|
||||
|
||||
if (inputs.CreemWebhookSecret && inputs.CreemWebhookSecret !== '') {
|
||||
options.push({
|
||||
key: 'CreemWebhookSecret',
|
||||
value: inputs.CreemWebhookSecret,
|
||||
});
|
||||
}
|
||||
|
||||
// Save test mode setting
|
||||
options.push({
|
||||
key: 'CreemTestMode',
|
||||
value: inputs.CreemTestMode ? 'true' : 'false',
|
||||
});
|
||||
|
||||
// Save products as JSON string
|
||||
options.push({ key: 'CreemProducts', value: JSON.stringify(products) });
|
||||
|
||||
// 发送请求
|
||||
const requestQueue = options.map((opt) =>
|
||||
API.put('/api/option/', {
|
||||
key: opt.key,
|
||||
value: opt.value,
|
||||
}),
|
||||
);
|
||||
|
||||
const results = await Promise.all(requestQueue);
|
||||
|
||||
// 检查所有请求是否成功
|
||||
const errorResults = results.filter((res) => !res.data.success);
|
||||
if (errorResults.length > 0) {
|
||||
errorResults.forEach((res) => {
|
||||
showError(res.data.message);
|
||||
});
|
||||
} else {
|
||||
showSuccess(t('更新成功'));
|
||||
// 更新本地存储的原始值
|
||||
setOriginInputs({ ...inputs });
|
||||
props.refresh?.();
|
||||
}
|
||||
} catch (error) {
|
||||
showError(t('更新失败'));
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
const openProductModal = (product = null) => {
|
||||
if (product) {
|
||||
setEditingProduct(product);
|
||||
setProductForm({ ...product });
|
||||
} else {
|
||||
setEditingProduct(null);
|
||||
setProductForm({
|
||||
name: '',
|
||||
productId: '',
|
||||
price: 0,
|
||||
quota: 0,
|
||||
currency: 'USD',
|
||||
});
|
||||
}
|
||||
setShowProductModal(true);
|
||||
};
|
||||
|
||||
const closeProductModal = () => {
|
||||
setShowProductModal(false);
|
||||
setEditingProduct(null);
|
||||
setProductForm({
|
||||
name: '',
|
||||
productId: '',
|
||||
price: 0,
|
||||
quota: 0,
|
||||
currency: 'USD',
|
||||
});
|
||||
};
|
||||
|
||||
const saveProduct = () => {
|
||||
if (
|
||||
!productForm.name ||
|
||||
!productForm.productId ||
|
||||
productForm.price <= 0 ||
|
||||
productForm.quota <= 0 ||
|
||||
!productForm.currency
|
||||
) {
|
||||
showError(t('请填写完整的产品信息'));
|
||||
return;
|
||||
}
|
||||
|
||||
let newProducts = [...products];
|
||||
if (editingProduct) {
|
||||
// 编辑现有产品
|
||||
const index = newProducts.findIndex(
|
||||
(p) => p.productId === editingProduct.productId,
|
||||
);
|
||||
if (index !== -1) {
|
||||
newProducts[index] = { ...productForm };
|
||||
}
|
||||
} else {
|
||||
// 添加新产品
|
||||
if (newProducts.find((p) => p.productId === productForm.productId)) {
|
||||
showError(t('产品ID已存在'));
|
||||
return;
|
||||
}
|
||||
newProducts.push({ ...productForm });
|
||||
}
|
||||
|
||||
setProducts(newProducts);
|
||||
closeProductModal();
|
||||
};
|
||||
|
||||
const deleteProduct = (productId) => {
|
||||
const newProducts = products.filter((p) => p.productId !== productId);
|
||||
setProducts(newProducts);
|
||||
};
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: t('产品名称'),
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
},
|
||||
{
|
||||
title: t('产品ID'),
|
||||
dataIndex: 'productId',
|
||||
key: 'productId',
|
||||
},
|
||||
{
|
||||
title: t('展示价格'),
|
||||
dataIndex: 'price',
|
||||
key: 'price',
|
||||
render: (price, record) =>
|
||||
`${record.currency === 'EUR' ? '€' : '¥'}${price}`,
|
||||
},
|
||||
{
|
||||
title: t('充值额度'),
|
||||
dataIndex: 'quota',
|
||||
key: 'quota',
|
||||
},
|
||||
{
|
||||
title: t('操作'),
|
||||
key: 'action',
|
||||
render: (_, record) => (
|
||||
<div className='flex gap-2'>
|
||||
<Button
|
||||
type='tertiary'
|
||||
size='small'
|
||||
onClick={() => openProductModal(record)}
|
||||
>
|
||||
{t('编辑')}
|
||||
</Button>
|
||||
<Button
|
||||
type='danger'
|
||||
theme='borderless'
|
||||
size='small'
|
||||
icon={<Trash2 size={14} />}
|
||||
onClick={() => deleteProduct(record.productId)}
|
||||
/>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<Spin spinning={loading}>
|
||||
<Form
|
||||
initValues={inputs}
|
||||
onValueChange={handleFormChange}
|
||||
getFormApi={(api) => (formApiRef.current = api)}
|
||||
>
|
||||
<Form.Section text={t('Creem 设置')}>
|
||||
<Text>
|
||||
{t('Creem 介绍')}
|
||||
<a href='https://creem.io' target='_blank' rel='noreferrer'>
|
||||
Creem Official Site
|
||||
</a>
|
||||
<br />
|
||||
</Text>
|
||||
<Banner type='info' description={t('Creem Setting Tips')} />
|
||||
|
||||
<Row gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}>
|
||||
<Col xs={24} sm={24} md={8} lg={8} xl={8}>
|
||||
<Form.Input
|
||||
field='CreemApiKey'
|
||||
label={t('API 密钥')}
|
||||
placeholder={t('Creem API 密钥,敏感信息不显示')}
|
||||
type='password'
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={24} sm={24} md={8} lg={8} xl={8}>
|
||||
<Form.Input
|
||||
field='CreemWebhookSecret'
|
||||
label={t('Webhook 密钥')}
|
||||
placeholder={t(
|
||||
'用于验证回调 new-api 的 webhook 请求的密钥,敏感信息不显示',
|
||||
)}
|
||||
type='password'
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={24} sm={24} md={8} lg={8} xl={8}>
|
||||
<Form.Switch
|
||||
field='CreemTestMode'
|
||||
label={t('测试模式')}
|
||||
extraText={t('启用后将使用 Creem Test Mode')}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<div style={{ marginTop: 24 }}>
|
||||
<div className='flex justify-between items-center mb-4'>
|
||||
<Text strong>{t('产品配置')}</Text>
|
||||
<Button
|
||||
type='primary'
|
||||
icon={<Plus size={16} />}
|
||||
onClick={() => openProductModal()}
|
||||
>
|
||||
{t('添加产品')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={products}
|
||||
pagination={false}
|
||||
empty={
|
||||
<div className='text-center py-8'>
|
||||
<Text type='tertiary'>{t('暂无产品配置')}</Text>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Button onClick={submitCreemSetting} style={{ marginTop: 16 }}>
|
||||
{t('更新 Creem 设置')}
|
||||
</Button>
|
||||
</Form.Section>
|
||||
</Form>
|
||||
|
||||
{/* 产品配置模态框 */}
|
||||
<Modal
|
||||
title={editingProduct ? t('编辑产品') : t('添加产品')}
|
||||
visible={showProductModal}
|
||||
onOk={saveProduct}
|
||||
onCancel={closeProductModal}
|
||||
maskClosable={false}
|
||||
size='small'
|
||||
centered
|
||||
>
|
||||
<div className='space-y-4'>
|
||||
<div>
|
||||
<Text strong className='block mb-2'>
|
||||
{t('产品名称')}
|
||||
</Text>
|
||||
<Input
|
||||
value={productForm.name}
|
||||
onChange={(value) =>
|
||||
setProductForm({ ...productForm, name: value })
|
||||
}
|
||||
placeholder={t('例如:基础套餐')}
|
||||
size='large'
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Text strong className='block mb-2'>
|
||||
{t('产品ID')}
|
||||
</Text>
|
||||
<Input
|
||||
value={productForm.productId}
|
||||
onChange={(value) =>
|
||||
setProductForm({ ...productForm, productId: value })
|
||||
}
|
||||
placeholder={t('例如:prod_6I8rBerHpPxyoiU9WK4kot')}
|
||||
size='large'
|
||||
disabled={!!editingProduct}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Text strong className='block mb-2'>
|
||||
{t('货币')}
|
||||
</Text>
|
||||
<Select
|
||||
value={productForm.currency}
|
||||
onChange={(value) =>
|
||||
setProductForm({ ...productForm, currency: value })
|
||||
}
|
||||
size='large'
|
||||
className='w-full'
|
||||
>
|
||||
<Select.Option value='USD'>{t('USD (美元)')}</Select.Option>
|
||||
<Select.Option value='EUR'>{t('EUR (欧元)')}</Select.Option>
|
||||
</Select>
|
||||
</div>
|
||||
<div>
|
||||
<Text strong className='block mb-2'>
|
||||
{t('价格')} (
|
||||
{productForm.currency === 'EUR' ? t('欧元') : t('美元')})
|
||||
</Text>
|
||||
<InputNumber
|
||||
value={productForm.price}
|
||||
onChange={(value) =>
|
||||
setProductForm({ ...productForm, price: value })
|
||||
}
|
||||
placeholder={t('例如:4.99')}
|
||||
min={0.01}
|
||||
precision={2}
|
||||
size='large'
|
||||
className='w-full'
|
||||
defaultValue={4.49}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Text strong className='block mb-2'>
|
||||
{t('充值额度')}
|
||||
</Text>
|
||||
<InputNumber
|
||||
value={productForm.quota}
|
||||
onChange={(value) =>
|
||||
setProductForm({ ...productForm, quota: value })
|
||||
}
|
||||
placeholder={t('例如:100000')}
|
||||
min={1}
|
||||
precision={0}
|
||||
size='large'
|
||||
className='w-full'
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
</Spin>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,971 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import {
|
||||
Banner,
|
||||
Button,
|
||||
Checkbox,
|
||||
Col,
|
||||
Form,
|
||||
Modal,
|
||||
Row,
|
||||
Spin,
|
||||
Table,
|
||||
TextArea,
|
||||
Typography,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
API,
|
||||
isRoot,
|
||||
removeTrailingSlash,
|
||||
showError,
|
||||
showSuccess,
|
||||
} from '../../../helpers';
|
||||
import { mergePayPalFeePolicyFormValues } from '../../../helpers/paypalPayment';
|
||||
|
||||
const { Text } = Typography;
|
||||
const SECRET_PLACEHOLDER = '***ALREADY_SET***';
|
||||
const PAYPAL_OPERATIONS_PAGE_SIZE = 20;
|
||||
|
||||
function normalizePayPalOperations(data) {
|
||||
if (!data || typeof data !== 'object' || Array.isArray(data)) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
...data,
|
||||
pending_count: Number.isFinite(Number(data.pending_count))
|
||||
? Number(data.pending_count)
|
||||
: 0,
|
||||
pending_page: Number.isFinite(Number(data.pending_page))
|
||||
? Number(data.pending_page)
|
||||
: 1,
|
||||
pending_page_size: Number.isFinite(Number(data.pending_page_size))
|
||||
? Number(data.pending_page_size)
|
||||
: 20,
|
||||
pending_orders: Array.isArray(data.pending_orders)
|
||||
? data.pending_orders.filter(
|
||||
(order) =>
|
||||
order &&
|
||||
typeof order === 'object' &&
|
||||
typeof order.trade_no === 'string' &&
|
||||
order.trade_no.trim() !== '',
|
||||
)
|
||||
: [],
|
||||
config_history: Array.isArray(data.config_history)
|
||||
? data.config_history
|
||||
: [],
|
||||
can_change_config: Boolean(data.can_change_config),
|
||||
};
|
||||
}
|
||||
|
||||
export default function SettingsPaymentGatewayPayPal(props) {
|
||||
const { t } = useTranslation();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [fxStatus, setFxStatus] = useState(null);
|
||||
const [feePolicy, setFeePolicy] = useState(null);
|
||||
const [feeAudits, setFeeAudits] = useState([]);
|
||||
const [feeAuditPage, setFeeAuditPage] = useState(1);
|
||||
const [feeAuditTotal, setFeeAuditTotal] = useState(0);
|
||||
const [operations, setOperations] = useState(null);
|
||||
const [operationsPage, setOperationsPage] = useState(1);
|
||||
const [selectedOperationOrderKeys, setSelectedOperationOrderKeys] = useState(
|
||||
[],
|
||||
);
|
||||
const [expireOrder, setExpireOrder] = useState(null);
|
||||
const [expireReason, setExpireReason] = useState('');
|
||||
const [forceExpire, setForceExpire] = useState(false);
|
||||
const [forceExpireConfirmed, setForceExpireConfirmed] = useState(false);
|
||||
const [batchExpire, setBatchExpire] = useState(null);
|
||||
const [batchExpireReason, setBatchExpireReason] = useState('');
|
||||
const [batchForceConfirmed, setBatchForceConfirmed] = useState(false);
|
||||
const formApiRef = useRef(null);
|
||||
const [inputs, setInputs] = useState({
|
||||
PayPalClientID: '',
|
||||
PayPalClientSecret: '',
|
||||
PayPalWebhookID: '',
|
||||
PayPalSandbox: true,
|
||||
PayPalMinTopUp: 1,
|
||||
PayPalFXMode: 'manual',
|
||||
PayPalFXProvider: 'open_exchange_rates',
|
||||
PayPalFXAPIKey: '',
|
||||
PayPalFXAdjustmentBps: 0,
|
||||
PayPalUserPaysFee: false,
|
||||
PayPalFeeRatePercent: 0,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const values = {
|
||||
PayPalClientID: props.options?.PayPalClientID || '',
|
||||
PayPalClientSecret: props.options?.PayPalClientSecret || '',
|
||||
PayPalWebhookID: props.options?.PayPalWebhookID || '',
|
||||
PayPalSandbox: props.options?.PayPalSandbox ?? true,
|
||||
PayPalMinTopUp: Number(props.options?.PayPalMinTopUp) || 1,
|
||||
PayPalFXMode: props.options?.PayPalFXMode || 'manual',
|
||||
PayPalFXProvider:
|
||||
props.options?.PayPalFXProvider || 'open_exchange_rates',
|
||||
PayPalFXAPIKey: props.options?.PayPalFXAPIKey || '',
|
||||
PayPalFXAdjustmentBps: Number(props.options?.PayPalFXAdjustmentBps) || 0,
|
||||
};
|
||||
setInputs((current) => {
|
||||
const next = {
|
||||
...values,
|
||||
PayPalUserPaysFee: current.PayPalUserPaysFee,
|
||||
PayPalFeeRatePercent: current.PayPalFeeRatePercent,
|
||||
};
|
||||
formApiRef.current?.setValues(next);
|
||||
return next;
|
||||
});
|
||||
}, [props.options]);
|
||||
|
||||
const refreshFXStatus = useCallback(async () => {
|
||||
try {
|
||||
const response = await API.get('/api/option/paypal/fx/status');
|
||||
if (response.data.success) setFxStatus(response.data.data);
|
||||
} catch {
|
||||
setFxStatus(null);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
refreshFXStatus();
|
||||
}, [refreshFXStatus]);
|
||||
|
||||
const refreshFeePolicy = useCallback(
|
||||
async (page = 1, preserveDraft = false) => {
|
||||
if (!isRoot()) return;
|
||||
try {
|
||||
const [policyResponse, auditResponse] = await Promise.all([
|
||||
API.get('/api/option/paypal/fee-policy'),
|
||||
API.get(
|
||||
`/api/option/paypal/fee-policy/audits?p=${page}&page_size=20`,
|
||||
),
|
||||
]);
|
||||
if (policyResponse.data.success) {
|
||||
const policy = policyResponse.data.data;
|
||||
setFeePolicy(policy);
|
||||
if (!preserveDraft) {
|
||||
setInputs((current) =>
|
||||
mergePayPalFeePolicyFormValues(current, policy),
|
||||
);
|
||||
if (formApiRef.current) {
|
||||
formApiRef.current.setValues(
|
||||
mergePayPalFeePolicyFormValues(
|
||||
formApiRef.current.getValues(),
|
||||
policy,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (auditResponse.data.success) {
|
||||
const auditData = auditResponse.data.data;
|
||||
setFeeAudits(auditData?.items || []);
|
||||
setFeeAuditPage(page);
|
||||
setFeeAuditTotal(Number(auditData?.total || 0));
|
||||
}
|
||||
} catch (error) {
|
||||
showError(error?.response?.data?.message || t('获取手续费策略失败'));
|
||||
}
|
||||
},
|
||||
[t],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
refreshFeePolicy(1);
|
||||
}, [refreshFeePolicy]);
|
||||
|
||||
const refreshOperations = useCallback(
|
||||
async (page = 1) => {
|
||||
if (!isRoot()) return;
|
||||
try {
|
||||
const response = await API.get(
|
||||
`/api/option/paypal/operations/preflight?p=${page}&page_size=${PAYPAL_OPERATIONS_PAGE_SIZE}`,
|
||||
);
|
||||
if (response?.data?.success) {
|
||||
setOperations(normalizePayPalOperations(response.data.data));
|
||||
setOperationsPage(page);
|
||||
}
|
||||
} catch (error) {
|
||||
showError(
|
||||
error?.response?.data?.message || t('获取 PayPal 订单预检信息失败'),
|
||||
);
|
||||
}
|
||||
},
|
||||
[t],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
refreshOperations(1);
|
||||
}, [refreshOperations]);
|
||||
|
||||
const inspectOperationOrder = async (tradeNo) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const response = await API.post(
|
||||
`/api/option/paypal/operations/orders/${encodeURIComponent(tradeNo)}/inspect`,
|
||||
);
|
||||
if (!response.data.success)
|
||||
throw new Error(response.data.message || t('查询失败'));
|
||||
const data = response.data.data;
|
||||
showSuccess(`${tradeNo}:PayPal 状态 ${data.remote_status}`);
|
||||
setSelectedOperationOrderKeys((keys) =>
|
||||
keys.filter((key) => key !== String(tradeNo)),
|
||||
);
|
||||
await refreshOperations(operationsPage);
|
||||
} catch (error) {
|
||||
showError(
|
||||
error?.response?.data?.message || error?.message || t('查询失败'),
|
||||
);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const reconcileOperationOrder = async (tradeNo) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const response = await API.post(
|
||||
`/api/option/paypal/operations/orders/${encodeURIComponent(tradeNo)}/reconcile`,
|
||||
);
|
||||
if (!response.data.success)
|
||||
throw new Error(response.data.message || t('对账失败'));
|
||||
showSuccess(t('PayPal 订单已触发对账'));
|
||||
setSelectedOperationOrderKeys((keys) =>
|
||||
keys.filter((key) => key !== String(tradeNo)),
|
||||
);
|
||||
await refreshOperations(operationsPage);
|
||||
} catch (error) {
|
||||
showError(
|
||||
error?.response?.data?.message || error?.message || t('对账失败'),
|
||||
);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const expireOperationOrder = async () => {
|
||||
const reason =
|
||||
typeof expireReason === 'string'
|
||||
? expireReason.trim()
|
||||
: String(expireReason ?? '').trim();
|
||||
if (!expireOrder || reason.length < 6) {
|
||||
showError(t('请填写至少 6 个字符的过期原因'));
|
||||
return;
|
||||
}
|
||||
if (forceExpire && !forceExpireConfirmed) {
|
||||
showError(t('请先确认强制过期风险'));
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
try {
|
||||
const response = await API.post(
|
||||
`/api/option/paypal/operations/orders/${encodeURIComponent(expireOrder.trade_no)}/expire`,
|
||||
{
|
||||
confirm_trade_no: expireOrder.trade_no,
|
||||
reason,
|
||||
force: forceExpire,
|
||||
},
|
||||
);
|
||||
if (!response.data.success)
|
||||
throw new Error(response.data.message || t('过期失败'));
|
||||
showSuccess(t('PayPal 订单已标记为过期'));
|
||||
setExpireOrder(null);
|
||||
setExpireReason('');
|
||||
setForceExpire(false);
|
||||
setForceExpireConfirmed(false);
|
||||
setSelectedOperationOrderKeys((keys) =>
|
||||
keys.filter((key) => key !== String(expireOrder.trade_no)),
|
||||
);
|
||||
await refreshOperations(operationsPage);
|
||||
} catch (error) {
|
||||
showError(
|
||||
error?.response?.data?.message || error?.message || t('过期失败'),
|
||||
);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const runBatchOperation = async (operation) => {
|
||||
if (selectedOperationOrderKeys.length === 0) {
|
||||
showError(t('请先勾选 PayPal 订单'));
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
try {
|
||||
const response = await API.post(
|
||||
'/api/option/paypal/operations/orders/batch',
|
||||
{
|
||||
trade_nos: selectedOperationOrderKeys,
|
||||
operation,
|
||||
},
|
||||
);
|
||||
if (!response?.data?.success) {
|
||||
throw new Error(response?.data?.message || t('批量操作失败'));
|
||||
}
|
||||
const data = response.data.data || {};
|
||||
const failedResults = (data.results || []).filter(
|
||||
(item) => !item.success,
|
||||
);
|
||||
showSuccess(
|
||||
`批量${operation === 'inspect' ? '查询' : '对账'}完成:成功 ${data.succeeded || 0} 笔,失败 ${data.failed || 0} 笔`,
|
||||
);
|
||||
if (failedResults.length > 0) {
|
||||
showError(
|
||||
failedResults
|
||||
.slice(0, 3)
|
||||
.map((item) => `${item.trade_no}:${item.message || t('操作失败')}`)
|
||||
.join(';'),
|
||||
);
|
||||
}
|
||||
setSelectedOperationOrderKeys([]);
|
||||
await refreshOperations(operationsPage);
|
||||
} catch (error) {
|
||||
showError(
|
||||
error?.response?.data?.message || error?.message || t('批量操作失败'),
|
||||
);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const openBatchExpire = (force) => {
|
||||
if (selectedOperationOrderKeys.length === 0) {
|
||||
showError(t('请先勾选 PayPal 订单'));
|
||||
return;
|
||||
}
|
||||
setBatchExpire({ tradeNos: selectedOperationOrderKeys, force });
|
||||
setBatchForceConfirmed(false);
|
||||
setBatchExpireReason(
|
||||
force
|
||||
? '管理员确认远端状态无法核验,强制关闭所选 PayPal 订单'
|
||||
: '确认所选 PayPal 订单均未完成支付',
|
||||
);
|
||||
};
|
||||
|
||||
const confirmBatchExpire = async () => {
|
||||
const reason = batchExpireReason.trim();
|
||||
if (!batchExpire || reason.length < 6) {
|
||||
showError(t('请填写至少 6 个字符的过期原因'));
|
||||
return;
|
||||
}
|
||||
if (batchExpire.force && !batchForceConfirmed) {
|
||||
showError(t('请先确认强制过期风险'));
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
try {
|
||||
const response = await API.post(
|
||||
'/api/option/paypal/operations/orders/batch',
|
||||
{
|
||||
trade_nos: batchExpire.tradeNos,
|
||||
operation: 'expire',
|
||||
reason,
|
||||
force: batchExpire.force,
|
||||
},
|
||||
);
|
||||
if (!response?.data?.success) {
|
||||
throw new Error(response?.data?.message || t('批量过期失败'));
|
||||
}
|
||||
const data = response.data.data || {};
|
||||
const failedResults = (data.results || []).filter(
|
||||
(item) => !item.success,
|
||||
);
|
||||
showSuccess(
|
||||
`批量${batchExpire.force ? '强制' : ''}过期完成:成功 ${data.succeeded || 0} 笔,失败 ${data.failed || 0} 笔`,
|
||||
);
|
||||
if (failedResults.length > 0) {
|
||||
showError(
|
||||
failedResults
|
||||
.slice(0, 3)
|
||||
.map((item) => `${item.trade_no}:${item.message || t('操作失败')}`)
|
||||
.join(';'),
|
||||
);
|
||||
}
|
||||
setBatchExpire(null);
|
||||
setBatchExpireReason('');
|
||||
setBatchForceConfirmed(false);
|
||||
setSelectedOperationOrderKeys([]);
|
||||
await refreshOperations(operationsPage);
|
||||
} catch (error) {
|
||||
showError(
|
||||
error?.response?.data?.message || error?.message || t('批量过期失败'),
|
||||
);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const submit = async () => {
|
||||
if (!props.options?.ServerAddress) {
|
||||
showError(t('请先填写服务器地址'));
|
||||
return;
|
||||
}
|
||||
const options = [
|
||||
{ key: 'PayPalClientID', value: inputs.PayPalClientID?.trim() },
|
||||
{ key: 'PayPalWebhookID', value: inputs.PayPalWebhookID?.trim() },
|
||||
{ key: 'PayPalSandbox', value: String(inputs.PayPalSandbox) },
|
||||
{ key: 'PayPalMinTopUp', value: String(inputs.PayPalMinTopUp || 1) },
|
||||
{ key: 'PayPalFXMode', value: inputs.PayPalFXMode || 'manual' },
|
||||
{
|
||||
key: 'PayPalFXProvider',
|
||||
value: inputs.PayPalFXProvider || 'open_exchange_rates',
|
||||
},
|
||||
{
|
||||
key: 'PayPalFXAdjustmentBps',
|
||||
value: String(inputs.PayPalFXAdjustmentBps || 0),
|
||||
},
|
||||
];
|
||||
if (
|
||||
inputs.PayPalClientSecret &&
|
||||
inputs.PayPalClientSecret !== SECRET_PLACEHOLDER
|
||||
) {
|
||||
options.push({
|
||||
key: 'PayPalClientSecret',
|
||||
value: inputs.PayPalClientSecret,
|
||||
});
|
||||
}
|
||||
if (inputs.PayPalFXAPIKey && inputs.PayPalFXAPIKey !== SECRET_PLACEHOLDER) {
|
||||
options.push({ key: 'PayPalFXAPIKey', value: inputs.PayPalFXAPIKey });
|
||||
}
|
||||
setLoading(true);
|
||||
try {
|
||||
for (const option of options) {
|
||||
const response = await API.put('/api/option/', option);
|
||||
if (!response.data.success) {
|
||||
throw new Error(response.data.message || t('更新失败'));
|
||||
}
|
||||
}
|
||||
if (isRoot()) {
|
||||
const rateBps = Math.round(
|
||||
Number(inputs.PayPalFeeRatePercent || 0) * 100,
|
||||
);
|
||||
if (
|
||||
rateBps < 0 ||
|
||||
rateBps > 2000 ||
|
||||
(inputs.PayPalUserPaysFee && rateBps < 1)
|
||||
) {
|
||||
throw new Error(t('手续费比例必须在有效范围内'));
|
||||
}
|
||||
const response = await API.put('/api/option/paypal/fee-policy', {
|
||||
user_pays_fee: Boolean(inputs.PayPalUserPaysFee),
|
||||
rate_bps: rateBps,
|
||||
expected_version: feePolicy?.version,
|
||||
});
|
||||
if (!response.data.success) {
|
||||
throw new Error(response.data.message || t('更新失败'));
|
||||
}
|
||||
}
|
||||
showSuccess(t('更新成功'));
|
||||
await props.refresh?.();
|
||||
await refreshFXStatus();
|
||||
await refreshFeePolicy(1);
|
||||
} catch (error) {
|
||||
if (error?.response?.status === 409) {
|
||||
await refreshFeePolicy(feeAuditPage, true);
|
||||
showError(t('手续费策略已被其他管理员更新,请重新确认'));
|
||||
} else {
|
||||
showError(
|
||||
error?.response?.data?.message || error?.message || t('更新失败'),
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const webhookBase = props.options?.ServerAddress
|
||||
? removeTrailingSlash(props.options.ServerAddress)
|
||||
: t('网站地址');
|
||||
const pendingOrders = Array.isArray(operations?.pending_orders)
|
||||
? operations.pending_orders
|
||||
: [];
|
||||
|
||||
const runFXAction = async (action) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const response = await API.post(`/api/option/paypal/fx/${action}`);
|
||||
if (!response.data.success) {
|
||||
throw new Error(response.data.message || t('操作失败'));
|
||||
}
|
||||
showSuccess(
|
||||
t(action === 'refresh' ? '汇率刷新成功' : '已确认手工兜底汇率'),
|
||||
);
|
||||
await refreshFXStatus();
|
||||
} catch (error) {
|
||||
showError(error?.message || t('操作失败'));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Spin spinning={loading}>
|
||||
<Form
|
||||
initValues={inputs}
|
||||
onValueChange={(values) => setInputs({ ...values })}
|
||||
getFormApi={(api) => (formApiRef.current = api)}
|
||||
>
|
||||
<Form.Section text={t('PayPal 设置')}>
|
||||
<Banner
|
||||
type='info'
|
||||
description={`${t('Webhook 地址')}:${webhookBase}/api/paypal/webhook`}
|
||||
/>
|
||||
{isRoot() && (
|
||||
<>
|
||||
<Row gutter={16} style={{ marginTop: 16 }}>
|
||||
<Col xs={24} md={8}>
|
||||
<Form.Switch
|
||||
field='PayPalUserPaysFee'
|
||||
label={t('用户承担支付服务费')}
|
||||
checkedText='|'
|
||||
uncheckedText='〇'
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={24} md={8}>
|
||||
<Form.InputNumber
|
||||
field='PayPalFeeRatePercent'
|
||||
label={t('支付服务费比例(%)')}
|
||||
min={inputs.PayPalUserPaysFee ? 0.01 : 0}
|
||||
max={20}
|
||||
precision={2}
|
||||
disabled={!inputs.PayPalUserPaysFee}
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={24} md={8}>
|
||||
<Text type='tertiary'>
|
||||
{t('手续费策略版本')}:{feePolicy?.version || '-'}
|
||||
<br />
|
||||
{t('最后更新')}:
|
||||
{feePolicy?.updated_at
|
||||
? new Date(feePolicy.updated_at * 1000).toLocaleString()
|
||||
: '-'}
|
||||
<br />
|
||||
{t('最后更新人')}:{feePolicy?.updated_by || '-'}
|
||||
</Text>
|
||||
</Col>
|
||||
</Row>
|
||||
<Banner
|
||||
type='info'
|
||||
description={t(
|
||||
'默认由平台承担;启用后将按配置比例向用户展示并收取支付服务费',
|
||||
)}
|
||||
style={{ marginTop: 16 }}
|
||||
/>
|
||||
<Table
|
||||
size='small'
|
||||
pagination={{
|
||||
currentPage: feeAuditPage,
|
||||
pageSize: 20,
|
||||
total: feeAuditTotal,
|
||||
showTotal: true,
|
||||
onPageChange: (page) => refreshFeePolicy(page, true),
|
||||
}}
|
||||
dataSource={feeAudits}
|
||||
rowKey='id'
|
||||
style={{ marginTop: 16 }}
|
||||
columns={[
|
||||
{
|
||||
title: t('版本'),
|
||||
dataIndex: 'policy_version',
|
||||
width: 80,
|
||||
},
|
||||
{
|
||||
title: t('承担方'),
|
||||
dataIndex: 'new_user_pays_fee',
|
||||
render: (value) => t(value ? '用户承担' : '平台承担'),
|
||||
},
|
||||
{
|
||||
title: t('费率'),
|
||||
dataIndex: 'new_rate_bps',
|
||||
render: (value) => `${(Number(value) / 100).toFixed(2)}%`,
|
||||
},
|
||||
{
|
||||
title: t('操作人'),
|
||||
dataIndex: 'operator_id',
|
||||
},
|
||||
{
|
||||
title: t('更新时间'),
|
||||
dataIndex: 'created_at',
|
||||
render: (value) =>
|
||||
value ? new Date(value * 1000).toLocaleString() : '-',
|
||||
},
|
||||
]}
|
||||
/>
|
||||
<Banner
|
||||
type={operations?.pending_count ? 'warning' : 'success'}
|
||||
description={
|
||||
operations
|
||||
? `配置切换预检:${operations.pending_count || 0} 笔 PayPal pending 订单;${
|
||||
operations.can_change_config
|
||||
? '可以切换环境或应用配置'
|
||||
: '请先隐藏新订单并完成历史订单排空'
|
||||
}`
|
||||
: '正在读取 PayPal 配置切换预检状态'
|
||||
}
|
||||
style={{ marginTop: 16 }}
|
||||
/>
|
||||
{pendingOrders.length > 0 && (
|
||||
<div
|
||||
className='flex flex-wrap items-center gap-2'
|
||||
style={{ marginTop: 12 }}
|
||||
>
|
||||
<Text type='tertiary'>
|
||||
已选 {selectedOperationOrderKeys.length} 笔
|
||||
</Text>
|
||||
<Button
|
||||
size='small'
|
||||
htmlType='button'
|
||||
disabled={selectedOperationOrderKeys.length === 0}
|
||||
onClick={() => runBatchOperation('inspect')}
|
||||
>
|
||||
批量查询远端状态
|
||||
</Button>
|
||||
<Button
|
||||
size='small'
|
||||
theme='solid'
|
||||
htmlType='button'
|
||||
disabled={selectedOperationOrderKeys.length === 0}
|
||||
onClick={() => runBatchOperation('reconcile')}
|
||||
>
|
||||
批量触发对账
|
||||
</Button>
|
||||
<Button
|
||||
size='small'
|
||||
type='danger'
|
||||
htmlType='button'
|
||||
disabled={selectedOperationOrderKeys.length === 0}
|
||||
onClick={() => openBatchExpire(false)}
|
||||
>
|
||||
批量确认过期
|
||||
</Button>
|
||||
<Button
|
||||
size='small'
|
||||
type='warning'
|
||||
htmlType='button'
|
||||
disabled={selectedOperationOrderKeys.length === 0}
|
||||
onClick={() => openBatchExpire(true)}
|
||||
>
|
||||
批量强制过期
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
{pendingOrders.length > 0 && (
|
||||
<Table
|
||||
size='small'
|
||||
rowKey='trade_no'
|
||||
dataSource={pendingOrders}
|
||||
rowSelection={{
|
||||
selectedRowKeys: selectedOperationOrderKeys,
|
||||
onChange: (keys) =>
|
||||
setSelectedOperationOrderKeys(keys.map(String)),
|
||||
}}
|
||||
pagination={{
|
||||
currentPage: operationsPage,
|
||||
pageSize: PAYPAL_OPERATIONS_PAGE_SIZE,
|
||||
total: Number(operations?.pending_count || 0),
|
||||
showTotal: true,
|
||||
onPageChange: (page) => {
|
||||
setSelectedOperationOrderKeys([]);
|
||||
refreshOperations(page);
|
||||
},
|
||||
}}
|
||||
scroll={{ x: 900 }}
|
||||
style={{ marginTop: 12 }}
|
||||
columns={[
|
||||
{ title: '本地订单号', dataIndex: 'trade_no' },
|
||||
{ title: 'PayPal Order ID', dataIndex: 'third_trade_no' },
|
||||
{ title: '环境', dataIndex: 'payment_environment' },
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'create_time',
|
||||
render: (value) =>
|
||||
value ? new Date(value * 1000).toLocaleString() : '-',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
render: (_, row) => (
|
||||
<div className='flex flex-wrap gap-2'>
|
||||
<Button
|
||||
size='small'
|
||||
htmlType='button'
|
||||
onClick={() => inspectOperationOrder(row.trade_no)}
|
||||
>
|
||||
查询远端状态
|
||||
</Button>
|
||||
<Button
|
||||
size='small'
|
||||
theme='solid'
|
||||
htmlType='button'
|
||||
onClick={() =>
|
||||
reconcileOperationOrder(row.trade_no)
|
||||
}
|
||||
disabled={!row.third_trade_no}
|
||||
>
|
||||
触发对账
|
||||
</Button>
|
||||
<Button
|
||||
size='small'
|
||||
type='danger'
|
||||
htmlType='button'
|
||||
onClick={() => {
|
||||
setExpireOrder(row);
|
||||
setForceExpire(false);
|
||||
setForceExpireConfirmed(false);
|
||||
setExpireReason('确认该订单未完成 PayPal 支付');
|
||||
}}
|
||||
>
|
||||
确认未付款并过期
|
||||
</Button>
|
||||
<Button
|
||||
size='small'
|
||||
type='warning'
|
||||
htmlType='button'
|
||||
onClick={() => {
|
||||
setExpireOrder(row);
|
||||
setForceExpire(true);
|
||||
setForceExpireConfirmed(false);
|
||||
setExpireReason(
|
||||
'管理员确认远端状态无法核验,强制关闭该 PayPal 订单',
|
||||
);
|
||||
}}
|
||||
>
|
||||
强制过期
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
)}
|
||||
<Button
|
||||
size='small'
|
||||
type='tertiary'
|
||||
htmlType='button'
|
||||
onClick={() => refreshOperations(operationsPage)}
|
||||
style={{ marginTop: 12 }}
|
||||
>
|
||||
刷新配置切换预检
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
<Banner
|
||||
type='warning'
|
||||
description={t(
|
||||
'订阅 CHECKOUT.ORDER.APPROVED、PAYMENT.CAPTURE.COMPLETED、PAYMENT.CAPTURE.PENDING、PAYMENT.CAPTURE.DECLINED、PAYMENT.CAPTURE.DENIED 和 CHECKOUT.PAYMENT-APPROVAL.REVERSED 事件',
|
||||
)}
|
||||
/>
|
||||
<Row gutter={16}>
|
||||
<Col xs={24} md={8}>
|
||||
<Form.Input field='PayPalClientID' label='Client ID' />
|
||||
</Col>
|
||||
<Col xs={24} md={8}>
|
||||
<Form.Input
|
||||
field='PayPalClientSecret'
|
||||
label='Client Secret'
|
||||
type='password'
|
||||
placeholder={t('敏感信息不会显示')}
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={24} md={8}>
|
||||
<Form.Input field='PayPalWebhookID' label='Webhook ID' />
|
||||
</Col>
|
||||
</Row>
|
||||
<Row gutter={16} style={{ marginTop: 16 }}>
|
||||
<Col xs={24} md={8}>
|
||||
<Form.Switch
|
||||
field='PayPalSandbox'
|
||||
label={t('Sandbox 测试环境')}
|
||||
checkedText='|'
|
||||
uncheckedText='〇'
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={24} md={8}>
|
||||
<Form.InputNumber
|
||||
field='PayPalMinTopUp'
|
||||
label={t('最低充值单位')}
|
||||
min={1}
|
||||
precision={0}
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={24} md={8}>
|
||||
<Text type='tertiary'>
|
||||
{t('结算币种')}:USD
|
||||
<br />
|
||||
{t('换算汇率')}:USDExchangeRate ={' '}
|
||||
{props.options?.USDExchangeRate || '-'}
|
||||
</Text>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row gutter={16} style={{ marginTop: 16 }}>
|
||||
<Col xs={24} md={8}>
|
||||
<Form.Select
|
||||
field='PayPalFXMode'
|
||||
label={t('汇率模式')}
|
||||
optionList={[
|
||||
{ label: t('手工汇率'), value: 'manual' },
|
||||
{ label: t('准实时汇率'), value: 'realtime' },
|
||||
]}
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={24} md={8}>
|
||||
<Form.Input
|
||||
field='PayPalFXAPIKey'
|
||||
label='Open Exchange Rates API Key'
|
||||
type='password'
|
||||
placeholder={t('敏感信息不会显示')}
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={24} md={8}>
|
||||
<Form.InputNumber
|
||||
field='PayPalFXAdjustmentBps'
|
||||
label={t('汇率保护加点(基点)')}
|
||||
min={0}
|
||||
max={300}
|
||||
precision={0}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
<Banner
|
||||
type={fxStatus?.latest_valid ? 'success' : 'warning'}
|
||||
description={
|
||||
fxStatus?.latest_valid
|
||||
? `${t('当前市场汇率')}:1 USD = ${fxStatus.latest_valid.market_rate} CNY`
|
||||
: t('暂无可用的市场汇率快照')
|
||||
}
|
||||
style={{ marginTop: 16 }}
|
||||
/>
|
||||
<div className='flex flex-wrap gap-2' style={{ marginTop: 12 }}>
|
||||
<Button onClick={submit} disabled={isRoot() && !feePolicy}>
|
||||
{t('更新 PayPal 设置')}
|
||||
</Button>
|
||||
<Button type='tertiary' onClick={() => runFXAction('refresh')}>
|
||||
{t('立即刷新汇率')}
|
||||
</Button>
|
||||
<Button type='warning' onClick={() => runFXAction('acknowledge')}>
|
||||
{t('确认手工兜底汇率')}
|
||||
</Button>
|
||||
</div>
|
||||
</Form.Section>
|
||||
</Form>
|
||||
<Modal
|
||||
title={
|
||||
forceExpire ? '确认强制过期 PayPal 订单' : '确认 PayPal 订单过期'
|
||||
}
|
||||
visible={Boolean(expireOrder)}
|
||||
onCancel={() => setExpireOrder(null)}
|
||||
onOk={expireOperationOrder}
|
||||
okText='确认过期'
|
||||
cancelText='取消'
|
||||
>
|
||||
{expireOrder && (
|
||||
<div className='space-y-3'>
|
||||
<Text>
|
||||
订单:<strong>{expireOrder.trade_no}</strong>
|
||||
</Text>
|
||||
<Banner
|
||||
type={forceExpire ? 'danger' : 'warning'}
|
||||
description={
|
||||
forceExpire
|
||||
? '强制过期会绕过远端查询失败或仍可支付状态,可能导致 PayPal 后续付款无法入账。已确认完成支付的订单仍会被拒绝。'
|
||||
: '系统会再次查询 PayPal 远端状态;如果已完成支付,将拒绝过期操作。请确认未付款后再提交。'
|
||||
}
|
||||
/>
|
||||
{forceExpire && (
|
||||
<Checkbox
|
||||
checked={forceExpireConfirmed}
|
||||
onChange={(event) =>
|
||||
setForceExpireConfirmed(
|
||||
Boolean(event?.target?.checked ?? event?.checked),
|
||||
)
|
||||
}
|
||||
>
|
||||
我确认已核对 PayPal 后台或业务记录,同意强制关闭该订单
|
||||
</Checkbox>
|
||||
)}
|
||||
<TextArea
|
||||
value={expireReason}
|
||||
onChange={(value) =>
|
||||
setExpireReason(
|
||||
typeof value === 'string'
|
||||
? value
|
||||
: value?.target?.value || '',
|
||||
)
|
||||
}
|
||||
rows={3}
|
||||
placeholder='填写处置原因,至少 6 个字符'
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
<Modal
|
||||
title={
|
||||
batchExpire?.force
|
||||
? '确认批量强制过期 PayPal 订单'
|
||||
: '确认批量 PayPal 订单过期'
|
||||
}
|
||||
visible={Boolean(batchExpire)}
|
||||
onCancel={() => setBatchExpire(null)}
|
||||
onOk={confirmBatchExpire}
|
||||
okText='确认批量过期'
|
||||
cancelText='取消'
|
||||
>
|
||||
{batchExpire && (
|
||||
<div className='space-y-3'>
|
||||
<Text>已选择 {batchExpire.tradeNos.length} 笔 PayPal 订单。</Text>
|
||||
<Banner
|
||||
type={batchExpire.force ? 'danger' : 'warning'}
|
||||
description={
|
||||
batchExpire.force
|
||||
? '批量强制过期会绕过远端查询失败或仍可支付状态;已确认完成支付的订单仍会逐笔拒绝。'
|
||||
: '系统会逐笔查询 PayPal 远端状态,已完成或仍可支付的订单会逐笔失败并返回原因。'
|
||||
}
|
||||
/>
|
||||
{batchExpire.force && (
|
||||
<Checkbox
|
||||
checked={batchForceConfirmed}
|
||||
onChange={(event) =>
|
||||
setBatchForceConfirmed(
|
||||
Boolean(event?.target?.checked ?? event?.checked),
|
||||
)
|
||||
}
|
||||
>
|
||||
我确认已核对所选订单,同意批量强制关闭
|
||||
</Checkbox>
|
||||
)}
|
||||
<TextArea
|
||||
value={batchExpireReason}
|
||||
onChange={(value) =>
|
||||
setBatchExpireReason(
|
||||
typeof value === 'string'
|
||||
? value
|
||||
: value?.target?.value || '',
|
||||
)
|
||||
}
|
||||
rows={3}
|
||||
placeholder='填写处置原因,至少 6 个字符'
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
</Spin>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useEffect, useState, useRef } from 'react';
|
||||
import {
|
||||
Banner,
|
||||
Button,
|
||||
Form,
|
||||
Row,
|
||||
Col,
|
||||
Typography,
|
||||
Spin,
|
||||
} from '@douyinfe/semi-ui';
|
||||
const { Text } = Typography;
|
||||
import {
|
||||
API,
|
||||
removeTrailingSlash,
|
||||
showError,
|
||||
showSuccess,
|
||||
} from '../../../helpers';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
export default function SettingsPaymentGateway(props) {
|
||||
const { t } = useTranslation();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [inputs, setInputs] = useState({
|
||||
StripeApiSecret: '',
|
||||
StripeWebhookSecret: '',
|
||||
StripePriceId: '',
|
||||
StripeUnitPrice: 8.0,
|
||||
StripeMinTopUp: 1,
|
||||
StripePromotionCodesEnabled: false,
|
||||
});
|
||||
const [originInputs, setOriginInputs] = useState({});
|
||||
const formApiRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (props.options && formApiRef.current) {
|
||||
const currentInputs = {
|
||||
StripeApiSecret: props.options.StripeApiSecret || '',
|
||||
StripeWebhookSecret: props.options.StripeWebhookSecret || '',
|
||||
StripePriceId: props.options.StripePriceId || '',
|
||||
StripeUnitPrice:
|
||||
props.options.StripeUnitPrice !== undefined
|
||||
? parseFloat(props.options.StripeUnitPrice)
|
||||
: 8.0,
|
||||
StripeMinTopUp:
|
||||
props.options.StripeMinTopUp !== undefined
|
||||
? parseFloat(props.options.StripeMinTopUp)
|
||||
: 1,
|
||||
StripePromotionCodesEnabled:
|
||||
props.options.StripePromotionCodesEnabled !== undefined
|
||||
? props.options.StripePromotionCodesEnabled
|
||||
: false,
|
||||
};
|
||||
setInputs(currentInputs);
|
||||
setOriginInputs({ ...currentInputs });
|
||||
formApiRef.current.setValues(currentInputs);
|
||||
}
|
||||
}, [props.options]);
|
||||
|
||||
const handleFormChange = (values) => {
|
||||
setInputs(values);
|
||||
};
|
||||
|
||||
const submitStripeSetting = async () => {
|
||||
if (props.options.ServerAddress === '') {
|
||||
showError(t('请先填写服务器地址'));
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
const options = [];
|
||||
|
||||
if (inputs.StripeApiSecret && inputs.StripeApiSecret !== '') {
|
||||
options.push({ key: 'StripeApiSecret', value: inputs.StripeApiSecret });
|
||||
}
|
||||
if (inputs.StripeWebhookSecret && inputs.StripeWebhookSecret !== '') {
|
||||
options.push({
|
||||
key: 'StripeWebhookSecret',
|
||||
value: inputs.StripeWebhookSecret,
|
||||
});
|
||||
}
|
||||
if (inputs.StripePriceId !== '') {
|
||||
options.push({ key: 'StripePriceId', value: inputs.StripePriceId });
|
||||
}
|
||||
if (
|
||||
inputs.StripeUnitPrice !== undefined &&
|
||||
inputs.StripeUnitPrice !== null
|
||||
) {
|
||||
options.push({
|
||||
key: 'StripeUnitPrice',
|
||||
value: inputs.StripeUnitPrice.toString(),
|
||||
});
|
||||
}
|
||||
if (
|
||||
inputs.StripeMinTopUp !== undefined &&
|
||||
inputs.StripeMinTopUp !== null
|
||||
) {
|
||||
options.push({
|
||||
key: 'StripeMinTopUp',
|
||||
value: inputs.StripeMinTopUp.toString(),
|
||||
});
|
||||
}
|
||||
if (
|
||||
originInputs['StripePromotionCodesEnabled'] !==
|
||||
inputs.StripePromotionCodesEnabled &&
|
||||
inputs.StripePromotionCodesEnabled !== undefined
|
||||
) {
|
||||
options.push({
|
||||
key: 'StripePromotionCodesEnabled',
|
||||
value: inputs.StripePromotionCodesEnabled ? 'true' : 'false',
|
||||
});
|
||||
}
|
||||
|
||||
// 发送请求
|
||||
const requestQueue = options.map((opt) =>
|
||||
API.put('/api/option/', {
|
||||
key: opt.key,
|
||||
value: opt.value,
|
||||
}),
|
||||
);
|
||||
|
||||
const results = await Promise.all(requestQueue);
|
||||
|
||||
// 检查所有请求是否成功
|
||||
const errorResults = results.filter((res) => !res.data.success);
|
||||
if (errorResults.length > 0) {
|
||||
errorResults.forEach((res) => {
|
||||
showError(res.data.message);
|
||||
});
|
||||
} else {
|
||||
showSuccess(t('更新成功'));
|
||||
// 更新本地存储的原始值
|
||||
setOriginInputs({ ...inputs });
|
||||
props.refresh?.();
|
||||
}
|
||||
} catch (error) {
|
||||
showError(t('更新失败'));
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<Spin spinning={loading}>
|
||||
<Form
|
||||
initValues={inputs}
|
||||
onValueChange={handleFormChange}
|
||||
getFormApi={(api) => (formApiRef.current = api)}
|
||||
>
|
||||
<Form.Section text={t('Stripe 设置')}>
|
||||
<Text>
|
||||
Stripe 密钥、Webhook 等设置请
|
||||
<a
|
||||
href='https://dashboard.stripe.com/developers'
|
||||
target='_blank'
|
||||
rel='noreferrer'
|
||||
>{t('点击此处')}</a>{t('进行设置,最好先在')}<a
|
||||
href='https://dashboard.stripe.com/test/developers'
|
||||
target='_blank'
|
||||
rel='noreferrer'
|
||||
>{t('测试环境')}</a>{t('进行测试。')}<br />
|
||||
</Text>
|
||||
<Banner
|
||||
type='info'
|
||||
description={`Webhook 填:${props.options.ServerAddress ? removeTrailingSlash(props.options.ServerAddress) : t('网站地址')}/api/stripe/webhook`}
|
||||
/>
|
||||
<Banner
|
||||
type='warning'
|
||||
description={`需要包含事件:checkout.session.completed 和 checkout.session.expired`}
|
||||
/>
|
||||
<Row gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}>
|
||||
<Col xs={24} sm={24} md={8} lg={8} xl={8}>
|
||||
<Form.Input
|
||||
field='StripeApiSecret'
|
||||
label={t('API 密钥')}
|
||||
placeholder={t(
|
||||
'sk_xxx 或 rk_xxx 的 Stripe 密钥,敏感信息不显示',
|
||||
)}
|
||||
type='password'
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={24} sm={24} md={8} lg={8} xl={8}>
|
||||
<Form.Input
|
||||
field='StripeWebhookSecret'
|
||||
label={t('Webhook 签名密钥')}
|
||||
placeholder={t('whsec_xxx 的 Webhook 签名密钥,敏感信息不显示')}
|
||||
type='password'
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={24} sm={24} md={8} lg={8} xl={8}>
|
||||
<Form.Input
|
||||
field='StripePriceId'
|
||||
label={t('商品价格 ID')}
|
||||
placeholder={t('price_xxx 的商品价格 ID,新建产品后可获得')}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row
|
||||
gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
|
||||
style={{ marginTop: 16 }}
|
||||
>
|
||||
<Col xs={24} sm={24} md={8} lg={8} xl={8}>
|
||||
<Form.InputNumber
|
||||
field='StripeUnitPrice'
|
||||
precision={2}
|
||||
label={t('充值价格(x元/美金)')}
|
||||
placeholder={t('例如:7,就是7元/美金')}
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={24} sm={24} md={8} lg={8} xl={8}>
|
||||
<Form.InputNumber
|
||||
field='StripeMinTopUp'
|
||||
label={t('最低充值美元数量')}
|
||||
placeholder={t('例如:2,就是最低充值2$')}
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={24} sm={24} md={8} lg={8} xl={8}>
|
||||
<Form.Switch
|
||||
field='StripePromotionCodesEnabled'
|
||||
size='default'
|
||||
checkedText='|'
|
||||
uncheckedText='〇'
|
||||
label={t('允许在 Stripe 支付中输入促销码')}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
<Button onClick={submitStripeSetting}>{t('更新 Stripe 设置')}</Button>
|
||||
</Form.Section>
|
||||
</Form>
|
||||
</Spin>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,352 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
Form,
|
||||
Button,
|
||||
Typography,
|
||||
Space,
|
||||
Divider,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import { API, showError, showSuccess } from '../../../helpers';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
const { Title, Text } = Typography;
|
||||
|
||||
const SettingsPaymentWechat = ({ options, refresh }) => {
|
||||
const { t } = useTranslation();
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const onSubmit = async (values) => {
|
||||
try {
|
||||
setLoading(true);
|
||||
|
||||
// 保存微信支付配置
|
||||
const configs = [
|
||||
{ key: 'WechatMchId', value: values.WechatMchId || '' },
|
||||
{ key: 'WechatAppId', value: values.WechatAppId || '' },
|
||||
// 如果敏感字段未修改(仍然是空或占位符),则使用占位符让后端跳过更新
|
||||
{
|
||||
key: 'WechatAPIv3Key',
|
||||
value:
|
||||
values.WechatAPIv3Key && values.WechatAPIv3Key.trim() !== ''
|
||||
? values.WechatAPIv3Key
|
||||
: '***ALREADY_SET***',
|
||||
},
|
||||
{ key: 'WechatSerialNo', value: values.WechatSerialNo || '' },
|
||||
{
|
||||
key: 'WechatPrivateKey',
|
||||
value:
|
||||
values.WechatPrivateKey && values.WechatPrivateKey.trim() !== ''
|
||||
? values.WechatPrivateKey
|
||||
: '***ALREADY_SET***',
|
||||
},
|
||||
{
|
||||
key: 'WechatNativeEnabled',
|
||||
value: values.WechatNativeEnabled ? 'true' : 'false',
|
||||
},
|
||||
{
|
||||
key: 'WechatH5Enabled',
|
||||
value: values.WechatH5Enabled ? 'true' : 'false',
|
||||
},
|
||||
{ key: 'WechatNotifyUrl', value: values.WechatNotifyUrl || '' },
|
||||
{
|
||||
key: 'WechatDescription',
|
||||
value: values.WechatDescription || '平台充值',
|
||||
},
|
||||
{
|
||||
key: 'WechatExpireMinutes',
|
||||
value: String(values.WechatExpireMinutes || 30),
|
||||
},
|
||||
// 公钥模式配置(2024年新商户)
|
||||
{
|
||||
key: 'WechatUsePublicKey',
|
||||
value: values.WechatUsePublicKey ? 'true' : 'false',
|
||||
},
|
||||
{ key: 'WechatPublicKeyID', value: values.WechatPublicKeyID || '' },
|
||||
{
|
||||
key: 'WechatPublicKeyPEM',
|
||||
value:
|
||||
values.WechatPublicKeyPEM && values.WechatPublicKeyPEM.trim() !== ''
|
||||
? values.WechatPublicKeyPEM
|
||||
: '***ALREADY_SET***',
|
||||
},
|
||||
// 手动证书模式配置
|
||||
{
|
||||
key: 'WechatUseManualCert',
|
||||
value: values.WechatUseManualCert ? 'true' : 'false',
|
||||
},
|
||||
{
|
||||
key: 'WechatPlatformCertPath',
|
||||
value: values.WechatPlatformCertPath || '',
|
||||
},
|
||||
{
|
||||
key: 'WechatPlatformCertPEM',
|
||||
value:
|
||||
values.WechatPlatformCertPEM &&
|
||||
values.WechatPlatformCertPEM.trim() !== ''
|
||||
? values.WechatPlatformCertPEM
|
||||
: '***ALREADY_SET***',
|
||||
},
|
||||
];
|
||||
|
||||
for (const config of configs) {
|
||||
const res = await API.put('/api/option/', config);
|
||||
if (!res.data.success) {
|
||||
throw new Error(`保存 ${config.key} 失败: ${res.data.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
showSuccess(t('微信支付配置保存成功'));
|
||||
if (refresh) refresh();
|
||||
} catch (error) {
|
||||
showError(error.message || t('保存失败'));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Title heading={5}>{t('微信支付配置')}</Title>
|
||||
<Text type='tertiary'>
|
||||
配置微信支付 Native(扫码)和 H5 支付方式。请前往{' '}
|
||||
<a
|
||||
href='https://pay.weixin.qq.com'
|
||||
target='_blank'
|
||||
rel='noopener noreferrer'
|
||||
>{t('微信支付商户平台')}</a>{' '}
|
||||
获取相关配置信息。
|
||||
</Text>
|
||||
|
||||
<Divider margin='12px' />
|
||||
|
||||
<Form
|
||||
labelPosition='left'
|
||||
labelAlign='right'
|
||||
labelWidth={180}
|
||||
onSubmit={onSubmit}
|
||||
initValues={{
|
||||
WechatMchId: options.WechatMchId || '',
|
||||
WechatAppId: options.WechatAppId || '',
|
||||
WechatAPIv3Key:
|
||||
options.WechatAPIv3Key &&
|
||||
options.WechatAPIv3Key !== '***ALREADY_SET***'
|
||||
? options.WechatAPIv3Key
|
||||
: '',
|
||||
WechatSerialNo: options.WechatSerialNo || '',
|
||||
WechatPrivateKey:
|
||||
options.WechatPrivateKey &&
|
||||
options.WechatPrivateKey !== '***ALREADY_SET***'
|
||||
? options.WechatPrivateKey
|
||||
: '',
|
||||
WechatNativeEnabled: options.WechatNativeEnabled || false,
|
||||
WechatH5Enabled: options.WechatH5Enabled || false,
|
||||
WechatNotifyUrl: options.WechatNotifyUrl || '',
|
||||
WechatDescription: options.WechatDescription || '平台充值',
|
||||
WechatExpireMinutes: options.WechatExpireMinutes || 30,
|
||||
// 公钥模式
|
||||
WechatUsePublicKey: options.WechatUsePublicKey || false,
|
||||
WechatPublicKeyID: options.WechatPublicKeyID || '',
|
||||
WechatPublicKeyPEM:
|
||||
options.WechatPublicKeyPEM &&
|
||||
options.WechatPublicKeyPEM !== '***ALREADY_SET***'
|
||||
? options.WechatPublicKeyPEM
|
||||
: '',
|
||||
// 手动证书模式
|
||||
WechatUseManualCert: options.WechatUseManualCert || false,
|
||||
WechatPlatformCertPath: options.WechatPlatformCertPath || '',
|
||||
WechatPlatformCertPEM:
|
||||
options.WechatPlatformCertPEM &&
|
||||
options.WechatPlatformCertPEM !== '***ALREADY_SET***'
|
||||
? options.WechatPlatformCertPEM
|
||||
: '',
|
||||
}}
|
||||
>
|
||||
<Form.Input
|
||||
field='WechatMchId'
|
||||
label={t('商户号 (Mch ID)')}
|
||||
placeholder={t('请输入微信支付商户号')}
|
||||
rules={[{ required: true, message: '请输入商户号' }]}
|
||||
/>
|
||||
|
||||
<Form.Input
|
||||
field='WechatAppId'
|
||||
label={t('应用 ID (App ID)')}
|
||||
placeholder={t('请输入微信应用 ID')}
|
||||
rules={[{ required: true, message: '请输入应用 ID' }]}
|
||||
/>
|
||||
|
||||
<Form.Input
|
||||
field='WechatAPIv3Key'
|
||||
label={t('APIv3 密钥')}
|
||||
placeholder={
|
||||
options.WechatAPIv3Key === '***ALREADY_SET***'
|
||||
? '已设置(留空不修改,填写新内容则更新)'
|
||||
: '请输入 APIv3 密钥'
|
||||
}
|
||||
mode='password'
|
||||
extraText={
|
||||
options.WechatAPIv3Key === '***ALREADY_SET***'
|
||||
? '✓ 已配置 APIv3 密钥(留空则保持不变)'
|
||||
: ''
|
||||
}
|
||||
/>
|
||||
|
||||
<Form.Input
|
||||
field='WechatSerialNo'
|
||||
label={t('证书序列号')}
|
||||
placeholder={t('请输入证书序列号')}
|
||||
rules={[{ required: true, message: '请输入证书序列号' }]}
|
||||
/>
|
||||
|
||||
<Form.TextArea
|
||||
field='WechatPrivateKey'
|
||||
label={t('商户私钥')}
|
||||
placeholder={
|
||||
options.WechatPrivateKey === '***ALREADY_SET***'
|
||||
? '已设置(留空不修改,填写新内容则更新)'
|
||||
: '请粘贴完整的 PEM 格式私钥内容(包含 -----BEGIN PRIVATE KEY----- 等)'
|
||||
}
|
||||
rows={6}
|
||||
extraText={
|
||||
options.WechatPrivateKey === '***ALREADY_SET***'
|
||||
? '✓ 已配置商户私钥(留空则保持不变)'
|
||||
: '支持直接粘贴 PEM 格式内容或填写文件路径'
|
||||
}
|
||||
/>
|
||||
|
||||
<Divider margin='12px' />
|
||||
|
||||
<Title heading={6} style={{ marginTop: 16, marginBottom: 8 }}>{t('公钥模式(2024年新商户必选)')}</Title>
|
||||
<Text type='tertiary' style={{ display: 'block', marginBottom: 12 }}>
|
||||
2024年后注册的微信支付商户默认使用公钥模式。如果初始化失败提示"无可用的平台证书",
|
||||
请从商户平台下载微信支付公钥并启用此模式。
|
||||
</Text>
|
||||
|
||||
<Form.Switch
|
||||
field='WechatUsePublicKey'
|
||||
label={t('启用公钥模式')}
|
||||
extraText='2024年新商户必须开启此选项'
|
||||
/>
|
||||
|
||||
<Form.Input
|
||||
field='WechatPublicKeyID'
|
||||
label={t('微信支付公钥 ID')}
|
||||
placeholder='PUB_KEY_ID_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
|
||||
extraText='从商户平台【API安全】→【微信支付公钥】获取,格式如 PUB_KEY_ID_xxx'
|
||||
/>
|
||||
|
||||
<Form.TextArea
|
||||
field='WechatPublicKeyPEM'
|
||||
label={t('微信支付公钥内容')}
|
||||
placeholder={
|
||||
options.WechatPublicKeyPEM === '***ALREADY_SET***'
|
||||
? '已设置(留空不修改,填写新内容则更新)'
|
||||
: '请粘贴完整的微信支付公钥 PEM 内容(包含 -----BEGIN PUBLIC KEY----- 等)'
|
||||
}
|
||||
rows={6}
|
||||
extraText={
|
||||
options.WechatPublicKeyPEM === '***ALREADY_SET***'
|
||||
? '✓ 已配置微信支付公钥(留空则保持不变)'
|
||||
: '从商户平台下载的公钥文件内容'
|
||||
}
|
||||
/>
|
||||
|
||||
<Divider margin='12px' />
|
||||
|
||||
<Title heading={6} style={{ marginTop: 16, marginBottom: 8 }}>{t('高级配置:手动平台证书模式(可选)')}</Title>
|
||||
<Text type='tertiary' style={{ display: 'block', marginBottom: 12 }}>{t('默认情况下,SDK 会自动下载微信平台证书,无需手动配置。仅在离线环境或网络受限时启用此选项。')}</Text>
|
||||
|
||||
<Form.Switch
|
||||
field='WechatUseManualCert'
|
||||
label={t('启用手动证书模式')}
|
||||
extraText='开启后需要手动配置平台证书,关闭则使用自动下载模式(推荐)'
|
||||
/>
|
||||
|
||||
<Form.Input
|
||||
field='WechatPlatformCertPath'
|
||||
label={t('平台证书文件路径')}
|
||||
placeholder='/data/certs/wechatpay_platform_cert.pem'
|
||||
extraText='平台证书文件的绝对路径(与下方 PEM 内容二选一)'
|
||||
/>
|
||||
|
||||
<Form.TextArea
|
||||
field='WechatPlatformCertPEM'
|
||||
label={t('平台证书 PEM 内容')}
|
||||
placeholder={
|
||||
options.WechatPlatformCertPEM === '***ALREADY_SET***'
|
||||
? '已设置(留空不修改,填写新内容则更新)'
|
||||
: '请粘贴完整的平台证书 PEM 内容(包含 -----BEGIN CERTIFICATE----- 等)'
|
||||
}
|
||||
rows={6}
|
||||
extraText={
|
||||
options.WechatPlatformCertPEM === '***ALREADY_SET***'
|
||||
? '✓ 已配置平台证书(留空则保持不变)'
|
||||
: '与上方文件路径二选一,优先使用文件路径'
|
||||
}
|
||||
/>
|
||||
|
||||
<Divider margin='12px' />
|
||||
|
||||
<Form.Switch
|
||||
field='WechatNativeEnabled'
|
||||
label={t('启用 Native 扫码支付')}
|
||||
extraText='用户扫描二维码完成支付'
|
||||
/>
|
||||
|
||||
<Form.Switch
|
||||
field='WechatH5Enabled'
|
||||
label={t('启用 H5 支付')}
|
||||
extraText='在手机浏览器中唤起微信支付'
|
||||
/>
|
||||
|
||||
<Divider margin='12px' />
|
||||
|
||||
<Form.Input
|
||||
field='WechatNotifyUrl'
|
||||
label={t('回调通知 URL')}
|
||||
placeholder={t('留空则使用默认地址')}
|
||||
extraText='默认: {服务器地址}/api/wechat/notify'
|
||||
/>
|
||||
|
||||
<Form.Input
|
||||
field='WechatDescription'
|
||||
label={t('商品描述')}
|
||||
placeholder={t('平台充值')}
|
||||
extraText='显示在微信支付界面的商品描述'
|
||||
/>
|
||||
|
||||
<Form.InputNumber
|
||||
field='WechatExpireMinutes'
|
||||
label={t('订单过期时间(分钟)')}
|
||||
min={1}
|
||||
max={1440}
|
||||
extraText='订单未支付的有效时间,默认 30 分钟'
|
||||
/>
|
||||
|
||||
<Space style={{ marginTop: 20 }}>
|
||||
<Button type='primary' htmlType='submit' loading={loading}>{t('保存配置')}</Button>
|
||||
</Space>
|
||||
</Form>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default SettingsPaymentWechat;
|
||||
Reference in New Issue
Block a user