Refactor payment verification and add MAC address guide
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 1m23s

- Updated payment verification logic in `actions/payment.ts` to remove unused code and improve clarity.
- Enhanced `DevicesToPay` component to handle separate states for wallet and transfer payment verification.
- Introduced a new `GetMacAccordion` component to guide users on finding their MAC addresses.
- Created a reusable accordion component in `ui/accordion.tsx` for better UI consistency.
- Integrated the MAC address guide into the device addition dialog.
- Updated Tailwind CSS configuration to include animations for the accordion component.
- Added Radix UI Accordion dependency to package.json and package-lock.json.
- Improved error handling in API response utility to log unauthorized responses.
This commit is contained in:
2025-05-30 23:53:08 +05:00
parent a093ab1666
commit 07349cda05
9 changed files with 625 additions and 211 deletions

View File

@ -138,19 +138,10 @@ export async function verifyPayment({ id, method }: UpdatePayment) {
}),
},
);
revalidatePath("/payments/[paymentsId]");
revalidatePath("/payments/[paymentId]", "page");
return handleApiResponse<Payment>(response, "updatePayment");
}
type VerifyPaymentType = {
userId: string;
paymentId?: string;
benefName: string;
accountNo?: string;
absAmount: string;
time: string;
type?: "TRANSFER" | "WALLET";
};
export async function getProfile() {
const session = await getServerSession(authOptions);
@ -167,114 +158,3 @@ export async function getProfile() {
return handleApiResponse<User>(response, "getProfile");
}
type VerifyPaymentResponse =
| {
success: boolean;
message: string;
}
| {
success: boolean;
message: string;
transaction: {
ref: string;
sourceBank: string;
trxDate: string;
};
};
// async function verifyExternalPayment(
// data: VerifyPaymentType,
// payment: PaymentWithDevices | null,
// ): Promise<VerifyPaymentResponse> {
// console.log("payment verify data ->", data);
// const response = await fetch(
// "https://verifypaymentsapi.baraveli.dev/verify-payment",
// {
// method: "POST",
// headers: { "Content-Type": "application/json" },
// body: JSON.stringify(data),
// },
// );
// const json = await response.json();
// console.log(json);
// if (!payment) {
// throw new Error("Payment verification failed or payment not found");
// }
// if (json.success) {
// const expiryDate = new Date();
// expiryDate.setMonth(expiryDate.getMonth() + payment.numberOfMonths);
// await prisma.payment.update({
// where: { id: payment.id },
// data: {
// paid: true,
// paidAt: new Date(),
// method: "TRANSFER",
// devices: {
// updateMany: payment.devices.map((device) => ({
// where: { id: device.id },
// data: {
// isActive: true,
// expiryDate: expiryDate,
// },
// })),
// },
// },
// });
// }
// return json;
// }
// async function updateDevices(payment: PaymentWithDevices | null) {
// if (!payment) return;
// const newDevices = payment.devices.map((d) => ({
// name: d.name,
// macAddress: formatMacAddress(d.mac),
// }));
// return await addDevicesToGroup({
// groupId: process.env.OMADA_GROUP_ID,
// siteId: process.env.OMADA_SITE_ID,
// newDevices,
// });
// }
// export async function verifyPayment(data: VerifyPaymentType) {
// try {
// const [payment, user] = await Promise.all([
// prisma.payment.findUnique({
// where: { id: data.paymentId },
// include: { devices: true },
// }),
// prisma.user.findUnique({
// where: { id: data.userId },
// }),
// ]);
// if (data.type === "WALLET") {
// console.log("WALLET");
// await processWalletPayment(user, payment, Number(data.absAmount));
// redirect("/payments");
// }
// if (data.type === "TRANSFER") {
// console.log({ data, payment });
// const verificationResult = await verifyExternalPayment(data, payment);
// await updateDevices(payment);
// revalidatePath("/payment[paymentId]");
// return verificationResult;
// }
// } catch (error) {
// console.error("Payment verification failed:", error);
// throw error; // Re-throw to handle at a higher level
// }
// }
// export async function addDevicesToOmada() {
// console.log("hi");
// }