@Override public RefundTransactionDTO requestRefund( RefoundFullDTO ref, ProfilePayPalDTO profile, MailPropertiesDTO mail) throws PayPalException, PayPalFailureException, PayPalPostRefundPaymentException { // TODO Auto-generated method stub List<String> articles = new ArrayList<>(); String art = null; for (ArticleRefounded artRef : ref.getCart()) { art = String.format( "%d %s %s %s", artRef.getPrdFullDTO().getIdProduct(), artRef.getPrdFullDTO().getDescription(), artRef.getTxSize(), artRef.getTxColor()); articles.add(art); } RefundTransactionDTO refTrans = getWrapper(profile) .refundTransaction( ref.getIdTransaction(), ref.getImRefound(), true, articles, ref.getIdRefound().toString()); try { updateStateRefund( refTrans.getREFUNDSTATUS(), refTrans.getPENDINGREASON(), null, ref, refTrans, mail); } catch (MailNotSendException e) { // TODO Auto-generated catch block log.error("Errore nell'invio della mail per la conferma del rimborso", e); } catch (PayPalException e) { throw new PayPalPostRefundPaymentException( e, ref.getIdRefound() != null ? ref.getIdRefound().toString() : "", "errore nella'aggiornamento dello stato dopo il rimborso"); } return refTrans; }
private void updateStateRefundIPN( OrderFullDTO order, IpnDTO ipnDTO, HashMap<String, String> responseMap, MailPropertiesDTO mailProps) throws PayPalException, MailNotSendException { log.info("refund updateStateRefundIPN"); List<RefoundFullDTO> refs = orderService.getRefounds(null, null, null, null, ipnDTO.getParent_txn_id(), null); BigDecimal reqToRefund = new BigDecimal(ipnDTO.getMc_gross().replace("-", "")); RefoundFullDTO ref = null; HashMap<Integer, String> idArticle = new HashMap<>(); for (String key : responseMap.keySet()) { log.info("key=" + key); if (key.contains("item_number")) { idArticle.put(Integer.parseInt(responseMap.get(key)), key); log.info("add product " + responseMap.get(key)); } } if (refs != null && !refs.isEmpty()) { log.info("individuato txtId in tabella order refound"); ref = refs.get(0); updateStateRefund( ipnDTO.getPayment_status(), null, ipnDTO.getParent_txn_id(), ref, null, mailProps); } else { // richiesta rimborso direttamente da paypal, non è presente in // OrderRefund log.info( "richiesta rimborso direttamente da paypal, non è presente parentTransactionID in OrderRefund"); ref = new RefoundFullDTO(); List<ArticleRefounded> artToRefund = new ArrayList<ArticleRefounded>(); BigDecimal imRefunded = BigDecimal.ZERO; for (ArticleFullDTO art : order.getCart()) { if (idArticle.containsKey(art.getPrdFullDTO().getIdProduct().intValue())) { log.info( "inserito articolo in articoli da rimborsare " + art.getPrdFullDTO().getIdProduct().intValue()); ArticleRefounded artref = new ArticleRefounded(art); artToRefund.add(artref); } } if (artToRefund.isEmpty()) { throw new PayPalException( "nessun articolo trovato per la somma " + ipnDTO.getMc_gross() + " ed ordine " + order.getIdOrder()); } ref.setCart(artToRefund); ref.setIdOrder(order.getIdOrder()); ref.setIdUser(order.getIdUser()); ref.setImRefound(reqToRefund); ref.setIdTransaction(ipnDTO.getParent_txn_id()); ref.setFgChangeRefound("R"); ref.setFgPartialRefound(order.getImOrdineSenzaSpese().compareTo(ref.getImRefound()) != 0); ref.setIdStato(TypeStateOrder.REFUNDED.getState()); try { ref = OthalaFactory.getOrderServiceInstance().insertRefound(ref, null); } catch (Exception e) { // TODO Auto-generated catch block log.error("errore in inserimento richiesta di rimborso da PayPal", e); throw new PayPalException(e); } log.info("inserimento richiesta di rimborso da PayPal eseguita correttamente"); } }