PaymentSetting.jsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. Copyright (C) 2025 QuantumNous
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. For commercial licensing, please contact support@quantumnous.com
  14. */
  15. import React, { useEffect, useState } from 'react';
  16. import { Card, Spin } from '@douyinfe/semi-ui';
  17. import SettingsGeneralPayment from '../../pages/Setting/Payment/SettingsGeneralPayment';
  18. import SettingsPaymentGateway from '../../pages/Setting/Payment/SettingsPaymentGateway';
  19. import SettingsPaymentGatewayStripe from '../../pages/Setting/Payment/SettingsPaymentGatewayStripe';
  20. import { API, showError, toBoolean } from '../../helpers';
  21. import { useTranslation } from 'react-i18next';
  22. const PaymentSetting = () => {
  23. const { t } = useTranslation();
  24. let [inputs, setInputs] = useState({
  25. ServerAddress: '',
  26. PayAddress: '',
  27. EpayId: '',
  28. EpayKey: '',
  29. Price: 7.3,
  30. MinTopUp: 1,
  31. TopupGroupRatio: '',
  32. CustomCallbackAddress: '',
  33. PayMethods: '',
  34. StripeApiSecret: '',
  35. StripeWebhookSecret: '',
  36. StripePriceId: '',
  37. StripeUnitPrice: 8.0,
  38. StripeMinTopUp: 1,
  39. });
  40. let [loading, setLoading] = useState(false);
  41. const getOptions = async () => {
  42. const res = await API.get('/api/option/');
  43. const { success, message, data } = res.data;
  44. if (success) {
  45. let newInputs = {};
  46. data.forEach((item) => {
  47. switch (item.key) {
  48. case 'TopupGroupRatio':
  49. try {
  50. newInputs[item.key] = JSON.stringify(
  51. JSON.parse(item.value),
  52. null,
  53. 2,
  54. );
  55. } catch (error) {
  56. console.error('解析TopupGroupRatio出错:', error);
  57. newInputs[item.key] = item.value;
  58. }
  59. break;
  60. case 'Price':
  61. case 'MinTopUp':
  62. case 'StripeUnitPrice':
  63. case 'StripeMinTopUp':
  64. newInputs[item.key] = parseFloat(item.value);
  65. break;
  66. default:
  67. if (item.key.endsWith('Enabled')) {
  68. newInputs[item.key] = toBoolean(item.value);
  69. } else {
  70. newInputs[item.key] = item.value;
  71. }
  72. break;
  73. }
  74. });
  75. setInputs(newInputs);
  76. } else {
  77. showError(t(message));
  78. }
  79. };
  80. async function onRefresh() {
  81. try {
  82. setLoading(true);
  83. await getOptions();
  84. } catch (error) {
  85. showError(t('刷新失败'));
  86. } finally {
  87. setLoading(false);
  88. }
  89. }
  90. useEffect(() => {
  91. onRefresh();
  92. }, []);
  93. return (
  94. <>
  95. <Spin spinning={loading} size='large'>
  96. <Card style={{ marginTop: '10px' }}>
  97. <SettingsGeneralPayment options={inputs} refresh={onRefresh} />
  98. </Card>
  99. <Card style={{ marginTop: '10px' }}>
  100. <SettingsPaymentGateway options={inputs} refresh={onRefresh} />
  101. </Card>
  102. <Card style={{ marginTop: '10px' }}>
  103. <SettingsPaymentGatewayStripe options={inputs} refresh={onRefresh} />
  104. </Card>
  105. </Spin>
  106. </>
  107. );
  108. };
  109. export default PaymentSetting;