invoice payments

This commit is contained in:
hamid zarghami
2026-02-24 12:34:04 +03:30
parent 7e17191c1b
commit 0aa70b251e
5 changed files with 172 additions and 3 deletions
+12 -1
View File
@@ -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,
});
};
+24 -1
View File
@@ -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;
};
+27 -1
View File
@@ -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[]>;