public Batch_Sale_Recon_Result Sale_Recon(Batch_Sale_Recon_Details details) { var returnBatch = new Batch_Sale_Recon_Result(); returnBatch.Batches = new List <Batch_Sale_Recon_Result_batch>(); //string dummySubIDxml = "<subs><sub><subid>183</subid><comref>THECODEGRO</comref><adate>04072015</adate><records>15</records><amount>1932.30</amount><status>1</status><rbr>1234</rbr><rej_records>2</rej_records><rej_amount>310.94</rej_amount>"; //dummySubIDxml += "<unpiad_records>0</unpiad_records><unpaid_amount>0.00</unpaid_amount><lunpaid_records>0</lunpaid_records><lunpaid_amount>0.00</lunpaid_amount><retamount>0.00</retamount><debitfee>0.00</debitfee>"; //dummySubIDxml += "<unpaidfee>0.00</unpaidfee><apiprocessing>3</apiprocessing></sub></subs>"; Dictionary <string, string> ValidationReqParams = new Dictionary <string, string>(); ValidationReqParams.Add("f", "subi"); ValidationReqParams.Add("p", "1"); ValidationReqParams.Add("cref", cref); ValidationReqParams.Add("subid", details.TransactionIdentifier); var statusCheck = GatewayUtils.PostMultiPartXMLTransaction(URL, ValidationReqParams, new XmlDocument[] { }, cookieJar); var stat_xml = new XmlDocument(); stat_xml.LoadXml(statusCheck); var subs = stat_xml.SelectNodes("/subs/sub"); if (subs.Count == 0) { return(returnBatch); } var apiProcessingNode = stat_xml.SelectNodes("/subs/sub/apiprocessing")[0]; var apiProcessing = int.Parse(apiProcessingNode.InnerText); var statusNode = stat_xml.SelectNodes("/subs/sub/status")[0]; var status = int.Parse(statusNode.InnerText); if (apiProcessing > 3) { returnBatch.Batches.Add(new Batch_Sale_Recon_Result_batch { BatchIdentifier = details.TransactionIdentifier, isBatchSuccess = false, lines = new List <Batch_Sale_Recon_Result_batch_line>() }); return(returnBatch); } if (status > 3) { returnBatch.Batches.Add(new Batch_Sale_Recon_Result_batch { BatchIdentifier = details.TransactionIdentifier, isBatchSuccess = false, lines = new List <Batch_Sale_Recon_Result_batch_line>() }); return(returnBatch); } if (status > 0) { //check cdv 0 Not done/Processing 3 Accepted 4 Rejected Dictionary <string, string> DebitsValidationReqParams = new Dictionary <string, string>(); DebitsValidationReqParams.Add("f", "subid"); DebitsValidationReqParams.Add("p", "1"); DebitsValidationReqParams.Add("cref", cref); DebitsValidationReqParams.Add("subid", details.TransactionIdentifier); var debitCall = GatewayUtils.PostMultiPartXMLTransaction(URL, DebitsValidationReqParams, new XmlDocument[] { }, cookieJar); var debitXml = new XmlDocument(); debitXml.LoadXml(debitCall); var debits = debitXml.SelectNodes("/sub/debit"); var batch = new Batch_Sale_Recon_Result_batch { BatchIdentifier = details.TransactionIdentifier, isBatchSuccess = true, lines = new List <Batch_Sale_Recon_Result_batch_line>() }; returnBatch.Batches.Add(batch); foreach (XmlNode node in debits) { var cdv = int.Parse(node.SelectNodes("cdv")[0].InnerText); if (cdv == 3) { var debitstatus = int.Parse(node.SelectNodes("debitstatus")[0].InnerText); if (debitstatus == 1 || debitstatus == 3 || debitstatus == 6 || debitstatus == 7) { batch.lines.Add(new Batch_Sale_Recon_Result_batch_line { Amount = decimal.Parse(node.SelectNodes("amount")[0].InnerText), isLineSuccess = false, LineError = node.SelectNodes("hmessage")[0].InnerText, LineIdentifier = node.SelectNodes("description")[0].InnerText }); } } if (cdv == 4 || cdv == 99) { batch.lines.Add(new Batch_Sale_Recon_Result_batch_line { Amount = decimal.Parse(node.SelectNodes("amount")[0].InnerText), isLineSuccess = false, LineError = node.SelectNodes("hmessage")[0].InnerText, LineIdentifier = node.SelectNodes("description")[0].InnerText }); } } return(returnBatch); } return(returnBatch); }
public Batch_Sale_Recon_Result Sale_Recon(Batch_Sale_Recon_Details details) { #region Error Condition Checking if (BankAccountEnabled && CreditCardEnabled) { throw new Exception("Mixed batching not allowed by gateway"); } if (!BankAccountEnabled && !CreditCardEnabled) { throw new Exception("Gateway not set up for any service"); } #endregion string result = ""; XElement doRDRequest = new XElement("rd_request"); doRDRequest.Add(new XElement("merchantno", MerchantNumber)); doRDRequest.Add(new XElement("merchantuid", MerchantUID)); doRDRequest.Add(new XElement("fromdate", details.ReconStartDate.ToString("yyMMdd"))); doRDRequest.Add(new XElement("todate", details.ReconEndDate.ToString("yyMMdd"))); if (BankAccountEnabled) { var client = getDebitOrderClient(); result = client.downloadRDFiles(doRDRequest.ToString()); } else if (CreditCardEnabled) { var client = getCollectionsClient(); result = client.downloadRDFiles(doRDRequest.ToString()); } var return_object = new Batch_Sale_Recon_Result { RequestXml = doRDRequest.ToString(), ResponseXml = result }; XmlDocument rdoc = new XmlDocument(); rdoc.LoadXml(result); XmlNodeList errorNodes = rdoc.GetElementsByTagName("rd_download_error"); //each file represents a batch if (errorNodes.Count > 0) { return_object.isRequestSuccess = false; return_object.ErrorMessage = errorNodes.ToString(); return(return_object); } XmlNodeList fileNodes = rdoc.GetElementsByTagName("rd_file"); //each file represents a batch List <Batch_Sale_Recon_Result_batch> batches = new List <Batch_Sale_Recon_Result_batch>(); foreach (XmlElement file in fileNodes) { Batch_Sale_Recon_Result_batch batch = new Batch_Sale_Recon_Result_batch { BatchDate = DateTime.Parse(file.SelectNodes("date_received").Item(0).InnerText), BatchIdentifier = file.SelectNodes("file_name").Item(0).InnerText, isBatchSuccess = true, NumberOfRecords = int.Parse(file.SelectNodes("num_records").Item(0).InnerText), Total = decimal.Parse(file.SelectNodes("rd_amount").Item(0).InnerText) }; var records = file.GetElementsByTagName("rd_record"); List <Batch_Sale_Recon_Result_batch_line> lines = new List <Batch_Sale_Recon_Result_batch_line>(); foreach (XmlNode record in records) { var recordNodes = record.ChildNodes; string branchcode = record.SelectNodes("branchcode").Item(0).InnerText; string accountno = record.SelectNodes("accountno").Item(0).InnerText; string accounttype = record.SelectNodes("accounttype").Item(0).InnerText; string accountname = record.SelectNodes("accountname").Item(0).InnerText; string debitamount = record.SelectNodes("debitamount").Item(0).InnerText; string actiondate = record.SelectNodes("actiondate").Item(0).InnerText; string statement_reference = record.SelectNodes("statement_reference").Item(0).InnerText; string status = record.SelectNodes("status").Item(0).InnerText; string rejection_code = record.SelectNodes("rejection_code").Item(0).InnerText; string rejection_reason = record.SelectNodes("rejection_reason").Item(0).InnerText; string original_sequencenumber = record.SelectNodes("original_sequencenumber").Item(0).InnerText; string transaction_reference = record.SelectNodes("transaction_reference").Item(0).InnerText; lines.Add(new Batch_Sale_Recon_Result_batch_line { isLineSuccess = false, isDebitedWithError = status != "Rejected", LineError = rejection_code + " - " + rejection_reason, LineIdentifier = transaction_reference, LineNumber = int.Parse(original_sequencenumber) }); } batch.lines = lines; batches.Add(batch); } return_object.Batches = batches; return_object.isRequestSuccess = true; return(return_object); }