Exemple #1
0
        public Transaction_Result Refund(Refund_Details details)
        {
            try
            {
                var     xmlString = getRefundXML(PayGateID, Password, details.TransactionIndex, details.Amount.HasValue ? (details.Amount * 100).ToString() : "");
                var     xml       = GatewayUtils.PostXMLTransaction(url, xmlString);
                XmlNode protocol  = xml.GetElementsByTagName("protocol").Item(0);
                XmlNode errorNode = protocol.SelectNodes("errorrx").Item(0);

                var reqXmlDoc = new XmlDocument();
                reqXmlDoc.LoadXml(xmlString);

                var reqstringwriter = new System.IO.StringWriter();
                reqXmlDoc.Save(reqstringwriter);

                var respstringwriter = new System.IO.StringWriter();
                xml.Save(respstringwriter);

                if (errorNode == null)
                {
                    XmlNode successNode       = protocol.SelectNodes("refundrx").Item(0);
                    string  transactionID     = successNode.Attributes.GetNamedItem("tid").Value;   //The unique reference number assign by PayGate to the original transaction.
                    string  customerReference = successNode.Attributes.GetNamedItem("cref").Value;  //This is your reference number for use by your internal systems. Must be different per transaction
                    string  status            = successNode.Attributes.GetNamedItem("stat").Value;  //Transaction status.
                    string  statusDesc        = successNode.Attributes.GetNamedItem("sdesc").Value; //Transaction status description.
                    string  resultCode        = successNode.Attributes.GetNamedItem("res").Value;   //Result Code
                    string  resultDesc        = successNode.Attributes.GetNamedItem("rdesc").Value; //Result Code description.
                    return(new Transaction_Result
                    {
                        TransactionIndex = transactionID,
                        isApproved = status != "0" && status != "2",
                        ApprovalCode = statusDesc,
                        ResultCode = resultCode,
                        ResultText = resultDesc,
                        FullRequest = reqstringwriter.ToString(),
                        FullResponse = respstringwriter.ToString()
                    });
                }
                else
                {
                    string errorCode = errorNode.Attributes.GetNamedItem("ecode").Value;
                    string errorDesc = errorNode.Attributes.GetNamedItem("edesc").Value;

                    return(new Transaction_Result
                    {
                        isApproved = false,
                        hasServerError = false,
                        ErrorCode = errorCode,
                        ErrorText = errorDesc,
                    });
                }
            }
            catch (Exception ex)
            {
                return(new Transaction_Result
                {
                    isApproved = false,
                    hasServerError = true,
                    ErrorText = ex.Message
                });
            }
        }
Exemple #2
0
        public Transaction_Result Auth(Sale_Details details)
        {
            try
            {
                var xmlString = getAuthXML(
                    PayGateID,
                    Password,
                    details.ExtRef,
                    details.CustomerFirstName + " " + details.CustomerLastName,
                    details.CardNumber,
                    GatewayUtils.formatExpiryDate(details.CardExpiryMonth, details.CardExpiryYear),
                    "0",                                    //budget period 0 == Straight
                    (details.Amount * 100).ToString("F0"),  //takes amounts in cents
                    details.CurrencyCode,
                    details.CardCCV
                    );

                var     xml       = GatewayUtils.PostXMLTransaction(url, xmlString);
                XmlNode protocol  = xml.GetElementsByTagName("protocol").Item(0);
                XmlNode errorNode = protocol.SelectNodes("errorrx").Item(0);

                string cardnumber = details.CardNumber;
                Regex  rgx        = new Regex(@"[^\d]");
                cardnumber = rgx.Replace(cardnumber, String.Empty); //removes dashes spaces, etc
                string last4digits = cardnumber.Substring(details.CardNumber.Length - 4);

                var stringwriter = new System.IO.StringWriter();
                var serializer   = new XmlSerializer(details.GetType());
                serializer.Serialize(stringwriter, details);
                var fullrequest = stringwriter.ToString();

                fullrequest = fullrequest.Replace(cardnumber, last4digits);
                fullrequest = fullrequest.Replace(details.CardCCV, "***");

                var respstringwriter = new System.IO.StringWriter();
                xml.Save(respstringwriter);

                if (errorNode == null)
                {
                    XmlNode successNode       = protocol.SelectNodes("authrx").Item(0);
                    string  transactionID     = successNode.Attributes.GetNamedItem("tid").Value;   //The unique reference number assign by PayGate to the original transaction.
                    string  customerReference = successNode.Attributes.GetNamedItem("cref").Value;  //This is your reference number for use by your internal systems. Must be different per transaction
                    string  status            = successNode.Attributes.GetNamedItem("stat").Value;  //Transaction status.
                    string  statusDesc        = successNode.Attributes.GetNamedItem("sdesc").Value; //Transaction status description.
                    string  resultCode        = successNode.Attributes.GetNamedItem("res").Value;   //Result Code
                    string  resultDesc        = successNode.Attributes.GetNamedItem("rdesc").Value; //Result Code description.
                    string  authCode          = successNode.Attributes.GetNamedItem("auth").Value;  //The Authorisation code returned by the acquirer (bank).
                    string  risk         = successNode.Attributes.GetNamedItem("risk").Value;       //X - NA, A - Authenticated, N - Not Authenticated This is a 2-character field containing a risk indicator for this transaction.
                    string  cardTypeCode = successNode.Attributes.GetNamedItem("ctype").Value;      //Card type code 0 - Unknown, 1 - Visa, 2 - MasterCard, 3 - Amex, 4 - Diners
                    return(new Transaction_Result
                    {
                        TransactionIndex = transactionID,
                        isApproved = status != "0" && status != "2",
                        hasServerError = false,
                        ApprovalCode = statusDesc,
                        ResultCode = resultCode,
                        ResultText = resultDesc,
                        ProcessorCode = authCode,
                        FullRequest = fullrequest,
                        FullResponse = xml.OuterXml
                    });
                }
                else
                {
                    string errorCode = errorNode.Attributes.GetNamedItem("ecode").Value;
                    string errorDesc = errorNode.Attributes.GetNamedItem("edesc").Value;

                    return(new Transaction_Result
                    {
                        isApproved = false,
                        hasServerError = false,
                        ErrorCode = errorCode,
                        ErrorText = errorDesc,
                    });
                }
            }
            catch (Exception ex)
            {
                return(new Transaction_Result
                {
                    isApproved = false,
                    hasServerError = true,
                    ErrorText = ex.Message
                });
            }
        }