mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-10-16 11:01:37 +00:00
add admin checks for admin pages and run biome formating 🔨
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 11m8s
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 11m8s
This commit is contained in:
@@ -8,7 +8,7 @@ import type {
|
||||
ApiResponse,
|
||||
NewPayment,
|
||||
Payment,
|
||||
Topup
|
||||
Topup,
|
||||
} from "@/lib/backend-types";
|
||||
import type { TopupResponse } from "@/lib/types";
|
||||
import { handleApiResponse } from "@/utils/tryCatch";
|
||||
@@ -24,7 +24,8 @@ export async function createPayment(data: NewPayment) {
|
||||
const session = await getServerSession(authOptions);
|
||||
console.log("data", data);
|
||||
const response = await fetch(
|
||||
`${process.env.SARLINK_API_BASE_URL // });
|
||||
`${
|
||||
process.env.SARLINK_API_BASE_URL // });
|
||||
}/api/billing/payment/`,
|
||||
{
|
||||
method: "POST",
|
||||
@@ -93,11 +94,17 @@ type GetPaymentProps = {
|
||||
[key: string]: string | number | undefined; // Allow additional properties for flexibility
|
||||
};
|
||||
|
||||
export async function getPayments(params: GetPaymentProps, allPayments = false) {
|
||||
export async function getPayments(
|
||||
params: GetPaymentProps,
|
||||
allPayments = false,
|
||||
) {
|
||||
// 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))}`)
|
||||
.map(
|
||||
([key, value]) =>
|
||||
`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`,
|
||||
)
|
||||
.join("&");
|
||||
const session = await getServerSession(authOptions);
|
||||
const response = await fetch(
|
||||
@@ -122,12 +129,17 @@ export async function getPayments(params: GetPaymentProps, allPayments = false)
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function getTopups(params: GenericGetResponseProps, all_topups = false) {
|
||||
|
||||
export async function getTopups(
|
||||
params: GenericGetResponseProps,
|
||||
all_topups = false,
|
||||
) {
|
||||
// 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))}`)
|
||||
.map(
|
||||
([key, value]) =>
|
||||
`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`,
|
||||
)
|
||||
.join("&");
|
||||
|
||||
const session = await getServerSession(authOptions);
|
||||
@@ -223,17 +235,17 @@ export type VerifyDevicePaymentState = {
|
||||
success: boolean;
|
||||
fieldErrors: Record<string, string>;
|
||||
payload?: FormData;
|
||||
}
|
||||
};
|
||||
|
||||
export async function verifyDevicePayment(
|
||||
_prevState: VerifyDevicePaymentState,
|
||||
formData: FormData
|
||||
formData: FormData,
|
||||
): Promise<VerifyDevicePaymentState> {
|
||||
const session = await getServerSession(authOptions);
|
||||
|
||||
// Get the payment ID and method from the form data
|
||||
const paymentId = formData.get('paymentId') as string;
|
||||
const method = formData.get('method') as "TRANSFER" | "WALLET";
|
||||
const paymentId = formData.get("paymentId") as string;
|
||||
const method = formData.get("method") as "TRANSFER" | "WALLET";
|
||||
|
||||
if (!paymentId) {
|
||||
return {
|
||||
@@ -266,14 +278,18 @@ export async function verifyDevicePayment(
|
||||
},
|
||||
);
|
||||
|
||||
const result = await handleApiResponse<Payment>(response, "verifyDevicePayment");
|
||||
const result = await handleApiResponse<Payment>(
|
||||
response,
|
||||
"verifyDevicePayment",
|
||||
);
|
||||
|
||||
revalidatePath("/payments/[paymentId]", "page");
|
||||
|
||||
return {
|
||||
message: method === "WALLET"
|
||||
? "Payment completed successfully using wallet!"
|
||||
: "Payment verification successful!",
|
||||
message:
|
||||
method === "WALLET"
|
||||
? "Payment completed successfully using wallet!"
|
||||
: "Payment verification successful!",
|
||||
success: true,
|
||||
fieldErrors: {},
|
||||
payment: result,
|
||||
@@ -281,7 +297,8 @@ export async function verifyDevicePayment(
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
message: error.message || "Payment verification failed. Please try again.",
|
||||
message:
|
||||
error.message || "Payment verification failed. Please try again.",
|
||||
success: false,
|
||||
fieldErrors: {},
|
||||
};
|
||||
@@ -295,7 +312,6 @@ export async function verifyDevicePayment(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export type VerifyTopupPaymentState = {
|
||||
transaction?: {
|
||||
sourceBank: string;
|
||||
@@ -305,15 +321,15 @@ export type VerifyTopupPaymentState = {
|
||||
success: boolean;
|
||||
fieldErrors: Record<string, string>;
|
||||
payload?: FormData;
|
||||
}
|
||||
};
|
||||
export async function verifyTopupPayment(
|
||||
_prevState: VerifyTopupPaymentState,
|
||||
formData: FormData
|
||||
formData: FormData,
|
||||
): Promise<VerifyTopupPaymentState> {
|
||||
const session = await getServerSession(authOptions);
|
||||
|
||||
// Get the topup ID from the form data or use a hidden input
|
||||
const topupId = formData.get('topupId') as string;
|
||||
const topupId = formData.get("topupId") as string;
|
||||
|
||||
if (!topupId) {
|
||||
return {
|
||||
@@ -335,7 +351,10 @@ export async function verifyTopupPayment(
|
||||
},
|
||||
);
|
||||
|
||||
const result = await handleApiResponse<TopupResponse>(response, "verifyTopupPayment");
|
||||
const result = await handleApiResponse<TopupResponse>(
|
||||
response,
|
||||
"verifyTopupPayment",
|
||||
);
|
||||
|
||||
revalidatePath("/top-ups/[topupId]", "page");
|
||||
|
||||
@@ -348,7 +367,8 @@ export async function verifyTopupPayment(
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
message: error.message || "Please check your payment details and try again.",
|
||||
message:
|
||||
error.message || "Please check your payment details and try again.",
|
||||
success: false,
|
||||
fieldErrors: {},
|
||||
};
|
||||
@@ -361,5 +381,3 @@ export async function verifyTopupPayment(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user