diff --git a/src/pages/pay/result.tsx b/src/pages/pay/result.tsx index cf92a36..2c56e24 100644 --- a/src/pages/pay/result.tsx +++ b/src/pages/pay/result.tsx @@ -9,16 +9,16 @@ import {useDownloadReceiptPDF} from "@/service/generate-pdf.ts"; import {useEffect} from "react"; import {useSetState} from "ahooks"; import {FailIcon} from "@/assets/images/pay/fail.tsx"; +import {updateBillPaymentSuccess} from "@/service/api/bill.ts"; -type PayResult = 'fail' | 'success' | 'cancel' | 'error'| string; -function updateBillSuccess(billId){ - return { - success: true, - data: { - billId - } - } +type PayResult = 'fail' | 'success' | 'cancel' | 'error' | string; + +function updateBillSuccess(billId: number, type: string, ref: string) { + updateBillPaymentSuccess(billId, ref, type).then(res => { + console.log(res) + }) } + const PayIndex = () => { const {t} = useTranslation() const {downloadPDF} = useDownloadReceiptPDF() @@ -27,7 +27,7 @@ const PayIndex = () => { result?: PayResult; id?: string; bill?: BillModel - status?: string|null; + status?: string | null; }>({}); const param = useParams<{ result: PayResult }>(); const [search] = useSearchParams(); // 参数有: from: asia_spay || flywire @@ -37,21 +37,22 @@ const PayIndex = () => { status = search.get('status') if (from) { setState({from}) - if(from == 'asia_spay') { - const refId = search.get('Ref') - // 参数无效 - if(!refId){ - setState({result:'fail'}) - return; - } + const bill = search.get('bill') + // 参数无效 + if (!bill) { + setState({result: 'fail'}) + return; + } + if (result == 'success') { + updateBillSuccess(Number(bill), from, (from == 'asia_pay' ? search.get('Ref')! : search.get('callback_id')!)); } } - setState({result,status}) + setState({result, status}) }, []); return (
- {state.result == 'success' ?<> + {state.result == 'success' ? <>
@@ -60,22 +61,22 @@ const PayIndex = () => { {t('pay.text_success')}
-
-
{t('bill.bill_number')}: PM-202405211114
+ {state.bill &&
+
{t('bill.bill_number')}: {state.bill.student_number || state.bill.application_number}
-
- :
-
- +
} + :
+
+

- {state.result == 'fail'?t('pay.text_failed'):( - state.result == 'cancel'?t('pay.text_canceled'):(t('pay.bill_error')) + {state.result == 'fail' ? t('pay.text_failed') : ( + state.result == 'cancel' ? t('pay.text_canceled') : (t('pay.bill_error')) )}

} diff --git a/src/service/api/bill.ts b/src/service/api/bill.ts index e8640ef..c7c2979 100644 --- a/src/service/api/bill.ts +++ b/src/service/api/bill.ts @@ -47,6 +47,9 @@ export function cancelBill(id: number) { } export function confirmBills(bill_ids: number[]) { - return post(`/api/bills/apply`, { bill_ids }) + return post(`/api/bills/apply`, {bill_ids}) } +export function updateBillPaymentSuccess(billId: number, merchant_ref: string,peyment_channel:string) { + return post(`api/bills/${billId}/finish`, {merchant_ref,peyment_channel}) +}