mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-07-03 06:48:21 +00:00
Enhance payment processing and device management features
- Updated `package.json` to add a new script for pushing Prisma database changes. - Refactored payment processing functions to include payment method handling for both wallet and transfer options. - Improved `DevicesTable` and `AdminDevicesTable` components to support new payment method display and user association. - Updated Prisma schema to introduce a new `PaymentType` enum and modified the `Payment` model to include a `method` field. - Enhanced UI components to improve user experience in displaying payment and device information. These changes improve the overall functionality and maintainability of the application, particularly in payment processing and device management.
This commit is contained in:
@ -78,11 +78,15 @@ async function processWalletPayment(
|
||||
data: {
|
||||
paid: true,
|
||||
paidAt: new Date(),
|
||||
method: "WALLET",
|
||||
devices: {
|
||||
updateMany: {
|
||||
where: { paymentId: payment.id },
|
||||
data: { isActive: true, expiryDate: expiryDate },
|
||||
},
|
||||
updateMany: payment.devices.map((device) => ({
|
||||
where: { id: device.id },
|
||||
data: {
|
||||
isActive: true,
|
||||
expiryDate: expiryDate,
|
||||
},
|
||||
})),
|
||||
},
|
||||
},
|
||||
}),
|
||||
@ -136,11 +140,15 @@ async function verifyExternalPayment(
|
||||
data: {
|
||||
paid: true,
|
||||
paidAt: new Date(),
|
||||
method: "TRANSFER",
|
||||
devices: {
|
||||
updateMany: {
|
||||
where: { paymentId: payment.id },
|
||||
data: { isActive: true, expiryDate: expiryDate },
|
||||
},
|
||||
updateMany: payment.devices.map((device) => ({
|
||||
where: { id: device.id },
|
||||
data: {
|
||||
isActive: true,
|
||||
expiryDate: expiryDate,
|
||||
},
|
||||
})),
|
||||
},
|
||||
},
|
||||
});
|
||||
@ -177,16 +185,19 @@ export async function verifyPayment(data: VerifyPaymentType) {
|
||||
]);
|
||||
|
||||
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);
|
||||
|
||||
const verificationResult = await verifyExternalPayment(data, payment);
|
||||
await updateDevices(payment);
|
||||
revalidatePath("/payment[paymentId]");
|
||||
|
||||
revalidatePath("/payment[paymentId]");
|
||||
|
||||
return verificationResult;
|
||||
return verificationResult;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Payment verification failed:", error);
|
||||
throw error; // Re-throw to handle at a higher level
|
||||
|
Reference in New Issue
Block a user