diff --git a/.env b/.env index 1b3b68f..1138966 100644 --- a/.env +++ b/.env @@ -8,3 +8,7 @@ AZURE_AD_CLIENT_ID=76adfa07-a614-4575-a6a1-e9b59d74920a # reCaptcha credentials NEXT_PUBLIC_RECAPTCHA=6Ld5tlYpAAAAAGp_3Y5Zp7idrOCLvPqdT2mOalfm #RECAPTCHA_SERVER= + +# EuPlatesc credentials +EUPLATESC_MERCHANT_ID=44841002813 +#EUPLATESC_KEY= diff --git a/.env.development b/.env.development index 582b392..4264680 100644 --- a/.env.development +++ b/.env.development @@ -8,3 +8,5 @@ NEXTAUTH_SECRET=dev # Connection string for Prisma DATABASE_URL="postgresql://taxes_app:dev_pwd@localhost:5432/taxes?schema=public" + +EUPLATESC_TEST_MODE=true diff --git a/.env.production b/.env.production index 2faf997..5c8e6cb 100644 --- a/.env.production +++ b/.env.production @@ -5,8 +5,5 @@ NEXT_PUBLIC_BASE_URL=https://ponou.unibuc.ro/ # NextAuth configuration NEXTAUTH_URL=https://ponou.unibuc.ro/ -# EuPlatesc credentials -EUPLATESC_MERCHANT_ID=44841002813 -#EUPLATESC_KEY= -EUPLATESC_TEST_MODE=true +EUPLATESC_TEST_MODE=false diff --git a/package-lock.json b/package-lock.json index 61900ea..e2c6120 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3312,6 +3312,7 @@ "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, "hasInstallScript": true, "optional": true, "os": [ @@ -6388,6 +6389,111 @@ "funding": { "url": "https://github.com/sponsors/colinhacks" } + }, + "node_modules/@next/swc-darwin-x64": { + "version": "15.1.6", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-15.1.6.tgz", + "integrity": "sha512-x1jGpbHbZoZ69nRuogGL2MYPLqohlhnT9OCU6E6QFewwup+z+M6r8oU47BTeJcWsF2sdBahp5cKiAcDbwwK/lg==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-arm64-gnu": { + "version": "15.1.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-15.1.6.tgz", + "integrity": "sha512-jar9sFw0XewXsBzPf9runGzoivajeWJUc/JkfbLTC4it9EhU8v7tCRLH7l5Y1ReTMN6zKJO0kKAGqDk8YSO2bg==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-arm64-musl": { + "version": "15.1.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-15.1.6.tgz", + "integrity": "sha512-+n3u//bfsrIaZch4cgOJ3tXCTbSxz0s6brJtU3SzLOvkJlPQMJ+eHVRi6qM2kKKKLuMY+tcau8XD9CJ1OjeSQQ==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-x64-gnu": { + "version": "15.1.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-15.1.6.tgz", + "integrity": "sha512-SpuDEXixM3PycniL4iVCLyUyvcl6Lt0mtv3am08sucskpG0tYkW1KlRhTgj4LI5ehyxriVVcfdoxuuP8csi3kQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-x64-musl": { + "version": "15.1.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-15.1.6.tgz", + "integrity": "sha512-L4druWmdFSZIIRhF+G60API5sFB7suTbDRhYWSjiw0RbE+15igQvE2g2+S973pMGvwN3guw7cJUjA/TmbPWTHQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-arm64-msvc": { + "version": "15.1.6", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-15.1.6.tgz", + "integrity": "sha512-s8w6EeqNmi6gdvM19tqKKWbCyOBvXFbndkGHl+c9YrzsLARRdCHsD9S1fMj8gsXm9v8vhC8s3N8rjuC/XrtkEg==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-x64-msvc": { + "version": "15.1.6", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-15.1.6.tgz", + "integrity": "sha512-6xomMuu54FAFxttYr5PJbEfu96godcxBTRk1OhAvJq0/EnmFU/Ybiax30Snis4vdWZ9LGpf7Roy5fSs7v/5ROQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } } } } diff --git a/src/actions/euplatesc.ts b/src/actions/euplatesc.ts index b7c4673..0724031 100644 --- a/src/actions/euplatesc.ts +++ b/src/actions/euplatesc.ts @@ -1,5 +1,3 @@ -"use server"; - import { EuPlatesc } from "euplatesc"; import { EuPlatescAccount } from "@prisma/client"; diff --git a/src/actions/forms.ts b/src/actions/forms.ts index c7d1512..709e6d6 100644 --- a/src/actions/forms.ts +++ b/src/actions/forms.ts @@ -1,4 +1,6 @@ "use server"; +import { redirect } from "next/navigation"; + import { ReCAPTCHAResponse } from "@/types/forms/agreements"; import { AccommodationTaxFormData } from "@/types/forms/dorms"; import { @@ -11,6 +13,8 @@ import { tuitionTaxFormSchema, } from "@/utils/forms/validationSchemas"; +import { EuPlatescPayment, generateEuPlatescPaymentUrl } from "./euplatesc"; + export async function validateReCAPTCHA(token: string): Promise { console.log("Validating ReCAPTCHA challenge response"); try { @@ -52,11 +56,43 @@ export async function submitAdmissionTaxForm( //redirect to error page return { success: false }; } - console.log(validate.data); + const { data } = validate; + + if (!prisma) { + console.error("Prisma client is null!"); + return { success: false }; + } + + const faculty = await prisma.faculty.findUnique({ + include: { + euPlatescAccount: true, + }, + where: { + id: data.facultyId, + }, + }); + + if (!faculty) { + console.error("Failed to find faculty with ID %d", data.facultyId); + return { success: false }; + } + + const account = faculty.euPlatescAccount!; - // revalidate admin path - // redirect to success page - return { success: true }; + const paymentData: EuPlatescPayment = { + account, + amount: data.amount, + invoiceId: "1234", + description: `Plata taxa de admitere ${faculty.nameRo}`, + billingEmail: data.email, + billingPhone: data.phoneNumber, + billingCountry: data.country, + billingCity: data.city, + billingAddress: data.address, + }; + const redirectUrl = generateEuPlatescPaymentUrl(paymentData); + + redirect(redirectUrl); } export async function submitTuitionTaxForm( @@ -69,11 +105,44 @@ export async function submitTuitionTaxForm( //redirect to error page return { success: false }; } - console.log(validate.data); - // revalidate admin path - // redirect to success page - return { success: true }; + const { data } = validate; + + if (!prisma) { + console.error("Prisma client is null!"); + return { success: false }; + } + + const faculty = await prisma.faculty.findUnique({ + include: { + euPlatescAccount: true, + }, + where: { + id: data.facultyId, + }, + }); + + if (!faculty) { + console.error("Failed to find faculty with ID %d", data.facultyId); + return { success: false }; + } + + const account = faculty.euPlatescAccount!; + + const paymentData: EuPlatescPayment = { + account, + amount: data.amount, + invoiceId: "1234", + description: `Plata taxa de studii ${faculty.nameRo}`, + billingEmail: data.email, + billingPhone: data.phoneNumber, + billingCountry: data.country, + billingCity: data.city, + billingAddress: data.address, + }; + const redirectUrl = generateEuPlatescPaymentUrl(paymentData); + + redirect(redirectUrl); } export async function submitAccomodationTaxForm( @@ -85,9 +154,42 @@ export async function submitAccomodationTaxForm( //redirect to error page return { success: false }; } - console.log(validate.data); - // revalidate admin path - // redirect to success page - return { success: true }; + const { data } = validate; + + if (!prisma) { + console.error("Prisma client is null!"); + return { success: false }; + } + + const dorm = await prisma.studentDorm.findUnique({ + include: { + euPlatescAccount: true, + }, + where: { + id: data.dormId, + }, + }); + + if (!dorm) { + console.error("Failed to find student dorm with ID %d", data.dormId); + return { success: false }; + } + + const account = dorm.euPlatescAccount!; + + const paymentData: EuPlatescPayment = { + account, + amount: data.amount, + invoiceId: "1234", + description: `Plata taxa camin ${dorm.name}`, + billingEmail: data.email, + billingPhone: data.phoneNumber, + billingCountry: data.country, + billingCity: data.city, + billingAddress: "", + }; + const redirectUrl = generateEuPlatescPaymentUrl(paymentData); + + redirect(redirectUrl); }