/** @return @throws IOException */ private SSLClient getSSLClient() throws KortathjonustanAuthorizationException { SSLClient client; try { String tmp = this.strKeystore; if (!tmp.startsWith( "/")) { // Backwards compatability when this looked like this /home/idegaweb/... // (marathon.is) tmp = this.bundle.getBundleBaseRealPath() + "/" + this.strKeystore; } client = new SSLClient( this.HOST_NAME, this.HOST_PORT, tmp, this.strKeystorePass, this.USER, this.PASSWORD); } catch (IOException e) { KortathjonustanAuthorizationException cce = new KortathjonustanAuthorizationException(); cce.setDisplayError("Cannot connect to Central Payment Server"); cce.setErrorMessage("Cannot get SSLClient instance"); cce.setErrorNumber("-"); cce.setParentException(e); throw cce; } return client; }
private Hashtable getFirstResponse() throws KortathjonustanAuthorizationException { Hashtable properties = null; // System.out.println(" ------ REQUEST ------"); // long lStartTime = System.currentTimeMillis(); try { SSLClient client = getSSLClient(); StringBuffer strPostData = new StringBuffer(); appendProperty(strPostData, this.PROPERTY_SITE, this.SITE); // "site=22" appendProperty(strPostData, this.PROPERTY_USER, this.USER); appendProperty(strPostData, this.PROPERTY_PASSWORD, this.PASSWORD); appendProperty(strPostData, this.PROPERTY_ACCEPTOR_TERM_ID, this.ACCEPTOR_TERM_ID); appendProperty(strPostData, this.PROPERTY_ACCEPTOR_IDENT, this.ACCEPTOR_IDENTIFICATION); appendProperty(strPostData, this.PROPERTY_CC_NUMBER, this.strCCNumber); appendProperty(strPostData, this.PROPERTY_CC_EXPIRE, this.strCCExpire); appendProperty(strPostData, this.PROPERTY_AMOUNT, this.strAmount); appendProperty(strPostData, this.PROPERTY_CURRENCY_CODE, this.strCurrencyCode); appendProperty(strPostData, this.PROPERTY_CURRENCY_EXPONENT, this.strCurrencyExponent); appendProperty(strPostData, this.PROPERTY_CARDHOLDER_NAME, this.strName); appendProperty(strPostData, this.PROPERTY_REFERENCE_ID, this.strReferenceNumber); appendProperty(strPostData, this.PROPERTY_CURRENT_DATE, this.strCurrentDate); appendProperty(strPostData, this.PROPERTY_CC_VERIFY_CODE, this.strCCVerify); addDefautProperties(strPostData); String strResponse = null; // System.out.println("Request [" + strPostData.toString() + "]"); try { strResponse = client.sendRequest(REQUEST_TYPE_AUTHORIZATION, strPostData.toString()); // System.out.println("[Korta] strResponse = "+strResponse); } catch (Exception e) { KortathjonustanAuthorizationException cce = new KortathjonustanAuthorizationException(); cce.setDisplayError("Cannot connect to Central Payment Server"); cce.setErrorMessage("SendRequest failed"); cce.setErrorNumber("-"); cce.setParentException(e); e.printStackTrace(); throw cce; } // System.out.println("Response [" + strResponse + "]"); if (strResponse == null) { KortathjonustanAuthorizationException cce = new KortathjonustanAuthorizationException(); cce.setDisplayError("Cannot connect to Central Payment Server"); cce.setErrorMessage("SendRequest returned null"); cce.setErrorNumber("-"); throw cce; } else if (!strResponse.startsWith(this.PROPERTY_ACTION_CODE)) { KortathjonustanAuthorizationException cce = new KortathjonustanAuthorizationException(); cce.setDisplayError("Cannot connect to Central Payment Server"); cce.setErrorMessage( "Invalid response from host, should start with d39 [" + strResponse + "]"); cce.setErrorNumber("-"); throw cce; } else { properties = parseResponse(strResponse); if (CODE_AUTHORIZATOIN_APPROVED.equals(properties.get(this.PROPERTY_ACTION_CODE))) { return properties; } else { KortathjonustanAuthorizationException cce = new KortathjonustanAuthorizationException(); try { cce.setDisplayError(properties.get(this.PROPERTY_ACTION_CODE_TEXT).toString()); } catch (NullPointerException n) { } try { cce.setErrorMessage(properties.get(this.PROPERTY_ERROR_TEXT).toString()); } catch (NullPointerException n) { } try { cce.setErrorNumber(properties.get(this.PROPERTY_ACTION_CODE).toString()); } catch (NullPointerException n) { } throw cce; } } } catch (UnsupportedEncodingException e) { KortathjonustanAuthorizationException cce = new KortathjonustanAuthorizationException(); cce.setDisplayError("Cannot connect to Central Payment Server"); cce.setErrorMessage("UnsupportedEncodingException"); cce.setErrorNumber("-"); cce.setParentException(e); throw cce; } }
private Hashtable finishTransaction(Hashtable properties) throws KortathjonustanAuthorizationException { // System.out.println(" ------ CAPTURE ------"); Hashtable captureProperties = new Hashtable(); try { SSLClient client = getSSLClient(); String strResponse = null; // System.out.println("strPostData [ "+strPostData.toString()+" ]"); try { strResponse = client.sendRequest(REQUEST_TYPE_CAPTURE, getPostData(properties)); } catch (Exception e) { KortathjonustanAuthorizationException cce = new KortathjonustanAuthorizationException(); cce.setDisplayError("Cannot connect to Central Payment Server"); cce.setErrorMessage("SendRequest failed"); cce.setErrorNumber("-"); cce.setParentException(e); throw cce; } // System.out.println("Response [ "+strResponse+" ]"); if (strResponse == null) { KortathjonustanAuthorizationException cce = new KortathjonustanAuthorizationException(); cce.setDisplayError("Cannot connect to Central Payment Server"); cce.setErrorMessage("SendRequest returned null"); cce.setErrorNumber("-"); throw cce; } else if (!strResponse.startsWith(this.PROPERTY_ACTION_CODE)) { KortathjonustanAuthorizationException cce = new KortathjonustanAuthorizationException(); cce.setDisplayError("Cannot connect to Central Payment Server"); cce.setErrorMessage( "Invalid response from host, should start with d39 [" + strResponse + "]"); cce.setErrorNumber("-"); throw cce; } else { captureProperties = parseResponse(strResponse); captureProperties.put( this.PROPERTY_CARD_BRAND_NAME, properties.get(this.PROPERTY_CARD_BRAND_NAME)); if (CODE_AUTHORIZATOIN_APPROVED.equals(captureProperties.get(this.PROPERTY_ACTION_CODE))) { return captureProperties; } else { KortathjonustanAuthorizationException cce = new KortathjonustanAuthorizationException(); cce.setDisplayError(captureProperties.get(this.PROPERTY_ACTION_CODE_TEXT).toString()); cce.setErrorMessage(captureProperties.get(this.PROPERTY_ERROR_TEXT).toString()); cce.setErrorNumber(captureProperties.get(this.PROPERTY_ACTION_CODE).toString()); throw cce; } } } catch (Exception e) { e.printStackTrace(); } return captureProperties; }