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; }
/** * This is never used... * * <p>Sends secure (SSL) a given PCC10 request to a given PCC10 end point and returns the * acknowledge (the response for the request). The message send contains in its SOAP header the * response URI. * * @param query the PCC9 request. It can not be null. * @param endpointURI the URI where the PCC10 end point runs. It can not be null. * @param responseEndpointURI the URI where the response to the PCC9 request will be send. It can * not be null. * @param keystoreFilePath the path for the SSL certificate file, it can not be null. * @param keystoreFilePassword the password for the SSL certificate file, it can not be null. * @return the acknowledge (the response for the request)for the given request. * @throws MalformedURLException if the specified PCC10 end point URI is malformed. */ static MCCIIN000002UV01 sendSecureMessage( QUPCIN043200UV01 query, String endpointURI, String keystoreFilePath, String keystoreFilePassword) throws MalformedURLException { if (keystoreFilePath == null) { final NullPointerException exception = new NullPointerException("The certPath argument can not be null."); LOGGER.error(exception.getMessage(), exception); throw exception; } if (keystoreFilePassword == null) { final NullPointerException exception = new NullPointerException("The certPassword argument can not be null."); LOGGER.error(exception.getMessage(), exception); throw exception; } com.sun.net.ssl.HostnameVerifier myHv = new com.sun.net.ssl.HostnameVerifier() { public boolean verify(String hostName, String a) { return true; } }; com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl .setDefaultHostnameVerifier(myHv); // or this... // com.sun.net.ssl.HostnameVerifier myHv = new com.sun.net.ssl.HostnameVerifier() { // public boolean verify(String hostName, String a) { // return true; // } // }; SSLClient.sslSetup(keystoreFilePath, keystoreFilePassword); final MCCIIN000002UV01 ack = sendMessage(query, endpointURI); return ack; }
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; } }
/* * public static void main(String[] args) throws Exception { String host = * "test.kortathjonustan.is"; int port = 8443; String SITE = "22"; String USER = * "idega"; String PASSWORD = "******"; String ACCEPTOR_TERM_ID = "90000022"; * String ACCEPTOR_IDENTIFICATION = "8180001"; * * String strCCNumber = "5413033024823099"; String strCCExpire = "0504"; * String strCCVerify = "150"; String strReferenceNumber = * Integer.toString((int) (Math.random() * 43200)); String keystore = * "/Applications/idega/webs/nat/idegaweb/bundles/com.idega.block.creditcard.bundle/resources/demoFolder/testkeys.jks"; * String keystorePass = "******"; * * KortathjonustanCreditCardClient client = new * KortathjonustanCreditCardClient(IWContext.getInstance(), host, port, * keystore, keystorePass, SITE, USER, PASSWORD, ACCEPTOR_TERM_ID, * ACCEPTOR_IDENTIFICATION); try { String tmp = client.doSale("Gr�mur Steri", * strCCNumber, strCCExpire.substring(2, 4), strCCExpire.substring(0, 2), * strCCVerify, 1, "ISK", strReferenceNumber ); * * //CreditCardBusiness cBus = (CreditCardBusiness) * IBOLookup.getServiceInstance(IWContext.getInstance(), * CreditCardBusiness.class); //KortathjonustanAuthorisationEntries entry = * (KortathjonustanAuthorisationEntries) cBus.getAuthorizationEntry(supp, * tmp); * * * //String tmp2 = client.doRefund(strCCNumber, strCCExpire.substring(2, 4), * strCCExpire.substring(0, 2), strCCVerify, 1, "ISK", * entry.getResponseString()); System.out.println("AuthorizationNumber = * "+tmp); //System.out.println("RefundAuthNumber = "+tmp2); } catch * (CreditCardAuthorizationException e) { System.out.println(" ---- Exception * ----"); System.out.println("DisplayText = "+e.getDisplayError()); * System.out.println("ErrorText = "+e.getErrorMessage()); * System.out.println("ErrorNum = "+e.getErrorNumber()); System.out.println(" * -----------------------"); e.printStackTrace(System.err); } * } * */ private Hashtable doRefund(int iAmountToRefund, Hashtable captureProperties, Object parentDataPK) throws CreditCardAuthorizationException { // TODO tjekka ef amountToRefund er sama og upphaflega refundi� ... // System.out.println(" ------ REFUND ------"); Hashtable refundProperties = new Hashtable(); try { int iAmount = 0; try { iAmount = Integer.parseInt(captureProperties.get(this.PROPERTY_AMOUNT).toString()); if (iAmountToRefund > iAmount) { CreditCardAuthorizationException e = new CreditCardAuthorizationException( "Amount to refund can not be higher that the original amount"); e.setDisplayError("Amount to refund can not be higher that the original amount"); throw e; } } catch (NumberFormatException e1) { throw new CreditCardAuthorizationException("Amount must be a number"); } StringBuffer strPostData = new StringBuffer(); // "DEFAULT" PROPERTIES appendProperty(strPostData, this.PROPERTY_USER, this.USER); appendProperty(strPostData, this.PROPERTY_PASSWORD, this.PASSWORD); appendProperty(strPostData, this.PROPERTY_SITE, this.SITE); appendProperty( strPostData, this.PROPERTY_CURRENT_DATE, getDateString(IWTimestamp.RightNow())); // TODO IMPLEMENT // appendProperty(strPostData, PROPERTY_MERCHANT_LANGUAGE) // appendProperty(strPostData, PROPERTY_CLIENT_LANGUAGE) appendProperty(strPostData, this.PROPERTY_AMOUNT_ECHO, this.strAmount); appendProperty(strPostData, this.PROPERTY_AMOUNT, Integer.toString(iAmountToRefund)); if (iAmount > iAmountToRefund) { appendProperty( strPostData, this.PROPERTY_AMOUNT_ECHO, captureProperties.get(this.PROPERTY_AMOUNT).toString()); } appendProperty( strPostData, this.PROPERTY_CURRENCY_EXPONENT, captureProperties.get(this.PROPERTY_CURRENCY_EXPONENT).toString()); appendProperty( strPostData, this.PROPERTY_REFERENCE_ID, captureProperties.get(this.PROPERTY_REFERENCE_ID).toString()); appendProperty( strPostData, this.PROPERTY_ACCEPTOR_TERM_ID, captureProperties.get(this.PROPERTY_ACCEPTOR_TERM_ID).toString()); appendProperty( strPostData, this.PROPERTY_ACCEPTOR_IDENT, captureProperties.get(this.PROPERTY_ACCEPTOR_IDENT).toString()); appendProperty( strPostData, this.PROPERTY_CURRENCY_CODE, captureProperties.get(this.PROPERTY_CURRENCY_CODE).toString()); appendProperty( strPostData, this.PROPERTY_ORIGINAL_DATA_ELEMENT, captureProperties.get(this.PROPERTY_ORIGINAL_DATA_ELEMENT).toString()); appendProperty( strPostData, this.PROPERTY_CURRENT_DATE_ECHO, captureProperties.get(this.PROPERTY_CURRENT_DATE).toString()); appendProperty( strPostData, this.PROPERTY_ACTION_CODE_ECHO, captureProperties.get(this.PROPERTY_ACTION_CODE).toString()); appendProperty( strPostData, this.PROPERTY_APPROVAL_CODE_ECHO, captureProperties.get(this.PROPERTY_APPROVAL_CODE).toString()); String strResponse = null; SSLClient client = getSSLClient(); // System.out.println("Request [" + strPostData.toString() + "]"); try { strResponse = client.sendRequest(REQUEST_TYPE_REVERSAL, strPostData.toString()); } catch (Exception e) { CreditCardAuthorizationException cce = new CreditCardAuthorizationException(); 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) { CreditCardAuthorizationException cce = new CreditCardAuthorizationException(); 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)) { CreditCardAuthorizationException cce = new CreditCardAuthorizationException(); cce.setDisplayError("Cannot connect to Central Payment Server"); cce.setErrorMessage( "Invalid response from host, should start with d39 [" + strResponse + "]"); cce.setErrorNumber("-"); throw cce; } else { refundProperties = parseResponse(strResponse); if (CODE_AUTHORIZATOIN_APPROVED.equals(refundProperties.get(this.PROPERTY_ACTION_CODE))) { return refundProperties; } else { CreditCardAuthorizationException cce = new CreditCardAuthorizationException(); cce.setDisplayError(refundProperties.get(this.PROPERTY_ACTION_CODE_TEXT).toString()); cce.setErrorMessage(refundProperties.get(this.PROPERTY_ERROR_TEXT).toString()); cce.setErrorNumber(refundProperties.get(this.PROPERTY_ACTION_CODE).toString()); throw cce; } } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return refundProperties; }