예제 #1
0
        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);
        }
예제 #2
0
        public Batch_Sale_Submit_Result Sale_Submit(Batch_Sale_Submit_Details details)
        {
            var RequestParams = new JavaScriptSerializer().Deserialize <Dictionary <string, string> >(details.RequestParams);

            var xml = new XmlDocument();

            xml.LoadXml(details.RequestFile);

            var result = GatewayUtils.PostMultiPartXMLTransaction(URL, RequestParams, new XmlDocument[] { xml }, cookieJar);

            var res_xml = new XmlDocument();

            res_xml.LoadXml(result);
            if (res_xml.FirstChild.NodeType == XmlNodeType.XmlDeclaration)
            {
                XmlDeclaration xmlDeclaration = (XmlDeclaration)res_xml.FirstChild;
                xmlDeclaration.Encoding = "UTF-16";
            }
            //*[@note]
            string errors       = "";
            bool   hasAuthError = false;

            XmlNodeList auth_nodes = res_xml.SelectNodes("/API/auth/*[@note]");

            foreach (XmlNode tag in auth_nodes)
            {
                var note = tag.Attributes["note"].Value.ToLower();
                if (note.Contains("invalid") || note.Contains("fail"))
                {
                    hasAuthError = true;
                    errors      += note;
                }
            }

            if (hasAuthError)
            {
                return(new Batch_Sale_Submit_Result
                {
                    isSubmitSuccess = false,
                    ErrorCode = "AUTH",
                    ErrorMessage = errors
                });
            }

            XmlNodeList nodes = res_xml.SelectNodes("/API/sub/*[@note]");

            foreach (XmlNode tag in nodes)
            {
                var note = tag.Attributes["note"].Value.ToLower();
                if (note.Contains("invalid") || note.Contains("fail"))
                {
                    errors += tag.Name + ": " + note + ",";
                }
            }

            if (errors.Length > 0)
            {
                errors.Remove(errors.Length - 1);
            }

            var adate    = res_xml.SelectNodes("/API/sub/adate")[0];
            var xml_node = res_xml.SelectNodes("/API/sub/xml")[0];
            var records  = res_xml.SelectNodes("/API/sub/records")[0];
            var amount   = res_xml.SelectNodes("/API/sub/amount")[0];
            var subid_S  = res_xml.SelectNodes("/API/sub/subid")[0];

            int subid = 0;

            int.TryParse(subid_S.InnerText, out subid);

            if (subid <= 0)
            {
                return(new Batch_Sale_Submit_Result
                {
                    RequestXml = details.RequestFile + "<params>" + details.RequestParams + "</params>",
                    ResponseXml = res_xml.InnerXml,
                    isSubmitSuccess = false,
                    ErrorMessage = errors,
                    TransactionIdentifier = subid.ToString()
                });
            }
            else
            {
                Dictionary <string, string> ValidationReqParams = new Dictionary <string, string>();
                ValidationReqParams.Add("f", "subi");
                ValidationReqParams.Add("p", "1");
                ValidationReqParams.Add("cref", cref);
                ValidationReqParams.Add("subid", subid.ToString());

                int i = 0;
                while (i < 3)
                {
                    //check validation status

                    var status   = GatewayUtils.PostMultiPartXMLTransaction(URL, ValidationReqParams, new XmlDocument[] { }, cookieJar);
                    var stat_xml = new XmlDocument();
                    stat_xml.LoadXml(status);

                    var apiProcessingNode = stat_xml.SelectNodes("/subs/sub/apiprocessing")[0];
                    var apiProcessing     = int.Parse(apiProcessingNode.InnerText);

                    if (apiProcessing < 3)
                    {
                        i++;
                    }
                    else
                    {
                        i = 3; //kill while loop
                        if (apiProcessing == 3)
                        {
                            return(new Batch_Sale_Submit_Result
                            {
                                RequestXml = details.RequestFile + "<params>" + details.RequestParams + "</params>",
                                ResponseXml = res_xml.InnerXml,
                                isSubmitSuccess = true,
                                ErrorMessage = subid_S.Attributes["note"].InnerText,
                                TransactionIdentifier = subid.ToString()
                            });
                        }
                        else
                        {
                            return(new Batch_Sale_Submit_Result
                            {
                                RequestXml = details.RequestFile + "<params>" + details.RequestParams + "</params>",
                                ResponseXml = res_xml.InnerXml,
                                isSubmitSuccess = false,
                                ErrorMessage = "Failed Validation",
                                TransactionIdentifier = subid.ToString()
                            });
                        }
                    }
                }


                return(new Batch_Sale_Submit_Result
                {
                    RequestXml = (details.RequestFile + "<params>" + details.RequestParams + "</params>").Replace("UTF-8", "UTF-16"),
                    ResponseXml = res_xml.InnerXml,
                    isSubmitSuccess = subid > 0,
                    ErrorMessage = "Validation took too long, success was assumed.",
                    TransactionIdentifier = subid.ToString()
                });
            }
        }