213 lines
6.7 KiB
React
213 lines
6.7 KiB
React
/*
|
||
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 <https://www.gnu.org/licenses/>.
|
||
|
||
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 <AlipayBrandIcon size={size} color='#1677FF' />;
|
||
if (type === 'wxpay')
|
||
return <WechatBrandIcon size={size} color='#07C160' />;
|
||
if (type === 'stripe')
|
||
return <StripeBrandIcon size={size} color='#635BFF' />;
|
||
if (type === 'paypal') return <PayPalBrandIcon size={size} />;
|
||
return <CreditCard size={size} className='text-brand' />;
|
||
};
|
||
|
||
// 原型未定义此弹窗:Ant Design 默认弹窗 + 统一规范(语义文字/分隔线,无渐变、光晕与动效)
|
||
return (
|
||
<Modal
|
||
title={t('充值确认')}
|
||
visible={open}
|
||
onOk={onlineTopUp}
|
||
onCancel={handleCancel}
|
||
maskClosable={false}
|
||
size='small'
|
||
centered
|
||
confirmLoading={confirmLoading}
|
||
okButtonProps={{ disabled: payPalQuoteExpired || amountLoading }}
|
||
okText={t('确认支付')}
|
||
cancelText={t('取消')}
|
||
className='payment-confirm-modal'
|
||
>
|
||
<Text type='tertiary' size='small'>
|
||
{t('请确认您的充值信息')}
|
||
</Text>
|
||
<dl className='payment-confirm-rows'>
|
||
<div>
|
||
<dt>{t('获得额度')}</dt>
|
||
<dd>{renderQuotaWithAmount(topUpCount)}</dd>
|
||
</div>
|
||
<div>
|
||
<dt>{t('实付金额')}</dt>
|
||
<dd>
|
||
{amountLoading ? (
|
||
<Skeleton.Title style={{ width: '80px', height: '24px' }} />
|
||
) : (
|
||
<>
|
||
<strong className='payment-confirm-amount'>
|
||
{renderAmount()}
|
||
</strong>
|
||
{hasDiscount && (
|
||
<AntTag variant='filled' color='success'>
|
||
{Math.round((1 - discountRate) * 100)}% OFF
|
||
</AntTag>
|
||
)}
|
||
</>
|
||
)}
|
||
</dd>
|
||
</div>
|
||
{hasDiscount && !amountLoading && (
|
||
<>
|
||
<div>
|
||
<dt>{t('原价')}</dt>
|
||
<dd>
|
||
<Text delete type='tertiary'>
|
||
¥{originalAmount.toFixed(2)}
|
||
</Text>
|
||
</dd>
|
||
</div>
|
||
<div>
|
||
<dt>{t('优惠减免')}</dt>
|
||
<dd className='payment-confirm-discount'>
|
||
- ¥{discountAmount.toFixed(2)}
|
||
</dd>
|
||
</div>
|
||
</>
|
||
)}
|
||
<div>
|
||
<dt>{t('支付方式')}</dt>
|
||
<dd className='payment-confirm-method'>
|
||
{renderPayIcon(paymentInfo.type, 16)}
|
||
{paymentInfo.name}
|
||
</dd>
|
||
</div>
|
||
{payWay === 'paypal' && payPalQuote ? (
|
||
<>
|
||
<div>
|
||
<dt>{t('充值金额')}</dt>
|
||
<dd>{formatPayPalAmount(payPalQuote.basePayAmount)}</dd>
|
||
</div>
|
||
<div>
|
||
<dt>{t('支付服务费')}</dt>
|
||
<dd>
|
||
{payPalQuote.feePayer === 'platform'
|
||
? t('平台承担')
|
||
: formatPayPalAmount(payPalQuote.serviceFee)}
|
||
</dd>
|
||
</div>
|
||
<div>
|
||
<dt>{t('实际支付')}</dt>
|
||
<dd>{formatPayPalAmount(payPalQuote.payAmount)}</dd>
|
||
</div>
|
||
<div>
|
||
<dt>
|
||
{t('汇率来源')}:{t(payPalQuote.exchangeRateSource)}
|
||
<br />1 USD = {payPalQuote.exchangeRate} CNY
|
||
</dt>
|
||
<dd className='payment-confirm-method'>
|
||
<Clock3 size={14} />
|
||
<Text
|
||
type={payPalQuoteExpired ? 'danger' : 'tertiary'}
|
||
size='small'
|
||
>
|
||
{payPalQuoteExpired
|
||
? t('报价已过期,请重新获取')
|
||
: `${t('报价剩余')} ${quoteRemaining}s`}
|
||
</Text>
|
||
</dd>
|
||
</div>
|
||
</>
|
||
) : null}
|
||
</dl>
|
||
<Text type='tertiary' size='small'>
|
||
{t('点击确认后将跳转至支付页面')}
|
||
</Text>
|
||
</Modal>
|
||
);
|
||
};
|
||
|
||
const formatPayPalAmount = (amount) => `$${Number(amount || 0).toFixed(2)} USD`;
|
||
|
||
export default PaymentConfirmModal;
|