diff --git a/src/app/pay/stripe-popup/page.tsx b/src/app/pay/stripe-popup/page.tsx index ecb709d..87fbff3 100644 --- a/src/app/pay/stripe-popup/page.tsx +++ b/src/app/pay/stripe-popup/page.tsx @@ -2,6 +2,7 @@ import { useSearchParams } from 'next/navigation'; import { useEffect, useState, useCallback, Suspense } from 'react'; +import { getPaymentMeta } from '@/lib/pay-utils'; function StripePopupContent() { const searchParams = useSearchParams(); @@ -254,7 +255,7 @@ function StripePopupContent() { 'w-full rounded-lg py-3 font-medium text-white shadow-md transition-colors', stripeSubmitting ? 'bg-gray-400 cursor-not-allowed' - : 'bg-[#635bff] hover:bg-[#5249d9] active:bg-[#4840c4]', + : getPaymentMeta('stripe').buttonClass, ].join(' ')} > {stripeSubmitting ? ( diff --git a/src/components/PaymentForm.tsx b/src/components/PaymentForm.tsx index f0def70..3e733ea 100644 --- a/src/components/PaymentForm.tsx +++ b/src/components/PaymentForm.tsx @@ -1,7 +1,7 @@ 'use client'; import { useState } from 'react'; -import { PAYMENT_TYPE_META, getPaymentIconType } from '@/lib/pay-utils'; +import { PAYMENT_TYPE_META, getPaymentIconType, getPaymentMeta } from '@/lib/pay-utils'; export interface MethodLimitInfo { available: boolean; @@ -327,9 +327,7 @@ export default function PaymentForm({ disabled={!isValid || loading} className={`w-full rounded-lg py-3 text-center font-medium text-white transition-colors ${ isValid && !loading - ? effectivePaymentType.startsWith('stripe') - ? 'bg-[#635bff] hover:bg-[#5851db] active:bg-[#4b44c7]' - : 'bg-blue-600 hover:bg-blue-700 active:bg-blue-800' + ? getPaymentMeta(effectivePaymentType).buttonClass : dark ? 'cursor-not-allowed bg-slate-700 text-slate-300' : 'cursor-not-allowed bg-gray-300' diff --git a/src/components/PaymentQRCode.tsx b/src/components/PaymentQRCode.tsx index 6517605..d1f0cca 100644 --- a/src/components/PaymentQRCode.tsx +++ b/src/components/PaymentQRCode.tsx @@ -2,6 +2,13 @@ import { useEffect, useMemo, useState, useCallback, useRef } from 'react'; import QRCode from 'qrcode'; +import { + isStripeType, + isRedirectPayment, + getPaymentMeta, + getPaymentIconSrc, + getPaymentChannelLabel, +} from '@/lib/pay-utils'; interface PaymentQRCodeProps { orderId: string; @@ -71,14 +78,13 @@ export default function PaymentQRCode({ const paymentMethodListenerAdded = useRef(false); // alipay_direct 使用电脑网站支付,payUrl 是跳转链接不是二维码内容 - const isAlipayDirect = paymentType === 'alipay_direct'; + const isRedirect = isRedirectPayment(paymentType); const qrPayload = useMemo(() => { - // alipay_direct 的 payUrl 是跳转链接,不应生成二维码 - if (isAlipayDirect && !qrCode) return ''; + if (isRedirect && !qrCode) return ''; const value = (qrCode || payUrl || '').trim(); return value; - }, [qrCode, payUrl, isAlipayDirect]); + }, [qrCode, payUrl, isRedirect]); useEffect(() => { let cancelled = false; @@ -115,7 +121,7 @@ export default function PaymentQRCode({ }, [qrPayload]); // Initialize Stripe Payment Element - const isStripe = paymentType?.startsWith('stripe'); + const isStripe = isStripeType(paymentType); useEffect(() => { if (!isStripe || !clientSecret || !stripePublishableKey) return; @@ -318,10 +324,10 @@ export default function PaymentQRCode({ } }; - const isWx = paymentType?.startsWith('wxpay'); - const iconSrc = isStripe ? '' : isWx ? '/icons/wxpay.svg' : '/icons/alipay.svg'; - const channelLabel = isStripe ? 'Stripe' : isWx ? '\u5FAE\u4FE1' : '\u652F\u4ED8\u5B9D'; - const iconBgClass = isStripe ? 'bg-[#635bff]' : isWx ? 'bg-[#07C160]' : 'bg-[#1677FF]'; + const meta = getPaymentMeta(paymentType || 'alipay'); + const iconSrc = getPaymentIconSrc(paymentType || 'alipay'); + const channelLabel = getPaymentChannelLabel(paymentType || 'alipay'); + const iconBgClass = meta.iconBg; if (cancelBlocked) { return ( @@ -414,7 +420,7 @@ export default function PaymentQRCode({ 'w-full rounded-lg py-3 font-medium text-white shadow-md transition-colors', stripeSubmitting ? 'bg-gray-400 cursor-not-allowed' - : 'bg-[#635bff] hover:bg-[#5249d9] active:bg-[#4840c4]', + : meta.buttonClass, ].join(' ')} > {stripeSubmitting ? ( @@ -457,16 +463,16 @@ export default function PaymentQRCode({ {TEXT_H5_HINT}
> - ) : isAlipayDirect && payUrl ? ( + ) : isRedirect && payUrl ? ( <> -
{TEXT_H5_HINT}
diff --git a/src/components/admin/PaymentMethodChart.tsx b/src/components/admin/PaymentMethodChart.tsx
index df21ef1..3d16fab 100644
--- a/src/components/admin/PaymentMethodChart.tsx
+++ b/src/components/admin/PaymentMethodChart.tsx
@@ -1,6 +1,6 @@
'use client';
-import { getPaymentTypeLabel } from '@/lib/pay-utils';
+import { getPaymentTypeLabel, getPaymentMeta } from '@/lib/pay-utils';
interface PaymentMethod {
paymentType: string;
@@ -14,14 +14,6 @@ interface PaymentMethodChartProps {
dark?: boolean;
}
-const TYPE_CONFIG: Record