diff --git a/src/actions/auth/identify.ts b/src/actions/auth/identify.ts index 9400e38..52f7b2b 100644 --- a/src/actions/auth/identify.ts +++ b/src/actions/auth/identify.ts @@ -1,3 +1,4 @@ +'use server' import {callByUser, callPublic} from '@/actions/base' export async function Identify(props: { diff --git a/src/actions/bill.ts b/src/actions/bill.ts index 5bf944d..912c8df 100644 --- a/src/actions/bill.ts +++ b/src/actions/bill.ts @@ -1,3 +1,4 @@ +'use server' import {Bill} from '@/lib/models' import {callByUser} from '@/actions/base' import {PageRecord} from '@/lib/api' diff --git a/src/actions/channel.ts b/src/actions/channel.ts index bbb6187..2c357f5 100644 --- a/src/actions/channel.ts +++ b/src/actions/channel.ts @@ -1,3 +1,4 @@ +'use server' import {callByUser} from '@/actions/base' async function createChannels(params: { diff --git a/src/actions/fake/tradeCallback.ts b/src/actions/fake/tradeCallback.ts deleted file mode 100644 index a2d8d05..0000000 --- a/src/actions/fake/tradeCallback.ts +++ /dev/null @@ -1,3 +0,0 @@ -export async function tradeCallbackByAlipay() { - -} diff --git a/src/actions/user.ts b/src/actions/user.ts new file mode 100644 index 0000000..f10a630 --- /dev/null +++ b/src/actions/user.ts @@ -0,0 +1,33 @@ +'use server' + +import {callByUser} from '@/actions/base' + +export async function RechargeByAlipay(props: { + amount: number +}) { + return callByUser<{ + trade_no: string + pay_url: string + }>('/api/user/recharge/prepare/alipay', props) +} + +export async function RechargeByAlipayConfirm(props: { + trade_no: string +}) { + return callByUser('/api/user/recharge/confirm/alipay', props) +} + +export async function RechargeByWechat(props: { + amount: number +}) { + return callByUser<{ + trade_no: string + pay_url: string + }>('/api/user/recharge/prepare/wechat', props) +} + +export async function RechargeByWechatConfirm(props: { + trade_no: string +}) { + return callByUser('/api/user/recharge/confirm/wechat', props) +} diff --git a/src/components/composites/purchase/_client/pay.tsx b/src/components/composites/purchase/_client/pay.tsx index b80b78a..35e6103 100644 --- a/src/components/composites/purchase/_client/pay.tsx +++ b/src/components/composites/purchase/_client/pay.tsx @@ -5,7 +5,7 @@ import alipay from '../_assets/alipay.svg' import wechat from '../_assets/wechat.svg' import balance from '../_assets/balance.svg' import Image from 'next/image' -import {useContext, useState} from 'react' +import {useContext, useRef, useState} from 'react' import {AuthContext} from '@/components/providers/AuthProvider' import {Alert, AlertDescription} from '@/components/ui/alert' import { @@ -21,6 +21,7 @@ import {ApiResponse} from '@/lib/api' import {toast} from 'sonner' import {Loader} from 'lucide-react' import {useRouter} from 'next/navigation' +import * as qrcode from 'qrcode' export type PayProps = { method: 'alipay' | 'wechat' | 'balance' @@ -34,6 +35,7 @@ export default function Pay(props: PayProps) { const ctx = useContext(AuthContext) const [open, setOpen] = useState(false) const [payInfo, setPayInfo] = useState() + const canvas = useRef(null) const onOpen = async () => { setOpen(true) @@ -58,6 +60,7 @@ export default function Pay(props: PayProps) { } setPayInfo(resp.data) + await qrcode.toCanvas(canvas.current, resp.data.pay_url) } const router = useRouter() @@ -172,13 +175,15 @@ export default function Pay(props: PayProps) {
{payInfo ? ( -