Пример #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
  private String generateHtmlOrder(
      OrderFullDTO order,
      MailPropertiesDTO mailDTO,
      Map<String, String> inlineImages,
      TypeStateOrder state,
      String xslTemplate,
      Integer idShop) {
    BufferedWriter out = null;
    FileWriter fstream = null;

    try {

      File xslFile = Template.getFile("it/othala/service/template/" + xslTemplate + ".xsl");
      File xmlTemp = File.createTempFile("xmlTemp", ".xml");
      fstream = new FileWriter(xmlTemp);

      out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(xmlTemp), "UTF8"));

      out.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
      out.write("<order>");
      out.write("<imgLogo>");
      out.write("cid:imageLogo");
      inlineImages.put("imageLogo", mailDTO.getPathImgLogo());
      out.write("</imgLogo>");

      out.write("<customer>");
      out.write("<name>" + order.getNameUser() + "</name>");
      out.write("<mail>" + order.getIdUser() + "</mail>");
      out.write("<surname>" + order.getSurnameUser() + "</surname>");
      out.write("</customer>");

      out.write("<number>" + order.getIdOrder() + "</number>");
      out.write("<transaction>" + order.getIdTransaction() + "</transaction>");
      if (state.getState() == TypeStateOrder.PENDING.getState()) {
        out.write("<pending>true</pending>");
      } else {
        if (state.getState() == TypeStateOrder.SPEDITO.getState()) {
          out.write("<pending>spedito</pending>");
        } else {
          out.write("<pending>false</pending>");
        }
      }

      out.write("<imgPayment>");
      out.write("cid:imgPayment");
      out.write("</imgPayment>");
      inlineImages.put("imgPayment", mailDTO.getPathImgPayment());
      String spese =
          order.getSpeseSpedizione().getImportoSpese().compareTo(BigDecimal.ZERO) == 0
              ? "0"
              : order.getSpeseSpedizione().getImportoSpese().toString();
      out.write("<deliveryCost>" + spese + "</deliveryCost>");
      out.write("<totalCost>" + order.getImOrdine() + "</totalCost>");

      out.write("<billingAddress>");
      out.write("<name><![CDATA[" + order.getBillingAddress().getNome() + "]]></name>");
      out.write("<surname><![CDATA[" + order.getBillingAddress().getCognome() + "]]></surname>");
      out.write("<telefono>" + order.getBillingAddress().getTel() + "</telefono>");
      out.write("<street>" + order.getBillingAddress().getVia() + "</street>");
      out.write("<zipCode>" + order.getBillingAddress().getCap() + "</zipCode>");
      out.write("<city>" + order.getBillingAddress().getComune() + "</city>");
      out.write("<prov>" + order.getBillingAddress().getProvincia() + "</prov>");
      out.write("<country>" + order.getBillingAddress().getNazione() + "</country>");
      out.write("</billingAddress>");
      out.write("<shippingAddress>");
      out.write("<name><![CDATA[" + order.getShippingAddress().getNome() + "]]></name>");
      out.write("<surname><![CDATA[" + order.getShippingAddress().getCognome() + "]]></surname>");
      out.write("<tel>" + order.getShippingAddress().getTel() + "</tel>");
      out.write("<street>" + order.getShippingAddress().getVia() + "</street>");
      out.write("<zipCode>" + order.getShippingAddress().getCap() + "</zipCode>");
      out.write("<city>" + order.getShippingAddress().getComune() + "</city>");
      out.write("<prov>" + order.getShippingAddress().getProvincia() + "</prov>");
      out.write("<country>" + order.getShippingAddress().getNazione() + "</country>");
      out.write("</shippingAddress>");

      out.write("<cart>");
      int i = 0;
      for (ArticleFullDTO art : order.getCart()) {
        if (art != null && idShop == null || art != null && idShop == art.getShop().getIdShop()) {

          out.write("<item>");
          out.write("<number>" + art.getPrdFullDTO().getIdProduct() + "</number>");
          out.write("<img>cid:imgArt" + i + "</img>");
          inlineImages.put(
              "imgArt" + i, mailDTO.getBasePathThumbinalsArticle() + art.getThumbnailsUrl());
          out.write("<brand>" + art.getPrdFullDTO().getTxBrand() + "</brand>");
          out.write("<description>" + art.getPrdFullDTO().getDescription() + "</description>");
          if (art.getCustom() == null) {
            art.setCustom("");
          }

          out.write("<custom><![CDATA[ " + art.getCustom() + "]]></custom>");
          out.write("<color>" + art.getTxColor() + "</color>");
          out.write("<size>" + art.getTxSize() + "</size>");
          out.write("<unitPrice>" + art.getPrdFullDTO().getRealPrice() + "</unitPrice>");
          out.write("<quantity>" + art.getQtBooked() + "</quantity>");
          out.write(
              "<price>"
                  + art.getPriceDiscounted().multiply(new BigDecimal(art.getQtBooked()))
                  + "</price>");

          ShopDTO shopStock =
              externalService.getShopStock(
                  art.getPrdFullDTO().getIdProduct(), art.getPgArticle(), art.getTxBarCode());

          out.write("<idshop>" + shopStock.getIdShop().toString() + "</idshop>");
          out.write("<desshop>" + shopStock.getTxShop() + "</desshop>");
          out.write("</item>");
          i++;
        }
      }
      out.write("</cart>");
      out.write("</order>");
      out.close();
      fstream.close();

      // scrivo il file xml temporaneo

      File htmlTemp = File.createTempFile("htmlTemp", ".html");

      // effetto la conversione xml,xsl to html scrivo il file html
      // temporaneo
      TransformerFactory tFactory = TransformerFactory.newInstance();
      Source xslSource = new javax.xml.transform.stream.StreamSource(xslFile);
      Source xmlSource = new javax.xml.transform.stream.StreamSource(xmlTemp);
      javax.xml.transform.stream.StreamResult result = new StreamResult(htmlTemp);
      Transformer transformer;
      transformer = tFactory.newTransformer(xslSource);
      transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
      transformer.transform(xmlSource, result);

      String html = IOUtils.toString(new FileInputStream(htmlTemp), "UTF-8");

      return html;

    } catch (Exception e) {
      log.error("errore formattazione html per invio mail", e);
      return null;
    } finally {
      if (out != null)
        try {
          out.close();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          log.error("errore chiusura outstream", e);
        }
      if (fstream != null)
        try {
          fstream.close();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          log.error("errore chiusura fstream", e);
        }
    }
  }