invoice charge wallet
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
VITE_TOKEN_NAME = 'dsc_token'
|
VITE_TOKEN_NAME = 'dsc_token'
|
||||||
VITE_REFRESH_TOKEN_NAME = 'dsc_refresh_token'
|
VITE_REFRESH_TOKEN_NAME = 'dsc_refresh_token'
|
||||||
VITE_BASE_URL = 'https://api.danakcorp.com'
|
VITE_BASE_URL = 'https://api.danakcorp.com'
|
||||||
# VITE_BASE_URL = 'http://192.168.1.108:4000'
|
# VITE_BASE_URL = 'http://192.168.1.113:4000'
|
||||||
+3
-1
@@ -264,7 +264,9 @@
|
|||||||
"discount_error": "کد تخفیف معتبر نیست",
|
"discount_error": "کد تخفیف معتبر نیست",
|
||||||
"pending": "در انتظار تایید",
|
"pending": "در انتظار تایید",
|
||||||
"discount_removed": "کد تخفیف با موفقیت حذف شد",
|
"discount_removed": "کد تخفیف با موفقیت حذف شد",
|
||||||
"remove_discount": "حذف تخفیف"
|
"remove_discount": "حذف تخفیف",
|
||||||
|
"charge_wallet": "شارژ کیف پول",
|
||||||
|
"sure_charge_wallet": "آیا از شارژ کیف پول اطمینان دارید؟"
|
||||||
},
|
},
|
||||||
"active": "فعال",
|
"active": "فعال",
|
||||||
"inactive": "غیرفعال",
|
"inactive": "غیرفعال",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { FC, useState } from 'react'
|
import { FC, useEffect, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { useParams } from 'react-router-dom'
|
import { useParams } from 'react-router-dom'
|
||||||
import { useApplyDiscount, useGetInvoiceDetail, useRemoveDiscount } from './hooks/useReceiptData'
|
import { useApplyDiscount, useGetInvoiceDetail, useRemoveDiscount } from './hooks/useReceiptData'
|
||||||
@@ -19,16 +19,21 @@ import { useGetProfile } from '../profile/hooks/useProfileData'
|
|||||||
import { toast } from 'react-toastify'
|
import { toast } from 'react-toastify'
|
||||||
import { ErrorType } from '../../helpers/types'
|
import { ErrorType } from '../../helpers/types'
|
||||||
import PDFGenerator from '../../components/PDFGenerator'
|
import PDFGenerator from '../../components/PDFGenerator'
|
||||||
|
import { useGetGetWays } from '../wallet/hooks/useWalletData'
|
||||||
|
import { GatewayItemType } from '../wallet/types/WalletTypes'
|
||||||
|
|
||||||
const ReceiptsDetail: FC = () => {
|
const ReceiptsDetail: FC = () => {
|
||||||
|
|
||||||
const { id } = useParams()
|
const { id } = useParams()
|
||||||
const { t } = useTranslation('global')
|
const { t } = useTranslation('global')
|
||||||
const [code, setCode] = useState<string>('')
|
const [code, setCode] = useState<string>('')
|
||||||
|
const [gateWayId, setGateWayId] = useState<string>('')
|
||||||
const getProfile = useGetProfile()
|
const getProfile = useGetProfile()
|
||||||
const getInvoce = useGetInvoiceDetail(id ? id : '')
|
const getInvoce = useGetInvoiceDetail(id ? id : '')
|
||||||
const applyDiscount = useApplyDiscount()
|
const applyDiscount = useApplyDiscount()
|
||||||
const removeDiscount = useRemoveDiscount()
|
const removeDiscount = useRemoveDiscount()
|
||||||
|
const getWays = useGetGetWays()
|
||||||
|
|
||||||
const handleApplyDiscount = () => {
|
const handleApplyDiscount = () => {
|
||||||
const params: ApplyDiscountType = {
|
const params: ApplyDiscountType = {
|
||||||
id: id ? id : '',
|
id: id ? id : '',
|
||||||
@@ -57,6 +62,15 @@ const ReceiptsDetail: FC = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
|
||||||
|
if (getWays.data) {
|
||||||
|
setGateWayId(getWays.data?.data?.paymentGateways?.[0]?.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
}, [getWays.data])
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='mt-4'>
|
<div className='mt-4'>
|
||||||
<Helmet>
|
<Helmet>
|
||||||
@@ -291,9 +305,30 @@ const ReceiptsDetail: FC = () => {
|
|||||||
<PayInvoice
|
<PayInvoice
|
||||||
id={id ? id : ''}
|
id={id ? id : ''}
|
||||||
refetch={getInvoce.refetch}
|
refetch={getInvoce.refetch}
|
||||||
|
gateWayId={gateWayId}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
getInvoce.data?.data?.remainingToCharge > 0 &&
|
||||||
|
<div className='flex mt-6 justify-center gap-2'>
|
||||||
|
{
|
||||||
|
getWays.data?.data?.paymentGateways?.map((item: GatewayItemType) => {
|
||||||
|
return (
|
||||||
|
<div key={item.id} className={clx(
|
||||||
|
'size-[72px] rounded-xl border border-border flex flex-col justify-center items-center',
|
||||||
|
gateWayId === item.id && 'border-black'
|
||||||
|
)}>
|
||||||
|
<img src={item.logoUrl} className='w-8' />
|
||||||
|
<div className='mt-1 text-[10px]'>
|
||||||
|
{item.name}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,32 +1,48 @@
|
|||||||
import { FC, Fragment, useState } from 'react'
|
import { FC, Fragment, useState } from 'react'
|
||||||
import Button from '../../../components/Button'
|
import Button from '../../../components/Button'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { usePayInvoice } from '../hooks/useReceiptData'
|
import { useGetInvoiceDetail, usePayInvoice } from '../hooks/useReceiptData'
|
||||||
import { toast } from 'react-toastify'
|
|
||||||
import { ErrorType } from '../../../helpers/types'
|
import { ErrorType } from '../../../helpers/types'
|
||||||
import ModalConfrim from '../../../components/ModalConfrim'
|
import ModalConfrim from '../../../components/ModalConfrim'
|
||||||
|
import { usePayment } from '../../wallet/hooks/useWalletData'
|
||||||
|
import { toast } from '../../../components/Toast'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
id: string,
|
id: string,
|
||||||
refetch: () => void,
|
refetch: () => void,
|
||||||
|
gateWayId: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
const PayInvoice: FC<Props> = ({ id, refetch }) => {
|
const PayInvoice: FC<Props> = ({ id, refetch, gateWayId }) => {
|
||||||
|
|
||||||
const { t } = useTranslation('global')
|
const { t } = useTranslation('global')
|
||||||
const [showModal, setShowModal] = useState<boolean>(false)
|
const [showModal, setShowModal] = useState<boolean>(false)
|
||||||
|
const getInvoce = useGetInvoiceDetail(id)
|
||||||
const payInvoice = usePayInvoice()
|
const payInvoice = usePayInvoice()
|
||||||
|
const payment = usePayment()
|
||||||
|
|
||||||
|
|
||||||
const handleConfrim = () => {
|
const handleConfrim = () => {
|
||||||
payInvoice.mutate(id, {
|
payInvoice.mutate(id, {
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
toast.success(t('success'))
|
toast(t('success'), 'success')
|
||||||
refetch()
|
refetch()
|
||||||
setShowModal(false)
|
setShowModal(false)
|
||||||
},
|
},
|
||||||
onError: (error: ErrorType) => {
|
onError: (error: ErrorType) => {
|
||||||
toast.error(error.response?.data?.error.message[0])
|
toast(error.response?.data?.error.message[0], 'error')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleChartWallet = () => {
|
||||||
|
payment.mutate({ amount: getInvoce.data?.data?.remainingToCharge, gatewayId: gateWayId, invoiceId: id }, {
|
||||||
|
onSuccess: (data) => {
|
||||||
|
window.location.href = data?.data?.redirectUrl
|
||||||
|
toast(t('wallet.transfer_to_getway'), 'success')
|
||||||
|
},
|
||||||
|
onError: (error: ErrorType) => {
|
||||||
|
toast(error.response?.data?.error.message[0], 'error')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -34,15 +50,15 @@ const PayInvoice: FC<Props> = ({ id, refetch }) => {
|
|||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<Button
|
<Button
|
||||||
label={t('receip.pay')}
|
label={getInvoce.data?.data?.remainingToCharge > 0 ? t('receip.charge_wallet') : t('receip.pay')}
|
||||||
onClick={() => setShowModal(true)}
|
onClick={() => setShowModal(true)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ModalConfrim
|
<ModalConfrim
|
||||||
isOpen={showModal}
|
isOpen={showModal}
|
||||||
close={() => setShowModal(false)}
|
close={() => setShowModal(false)}
|
||||||
onConfrim={handleConfrim}
|
onConfrim={getInvoce.data?.data?.remainingToCharge > 0 ? handleChartWallet : handleConfrim}
|
||||||
label={t('receip.sure_confrim_pay')}
|
label={getInvoce.data?.data?.remainingToCharge > 0 ? t('receip.sure_charge_wallet') : t('receip.sure_confrim_pay')}
|
||||||
isLoading={payInvoice.isPending}
|
isLoading={payInvoice.isPending}
|
||||||
/>
|
/>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export type PaymentType = {
|
export type PaymentType = {
|
||||||
amount: number;
|
amount: number;
|
||||||
gatewayId: string;
|
gatewayId: string;
|
||||||
|
invoiceId?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type GatewayItemType = {
|
export type GatewayItemType = {
|
||||||
|
|||||||
Reference in New Issue
Block a user