package it.acxent.bank.xpay; import it.acxent.bank._BankAdapter; import it.acxent.common.Parm; import it.acxent.common.StatusMsg; import it.acxent.db.ApplParmFull; import it.acxent.db.DBAdapter; import it.acxent.reg.EcDc; import java.net.URLEncoder; public class XpayReq extends _BankAdapter { public static final String LANG_CODE_IT = "ITA"; public static final String LANG_CODE_EN = "ENG"; public static final String LANG_CODE_ES = "SPA"; public static final String LANG_CODE_FR = "FRA"; public static final String LANG_CODE_DE = "GER"; public static final String LANG_CODE_ITA_ENG = "ITA-ENG"; public static final String LANG_CODE_JPN = "JPN"; public static final String DIV_CODE_LIRA = "18"; public static final String DIV_CODE_EURO = "242"; public static final String DIV_CODE_STERLINE = "2"; public static final String DIV_CODE_YEN = "71"; public static final String DIV_CODE_DOLLARL_HK = "103"; public static final String DIV_CODE_REAL = "234"; private String divisa; private String codTrans; private String mail; private String importo; private String languageId; public static final String TEST_ALIAS = "payment_3444153"; public static final String P_XPAY_MAC_KEY = "XPAY_MAC_KEY"; public static final String P_XPAY_URL_RESPONSE = "XPAY_URL_RESPONSE"; public static final String P_XPAY_ALIAS = "XPAY_ALIAS"; public static final String P_XPAY_PAYMENT_OK_PAGE = "XPAY_PAY_OK"; public static final String P_XPAY_PAYMENT_ERROR_PAGE = "XPAY_PAY_KO"; public static final String P_XPAY_URL_RESPONSE_NULL = "XPAY_URL_RESPONSE_NULL"; public static final String TEST_MAC = "TLGHTOWIZXQPTIZRALWKG"; public static final String REQ_URL = "https://ecommerce.keyclient.it/ecomm/ecomm/DispatcherServlet"; public static final String TEST_REQ_URL = "https://coll-ecommerce.keyclient.it/ecomm/ecomm/DispatcherServlet"; public static final String DIV_CODE_DOLLARI = "1"; public XpayReq() {} public XpayReq(ApplParmFull apFull) { setAp(apFull); } public String getCodTrans() { return (this.codTrans == null) ? "" : this.codTrans; } public void setCodTrans(String myamount) { this.codTrans = myamount; } public String getImporto() { return (this.importo == null) ? "" : this.importo; } public void setImporto(String mybuyeremail) { this.importo = mybuyeremail; } public String getMail() { return (this.mail == null) ? "" : this.mail; } public void setMail(String mybuyername) { this.mail = mybuyername; } public String getDivisa() { return (this.divisa == null) ? "" : this.divisa; } public void setDivisa(String mycurrency) { this.divisa = mycurrency; } public String getAlias() { return getParm("XPAY_ALIAS").getTesto(); } private String getMylanguageCode() { if (getLanguageId().toLowerCase().equals("it")) return "ITA"; if (getLanguageId().toLowerCase().equals("en")) return "ENG"; if (getLanguageId().toLowerCase().equals("es\t")) return "SPA"; if (getLanguageId().toLowerCase().equals("fr")) return "FRA"; if (getLanguageId().toLowerCase().equals("de")) return "GER"; return ""; } public String getMacEsempio() { String temp = "codTrans=" + getCodTrans() + "divisa=" + getDivisa() + "importo=1" + getKey(); System.out.println("stringa mac: " + temp); String res = ""; try { res = EcDc.cryptSHA1Plain(temp); System.out.println(res); } catch (Exception e) { e.printStackTrace(); } return res; } public String getMac() { String temp = "codTrans=" + getCodTrans() + "divisa=" + getDivisa() + "importo=" + getImportoUrl() + getKey(); String res = ""; try { res = EcDc.cryptSHA1Plain(temp); } catch (Exception e) { e.printStackTrace(); } return res; } public String getLanguageId() { return (this.languageId == null) ? "" : this.languageId; } public void setLanguageId(String lang) { this.languageId = lang; } public String getFullRequestUrl() { StringBuffer theUrl = new StringBuffer("https://ecommerce.keyclient.it/ecomm/ecomm/DispatcherServlet"); theUrl.append("alias="); theUrl.append(getAlias()); theUrl.append("&importo="); theUrl.append(getImporto()); theUrl.append("&divisa="); theUrl.append(getDivisa()); theUrl.append("&codTrans="); theUrl.append(getCodTrans()); theUrl.append("&mail="); theUrl.append(getMail()); theUrl.append("&mac="); try { theUrl.append(URLEncoder.encode(getMac(), "UTF-8")); } catch (Exception e) { e.printStackTrace(); } theUrl.append("&languageId="); theUrl.append(getLanguageId()); theUrl.append("&url="); theUrl.append(getUrl()); if (!getUrl_back().isEmpty()) { theUrl.append("&url_back="); theUrl.append(getUrl_back()); } return theUrl.toString(); } public String getRequestUrl() { StringBuffer theUrl = new StringBuffer("https://ecommerce.keyclient.it/ecomm/ecomm/DispatcherServlet"); theUrl.append("?alias="); theUrl.append(getAlias()); theUrl.append("&importo="); theUrl.append(getImportoUrl()); theUrl.append("&divisa="); theUrl.append(getDivisa()); theUrl.append("&codTrans="); theUrl.append(getCodTrans()); theUrl.append("&mail="); theUrl.append(getMail()); theUrl.append("&mac="); try { theUrl.append(URLEncoder.encode(getMac(), "UTF-8")); } catch (Exception e) { e.printStackTrace(); } theUrl.append("&languageId="); theUrl.append(getLanguageId()); theUrl.append("&url="); theUrl.append(getUrl()); if (!getUrl_back().isEmpty()) { theUrl.append("&url_back="); theUrl.append(getUrl_back()); } return theUrl.toString(); } public String getKey() { return getParm("XPAY_MAC_KEY").getTesto(); } public String getImportoUrl() { if (this.importo == null) return "0000"; String temp = this.importo; if (temp.indexOf('.') < 0) { temp = temp + "00"; } else if (temp.length() - temp.indexOf('.') < 3) { temp = temp + "0"; } return temp.replace(".", ""); } public String getUrl() { return getParm("XPAY_URL_RESPONSE").getTesto(); } public String getUrl_back() { return getParm("XPAY_URL_RESPONSE_NULL").getTesto(); } public String getTestRequestUrl() { StringBuffer theUrl = new StringBuffer("https://coll-ecommerce.keyclient.it/ecomm/ecomm/DispatcherServlet"); theUrl.append("?alias="); theUrl.append("payment_3444153"); theUrl.append("&importo=1"); theUrl.append("&divisa="); theUrl.append(getDivisa()); theUrl.append("&codTrans="); theUrl.append(getCodTrans()); theUrl.append("&mail="); theUrl.append(getMail()); theUrl.append("&mac="); try { theUrl.append(URLEncoder.encode(getMacEsempio(), "UTF-8")); } catch (Exception e) { e.printStackTrace(); } theUrl.append("&languageId="); theUrl.append(getLanguageId()); theUrl.append("&url="); theUrl.append(getUrl()); if (!getUrl_back().isEmpty()) { theUrl.append("&url_back="); theUrl.append(getUrl_back()); } return theUrl.toString(); } public static void initApplicationParms(ApplParmFull ap) { boolean debug = false; if (ap != null) { DBAdapter.logDebug(debug, "Xpay initParms: start"); String l_tipoParm = "XPAY"; StatusMsg.updateMsgByTag(ap, "INIT", l_tipoParm); Parm bean = new Parm(ap); bean.findByCodice("XPAY_PAY_KO"); bean.setFlgAdmin(0L); bean.setTipoParm(l_tipoParm); bean.setCodice("XPAY_PAY_KO"); bean.setDescrizione("XPAY_PAY_KO"); bean.setFlgTipo(0L); if (bean.getTesto().equals("")) bean.setTesto("payRes.jsp"); bean.setNota("XPAY_PAY_KO"); bean.save(); bean.findByCodice("XPAY_PAY_OK"); bean.setFlgAdmin(0L); bean.setTipoParm(l_tipoParm); bean.setCodice("XPAY_PAY_OK"); bean.setDescrizione("XPAY_PAY_OK"); bean.setFlgTipo(0L); if (bean.getTesto().equals("")) bean.setTesto("payRes.jsp"); bean.setNota("XPAY_PAY_OK"); bean.save(); bean.findByCodice("XPAY_MAC_KEY"); bean.setFlgAdmin(0L); bean.setTipoParm(l_tipoParm); bean.setCodice("XPAY_MAC_KEY"); bean.setDescrizione("XPAY_MAC_KEY"); bean.setFlgTipo(0L); if (bean.getTesto().equals("")) bean.setTesto("TLGHTOWIZXQPTIZRALWKG"); if (bean.getNota().isEmpty()) bean.setNota("XPAY_MAC_KEY. mac di esempio: TLGHTOWIZXQPTIZRALWKG"); bean.save(); bean.findByCodice("XPAY_ALIAS"); bean.setFlgAdmin(0L); bean.setTipoParm(l_tipoParm); bean.setCodice("XPAY_ALIAS"); bean.setDescrizione("XPAY_ALIAS"); bean.setFlgTipo(0L); if (bean.getTesto().equals("")) bean.setTesto("payment_3444153"); if (bean.getNota().isEmpty()) bean.setNota("XPAY_MAC_KEY. ALIAS DI TEST: payment_3444153"); bean.save(); bean.findByCodice("XPAY_URL_RESPONSE_NULL"); bean.setFlgAdmin(0L); bean.setTipoParm(l_tipoParm); bean.setCodice("XPAY_URL_RESPONSE_NULL"); bean.setDescrizione("XPAY_URL_RESPONSE_NULL"); bean.setFlgTipo(0L); if (bean.getTesto().equals("")) bean.setTesto("http://localhost/td/RicevutaXPAY.abl"); bean.setNota("XPAY_PAY_OK"); bean.save(); bean.findByCodice("XPAY_URL_RESPONSE"); bean.setFlgAdmin(0L); bean.setTipoParm(l_tipoParm); bean.setCodice("XPAY_URL_RESPONSE"); bean.setDescrizione("XPAY_URL_RESPONSE"); bean.setFlgTipo(0L); if (bean.getTesto().equals("")) bean.setTesto("http://localhost/td/RicevutaXPAY.abl"); bean.setNota("XPAY_URL_RESPONSE"); bean.save(); DBAdapter.logDebug(debug, "Xpay initParms: false"); } } }