/* 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 './payment-confirm.css'; import React, { useEffect, useState } from 'react'; import { Tag as AntTag } from 'antd'; import { Modal, Typography, Skeleton } from '@/components/ui'; import { CreditCard, Clock3 } from 'lucide-react'; import { AlipayBrandIcon, WechatBrandIcon, StripeBrandIcon, PayPalBrandIcon, } from '../../common/icons/BrandIcons'; const { Text } = Typography; const PaymentConfirmModal = ({ t, open, onlineTopUp, handleCancel, confirmLoading, topUpCount, renderQuotaWithAmount, amountLoading, renderAmount, payWay, payMethods, // 新增:用于显示折扣明细 amountNumber, discountRate, payPalQuote, }) => { const [now, setNow] = useState(() => Date.now()); useEffect(() => { if (!open || payWay !== 'paypal') return undefined; setNow(Date.now()); const timer = window.setInterval(() => setNow(Date.now()), 1000); return () => window.clearInterval(timer); }, [open, payWay]); const quoteRemaining = Math.max( 0, Math.ceil((payPalQuote?.quoteExpiresAt || 0) - now / 1000), ); const payPalQuoteExpired = payWay === 'paypal' && quoteRemaining === 0; const hasDiscount = discountRate && discountRate > 0 && discountRate < 1 && amountNumber > 0; const originalAmount = hasDiscount ? amountNumber / discountRate : 0; const discountAmount = hasDiscount ? originalAmount - amountNumber : 0; // 获取支付方式图标和颜色 const getPaymentInfo = () => { const payMethod = payMethods?.find((method) => method.type === payWay); if (payMethod) { return { name: payMethod.name, type: payMethod.type, color: payMethod.color, }; } if (payWay === 'alipay') return { name: t('支付宝'), type: 'alipay' }; if (payWay === 'stripe') return { name: 'Stripe', type: 'stripe' }; if (payWay === 'paypal') return { name: 'PayPal', type: 'paypal' }; return { name: t('微信'), type: 'wxpay' }; }; const paymentInfo = getPaymentInfo(); const renderPayIcon = (type, size = 20) => { if (type === 'alipay') return ; if (type === 'wxpay') return ; if (type === 'stripe') return ; if (type === 'paypal') return ; return ; }; // 原型未定义此弹窗:Ant Design 默认弹窗 + 统一规范(语义文字/分隔线,无渐变、光晕与动效) return ( {t('请确认您的充值信息')}
{t('获得额度')}
{renderQuotaWithAmount(topUpCount)}
{t('实付金额')}
{amountLoading ? ( ) : ( <> {renderAmount()} {hasDiscount && ( {Math.round((1 - discountRate) * 100)}% OFF )} )}
{hasDiscount && !amountLoading && ( <>
{t('原价')}
¥{originalAmount.toFixed(2)}
{t('优惠减免')}
- ¥{discountAmount.toFixed(2)}
)}
{t('支付方式')}
{renderPayIcon(paymentInfo.type, 16)} {paymentInfo.name}
{payWay === 'paypal' && payPalQuote ? ( <>
{t('充值金额')}
{formatPayPalAmount(payPalQuote.basePayAmount)}
{t('支付服务费')}
{payPalQuote.feePayer === 'platform' ? t('平台承担') : formatPayPalAmount(payPalQuote.serviceFee)}
{t('实际支付')}
{formatPayPalAmount(payPalQuote.payAmount)}
{t('汇率来源')}:{t(payPalQuote.exchangeRateSource)}
1 USD = {payPalQuote.exchangeRate} CNY
{payPalQuoteExpired ? t('报价已过期,请重新获取') : `${t('报价剩余')} ${quoteRemaining}s`}
) : null}
{t('点击确认后将跳转至支付页面')}
); }; const formatPayPalAmount = (amount) => `$${Number(amount || 0).toFixed(2)} USD`; export default PaymentConfirmModal;