private hiddenValues verifyUpload(string htmlInput) { //Initialize output hiddenValues output = new hiddenValues(false, "Failed to find view state", "Failed to find login key"); //run regex hiddenValues regexOutput = regexDualSearch(htmlInput, "(?<=Received successfully. FileID = )([[0-9]*)", "(?<=Number of transactions in the batch : )([[0-9]*)"); //go through results if (regexOutput.success) { output.success = true; output.value1 = regexOutput.value1; output.value2 = regexOutput.value2; } else { if (regexOutput.value1 != "") { output.value1 = regexOutput.value1; } if (regexOutput.value2 != "") { output.value2 = regexOutput.value2; } } //done return(output); }
private hiddenValues getLogonValues(string htmlInput) { //Initialize output hiddenValues output = new hiddenValues(false, "Failed to find view state", "Failed to find login key"); //run regex hiddenValues regexOutput = regexDualSearch(htmlInput, "(?<=\"__VIEWSTATE\" value=\")([ \\=A-Za-z0-9+/:|]*)(?=\")", "(?<=__LOGIN_PAGE_KEY\" value=\")([ \\=A-Za-z0-9+\\*/:|]*)(?=\")"); //go through results if (regexOutput.success) { output.success = true; output.value1 = regexOutput.value1; output.value2 = regexOutput.value2; } else { if (regexOutput.value1 != "") { output.value1 = regexOutput.value1; } if (regexOutput.value2 != "") { output.value2 = regexOutput.value2; } } //done return(output); }
private hiddenValues getUploadValues(string htmlInput) { //Initialize output hiddenValues output = new hiddenValues(false, "Failed to find view state", "Failed to find login key"); //run regex hiddenValues regexOutput = regexDualSearch(htmlInput, "(?<=SessionToken=)([ \\=A-Za-z0-9+/:|%_]*)(?=\">)", "(?<=o.value = \")([ \\=A-Za-z0-9+/:|%_]*)"); //go through results if (regexOutput.success) { output.success = true; output.value1 = regexOutput.value1; output.value2 = regexOutput.value2; } else { if (regexOutput.value1 != "") { output.value1 = regexOutput.value1; } if (regexOutput.value2 != "") { output.value2 = regexOutput.value2; } } //done return(output); }
private hiddenValues regexDualSearch(string input, string pattern1, string pattern2) { //Initialize output hiddenValues output = new hiddenValues(false); //search for the viewstate variable string p1 = regexSearch(input, pattern1); if (p1 != null) { output.value1 = p1; output.success = true; } else { output.success = false; } //search for the login key variable string p2 = regexSearch(input, pattern2); if (p2 != null) { output.value2 = p2; output.success = true; } else { output.success = false; } //All done return(output); }
public BatchResult BatchUpload(string username, string password, string batch, bool sandbox = true) { //Pages the module uploads information too string logon; string uploadPage; string uploadPostPage; if (sandbox) { logon = "https://sandbox.authorize.net/UI/themes/sandbox/logon.aspx"; uploadPage = "https://sandbox.authorize.net/UI/themes/sandbox/popup.aspx?page=batchupload&sub=newfile"; uploadPostPage = "https://test.authorize.net/batchprocessing/batchupload.dll?page=batchupload&sub=newfile&SessionToken="; } else { //YOU MUST FIND AND ADD THE NON SANDBOX URLS HERE AS I DO NOT KNOW THEM //these urls MIGHT worlk i only constructed them based on guessing logon = "https://account.authorize.net/ui/themes/anet/logon.aspx"; uploadPage = "https://account.authorize.net/ui/themes/sandbox/popup.aspx?page=batchupload&sub=newfile"; uploadPostPage = "https://account.authorize.net/batchprocessing/batchupload.dll?page=batchupload&sub=newfile&SessionToken="; } //initialize the result BatchResult output = new BatchResult(); //Go the the logon page so we can obtain values we need for the next string logonGet = getRequest(logon); hiddenValues logonKeys = getLogonValues(logonGet); //if we found the required information continue if (logonKeys.success) { //we have obtained the first logon page NameValueCollection logonAuthData = new NameValueCollection(); logonAuthData["MerchantLogin"] = username; logonAuthData["Password"] = password; logonAuthData["__LOGIN_PAGE_KEY"] = logonKeys.value2; logonAuthData["__VIEWSTATE"] = logonKeys.value1; logonAuthData["__VIEWSTATEENCRYPTED"] = ""; logonAuthData["__PAGE_KEY"] = ""; //now that we have collected all the data, let's proceed to logon string logonPost = postRequest(logon, logonAuthData, logon); bool loggedIn = checkLoggedIn(logonPost); if (loggedIn) { //we have successfuly logged on //go to the page before we upload a transaction //this page has required details before we can proceed to the next string upPage = getRequest(uploadPage); hiddenValues uploadKeys = getUploadValues(upPage); //if we found the required information continue if (uploadKeys.success) { //set post data NameValueCollection uploadFileData = new NameValueCollection(); uploadFileData["__PAGE_KEY"] = uploadKeys.value2; //upload file and check result string uploadFile = postUpload(uploadPostPage + uploadKeys.value1, uploadFileData, batch); hiddenValues uploadVerify = verifyUpload(uploadFile); //now that we uploaded the file check if there was an error if (uploadVerify.success) { output.success = true; output.id = uploadVerify.value1; output.count = uploadVerify.value2; output.result = "Uploaded transaction details successfuly"; output.debug = uploadFile; } else { output.success = false; output.debug = uploadFile; output.result = postUploadError(uploadFile); } } else { output.success = false; output.debug = upPage; output.result = "Failue finding upload keys"; } } else { output.success = false; output.debug = logonPost; output.result = "Failure logging in"; } } else { output.success = false; output.debug = logonGet; output.result = "Failure finding login keys"; } return(output); }
private hiddenValues verifyUpload(string htmlInput) { //Initialize output hiddenValues output = new hiddenValues(false, "Failed to find view state", "Failed to find login key"); //run regex hiddenValues regexOutput = regexDualSearch(htmlInput, "(?<=Received successfully. FileID = )([[0-9]*)", "(?<=Number of transactions in the batch : )([[0-9]*)"); //go through results if (regexOutput.success) { output.success = true; output.value1 = regexOutput.value1; output.value2 = regexOutput.value2; } else { if (regexOutput.value1 != "") output.value1 = regexOutput.value1; if (regexOutput.value2 != "") output.value2 = regexOutput.value2; } //done return output; }
private hiddenValues getUploadValues(string htmlInput) { //Initialize output hiddenValues output = new hiddenValues(false, "Failed to find view state", "Failed to find login key"); //run regex hiddenValues regexOutput = regexDualSearch(htmlInput, "(?<=SessionToken=)([ \\=A-Za-z0-9+/:|%_]*)(?=\">)", "(?<=o.value = \")([ \\=A-Za-z0-9+/:|%_]*)"); //go through results if (regexOutput.success) { output.success = true; output.value1 = regexOutput.value1; output.value2 = regexOutput.value2; } else { if (regexOutput.value1 != "") output.value1 = regexOutput.value1; if (regexOutput.value2 != "") output.value2 = regexOutput.value2; } //done return output; }
private hiddenValues getLogonValues(string htmlInput) { //Initialize output hiddenValues output = new hiddenValues(false, "Failed to find view state", "Failed to find login key"); //run regex hiddenValues regexOutput = regexDualSearch(htmlInput, "(?<=\"__VIEWSTATE\" value=\")([ \\=A-Za-z0-9+/:|]*)(?=\")", "(?<=__LOGIN_PAGE_KEY\" value=\")([ \\=A-Za-z0-9+\\*/:|]*)(?=\")"); //go through results if (regexOutput.success) { output.success = true; output.value1 = regexOutput.value1; output.value2 = regexOutput.value2; } else { if (regexOutput.value1 != "") output.value1 = regexOutput.value1; if (regexOutput.value2 != "") output.value2 = regexOutput.value2; } //done return output; }
private hiddenValues regexDualSearch(string input, string pattern1, string pattern2) { //Initialize output hiddenValues output = new hiddenValues(false); //search for the viewstate variable string p1 = regexSearch(input, pattern1); if (p1 != null) { output.value1 = p1; output.success = true; } else output.success = false; //search for the login key variable string p2 = regexSearch(input, pattern2); if (p2 != null) { output.value2 = p2; output.success = true; } else output.success = false; //All done return output; }