Skip to content

Commit

Permalink
Make the EuPlatesc integration work
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielMajeri committed Jan 31, 2025
1 parent 83fdb88 commit bc4c8e7
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 18 deletions.
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ AZURE_AD_CLIENT_ID=76adfa07-a614-4575-a6a1-e9b59d74920a
# reCaptcha credentials
NEXT_PUBLIC_RECAPTCHA=6Ld5tlYpAAAAAGp_3Y5Zp7idrOCLvPqdT2mOalfm
#RECAPTCHA_SERVER=<sensitive>

# EuPlatesc credentials
EUPLATESC_MERCHANT_ID=44841002813
#EUPLATESC_KEY=<sensitive>
2 changes: 2 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 1 addition & 4 deletions .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -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=<sensitive>
EUPLATESC_TEST_MODE=true
EUPLATESC_TEST_MODE=false

106 changes: 106 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/actions/euplatesc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use server";

import { EuPlatesc } from "euplatesc";
import { EuPlatescAccount } from "@prisma/client";

Check failure on line 2 in src/actions/euplatesc.ts

View workflow job for this annotation

GitHub Actions / check

Module '"@prisma/client"' has no exported member 'EuPlatescAccount'.

Expand Down
126 changes: 114 additions & 12 deletions src/actions/forms.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"use server";
import { redirect } from "next/navigation";

import { ReCAPTCHAResponse } from "@/types/forms/agreements";
import { AccommodationTaxFormData } from "@/types/forms/dorms";
import {
Expand All @@ -11,6 +13,8 @@ import {
tuitionTaxFormSchema,
} from "@/utils/forms/validationSchemas";

import { EuPlatescPayment, generateEuPlatescPaymentUrl } from "./euplatesc";

export async function validateReCAPTCHA(token: string): Promise<boolean> {
console.log("Validating ReCAPTCHA challenge response");
try {
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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);
}

0 comments on commit bc4c8e7

Please sign in to comment.