支付流程重新设计枚举值更新传参方式
This commit is contained in:
@@ -9,9 +9,14 @@ import {Alert, AlertTitle} from '@/components/ui/alert'
|
||||
import {toast} from 'sonner'
|
||||
import {useRouter} from 'next/navigation'
|
||||
import {completeResource, createResource, prepareResource} from '@/actions/resource'
|
||||
import {PaymentMethod, Platform, usePlatformType} from '@/lib/models/trade'
|
||||
import {
|
||||
TradePlatform,
|
||||
usePlatformType,
|
||||
TradeMethod,
|
||||
TradeMethodDecoration,
|
||||
} from '@/lib/models/trade'
|
||||
import {PaymentModal} from '@/components/composites/payment/payment-modal'
|
||||
import type {Trade} from '@/components/composites/payment/types'
|
||||
import {PaymentProps} from '@/components/composites/payment/type'
|
||||
|
||||
export type PayProps = {
|
||||
method: 'alipay' | 'wechat' | 'balance'
|
||||
@@ -20,10 +25,12 @@ export type PayProps = {
|
||||
}
|
||||
|
||||
export default function Pay(props: PayProps) {
|
||||
console.log(props, 'props')
|
||||
|
||||
const profile = useProfileStore(store => store.profile)
|
||||
const refreshProfile = useProfileStore(store => store.refreshProfile)
|
||||
const [open, setOpen] = useState(false)
|
||||
const [trade, setTrade] = useState<Trade | null>(null)
|
||||
const [trade, setTrade] = useState<PaymentProps | null>(null)
|
||||
const router = useRouter()
|
||||
const platform = usePlatformType()
|
||||
|
||||
@@ -32,18 +39,16 @@ export default function Pay(props: PayProps) {
|
||||
|
||||
if (props.method === 'balance') return
|
||||
|
||||
// 准备支付信息
|
||||
const paymentMethod = props.method === 'alipay'
|
||||
? platform === Platform.Mobile
|
||||
? PaymentMethod.SftAlipay // 4
|
||||
: PaymentMethod.Alipay // 1
|
||||
: platform === Platform.Mobile
|
||||
? PaymentMethod.SftWeChat // 5
|
||||
: PaymentMethod.WeChat // 2
|
||||
const method = platform === TradePlatform.Desktop
|
||||
? TradeMethod.Sft
|
||||
: props.method === 'alipay'
|
||||
? TradeMethod.SftAlipay
|
||||
: TradeMethod.SftWechat
|
||||
console.log(method, 'methodConfig')
|
||||
|
||||
const res = {
|
||||
...props.resource,
|
||||
payment_method: paymentMethod,
|
||||
payment_method: method,
|
||||
payment_platform: platform,
|
||||
}
|
||||
console.log(res, '请求参数')
|
||||
@@ -57,9 +62,11 @@ export default function Pay(props: PayProps) {
|
||||
|
||||
setTrade({
|
||||
inner_no: resp.data.trade_no,
|
||||
method: props.method === 'alipay' ? PaymentMethod.Alipay : PaymentMethod.WeChat,
|
||||
pay_url: resp.data.pay_url,
|
||||
amount: Number(props.amount),
|
||||
platform: platform,
|
||||
method: method,
|
||||
decoration: TradeMethodDecoration[props.method],
|
||||
})
|
||||
}
|
||||
|
||||
@@ -178,11 +185,17 @@ export default function Pay(props: PayProps) {
|
||||
{/* 支付宝/微信支付使用公共组件 */}
|
||||
{props.method !== 'balance' && trade && (
|
||||
<PaymentModal
|
||||
open={open}
|
||||
onOpenChange={setOpen}
|
||||
trade={trade}
|
||||
platform={platform}
|
||||
onSuccess={onSubmit}
|
||||
{...trade}
|
||||
onSuccess={() => {
|
||||
toast.success('支付成功')
|
||||
setTrade(null)
|
||||
setOpen(false)
|
||||
refreshProfile()
|
||||
}}
|
||||
onClose={() => {
|
||||
setTrade(null)
|
||||
setOpen(false)
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user