PaymentSetting.jsx 4.7 KB

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