Ejemplo n.º 1
0
  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;
  }
Ejemplo n.º 2
0
  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");
    }
  }