mirror of
				https://github.com/i701/sarlink-portal.git
				synced 2025-11-03 18:07:00 +00:00 
			
		
		
		
	Enhance payment processing and user interaction features
- Updated createPayment function to log payment data more clearly. - Introduced verifyPayment function for validating payments via an external API. - Enhanced DevicesToPay component to include user information and payment verification functionality. - Added formatDate utility for consistent date formatting across the application. - Updated Prisma schema to include account number for users. - Refactored layout and device cart components for improved user experience and responsiveness.
This commit is contained in:
		@@ -5,7 +5,7 @@ import type { PaymentType } from "@/lib/types";
 | 
			
		||||
import { revalidatePath } from "next/cache";
 | 
			
		||||
 | 
			
		||||
export async function createPayment(data: PaymentType) {
 | 
			
		||||
	console.log("hi", data);
 | 
			
		||||
	console.log("data", data);
 | 
			
		||||
	const payment = await prisma.payment.create({
 | 
			
		||||
		data: {
 | 
			
		||||
			amount: data.amount,
 | 
			
		||||
@@ -24,3 +24,48 @@ export async function createPayment(data: PaymentType) {
 | 
			
		||||
	revalidatePath("/devices");
 | 
			
		||||
	return payment;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type VerifyPaymentType = {
 | 
			
		||||
	paymentId?: string;
 | 
			
		||||
	benefName: string;
 | 
			
		||||
	accountNo?: string;
 | 
			
		||||
	absAmount: string;
 | 
			
		||||
	time: string;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export async function verifyPayment(data: VerifyPaymentType) {
 | 
			
		||||
	console.log({ data });
 | 
			
		||||
	try {
 | 
			
		||||
		const payment = await prisma.payment.findUnique({
 | 
			
		||||
			where: {
 | 
			
		||||
				id: data.paymentId,
 | 
			
		||||
			},
 | 
			
		||||
		});
 | 
			
		||||
		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 (json.success === true) {
 | 
			
		||||
			await prisma.payment.update({
 | 
			
		||||
				where: {
 | 
			
		||||
					id: payment?.id,
 | 
			
		||||
				},
 | 
			
		||||
				data: {
 | 
			
		||||
					paid: true,
 | 
			
		||||
				},
 | 
			
		||||
			});
 | 
			
		||||
		}
 | 
			
		||||
		revalidatePath("/payment[paymentId]");
 | 
			
		||||
		return json;
 | 
			
		||||
	} catch (error) {
 | 
			
		||||
		console.error(error);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user