Example #1
0
        public override void ProcessTransaction(Transaction t)
        {
            bool result = false;

            try
            {
                string url = LiveUrl;
                if (Settings.DeveloperMode)
                {
                    url = DeveloperUrl;
                }

                // Build Data String
                // Card Number and Expiration
                string expDate = string.Empty;
                if (t.Card.ExpirationMonth < 10)
                {
                    expDate = "0" + t.Card.ExpirationMonth.ToString();
                }
                else
                {
                    expDate = t.Card.ExpirationMonth.ToString();
                }
                if (t.Card.ExpirationYear > 99)
                {
                    expDate += t.Card.ExpirationYear.ToString().Substring(2, 2);
                }
                else
                {
                    expDate += t.Card.ExpirationYear.ToString();
                }


                // Set Parameters
                StringBuilder sb       = new StringBuilder();
                string        postData = string.Empty;

                sb.Append("UserName="******"&Password="******"&Amount=");
                sb.Append(SafeWriteString(t.Amount.ToString()));
                sb.Append("&InvNum=");
                sb.Append(SafeWriteString(t.MerchantInvoiceNumber));
                sb.Append("&Street=");
                sb.Append(SafeWriteString(t.Customer.Street));
                sb.Append("&Zip=");
                sb.Append(SafeWriteString(t.Customer.PostalCode));
                sb.Append("&NameOnCard=");
                sb.Append(SafeWriteString(t.Card.CardHolderName));

                sb.Append("&MagData=");

                // Extra Tags
                StringBuilder sbextra = new StringBuilder();
                sbextra.Append("<CustomerId>" + TextHelper.XmlEncode(t.Customer.Email) + "</CustomerId>");
                sbextra.Append("<City>" + TextHelper.XmlEncode(t.Customer.City) + "</City>");
                if (t.Customer.Region != string.Empty)
                {
                    sbextra.Append("<BillToState>" + TextHelper.XmlEncode(t.Customer.Region) + "</BillToState>");
                }
                if (Settings.TrainingMode)
                {
                    sbextra.Append("<TrainingMode>T</TrainingMode>");
                }
                sbextra.Append("<EntryMode>MANUAL</EntryMode>");

                switch (t.Action)
                {
                case ActionType.CreditCardCharge:
                    // Charge
                    sb.Append("&TransType=");
                    sb.Append(SafeWriteString("Sale"));
                    sb.Append("&PNRef=");
                    break;

                case ActionType.CreditCardHold:
                    // Authorize
                    sb.Append("&TransType=");
                    sb.Append(SafeWriteString("Auth"));
                    sb.Append("&PNRef=");
                    break;

                case ActionType.CreditCardCapture:
                    // Capture, Post Authorize
                    sb.Append("&TransType=");
                    sb.Append(SafeWriteString("Force"));
                    sb.Append("&PNRef=");
                    sb.Append(SafeWriteString(t.PreviousTransactionNumber));
                    sbextra.Append("<AuthCode>" + t.PreviousTransactionAuthCode + "</AuthCode>");
                    break;

                case ActionType.CreditCardVoid:
                    // Void
                    sb.Append("&TransType=");
                    sb.Append(SafeWriteString("Void"));
                    sb.Append("&PNRef=");
                    sb.Append(SafeWriteString(t.PreviousTransactionNumber));
                    break;

                case ActionType.CreditCardRefund:
                    // Refund, Credit
                    sb.Append("&TransType=");
                    sb.Append(SafeWriteString("Return"));
                    sb.Append("&PNRef=");
                    sb.Append(SafeWriteString(t.PreviousTransactionNumber));
                    break;
                }

                // Add Card Number, CVV Code and Expiration Date
                sb.Append("&CardNum=");
                sb.Append(SafeWriteString(t.Card.CardNumber));

                sb.Append("&CVNum=");
                if (t.Card.SecurityCode.Length > 0)
                {
                    sb.Append(SafeWriteString(t.Card.SecurityCode));
                }

                sb.Append("&ExpDate=");
                if (t.Action != ActionType.CreditCardVoid)
                {
                    sb.Append(SafeWriteString(expDate));
                }

                // Write Extra Tags
                sb.Append("&ExtData=");
                sb.Append(SafeWriteString(sbextra.ToString()));


                // Dump string builder to string to send to Authorize.Net
                postData = sb.ToString();

                string xmlresponse = string.Empty;
                try
                {
                    xmlresponse = NetworkUtilities.SendRequestByPost(url, postData);
                }
                catch (Exception ex)
                {
                    throw new ArgumentException("Error: URL|" + url + "  POST|" + postData + " RESPONSE|" + xmlresponse + " :: " + ex.Message);
                }

                if (Settings.EnableDebugTracing)
                {
                    t.Result.Messages.Add(new Message(postData, "TRACE-POST:", MessageType.Error));
                    t.Result.Messages.Add(new Message(xmlresponse, "TRACE-REPLY:", MessageType.Error));
                }

                XDocument       response = XDocument.Parse(xmlresponse);
                XNamespace      ns       = response.Root.Attribute("xmlns").Value ?? "";
                PayLeapResponse r        = new PayLeapResponse();
                r.Parse(response);

                if (r != null)
                {
                    t.Result.CvvCode                 = CvnResponseType.Unavailable;
                    t.Result.ResponseCode            = r.AuthCode;
                    t.Result.ResponseCodeDescription = r.Message;
                    t.Result.ReferenceNumber         = r.PNRef;
                    t.Result.ReferenceNumber2        = r.AuthCode;
                    t.Result.AvsCode                 = ParseAvsCode(r.GetAVSResult);

                    if (r.Result == "0")
                    {
                        result = true;
                    }
                    else
                    {
                        result = false;
                        t.Result.Messages.Add(new Message(r.RespMSG, r.AuthCode, MessageType.Warning));
                    }
                }
            }
            catch (Exception ex)
            {
                result = false;
                t.Result.Messages.Add(new Message("Unknown Payment Error: " + ex.Message, "BVP_PL_1001", MessageType.Error));
                t.Result.Messages.Add(new Message("Stack Trace " + ex.StackTrace, "STACKTRACE", MessageType.Error));
            }

            t.Result.Succeeded = result;
        }
Example #2
0
        public override void ProcessTransaction(Transaction t)
        {
            bool result = false;

            try
            {
                string url = LiveUrl;                
                if (Settings.DeveloperMode)
                {
                    url = DeveloperUrl;
                }
                
                // Build Data String
                // Card Number and Expiration
                string expDate = string.Empty;
                if (t.Card.ExpirationMonth < 10)
                {
                    expDate = "0" + t.Card.ExpirationMonth.ToString();
                }
                else
                {
                    expDate = t.Card.ExpirationMonth.ToString();
                }
                if (t.Card.ExpirationYear > 99)
                {
                    expDate += t.Card.ExpirationYear.ToString().Substring(2, 2);
                }
                else
                {
                    expDate += t.Card.ExpirationYear.ToString();
                }


                // Set Parameters
                StringBuilder sb = new StringBuilder();
                string postData = string.Empty;

                sb.Append("UserName="******"&Password="******"&Amount=");
                sb.Append(SafeWriteString(t.Amount.ToString()));
                sb.Append("&InvNum=");
                sb.Append(SafeWriteString(t.MerchantInvoiceNumber));                
                sb.Append("&Street=");
                sb.Append(SafeWriteString(t.Customer.Street));                                
                sb.Append("&Zip=");
                sb.Append(SafeWriteString(t.Customer.PostalCode));
                sb.Append("&NameOnCard=");
                sb.Append(SafeWriteString(t.Card.CardHolderName));

                sb.Append("&MagData=");

                // Extra Tags
                StringBuilder sbextra = new StringBuilder();
                sbextra.Append("<CustomerId>" + TextHelper.XmlEncode(t.Customer.Email) + "</CustomerId>");
                sbextra.Append("<City>" + TextHelper.XmlEncode(t.Customer.City) + "</City>");                
                if (t.Customer.Region != string.Empty)
                {
                    sbextra.Append("<BillToState>" + TextHelper.XmlEncode(t.Customer.Region) + "</BillToState>");                                        
                }                
                if (Settings.TrainingMode)
                {
                    sbextra.Append("<TrainingMode>T</TrainingMode>");
                }
                sbextra.Append("<EntryMode>MANUAL</EntryMode>");
                               
                switch (t.Action)
                {
                    case ActionType.CreditCardCharge:
                        // Charge
                        sb.Append("&TransType=");
                        sb.Append(SafeWriteString("Sale"));
                        sb.Append("&PNRef=");
                        break;
                    case ActionType.CreditCardHold:
                        // Authorize
                        sb.Append("&TransType=");
                        sb.Append(SafeWriteString("Auth"));
                        sb.Append("&PNRef=");
                        break;
                    case ActionType.CreditCardCapture:
                        // Capture, Post Authorize
                        sb.Append("&TransType=");
                        sb.Append(SafeWriteString("Force"));
                        sb.Append("&PNRef=");
                        sb.Append(SafeWriteString(t.PreviousTransactionNumber));
                        sbextra.Append("<AuthCode>" + t.PreviousTransactionAuthCode + "</AuthCode>");
                        break;
                    case ActionType.CreditCardVoid:
                        // Void
                        sb.Append("&TransType=");
                        sb.Append(SafeWriteString("Void"));
                        sb.Append("&PNRef=");
                        sb.Append(SafeWriteString(t.PreviousTransactionNumber));                        
                        break;
                    case ActionType.CreditCardRefund:
                        // Refund, Credit
                        sb.Append("&TransType=");
                        sb.Append(SafeWriteString("Return"));
                        sb.Append("&PNRef=");
                        sb.Append(SafeWriteString(t.PreviousTransactionNumber));                        
                        break;
                }

                // Add Card Number, CVV Code and Expiration Date
                sb.Append("&CardNum=");
                sb.Append(SafeWriteString(t.Card.CardNumber));
                
                    sb.Append("&CVNum=");
                    if (t.Card.SecurityCode.Length > 0)
                    {
                    sb.Append(SafeWriteString(t.Card.SecurityCode));
                    }

                    sb.Append("&ExpDate=");
                    if (t.Action != ActionType.CreditCardVoid)
                    {
                    sb.Append(SafeWriteString(expDate));
                    }

                // Write Extra Tags
                sb.Append("&ExtData=");
                sb.Append(SafeWriteString(sbextra.ToString()));
               

                // Dump string builder to string to send to Authorize.Net
                postData = sb.ToString();

                string xmlresponse = string.Empty;
                try
                {
                    xmlresponse = NetworkUtilities.SendRequestByPost(url, postData);
                }
                catch (Exception ex)
                {
                    throw new ArgumentException("Error: URL|" + url + "  POST|" + postData + " RESPONSE|" + xmlresponse + " :: " + ex.Message); 
                }

                if (Settings.EnableDebugTracing)
                {
                   t.Result.Messages.Add(new Message(postData,"TRACE-POST:", MessageType.Error));
                    t.Result.Messages.Add(new Message(xmlresponse,"TRACE-REPLY:", MessageType.Error));
                }

                XDocument response = XDocument.Parse(xmlresponse);
                XNamespace ns = response.Root.Attribute("xmlns").Value ?? "";
                PayLeapResponse r = new PayLeapResponse();
                r.Parse(response);                

                if (r != null)
                {
                    t.Result.CvvCode = CvnResponseType.Unavailable;
                    t.Result.ResponseCode = r.AuthCode;
                    t.Result.ResponseCodeDescription = r.Message;
                    t.Result.ReferenceNumber = r.PNRef;
                    t.Result.ReferenceNumber2 = r.AuthCode;
                    t.Result.AvsCode = ParseAvsCode(r.GetAVSResult);

                    if (r.Result == "0")
                    {
                        result = true;
                    }
                    else
                    {
                        result = false;
                        t.Result.Messages.Add(new Message(r.RespMSG, r.AuthCode, MessageType.Warning));
                    }
                }                                
                                                      
            }
            catch (Exception ex)
            {
                result = false;
                t.Result.Messages.Add(new Message("Unknown Payment Error: " + ex.Message, "BVP_PL_1001", MessageType.Error));
                t.Result.Messages.Add(new Message("Stack Trace " + ex.StackTrace, "STACKTRACE", MessageType.Error));
            }

            t.Result.Succeeded = result;
         
        }