private RefundTransactionDTO updateStateRefund( String paypalStatus, String pendingReason, String parentTransactionID, RefoundFullDTO ref, RefundTransactionDTO refTrans, MailPropertiesDTO mailProps) throws PayPalException, MailNotSendException { if (ref == null) { log.info("ref null updateStateRefund"); List<RefoundFullDTO> refs = orderService.getRefounds(null, null, null, null, parentTransactionID, null); if (refs != null && refs.isEmpty()) { ref = refs.get(0); } else { // richiesta rimborso direttamente da paypal, non è presente in // OrderRefund log.info( "richiesta rimborso direttamente da paypal, non è presente parentTransactionID in OrderRefund"); // inserire manualmente la richiesta in OrderRefound/annullare // l'ordine. return null; } } if (refTrans == null) { refTrans = new RefundTransactionDTO(); } if (isPaymenRefunded(paypalStatus)) { orderService.updateStateRefound( ref.getIdRefound(), TypeStateOrder.REFOUND_COMPLETED, pendingReason); try { OthalaFactory.getOrderServiceInstance().sendMailConfirmReso(ref.getIdRefound(), mailProps); } catch (Exception e) { throw new MailNotSendException(e); } } else if (isPaymentPending(paypalStatus)) { orderService.updateStateRefound(ref.getIdRefound(), TypeStateOrder.PENDING, pendingReason); refTrans.setPending(true); } else if (isPaymentKO(paypalStatus)) { orderService.updateStateRefound( ref.getIdRefound(), TypeStateOrder.REFOUND_REFUSED, pendingReason); refTrans.setFailed(true); } else if (isPaymenInstant(paypalStatus)) { orderService.updateStateRefound(ref.getIdRefound(), TypeStateOrder.INSTANT, pendingReason); refTrans.setInstant(true); } else { // throw new // PayPalException(String.format("Stati %s non ammesso nella fase di rimborso", // paypalStatus)); log.info( String.format("nessuna operazione da fare per lo stato %s di rimborso", paypalStatus)); } return refTrans; }