feat: enhance payment retrieval with flexible query parameters and add dynamic filters to payments page

This commit is contained in:
2025-07-05 20:39:28 +05:00
parent 135edf80a8
commit 9fe3c3b774
4 changed files with 62 additions and 22 deletions

View File

@ -90,10 +90,19 @@ export async function getPayment({ id }: { id: string }) {
return data;
}
export async function getPayments() {
type GetPaymentProps = {
[key: string]: string | number | undefined; // Allow additional properties for flexibility
};
export async function getPayments(params: GetPaymentProps) {
// Build query string from all defined params
const query = Object.entries(params)
.filter(([_, value]) => value !== undefined && value !== "")
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`)
.join("&");
const session = await getServerSession(authOptions);
const response = await fetch(
`${process.env.SARLINK_API_BASE_URL}/api/billing/payment/`,
`${process.env.SARLINK_API_BASE_URL}/api/billing/payment/?${query}`,
{
method: "GET",
headers: {