protected Dictionary <string, string> getSecurityKeys(string payLoad, PayeezyRequestOptions requestOptions) { Dictionary <string, string> returnMap = new Dictionary <string, string>(); if (requestOptions == null) { throw new Exception("Payeezy Request Options not set"); } //try { // long nonce = Math.Abs(SecureRandom.getInstance("SHA1PRNG").nextLong()); //returnMap.put(APIResourceConstants.SecurityConstants.NONCE, Long.ToString(nonce)); returnMap.Add(APIResourceConstants.SecurityConstants.APIKEY, requestOptions.getApiKey()); //returnMap.Add(APIResourceConstants.SecurityConstants.TIMESTAMP, Long.toString(System.currentTimeMillis())); returnMap.Add(APIResourceConstants.SecurityConstants.TOKEN, requestOptions.getToken()); returnMap.Add(APIResourceConstants.SecurityConstants.APISECRET, requestOptions.getSecret()); returnMap.Add(APIResourceConstants.SecurityConstants.PAYLOAD, payLoad); returnMap.Add(APIResourceConstants.SecurityConstants.AUTHORIZE, getMacValue(returnMap)); return(returnMap); //} catch (ExecutionEngineException e) { // MessageLogger.logMessage(e.getMessage()); // throw new RuntimeException(e.getMessage(),e); //} // catch // { // } }
/** * Reads the required credentials and the host information from VCAP_SERVICES variables * making it cloudfoundry aware * @param method * @param payload * @return * @throws Exception */ public PayeezyResponse execute(RequestMethod method, Object payload) { //string envstring = System.getenv("VCAP_SERVICES"); string apikey = null; string token = null; string secret = null; string url = null; //JSONParser jsonParser = new JSONParser(); var jsonParser = new JSONHelper <Object>(); apikey = (string)jsonParser.fromJson("apikey"); token = (string)jsonParser.fromJson("token"); secret = (string)jsonParser.fromJson("secret"); url = (string)jsonParser.fromJson("uri"); if (url != null && !url.Contains("https")) { url = "https://" + url; } //try //{ // //JSONObject vcapServiceObject = (JSONObject)jsonParser.parse(envstring); // //JSONArray payeezyJsonArray = (JSONArray)vcapServiceObject.get("payeezy-service"); // //JSONObject payeezyObject = (JSONObject)payeezyJsonArray.get(0); // if (payeezyObject != null) // { // JSONObject credentialsObject = (JSONObject)payeezyObject.get("credentials"); // apikey = (string)credentialsObject.get("apikey"); // token = (string)credentialsObject.get("token"); // secret = (string)credentialsObject.get("secret"); // url = (string)credentialsObject.get("uri"); // if (url != null && !url.Contains("https")) // { // url = "https://" + url; // } // } //} //catch (ParseException ex) //{ // //ex.printStackTrace(); //} PayeezyRequestOptions requestOptions = new PayeezyRequestOptions(apikey, token, secret); return(execute(url, method, requestOptions, payload)); }
/** * Method that executes a GET and POST for the provided payload * @param URL * @param method * @param requestOptions * @param payload * @return * @throws Exception */ public PayeezyResponse execute(string URL, RequestMethod method, PayeezyRequestOptions requestOptions, Object payload) { switch ((int)method) { case 1: return(executeGetRequest(URL, (Dictionary <string, string>)payload)); case 2: //return executePostRequest(URL, (string)payload, requestOptions); return(null); case 3: return(null); //return executePostRequest(URL, (string)payload, requestOptions); default: throw new Exception("Unsupported Request Method"); } }
/** * API Call to search for events * @param URL * @param queryMap * @param requestOptions * @return * @throws Exception */ public PayeezyResponse getEvents(string URL, Dictionary <string, string> queryMap, PayeezyRequestOptions requestOptions) { URL = URL + APIResourceConstants.SECURE_TOKEN_URL; PayeezyResponse payeezyResponse = payeezyClient.execute(URL, RequestMethod.GET, requestOptions, queryMap); return(payeezyResponse); }