Пример #1
0
  @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;
  }
Пример #2
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;
  }