use of org.esupportail.papercut.domain.PayboxPapercutTransactionLog in project esup-papercut by EsupPortail.
the class EsupPaperCutService method payboxCallback.
public boolean payboxCallback(String montant, String reference, String auto, String erreur, String idtrans, String signature, String queryString, String ip, String currentUserUid) {
List<PayboxPapercutTransactionLog> txLogs = PayboxPapercutTransactionLog.findPayboxPapercutTransactionLogsByIdtransEquals(idtrans, null, null).getResultList();
boolean newTxLog = txLogs.size() == 0;
PayboxPapercutTransactionLog txLog = txLogs.size() > 0 ? txLogs.get(0) : null;
if (txLog == null) {
txLog = new PayboxPapercutTransactionLog();
} else {
if ("OK".equals(txLog.getPapercutWsCallStatus()) || !"00000".equals(txLog.getErreur())) {
log.info("This transaction + " + idtrans + " is already OK");
return true;
}
}
txLog.setMontant(montant);
txLog.setReference(reference);
txLog.setAuto(auto);
txLog.setErreur(erreur);
txLog.setIdtrans(idtrans);
txLog.setSignature(signature);
txLog.setTransactionDate(new Date());
String uid = reference.split("@")[0];
uid = uid.substring(payBoxService.getNumCommandePrefix().length(), uid.length());
txLog.setUid(uid);
String paperCutContext = reference.split("@")[1];
txLog.setPaperCutContext(paperCutContext);
// if paybox server OR connected user ok
if (payBoxService.isPayboxServer(ip) || uid.equals(currentUserUid)) {
// check signature == message come from paybox
if (payBoxService.checkPayboxSignature(queryString, signature)) {
String papercutOldSolde = papercutService.getUserPapercutInfos(uid).getBalance();
txLog.setPapercutOldSolde(papercutOldSolde);
// TODO Vérifier que le montant correspondait bien à la demande initiale ?
if ("00000".equals(erreur)) {
try {
log.info("Transaction : " + reference + " pour un montant de " + montant + " OK !");
double montantEuros = new Double(montant) / 100.0;
papercutService.creditUserBalance(uid, montantEuros, idtrans);
txLog.setPapercutWsCallStatus("OK");
String papercutNewSolde = papercutService.getUserPapercutInfos(uid).getBalance();
txLog.setPapercutNewSolde(papercutNewSolde);
if (newTxLog) {
txLog.persist();
} else {
txLog.merge();
}
} catch (Exception ex) {
log.error("Exception during creditUserBalance on papercut ?", ex);
txLog.setPapercutWsCallStatus("ERREUR");
}
} else {
log.info("'Erreur' " + erreur + " (annulation) lors de la transaction paybox : " + reference + " pour un montant de " + montant);
}
} else {
log.error("signature checking of paybox failed, transaction " + txLog + " canceled.");
}
return true;
} else {
log.warn("this ip " + ip + " is not trusted for the paybox transaction, " + "or this user " + uid + " does'nt correspond to this user " + currentUserUid + " (validatePayboxJustWithRedirection mode), " + "transaction " + txLog + " canceled.");
}
return false;
}
use of org.esupportail.papercut.domain.PayboxPapercutTransactionLog in project esup-papercut by EsupPortail.
the class EsupPapercutPortletController method archiveAll.
@Transactional
// action phase
@RequestMapping(params = "action=archiveAll")
public void archiveAll(ActionRequest request, ActionResponse response) {
if (isAdmin(request)) {
String paperCutContext = request.getPreferences().getValue(PREF_PAPERCUT_CONTEXT, null);
List<PayboxPapercutTransactionLog> txLogs = PayboxPapercutTransactionLog.findPayboxPapercutTransactionLogsByArchivedAndPaperCutContextEquals(false, paperCutContext).getResultList();
for (PayboxPapercutTransactionLog txLog : txLogs) {
txLog.setArchived(true);
}
}
response.setRenderParameter("action", "admin");
}
use of org.esupportail.papercut.domain.PayboxPapercutTransactionLog in project esup-papercut by EsupPortail.
the class EsupPapercutPortletController method renderView.
@RequestMapping
public ModelAndView renderView(RenderRequest request, RenderResponse response) {
ModelMap model = new ModelMap();
model.put("htmlHeader", request.getPreferences().getValue("htmlHeader", ""));
model.put("htmlFooter", request.getPreferences().getValue("htmlFooter", ""));
model.put("payboxMontantMin", request.getPreferences().getValue("payboxMontantMin", "0.5"));
model.put("payboxMontantMax", request.getPreferences().getValue("payboxMontantMax", "5.0"));
model.put("payboxMontantStep", request.getPreferences().getValue("payboxMontantStep", "0.5"));
model.put("payboxMontantDefaut", request.getPreferences().getValue("payboxMontantDefaut", "2.0"));
double papercutSheetCost = Double.parseDouble(request.getPreferences().getValue("papercutSheetCost", "-1"));
double papercutColorSheetCost = Double.parseDouble(request.getPreferences().getValue("papercutColorSheetCost", "-1"));
String paperCutContext = request.getPreferences().getValue(PREF_PAPERCUT_CONTEXT, null);
EsupPaperCutService esupPaperCutService = esupPaperCutServices.get(paperCutContext);
String uid = getUid(request);
String userMail = getUserMail(request);
// check if the user can make a transaction
int transactionNbMax = Integer.parseInt(request.getPreferences().getValue("transactionNbMax", "-1"));
BigDecimal transactionMontantMax = new BigDecimal(request.getPreferences().getValue("transactionMontantMax", "-1"));
boolean canMakeTransaction = true;
// constraints via transactionNbMax
if (transactionNbMax > -1) {
long nbTransactionsNotArchived = PayboxPapercutTransactionLog.countFindPayboxPapercutTransactionLogsByUidEqualsAndPaperCutContextEqualsAndArchived(uid, paperCutContext, false);
if (transactionNbMax <= nbTransactionsNotArchived) {
canMakeTransaction = false;
}
}
BigDecimal payboxMontantMin = new BigDecimal(request.getPreferences().getValue("payboxMontantMin", "0.5"));
BigDecimal payboxMontantMax = new BigDecimal(request.getPreferences().getValue("payboxMontantMax", "5.0"));
BigDecimal payboxMontantStep = new BigDecimal(request.getPreferences().getValue("payboxMontantStep", "0.5"));
BigDecimal payboxMontantDefaut = new BigDecimal(request.getPreferences().getValue("payboxMontantDefaut", "2.0"));
// constraints on the slider via transactionMontantMax
if (canMakeTransaction && transactionMontantMax.intValue() > -1) {
List<PayboxPapercutTransactionLog> transactionsNotArchived = PayboxPapercutTransactionLog.findPayboxPapercutTransactionLogsByUidEqualsAndPaperCutContextEqualsAndArchived(uid, paperCutContext, false).getResultList();
BigDecimal montantTotalTransactionsNotArchived = new BigDecimal("0");
for (PayboxPapercutTransactionLog txLog : transactionsNotArchived) {
montantTotalTransactionsNotArchived = montantTotalTransactionsNotArchived.add(new BigDecimal(txLog.getMontant()));
}
transactionMontantMax = transactionMontantMax.multiply(new BigDecimal("100")).subtract(montantTotalTransactionsNotArchived);
if (transactionMontantMax.doubleValue() < payboxMontantMax.doubleValue() * 100) {
payboxMontantMax = transactionMontantMax.divide(payboxMontantStep).multiply(payboxMontantStep);
payboxMontantMax = payboxMontantMax.divide(new BigDecimal("100"));
if (payboxMontantDefaut.compareTo(payboxMontantMax) == 1) {
payboxMontantDefaut = payboxMontantMax;
}
if (payboxMontantMax.compareTo(payboxMontantMin) == -1) {
canMakeTransaction = false;
}
model.put("payboxMontantMax", payboxMontantMax.doubleValue());
model.put("payboxMontantDefaut", payboxMontantDefaut.doubleValue());
}
}
// generation de l'ensemble des payboxForm : payboxMontantMin -> payboxMontantMax par pas de payboxMontantStep
String portletContextPath = ((RenderResponse) response).createRenderURL().toString();
Map<Integer, PayBoxForm> payboxForms = new HashMap<Integer, PayBoxForm>();
for (BigDecimal montant = payboxMontantMin; montant.compareTo(payboxMontantMax) <= 0; montant = montant.add(payboxMontantStep)) {
PayBoxForm payBoxForm = esupPaperCutService.getPayBoxForm(uid, userMail, montant.doubleValue(), paperCutContext, portletContextPath);
if (papercutSheetCost > 0) {
int nbSheets = (int) (montant.doubleValue() / papercutSheetCost);
payBoxForm.setNbSheets(nbSheets);
}
if (papercutColorSheetCost > 0) {
int nbColorSheets = (int) (montant.doubleValue() / papercutColorSheetCost);
payBoxForm.setNbColorSheets(nbColorSheets);
}
payboxForms.put(montant.multiply(new BigDecimal(100)).intValue(), payBoxForm);
}
Map<Integer, PayBoxForm> sortedMap = new TreeMap<Integer, PayBoxForm>(payboxForms);
model.put("payboxForms", sortedMap);
model.put("payboxMontantDefautCents", payboxMontantDefaut.multiply(new BigDecimal(100)).intValue());
model.put("canMakeTransaction", canMakeTransaction);
UserPapercutInfos userPapercutInfos = esupPaperCutService.getUserPapercutInfos(uid);
model.put("userPapercutInfos", userPapercutInfos);
boolean isAdmin = isAdmin(request);
boolean isManager = isManager(request);
model.put("isAdmin", isAdmin);
model.put("isManager", isManager);
model.put("active", "home");
return new ModelAndView(getViewName(request, "index"), model);
}
use of org.esupportail.papercut.domain.PayboxPapercutTransactionLog in project esup-papercut by EsupPortail.
the class EsupPapercutPortletController method archive.
@Transactional
// action phase
@RequestMapping(params = "action=archive")
public void archive(@RequestParam(value = "txLogId", required = true) Long txLogId, ActionRequest request, ActionResponse response) {
if (isAdmin(request)) {
PayboxPapercutTransactionLog txLog = PayboxPapercutTransactionLog.findPayboxPapercutTransactionLog(txLogId);
txLog.setArchived(true);
}
Map<String, String[]> parameters = new HashMap<String, String[]>();
parameters.put("action", new String[] { "show" });
parameters.put("id", new String[] { String.valueOf(txLogId) });
response.setRenderParameters(parameters);
}
use of org.esupportail.papercut.domain.PayboxPapercutTransactionLog in project esup-papercut by EsupPortail.
the class PayBoxResourceController method getCsv.
@RequestMapping("/csv")
@Transactional
public void getCsv(HttpServletRequest request, HttpServletResponse response) throws IOException {
HttpSession session = request.getSession();
String sharedSessionId = request.getParameter("sharedSessionId");
if (sharedSessionId != null) {
EsupPapercutSessionObject objectShared = (EsupPapercutSessionObject) session.getAttribute(sharedSessionId);
if (objectShared.isIsAdmin()) {
StopWatch stopWatch = new StopWatch("Stream - build CSV and send it");
stopWatch.start();
response.setContentType("text/csv");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-Disposition", "attachment; filename=\"paybox_papercut_transaction_log.csv\"");
Writer writer = new OutputStreamWriter(response.getOutputStream(), "UTF8");
String csv = "Date transaction,uid,montant,ID transaction paybox";
writer.write(csv);
TypedQuery<PayboxPapercutTransactionLog> txLogsQuery = PayboxPapercutTransactionLog.findPayboxPapercutTransactionLogsByPaperCutContextEquals(objectShared.getPaperCutContext(), "transactionDate", "asc");
int offset = 0;
int nbLine = 0;
List<PayboxPapercutTransactionLog> txLogs;
while ((txLogs = txLogsQuery.setFirstResult(offset).setMaxResults(1000).getResultList()).size() > 0) {
log.debug("Build CSV Iteration - offset : " + offset);
for (PayboxPapercutTransactionLog txLog : txLogs) {
csv = "";
csv = csv + "\r\n";
csv = csv + txLog.getTransactionDate() + ",";
csv = csv + txLog.getUid() + ",";
csv = csv + txLog.getMontant() + ",";
csv = csv + txLog.getIdtrans();
writer.write(csv);
nbLine++;
}
offset += txLogs.size();
}
stopWatch.stop();
log.info("CSV of " + nbLine + " lines sent in " + stopWatch.getTotalTimeSeconds() + " sec.");
writer.close();
}
}
}
Aggregations