PaymentSetting.jsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. AmountOptions: '',
  35. AmountDiscount: '',
  36. StripeApiSecret: '',
  37. StripeWebhookSecret: '',
  38. StripePriceId: '',
  39. StripeUnitPrice: 8.0,
  40. StripeMinTopUp: 1,
  41. StripePromotionCodesEnabled: false,
  42. });
  43. let [loading, setLoading] = useState(false);
  44. const getOptions = async () => {
  45. const res = await API.get('/api/option/');
  46. const { success, message, data } = res.data;
  47. if (success) {
  48. let newInputs = {};
  49. data.forEach((item) => {
  50. switch (item.key) {
  51. case 'TopupGroupRatio':
  52. try {
  53. newInputs[item.key] = JSON.stringify(
  54. JSON.parse(item.value),
  55. null,
  56. 2,
  57. );
  58. } catch (error) {
  59. console.error('解析TopupGroupRatio出错:', error);
  60. newInputs[item.key] = item.value;
  61. }
  62. break;
  63. case 'payment_setting.amount_options':
  64. try {
  65. newInputs['AmountOptions'] = JSON.stringify(
  66. JSON.parse(item.value),
  67. null,
  68. 2,
  69. );
  70. } catch (error) {
  71. console.error('解析AmountOptions出错:', error);
  72. newInputs['AmountOptions'] = item.value;
  73. }
  74. break;
  75. case 'payment_setting.amount_discount':
  76. try {
  77. newInputs['AmountDiscount'] = JSON.stringify(
  78. JSON.parse(item.value),
  79. null,
  80. 2,
  81. );
  82. } catch (error) {
  83. console.error('解析AmountDiscount出错:', error);
  84. newInputs['AmountDiscount'] = item.value;
  85. }
  86. break;
  87. case 'Price':
  88. case 'MinTopUp':
  89. case 'StripeUnitPrice':
  90. case 'StripeMinTopUp':
  91. newInputs[item.key] = parseFloat(item.value);
  92. break;
  93. default:
  94. if (item.key.endsWith('Enabled')) {
  95. newInputs[item.key] = toBoolean(item.value);
  96. } else {
  97. newInputs[item.key] = item.value;
  98. }
  99. break;
  100. }
  101. });
  102. setInputs(newInputs);
  103. } else {
  104. showError(t(message));
  105. }
  106. };
  107. async function onRefresh() {
  108. try {
  109. setLoading(true);
  110. await getOptions();
  111. } catch (error) {
  112. showError(t('刷新失败'));
  113. } finally {
  114. setLoading(false);
  115. }
  116. }
  117. useEffect(() => {
  118. onRefresh();
  119. }, []);
  120. return (
  121. <>
  122. <Spin spinning={loading} size='large'>
  123. <Card style={{ marginTop: '10px' }}>
  124. <SettingsGeneralPayment options={inputs} refresh={onRefresh} />
  125. </Card>
  126. <Card style={{ marginTop: '10px' }}>
  127. <SettingsPaymentGateway options={inputs} refresh={onRefresh} />
  128. </Card>
  129. <Card style={{ marginTop: '10px' }}>
  130. <SettingsPaymentGatewayStripe options={inputs} refresh={onRefresh} />
  131. </Card>
  132. </Spin>
  133. </>
  134. );
  135. };
  136. export default PaymentSetting;