Exemple #1
0
        public Transaction_Result Auth(Sale_Details details)
        {
            try
            {
                var    gateway        = newClient();
                string cardtypestring = ((string)Enum.GetName(typeof(CardTypeEnum), details.CardType)).ToLower();
                string cardtypeval    = ""; //convert from string to mygate number
                switch (cardtypestring)
                {
                case ("american_express"):
                {
                    cardtypeval = "1";
                }
                break;

                case ("discover"):
                {
                    cardtypeval = "2";
                }
                break;

                case ("mastercard"):
                {
                    cardtypeval = "3";
                }
                break;

                case ("visa"):
                {
                    cardtypeval = "4";
                }
                break;

                case ("diners_club"):
                {
                    cardtypeval = "5";
                }
                break;

                default:
                {
                    cardtypeval = "-1";
                }
                break;
                }

                object[] arrResults = gateway.fProcess(
                    "01",                                                       //GatewayID
                    MerchantUID,                                                //MerchantUID
                    PaymentApplicationUID,                                      //ApplicationUID
                    "1",                                                        //1 Authorization Request                           //Action
                    "",                                                         //TransactionIndex
                    "Default",                                                  //Terminal
                    Mode,                                                       //Mode
                    details.ExtRef,                                             //MerchantReference
                    details.Amount.ToString("F2"),                              //Amount
                    details.CurrencyCode,                                       //Currency
                    "",                                                         //CashBackAmount
                    cardtypeval,                                                //CardType
                    "",                                                         //AccountType
                    details.CardNumber,                                         //CardNumber
                    details.CustomerFirstName + " " + details.CustomerLastName, //CardHolder
                    details.CardCCV,                                            //CCVNumber
                    details.CardExpiryMonth.ToString(),                         //ExpiryMonth
                    details.CardExpiryYear.ToString(),                          //ExpiryYear
                    "0",                                                        //Budget - 0 Straight, 1 budget
                    "",                                                         //BudgetPeriod
                    "",                                                         //AuthorizationNumber
                    "",                                                         //PIN
                    "",                                                         //DebugMode
                    "",                                                         //eCommerceIndicator
                    "",                                                         //verifiedByVisaXID
                    "",                                                         //verifiedByVisaCAFF
                    "",                                                         //secureCodeUCAF
                    "",                                                         //UCI
                    details.IPAddress,                                          //IP Address
                    details.CustomerCountryCodeTwoLetter,                       //Shipping Country Code,
                    ""                                                          //Purchase Items ID
                    );

                var results = formatResult(arrResults);

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

                var stringwriter = new System.IO.StringWriter();
                var xmlwriter    = XmlWriter.Create(stringwriter, new XmlWriterSettings {
                    NewLineHandling = NewLineHandling.None
                });
                var serializer = new XmlSerializer(details.GetType());
                serializer.Serialize(xmlwriter, details);
                var fullrequest = stringwriter.ToString();

                if (cardnumber.Length > 0) //added if statement because crashes if string length 0
                {
                    fullrequest = fullrequest.Replace(cardnumber, last4digits);
                }
                if (details.CardCCV.Length > 0) //added if statement because crashes if string length 0
                {
                    fullrequest = fullrequest.Replace(details.CardCCV, "***");
                }

                results.FullRequest = fullrequest;

                return(results);
            }
            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
                });
            }
        }