/* 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 . For commercial licensing, please contact support@quantumnous.com */ import React, { useState } from 'react'; import { Form, Button, Typography, Space, Divider } from '@/components/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 ( <> {t('支付宝配置')} {t('配置支付宝电脑网站支付、手机网站支付和当面付扫码支付。请前往')}{' '} {t('支付宝开放平台')} {' '} {t('获取相关配置信息。')}
); }; export default SettingsPaymentAlipay;