/* 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 { Check as ActionCheck } from '@/components/common/icons/ActionIcons'; import React from 'react'; import { Alert } from 'antd'; import { Button, Spin, Tooltip } from '@/components/ui'; import { AlipayBrandIcon, StripeBrandIcon, PayPalBrandIcon, } from '../../components/common/icons/BrandIcons'; import { getCurrencyConfig } from '../../helpers/render'; import { formatNumber, toFiniteNumber } from '../../helpers/safeDisplay'; import { CUSTOMER_SERVICE_OPEN_EVENT } from '../../components/customer-service'; import { showInfo } from '../../helpers'; import AmountCard from './AmountCard'; import { useMinimumLoadingTime } from '../../hooks/common/useMinimumLoadingTime'; const formatCny = (value) => { const number = toFiniteNumber(value); if (number === null) return '-'; return ( '¥' + number.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2, }) ); }; // 需要发票时的联系提示(原型:充值订单按钮下方) export const InvoiceNote = ({ t }) => (

{t('需要发票?')}

); const RechargePanel = ({ t, statusLoading, enableOnlineTopUp, enableWechatTopUp, enableAlipayTopUp, enableStripeTopUp, enablePayPalTopUp, enableCreemTopUp, creemProducts, creemPreTopUp, presetAmounts, selectedPreset, selectedPresetObj, selectPresetAmount, priceRatio, topUpCount, amount, amountLoading, payMethods, preTopUp, paymentLoading, payWay, payPalQuote, topupInfo, }) => { useMinimumLoadingTime(amountLoading); // Creem 使用独立产品选择;其余渠道共用金额和支付方式区块。 const hasStandardOnlinePayment = enableOnlineTopUp || enableWechatTopUp || enableAlipayTopUp || enableStripeTopUp || enablePayPalTopUp; const hasAnyOnlinePayment = hasStandardOnlinePayment || enableCreemTopUp; // 与原逻辑一致的支付方式可用性判断 const isMethodDisabled = (method) => { const minTopupVal = Number(method.min_topup) || 0; const isStripe = method.type === 'stripe'; const isPayPal = method.type === 'paypal'; const isWechat = method.type === 'wxpay'; const isAlipay = method.type === 'alipay'; return ( (!enableOnlineTopUp && !isStripe && !isPayPal && !isWechat && !isAlipay) || (!enableStripeTopUp && isStripe) || (!enablePayPalTopUp && isPayPal) || (!enableWechatTopUp && isWechat) || (!enableAlipayTopUp && isAlipay) || minTopupVal > Number(topUpCount || 0) ); }; // 渲染支付方式图标(微信为原型中的绿色圆点) const renderPayIcon = (type) => { if (type === 'alipay') return ; if (type === 'wxpay') return ; if (type === 'stripe') return ; if (type === 'paypal') return ; return null; }; // ---- 充值订单:仅由已选档位、金额与支付方式派生展示 ---- const { symbol } = getCurrencyConfig(); const preset = selectedPreset !== null ? selectedPresetObj : null; const presetValue = toFiniteNumber(preset?.value) ?? 0; const discount = toFiniteNumber(preset?.discount ?? topupInfo?.discount?.[preset?.value]) ?? 1.0; const isNewVersion = preset?.id !== undefined; const originalPrice = preset ? isNewVersion ? presetValue : presetValue * (toFiniteNumber(priceRatio) ?? 0) : 0; const arrivalText = preset ? preset.label || (isNewVersion ? formatCny(preset.value) : `${symbol}${presetValue.toLocaleString('en-US')}`) : '-'; const selectedMethod = payMethods?.find((method) => method.type === payWay); const payPalQuoted = payWay === 'paypal' && payPalQuote; // 应付金额:人民币取已计算的 amount;PayPal 取已获取的美元报价(原型中币种符号为小字) const payable = !preset ? null : payWay === 'paypal' ? payPalQuoted ? { symbol: '$', value: formatNumber(payPalQuote.payAmount, 2, '0.00'), unit: 'USD', } : null : { symbol: '¥', value: formatCny(amount).slice(1) }; const canPay = Boolean(preset) && Boolean(selectedMethod) && !isMethodDisabled(selectedMethod) && Boolean(payable) && !amountLoading; if (statusLoading) { return (
); } if (!hasAnyOnlinePayment) { return ( <> ); } return ( <> {hasStandardOnlinePayment && (

{t('选择充值额度')}

{t('按需充值,余额可用于平台模型调用。')}

{presetAmounts.slice(0, 8).map((item, index) => ( selectPresetAmount(item)} topupInfo={topupInfo} priceRatio={priceRatio} t={t} /> ))}

{t('支付方式')}

{payMethods && payMethods.length > 0 ? (
{payMethods.map((method) => { const minTopupVal = Number(method.min_topup) || 0; const disabled = isMethodDisabled(method); const selected = payWay === method.type; const button = ( ); if (disabled && minTopupVal > Number(topUpCount || 0)) { return ( {button} ); } return button; })}
) : (
{t('暂无可用的支付方式,请联系管理员配置')}
)}
)} {/* Creem 充值 */} {enableCreemTopUp && creemProducts.length > 0 && (

{t('Creem 充值')}

{creemProducts.map((product, index) => ( ))}
)} {hasStandardOnlinePayment && (

{t('充值订单')}

{t('到账额度')}
{arrivalText}
{t('优惠金额')}
{preset ? formatCny(originalPrice * (1 - discount)) : '-'}
{t('支付方式')}
{selectedMethod?.name || '-'}
{payPalQuoted && (
{t('支付服务费')}
{`$${formatNumber(payPalQuote.serviceFee, 2, '0.00')} USD`}
)}
{t('应付金额')} {payable ? ( <> {payable.symbol} {payable.value} {payable.unit && ( {payable.unit} )} ) : ( '-' )} {/* 与点击支付方式相同:进入原有的预充值校验与确认弹窗 */}
)} ); }; export default RechargePanel;