Refactor Omada actions and enhance payment processing

- Simplified fetchOmadaGroupProfiles function by removing unnecessary parameters and using environment variables for base URL and API key.
- Improved error handling in fetchOmadaGroupProfiles to check for error codes in the response.
- Updated addDevicesToGroup function to remove redundant parameters and streamline device addition logic.
- Integrated formatMacAddress utility to ensure consistent MAC address formatting during payment verification.
- Enhanced verifyPayment function to include device addition upon successful payment verification, with improved logging.
- Refactored DevicesToPay component to clean up payment verification logic and improve UI responsiveness.

These changes enhance the clarity and efficiency of device management and payment processing functionalities.
This commit is contained in:
2024-12-21 00:24:29 +05:00
parent 1d6f4faf7e
commit 586c0e7210
4 changed files with 57 additions and 86 deletions

View File

@ -2,6 +2,7 @@
import prisma from "@/lib/db";
import type { PaymentType } from "@/lib/types";
import { formatMacAddress } from "@/lib/utils";
import { revalidatePath } from "next/cache";
import { addDevicesToGroup } from "./omada-actions";
@ -60,7 +61,7 @@ export async function verifyPayment(data: VerifyPaymentType) {
const newDevices = payment?.devices.map((d) => {
return {
name: d.name,
macAddress: d.mac,
macAddress: formatMacAddress(d.mac),
};
});
if (json.success === true) {
@ -73,17 +74,18 @@ export async function verifyPayment(data: VerifyPaymentType) {
paid: true,
},
}),
addDevicesToGroup({
groupId: process.env.OMADA_GROUP_ID,
omadacId: process.env.OMADA_CID,
siteId: process.env.OMADA_SITE_ID,
newDevices: newDevices || [],
}),
]);
}
const res = await addDevicesToGroup({
groupId: process.env.OMADA_GROUP_ID,
siteId: process.env.OMADA_SITE_ID,
newDevices: newDevices || [],
});
revalidatePath("/payment[paymentId]");
return json;
console.log(res);
return res;
} catch (error) {
console.error(error);
}