✨ process pay result
This commit is contained in:
parent
c2e03aedb9
commit
b288cad771
@ -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')
|
||||
const bill = search.get('bill')
|
||||
// 参数无效
|
||||
if(!refId){
|
||||
setState({result:'fail'})
|
||||
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 (<div className={styles.container}>
|
||||
<PayLogo/>
|
||||
{state.result == 'success' ?<>
|
||||
{state.result == 'success' ? <>
|
||||
<div className={styles.paySuccess}>
|
||||
<div className={styles.successIcon}>
|
||||
<SuccessIcon/>
|
||||
@ -60,22 +61,22 @@ const PayIndex = () => {
|
||||
{t('pay.text_success')}
|
||||
</h2>
|
||||
</div>
|
||||
<div className={styles.payConfirm}>
|
||||
<div className="student-email">{t('bill.bill_number')}: PM-202405211114</div>
|
||||
{state.bill && <div className={styles.payConfirm}>
|
||||
<div className="student-email">{t('bill.bill_number')}: {state.bill.student_number || state.bill.application_number}</div>
|
||||
<div className="pay-submit">
|
||||
<Button
|
||||
theme={'solid'}
|
||||
onClick={() => downloadPDF({id: Date.now()})}
|
||||
onClick={() => downloadPDF(state.bill!)}
|
||||
style={{width: 250, marginTop: 20}}>{t('bill.download_receipt')}</Button>
|
||||
</div>
|
||||
</div>
|
||||
</>:<div className={styles.paySuccess}>
|
||||
<div className={styles.successIcon} style={{color:'#f05672'}}>
|
||||
<FailIcon />
|
||||
</div>}
|
||||
</> : <div className={styles.paySuccess}>
|
||||
<div className={styles.successIcon} style={{color: '#f05672'}}>
|
||||
<FailIcon/>
|
||||
</div>
|
||||
<h2 className={`${styles.payText} pay-text`}>
|
||||
{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'))
|
||||
)}
|
||||
</h2>
|
||||
</div>}
|
||||
|
@ -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})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user