@Override public void sendMailAcceptedPyamentAfterPending( OrderFullDTO order, MailPropertiesDTO mailProps, TypeStateOrder state) throws MailNotSendException { // TODO Auto-generated method stub String content = null; String mail = order.getIdUser(); try { content = Template.getContenFile(TipoTemplate.MailIPNAcceptedPaymemtAfetPending); } catch (IOException e) { // TODO Auto-generated catch block throw new MailNotSendException(e); } content = content.replaceAll( "<COMPANY_NAME>", mailProps.getCompanyName() == null ? "" : mailProps.getCompanyName()); content = content.replaceAll("<NAME>", order.getNameUser() + " " + order.getSurnameUser()); content = content.replaceAll("<idTransazione>", order.getIdTransaction()); content = content.replaceAll("<idOrder>", String.valueOf(order.getIdOrder())); content = content.replaceAll("<importo>", OthalaCommonUtils.getImporto(order.getImOrdine())); String subject = "Pagamento Accettato "; subject += mailProps.getCompanyName(); mailService.inviaMail(new String[] {mail}, subject, content, mailProps); // invia le mail al cliente e ai negozi sUll'avvenuta ricezione // delpagamento sendMailAcceptedPyament(order, mailProps, TypeStateOrder.getDescrState(state.getState())); }
@Override public void sendMailRefusedPayment(OrderFullDTO order, MailPropertiesDTO mailProps) throws MailNotSendException { // TODO Auto-generated method stub String content = null; String mail = order.getIdUser(); try { content = Template.getContenFile(TipoTemplate.MailIPNRefusePayment); } catch (IOException e) { // TODO Auto-generated catch block throw new MailNotSendException(e); } content = content.replaceAll("<COMPANY_NAME>", mailProps.getCompanyName()); content = content.replaceAll("<NAME>", order.getNameUser() + " " + order.getSurnameUser()); content = content.replaceAll("<idTransazione>", order.getIdTransaction()); content = content.replaceAll("<idOrder>", String.valueOf(order.getIdOrder())); content = content.replaceAll("<importo>", OthalaCommonUtils.getImporto(order.getImOrdine())); String subject = "Pagamento Rifiutato "; subject += mailProps.getCompanyName(); mailService.inviaMail(new String[] {mail}, subject, content, mailProps); }
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); } } }
@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; } } } */ } }