Fees and structures added
This commit is contained in:
@@ -97,30 +97,29 @@ public class StudentMenuHandler {
|
||||
sendSemesterSelection(phoneNumber, token);
|
||||
break;
|
||||
|
||||
case "student_fee_details":
|
||||
case "student_fee_details": {
|
||||
String rawFees = imsApiService.getFees(token);
|
||||
String rawExamFees = imsApiService.getExamFees(token);
|
||||
String bodyText = MessageFormatter.formatFeesAndExamFees(rawFees, rawExamFees);
|
||||
String bodyText = MessageFormatter.formatAcademicFeesOnly(rawFees);
|
||||
|
||||
List<Map<String, String>> receiptRows = MessageFormatter.extractReceiptRows(rawExamFees);
|
||||
List<Map<String, String>> feeButtons = new ArrayList<>();
|
||||
Map<String, String> examBtn = new HashMap<>();
|
||||
examBtn.put("id", "student_exam_fees");
|
||||
examBtn.put("title", "Exam Fees");
|
||||
feeButtons.add(examBtn);
|
||||
|
||||
if (!receiptRows.isEmpty()) {
|
||||
// Max 10 items in a list. Limit to 10 if necessary.
|
||||
if (receiptRows.size() > 10) receiptRows = receiptRows.subList(0, 10);
|
||||
|
||||
sessionService.setUserState(phoneNumber, UserState.AWAITING_RECEIPT_SELECTION);
|
||||
|
||||
// Meta API interactive list body limit is 1024 characters
|
||||
if (bodyText.length() > 1024) bodyText = bodyText.substring(0, 1021) + "...";
|
||||
|
||||
Map<String, Object> listMessage = WhatsAppMessageBuilder.buildListMessage(
|
||||
"Receipts", bodyText, "Download Receipt", receiptRows
|
||||
);
|
||||
messageService.sendInteractiveMessage(phoneNumber, listMessage);
|
||||
} else {
|
||||
sendResponseWithMenu(phoneNumber, bodyText);
|
||||
Map<String, String> historyBtn = new HashMap<>();
|
||||
historyBtn.put("id", "student_payment_history");
|
||||
historyBtn.put("title", "Payment History");
|
||||
feeButtons.add(historyBtn);
|
||||
|
||||
if (bodyText.length() > 1020) {
|
||||
bodyText = bodyText.substring(0, 1017) + "...";
|
||||
}
|
||||
|
||||
Map<String, Object> feeButtonMessage = WhatsAppMessageBuilder.buildButtonMessage(bodyText, feeButtons);
|
||||
messageService.sendInteractiveMessage(phoneNumber, feeButtonMessage);
|
||||
break;
|
||||
}
|
||||
|
||||
case "student_raise_grievance":
|
||||
grievanceHandler.startGrievanceFlow(phoneNumber);
|
||||
@@ -209,15 +208,31 @@ public class StudentMenuHandler {
|
||||
}
|
||||
|
||||
try {
|
||||
String historyId = selectedOptionId.replace("receipt_", "");
|
||||
byte[] pdfBytes = imsApiService.getExamFeeReceiptPdf(token, historyId);
|
||||
byte[] pdfBytes = null;
|
||||
String fileName = "Receipt.pdf";
|
||||
String docMessage = "Here is your Fee Receipt!";
|
||||
|
||||
if (selectedOptionId.startsWith("exam_")) {
|
||||
String longId = sessionService.getReceiptIdMapping(phoneNumber, selectedOptionId);
|
||||
pdfBytes = imsApiService.getExamFeeReceiptPdf(token, longId);
|
||||
fileName = "Exam_Receipt.pdf";
|
||||
docMessage = "Here is your Exam Fee Receipt!";
|
||||
} else if (selectedOptionId.startsWith("acad_")) {
|
||||
String longId = sessionService.getReceiptIdMapping(phoneNumber, selectedOptionId);
|
||||
pdfBytes = imsApiService.getAcademicFeeReceiptPdf(token, longId);
|
||||
fileName = "Academic_Receipt.pdf";
|
||||
docMessage = "Here is your Academic Fee Receipt!";
|
||||
} else if (selectedOptionId.startsWith("cons_")) {
|
||||
String longId = sessionService.getReceiptIdMapping(phoneNumber, selectedOptionId);
|
||||
pdfBytes = imsApiService.getConsolidatedAcademicFeeReceiptPdf(token, longId);
|
||||
fileName = "Consolidated_Receipt.pdf";
|
||||
docMessage = "Here is your Consolidated Academic Fee Receipt!";
|
||||
}
|
||||
|
||||
if (pdfBytes != null) {
|
||||
String fileName = "Receipt_" + historyId + ".pdf";
|
||||
String mediaId = messageService.uploadMedia(pdfBytes, fileName, "application/pdf");
|
||||
|
||||
if (mediaId != null) {
|
||||
messageService.sendDocumentMessage(phoneNumber, mediaId, "Here is your Exam Fee Receipt!", fileName);
|
||||
messageService.sendDocumentMessage(phoneNumber, mediaId, docMessage, fileName);
|
||||
sendResponseWithMenu(phoneNumber, "Select an option from the menu below.");
|
||||
} else {
|
||||
sendResponseWithMenu(phoneNumber, "Failed to upload the receipt document to WhatsApp.");
|
||||
@@ -249,6 +264,59 @@ public class StudentMenuHandler {
|
||||
sendResponseWithMenu(phoneNumber, "Select an option from the menu below.");
|
||||
}
|
||||
|
||||
public void handleExamFees(String phoneNumber) {
|
||||
String token = sessionService.getImsToken(phoneNumber);
|
||||
if (token == null) {
|
||||
messageService.sendMessage(phoneNumber, "Your session has expired. Please type 'Reset' to login again.");
|
||||
return;
|
||||
}
|
||||
|
||||
String rawExamFees = imsApiService.getExamFees(token);
|
||||
String formattedExamFees = MessageFormatter.formatExamFees(rawExamFees);
|
||||
sendResponseWithMenu(phoneNumber, formattedExamFees);
|
||||
}
|
||||
|
||||
public void handlePaymentHistory(String phoneNumber) {
|
||||
String token = sessionService.getImsToken(phoneNumber);
|
||||
if (token == null) {
|
||||
messageService.sendMessage(phoneNumber, "Your session has expired. Please type 'Reset' to login again.");
|
||||
return;
|
||||
}
|
||||
|
||||
String rawExamFees = imsApiService.getExamFees(token);
|
||||
String rawFeesHistory = imsApiService.getAcademicFeesHistory(token);
|
||||
|
||||
String formattedHistory = MessageFormatter.formatCombinedPaymentHistory(rawExamFees, rawFeesHistory);
|
||||
|
||||
Map<String, String> idMappings = new HashMap<>();
|
||||
List<Map<String, String>> examRows = MessageFormatter.extractReceiptRows(rawExamFees, idMappings);
|
||||
List<Map<String, String>> acadRows = MessageFormatter.extractAcademicReceiptRows(rawFeesHistory, idMappings);
|
||||
List<Map<String, String>> consRows = MessageFormatter.extractConsolidatedReceiptRows(rawFeesHistory, idMappings);
|
||||
|
||||
sessionService.storeReceiptIdMappings(phoneNumber, idMappings);
|
||||
|
||||
List<Map<String, String>> receiptRows = new ArrayList<>();
|
||||
receiptRows.addAll(examRows);
|
||||
receiptRows.addAll(acadRows);
|
||||
receiptRows.addAll(consRows);
|
||||
|
||||
if (!receiptRows.isEmpty()) {
|
||||
if (receiptRows.size() > 10) receiptRows = receiptRows.subList(0, 10);
|
||||
sessionService.setUserState(phoneNumber, UserState.AWAITING_RECEIPT_SELECTION);
|
||||
|
||||
if (formattedHistory.length() > 1024) {
|
||||
formattedHistory = formattedHistory.substring(0, 1021) + "...";
|
||||
}
|
||||
|
||||
Map<String, Object> listMessage = WhatsAppMessageBuilder.buildListMessage(
|
||||
"Receipts", formattedHistory, "Download Receipt", receiptRows
|
||||
);
|
||||
messageService.sendInteractiveMessage(phoneNumber, listMessage);
|
||||
} else {
|
||||
sendResponseWithMenu(phoneNumber, formattedHistory);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendResponseWithMenu(String phoneNumber, String bodyText) {
|
||||
// Meta API interactive list body limit is 1024 characters
|
||||
if (bodyText.length() > 1024) {
|
||||
|
||||
Reference in New Issue
Block a user