Search in sources :

Example 11 with PayPapercutTransactionLog

use of org.esupportail.papercut.domain.PayPapercutTransactionLog in project esup-papercut by EsupPortail.

the class EsupPaperCutService method payboxCallback.

public boolean payboxCallback(EsupPapercutContext context, Integer montant, String reference, String auto, String erreur, String idtrans, String signature, String queryString, String ip, String currentUserUid) {
    List<PayPapercutTransactionLog> txLogs = papercutDaoService.findPayPapercutTransactionLogsByIdtransAndPayMode(idtrans, PayMode.PAYBOX, PageRequest.of(0, Integer.MAX_VALUE)).getContent();
    if (txLogs.size() > 0) {
        log.info("This transaction + " + idtrans + " is already OK");
        return true;
    }
    PayPapercutTransactionLog txLog = new PayPapercutTransactionLog();
    txLog.setPayMode(PayMode.PAYBOX);
    txLog.setMontant(montant);
    txLog.setIdtrans(idtrans);
    txLog.setTransactionDate(new Date());
    txLog.setReference(reference);
    String uid = reference.split("@")[0];
    uid = uid.substring(context.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(context, ip) || uid.equals(currentUserUid)) {
        // check signature == message come from paybox
        if (payBoxService.checkPayboxSignature(context, queryString, signature)) {
            String papercutOldSolde = papercutService.getUserPapercutInfos(context, uid).getBalance();
            txLog.setPapercutOldSolde(papercutOldSolde);
            if ("00000".equals(erreur)) {
                try {
                    log.info("Transaction : " + reference + " pour un montant de " + montant + " OK !");
                    double montantEuros = new Double(montant) / 100.0;
                    papercutService.creditUserBalance(context, uid, montantEuros, idtrans, PayMode.PAYBOX);
                    String papercutNewSolde = papercutService.getUserPapercutInfos(context, uid).getBalance();
                    txLog.setPapercutNewSolde(papercutNewSolde);
                    papercutDaoService.persist(txLog);
                } catch (Exception ex) {
                    log.error("Exception during creditUserBalance on papercut ?", ex);
                }
            } 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;
}
Also used : PayPapercutTransactionLog(org.esupportail.papercut.domain.PayPapercutTransactionLog) Date(java.util.Date)

Aggregations

PayPapercutTransactionLog (org.esupportail.papercut.domain.PayPapercutTransactionLog)11 Transactional (org.springframework.transaction.annotation.Transactional)6 Date (java.util.Date)2 EsupPapercutContext (org.esupportail.papercut.config.EsupPapercutContext)2 Pageable (org.springframework.data.domain.Pageable)2 Scheduled (org.springframework.scheduling.annotation.Scheduled)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 TreeMap (java.util.TreeMap)1 IzlyPayForm (org.esupportail.papercut.domain.IzlyPayForm)1 PayBoxForm (org.esupportail.papercut.domain.PayBoxForm)1 UserPapercutInfos (org.esupportail.papercut.domain.UserPapercutInfos)1 StopWatch (org.springframework.util.StopWatch)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1