Example #1
0
        public Batch_Sale_Submit_Result Sale_Submit(Batch_Sale_Submit_Details details)
        {
            var client = getNIWSNIFClient();
            var result = client.BatchFileUpload(ServiceKey, details.RequestFile);

            var uploadReport = client.RequestFileUploadReport(ServiceKey, result);

            var isSuccess = !uploadReport.ToLower().Contains("unsuccessful");

            if (isSuccess)
            {
                return(new Batch_Sale_Submit_Result {
                    isSubmitSuccess = isSuccess, RequestXml = details.RequestFile, ResponseXml = uploadReport, TransactionIdentifier = result
                });
            }
            else
            {
                return(new Batch_Sale_Submit_Result {
                    ErrorMessage = uploadReport, isSubmitSuccess = isSuccess, RequestXml = details.RequestFile, ResponseXml = uploadReport, TransactionIdentifier = result
                });
            }
        }
        public Batch_Sale_Submit_Result Sale_Submit(Batch_Sale_Submit_Details details)
        {
            var returnXml = PostXMLTransaction("https://www.paygate.co.za/payxml/process.trans", details.RequestFile);

            //process results
            XmlNode protocol  = returnXml.GetElementsByTagName("protocol").Item(0);
            XmlNode errorNode = protocol.SelectNodes("errorrx").Item(0);

            if (errorNode == null)
            {
                XmlNode successNode = protocol.SelectNodes("authrx").Item(0);

                if (successNode == null)
                {
                    throw new Exception("Invalid results from gateway");
                }

                return(new Batch_Sale_Submit_Result
                {
                    RequestXml = details.RequestFile,
                    ResponseXml = returnXml.InnerXml.ToString(),
                    isSubmitSuccess = true,
                    TransactionIdentifier = successNode.Attributes.GetNamedItem("tid").Value
                });
            }
            else
            {
                return(new Batch_Sale_Submit_Result
                {
                    RequestXml = details.RequestFile,
                    ResponseXml = returnXml.InnerXml.ToString(),
                    isSubmitSuccess = false,
                    ErrorCode = errorNode.Attributes.GetNamedItem("ecode").Value,
                    ErrorMessage = errorNode.Attributes.GetNamedItem("edesc").Value
                });
            }
        }
Example #3
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()
                });
            }
        }
Example #4
0
        public Batch_Sale_Submit_Result Sale_Submit(Batch_Sale_Submit_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");
            }

            if (String.IsNullOrEmpty(details.RequestFile))
            {
                throw new Exception("Batch has to be built before submission");
            }
            #endregion

            string result = "";

            if (BankAccountEnabled)
            {
                var client = getDebitOrderClient();
                result = client.uploadDebitFile(details.RequestFile);
            }
            else if (CreditCardEnabled)
            {
                var client = getCollectionsClient();
                result = client.uploadDebitFile(details.RequestFile);
            }

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(result);

            XmlNodeList errorNodes = doc.GetElementsByTagName("debituploaderror");
            if (errorNodes.Count > 0)
            {
                //since the whole file wont go through if theres errors theres no need for us to process the error here
                return(new Batch_Sale_Submit_Result {
                    isSubmitSuccess = false, RequestXml = details.RequestFile, ResponseXml = result, ErrorMessage = errorNodes.ToString()
                });
            }
            else
            {
                XmlNodeList doResultNodes         = doc.GetElementsByTagName("debitorderresult");
                string      TransactionIdentifier = "";
                if (doResultNodes.Count > 0) //process successes
                {
                    var refNumNode = doResultNodes[0].SelectNodes("transactionreference").Item(0);
                    TransactionIdentifier = refNumNode.InnerText;
                }
                else
                {
                    throw new Exception("Invalid response from gateway");
                }

                return(new Batch_Sale_Submit_Result {
                    isSubmitSuccess = true, RequestXml = details.RequestFile, ResponseXml = result, TransactionIdentifier = TransactionIdentifier
                });
            }
        }