Пример #1
0
  @Override
  public DoExpressCheckoutPaymentDTO doExpressCheckoutPayment(
      GetExpressCheckoutDetailsDTO details, ProfilePayPalDTO profile, OrderFullDTO order)
      throws PayPalFundingFailureException, PayPalException, PayPalFailureException,
          StockNotPresentException, PayPalPostPaymentException {
    // TODO Auto-generated method stub

    // VERIFICO LA GIACENZA
    orderService.checkQtaInStock(order.getIdOrder(), order);

    // effettuo il doCheckOut, si paga...
    DoExpressCheckoutPaymentDTO checkDTO =
        getWrapper(profile)
            .doExpressCheckoutPayment(
                details, profilePayPal.getNotifyUrl(), profilePayPal.getRedirectUrl());
    order.setIdTransaction(checkDTO.getPAYMENTINFO_0_TRANSACTIONID());
    order.setIdStato(
        TypeStateOrder.fromString(checkDTO.getPAYMENTINFO_0_PAYMENTSTATUS()).getState());
    order.setPendingReason(checkDTO.getPAYMENTINFO_0_PENDINGREASON());

    try {
      // aggiorno l'ordine con lo stato, se completed o pending facciamo
      // anche
      // il decremento della qta
      TypeStateOrder state = TypeStateOrder.fromString(checkDTO.getPAYMENTINFO_0_PAYMENTSTATUS());
      log.info(
          String.format(
              "stato PayPal %s- stato Othala %s",
              checkDTO.getPAYMENTINFO_0_PAYMENTSTATUS(), Integer.toString(state.getState())));
      if (isPaymentCompleted(checkDTO.getPAYMENTINFO_0_PAYMENTSTATUS())
          || isPaymentPending(checkDTO.getPAYMENTINFO_0_PAYMENTSTATUS())) {
        orderService.confirmOrderPayment(order);
      } else {
        orderService.updateStateOrder(order.getIdOrder(), order, state);
      }

      // salvo il messaggio
      MessageIpnDTO ipn = new MessageIpnDTO();
      ipn.setFgElaborato(false);
      ipn.setIdOrder(order.getIdOrder());
      ipn.setIdTransaction(order.getIdTransaction());
      ipn.setTxMessage(checkDTO.getOkMessage());
      if (state.getState() == TypeStateOrder.PENDING.getState()) {
        ipn.setTxNote(checkDTO.getPAYMENTINFO_0_PENDINGREASON());
      }

      ipn.setTxStato(checkDTO.getPAYMENTINFO_0_PAYMENTSTATUS());
      messageIpnDAO.insertMessageIpn(ipn);

    } catch (Throwable e) {
      log.error("errore PaymentService dopo il pagamento", e);
      throw new PayPalPostPaymentException(
          e, order.getIdOrder(), "errore nel docheckout dopo il pagamento");
    }
    return checkDTO;
  }
Пример #2
0
  @Override
  public void sendMailAcceptedPyament(OrderFullDTO order, MailPropertiesDTO mailDTO, String status)
      throws MailNotSendException {
    TypeStateOrder state = TypeStateOrder.fromString(status);
    URL res = Thread.currentThread().getContextClassLoader().getResource("");
    Map<String, String> inlineImages = new HashMap<String, String>();
    String basePath = res.getPath().replace("/WEB-INF/classes", "");
    basePath = basePath.replace("/", "");
    String template =
        Template.getNomeFile("mailConfermaOrdine", order.getShippingAddress().getNazione());
    String html = generateHtmlOrder(order, mailDTO, inlineImages, state, template, null);

    String oggetto = null;
    if (state == TypeStateOrder.SPEDITO) {
      oggetto = "Spedizione ordine";
    } else {
      oggetto = "Conferma ordine";
    }

    mailService.inviaHTMLMail(
        new String[] {order.getIdUser()}, oggetto, html, inlineImages, mailDTO, true);

    List<ShopDTO> lsShop = productDAO.listShop();
    if (state == TypeStateOrder.SPEDITO) {

    } else {
      /*
       * for (ArticleFullDTO art : order.getCart()) {
       *
       * ShopDTO shopStock =
       * externalService.getShopStock(art.getPrdFullDTO().getIdProduct(),
       * art.getPgArticle(), art.getTxBarCode());
       *
       * art.getShop().setIdShop(shopStock.getIdShop());
       * art.getShop().setTxShop(shopStock.getTxShop());
       *
       * }
       */

      html = generateHtmlOrder(order, mailDTO, inlineImages, state, "mailInserimentoOrdine", null);

      mailService.inviaHTMLMail(
          new String[] {lsShop.get(0).getTxMail()},
          "Nuovo Ordine WEB",
          html,
          inlineImages,
          mailDTO,
          true);

      // Cambiare
      // Creare un metodo doppio in externalservice che tira fuori nel
      // caso del deg il magazzino con maggior capienza
      // nel caso normale il negozio
      // Poi
      // Per ogni articolo va preso il magazzino con maggior capienza e
      // mandata la mail per deg
      // Per ogni articolo mandare la mail al negozio
      // invia la mai di notifica ordine ai negozi
      /*
       * List<ShopDTO> lstShop = new ArrayList<ShopDTO>(); lstShop =
       * productDAO.listShop(); for (int i = 0; i < lstShop.size(); i++) {
       * for (ArticleFullDTO art : order.getCart()) { if
       * (art.getShop().getIdShop() == lstShop.get(i).getIdShop()) { html
       * = generateHtmlOrder(order, mailDTO, inlineImages, state,
       * "mailInserimentoOrdine", lstShop .get(i).getIdShop());
       * mailService.inviaHTMLMail(new String[] {
       * lstShop.get(i).getTxMail() }, "Nuovo Ordine WEB", html,
       * inlineImages, mailDTO, true); break; } } }
       */
    }
  }
Пример #3
0
  @Override
  public void processIpnMessage(
      String originalRequest, ProfilePayPalDTO profile, MailPropertiesDTO mailProps)
      throws PayPalException, PayPalIpnErrorException {

    log.info("IPN Original Request:" + originalRequest);
    String responseRequest = originalRequest + "&cmd=_notify-validate";
    StringBuilder sb = new StringBuilder();
    boolean errorFormalMessage = false;
    OrderFullDTO order = null;

    try {
      // resend message to PayPal for securiry protocol
      HashMap<String, String> responseMap = getWrapper(profile).getNotificationIPN(responseRequest);
      IpnDTO ipnDTO = valueOf(responseMap);
      log.info(String.format("prosessIpnMessage, ipnDTO: %s", ipnDTO.toString()));

      // check that txn_id has not been previously processed
      String txn_id = ipnDTO.getTxn_id();
      Integer idOrder = Integer.valueOf(ipnDTO.getCustom());

      TypeStateOrder state = TypeStateOrder.fromString(ipnDTO.getPayment_status());
      if (!exitsIdTransaction(txn_id, ipnDTO.getPayment_status())) {

        // check that receiver_email is your Primary PayPal email
        String recEmailMerchant = profile.getReceiverEmail();
        String receiver_email = ipnDTO.getReceiver_email();
        if (!recEmailMerchant.trim().equalsIgnoreCase(receiver_email)) {
          sb.append(
              String.format(
                  "messagio non elaborato: emailMerchant %s diversa dalla mail %s presente nel messaggio %s",
                  recEmailMerchant, receiver_email, ipnDTO.toString()));
          errorFormalMessage = true;
        }

        if (!ipnDTO.getMc_currency().trim().equalsIgnoreCase("EUR")) {
          sb.append(
              String.format(
                  "messagio non elaborato:divisa accettata %s diversa dalla divisa %s presente nel messaggio %s",
                  "EUR", ipnDTO.getMc_currency(), ipnDTO.toString()));
          errorFormalMessage = true;
        }

        if (errorFormalMessage) {
          log.error(
              String.format(
                  "Messagio %s non elaborato, ci sono errori formali: %s",
                  ipnDTO.getTxn_id(), sb.toString()));
          return;
        }

        // inserisco il messaggio
        MessageIpnDTO ipnMessage = new MessageIpnDTO();
        ipnMessage.setIdOrder(idOrder);
        ipnMessage.setFgElaborato(!errorFormalMessage);
        ipnMessage.setIdTransaction(txn_id);
        ipnMessage.setTxMessage(ipnDTO.toString());
        ipnMessage.setTxStato(ipnDTO.getPayment_status());
        ipnMessage.setTxNote(sb.toString());
        insertMessage(ipnMessage);

        // verifica se richiesta di rimborso
        if (ipnDTO.getParent_txn_id() != null
            && ipnDTO.getReason_code().equalsIgnoreCase("refund")) {
          log.info("refund trovato txtId = " + ipnDTO.getParent_txn_id());
          try {
            if (idOrder != null) {
              order = orderService.getOrders(idOrder, null, null, null).get(0);
            }

            updateStateRefundIPN(order, ipnDTO, responseMap, null);
          } catch (MailNotSendException e) {
            // TODO Auto-generated catch block
            log.error("errore nell'invio della mail per il conferma rimborso", e);
          }
          return;
        }

        // è presente un ordine, recupero i dettagli
        if (idOrder != null) {
          order = orderService.getOrders(idOrder, null, null, null).get(0);
          // check that payment_amount/payment_currency are correct
          BigDecimal mc_grossBD = new BigDecimal(ipnDTO.getMc_gross());
          if (order.getImOrdine().compareTo(mc_grossBD.abs()) != 0) {
            sb.append(
                String.format(
                    "messagio non elaborato: importo db %s diverso dalla importo %s presente nel messaggio %s",
                    order.getImOrdine(), ipnDTO.getMc_gross(), ipnDTO.toString()));
            errorFormalMessage = true;
          }
        }

        // message is correct, process message

        if (isPaymentKO(ipnDTO.getPayment_status())) {
          // inviare una mail in cui si comunica che PayPal non ha
          // accettato il pagamento
          if (idOrder != null) {
            // siamo nel caso di express checkout
            orderService.increaseQtaArticle(order, state);
            try {

              sendMailRefusedPayment(order, mailProps);
            } catch (MailNotSendException e) {
              // TODO Auto-generated catch block
              log.error(
                  String.format("errore nell'invio della mail di rifuto", order.getIdOrder()), e);
            }
          }
        } else if (isPaymentCompleted(ipnDTO.getPayment_status())) {
          // inviare una mail in cui si comunica che PayPal ha
          // accettato il pagamento
          if (idOrder != null) {
            int oldState = order.getIdStato();
            log.info(String.format("Old state %d ", oldState));
            orderService.updateStateOrder(idOrder, order, state);
            try {
              if (oldState != TypeStateOrder.COMPLETEDFUNDSHELD.getState()) {
                // questo stato è gia considerato completed, non
                // ha senso reinviare la mail;
                sendMailAcceptedPyamentAfterPending(order, mailProps, state);
              }
            } catch (MailNotSendException e) {
              // TODO Auto-generated catch block
              log.error(
                  String.format(
                      "errore nell'invio della mail di accettazione pagamento", order.getIdOrder()),
                  e);
            }
          }
        } else {
          // nessuna elaborazione da fare
          log.error(
              String.format(
                  "stato del messaggio %s, per il transactionId %s, non ammesso. Nessuna elaborazione da fare, messaggio %s",
                  ipnDTO.getPayment_status(), ipnDTO.getTxn_id(), ipnDTO.toString()));
        }

        return;

      } else {
        // messaggio già elaborato
        log.error(
            String.format(
                "transactionId %s del messaggio %s già elaborato ", txn_id, originalRequest));
        return;
      }

    } catch (PayPalIpnInvalidException e) {
      // TODO Auto-generated catch block
      log.error("invalid nella ricezione IPN da paypal, messaggion non corretto", e);
    } catch (PayPalIpnErrorException e) {
      // TODO Auto-generated catch block
      log.error("stringa non prevista nella ricezione IPN da paypal", e);
      throw e;
    } catch (PayPalException e) {
      // TODO Auto-generated catch block
      log.error("errore imprevisto sull'invio del messaggio IPN verso paypal", e);
      throw e;
    }
  }