invoice payments
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import * as api from "../service/PaymentService";
|
||||
import type { PayInvoiceParamsType } from "../types/Types";
|
||||
|
||||
@@ -13,3 +13,14 @@ export const usePayInvoice = () => {
|
||||
}) => api.payInvoice(invoiceId, params),
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetPaymentInvoice = (
|
||||
invoiceId?: string,
|
||||
page: number = 1,
|
||||
) => {
|
||||
return useQuery({
|
||||
queryKey: ["payment", invoiceId, page],
|
||||
queryFn: () => api.getPaymentInvoice(invoiceId, page),
|
||||
enabled: !!invoiceId,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import axios from "@/config/axios";
|
||||
import type { PayInvoiceParamsType } from "../types/Types";
|
||||
import type {
|
||||
GetPaymentInvoiceResponseType,
|
||||
PayInvoiceParamsType,
|
||||
} from "../types/Types";
|
||||
|
||||
export const payInvoice = async (
|
||||
invoiceId: string,
|
||||
@@ -11,3 +14,23 @@ export const payInvoice = async (
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
const DEFAULT_PAGE_SIZE = 10;
|
||||
|
||||
export const getPaymentInvoice = async (
|
||||
invoiceId?: string,
|
||||
page: number = 1,
|
||||
limit: number = DEFAULT_PAGE_SIZE,
|
||||
): Promise<GetPaymentInvoiceResponseType> => {
|
||||
const { data } = await axios.get<GetPaymentInvoiceResponseType>(
|
||||
`/public/payments`,
|
||||
{
|
||||
params: {
|
||||
invoiceId,
|
||||
page,
|
||||
limit,
|
||||
},
|
||||
},
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import type { PaymentGatewayEnum, PaymentMethodEnum } from "../enum/Enum";
|
||||
import type { BaseResponse } from "@/shared/types/Types";
|
||||
import type {
|
||||
PaymentGatewayEnum,
|
||||
PaymentMethodEnum,
|
||||
PaymentStatusEnum,
|
||||
} from "../enum/Enum";
|
||||
|
||||
export type PayInvoiceParamsType = {
|
||||
amount: number;
|
||||
@@ -7,3 +12,24 @@ export type PayInvoiceParamsType = {
|
||||
description: string;
|
||||
attachments: string[];
|
||||
};
|
||||
|
||||
export type PaymentItemType = {
|
||||
id: string;
|
||||
createdAt: string;
|
||||
deletedAt: string | null;
|
||||
invoice: string;
|
||||
creator: string | null;
|
||||
amount: number;
|
||||
token: string | null;
|
||||
method: PaymentMethodEnum | string;
|
||||
gateway: PaymentGatewayEnum | string | null;
|
||||
transactionId: string | null;
|
||||
status: PaymentStatusEnum | string;
|
||||
verifyResponse: unknown;
|
||||
paidAt: string | null;
|
||||
failedAt: string | null;
|
||||
attachments: string[] | null;
|
||||
description: string | null;
|
||||
};
|
||||
|
||||
export type GetPaymentInvoiceResponseType = BaseResponse<PaymentItemType[]>;
|
||||
|
||||
Reference in New Issue
Block a user