Example #1
0
        public FirstPayXmlResponse QueryGatewayForOrder(int orderNumber)
        {
            string result = AppLogic.ro_OK;
            bool   useLiveTransactions = AppLogic.AppConfigBool("UseLiveTransactions");

            try
            {
                Encoding           encoding           = System.Text.Encoding.GetEncoding(1252);
                FirstPayXmlCommand transactionCommand = new FirstPayXmlCommand(transaction_center_id.ToString(), gateway_id, processor_id);

                transactionCommand.Query(orderNumber.ToString(), DateTime.Today.AddDays(-1), DateTime.Today.AddDays(1));

                string rawResponseString = "";
                FirstPayXmlResponse xmlResponse;

                if (GetXmlResponse(transactionCommand.InnerXml, out rawResponseString, out xmlResponse))
                {
                    return(xmlResponse);
                }
            }
            catch { }


            return(null);
        }
Example #2
0
        // if RefundAmount == 0.0M, then then ENTIRE order amount will be refunded!
        public override string RefundOrder(int originalOrderNumber, int newOrderNumber, decimal refundAmount, string refundReason, Address useBillingAddress)
        {
            string result = AppLogic.ro_OK;
            bool   useLiveTransactions = AppLogic.AppConfigBool("UseLiveTransactions");

            //Will add parameters to this as we get data back from other querys etc. So I don't have to repeat code
            List <SqlParameter> sqlParams = new List <SqlParameter>();

            sqlParams.Add(new SqlParameter("@OrderNumber", originalOrderNumber));

            using (SqlConnection dbconn = DB.dbConn())
            {
                dbconn.Open();
                using (SqlCommand cmd = new SqlCommand("update orders set RefundTXCommand=NULL, RefundTXResult=NULL where OrderNumber=@OrderNumber;", dbconn))
                {
                    cmd.Parameters.AddRange(sqlParams.ToArray());
                    cmd.ExecuteNonQuery();
                    cmd.Parameters.Clear();
                }
            }

            string   TransID           = "";
            string   AuthorizationCode = "";
            Decimal  OrderTotal        = System.Decimal.Zero;
            Order    order             = new Order(originalOrderNumber);
            Customer ThisCustomer      = new Customer(order.CustomerID);

            using (SqlConnection dbconn = DB.dbConn())
            {
                dbconn.Open();
                using (SqlCommand cmd = new SqlCommand("select * from orders with (NOLOCK)  where OrderNumber=@OrderNumber;", dbconn))
                {
                    cmd.Parameters.AddRange(sqlParams.ToArray());
                    using (IDataReader rs = cmd.ExecuteReader())
                    {
                        if (rs.Read())
                        {
                            TransID           = DB.RSField(rs, "AuthorizationPNREF");
                            AuthorizationCode = DB.RSField(rs, "AuthorizationCode");
                            OrderTotal        = DB.RSFieldDecimal(rs, "OrderTotal");
                        }
                    }
                    cmd.Parameters.Clear();
                }
            }

            if (TransID.Length == 0 || TransID == "0")
            {
                result = "Invalid or Empty Transaction ID";
            }
            else
            {
                try
                {
                    string[] TXInfo = TransID.Split('|');

                    Encoding           encoding           = System.Text.Encoding.GetEncoding(1252);
                    FirstPayXmlCommand transactionCommand = new FirstPayXmlCommand(transaction_center_id.ToString(), gateway_id, processor_id);

                    transactionCommand.Credit(TXInfo[0], Localization.CurrencyStringForGatewayWithoutExchangeRate(refundAmount == System.Decimal.Zero ? OrderTotal : refundAmount));

                    string rawResponseString = "";
                    FirstPayXmlResponse xmlResponse;

                    if (GetXmlResponse(transactionCommand.InnerXml, out rawResponseString, out xmlResponse))
                    {
                        string responseCode            = "";
                        string responseError           = "";
                        string authResponse            = "";
                        string responseReferenceNumber = "";

                        if (xmlResponse.Fields.Count > 0)
                        {
                            responseCode            = xmlResponse.Fields.ContainsKey("status1") ? xmlResponse.Fields["status1"] : "";
                            authResponse            = xmlResponse.Fields.ContainsKey("response1") ? xmlResponse.Fields["response1"] : "";
                            responseError           = xmlResponse.Fields.ContainsKey("error1") ? xmlResponse.Fields["error1"] : "";
                            responseReferenceNumber = xmlResponse.Fields.ContainsKey("reference_number1") ? xmlResponse.Fields["reference_number1"] : "";
                        }

                        if (responseCode == "1")
                        {
                            result = AppLogic.ro_OK;
                        }
                        else if (responseCode == "2")
                        {
                            result = "REJECTED";
                            if (authResponse.Length > 0)
                            {
                                result += ". " + authResponse;
                                result += " : This order may not have settled yet, try void instead.";
                            }
                        }
                        else if (responseCode == "0")
                        {
                            result = "Error: " + authResponse + " | " + responseError;
                        }
                        else
                        {
                            result = "System Error: " + rawResponseString;
                        }

                        OrderTransactionCollection transactions = new OrderTransactionCollection(order.OrderNumber);
                        transactions.AddTransaction(AppLogic.ro_TXStateRefunded, transactionCommand.InnerXml.Replace(gateway_id, "***"), rawResponseString, responseReferenceNumber, responseCode, AppLogic.ro_PMCreditCard, DisplayName(ThisCustomer.LocaleSetting), order.OrderBalance);

                        sqlParams.Add(new SqlParameter("@Result", result));
                        sqlParams.Add(new SqlParameter("@Command", transactionCommand.InnerXml.Replace(gateway_id, "***")));

                        if (result == AppLogic.ro_OK)
                        {
                            using (SqlConnection dbconn = DB.dbConn())
                            {
                                dbconn.Open();
                                using (SqlCommand cmd = new SqlCommand("update orders set RefundTXResult=@Result, RefundTXCommand=@Command where OrderNumber=@OrderNumber;", dbconn))
                                {
                                    cmd.Parameters.AddRange(sqlParams.ToArray());
                                    cmd.ExecuteNonQuery();
                                    cmd.Parameters.Clear();
                                }
                            }
                        }
                        else
                        {
                            using (SqlConnection dbconn = DB.dbConn())
                            {
                                dbconn.Open();
                                using (SqlCommand cmd = new SqlCommand("update orders set RefundTXResult=@Result, RefundTXCommand=@Command where OrderNumber=@OrderNumber;", dbconn))
                                {
                                    cmd.Parameters.AddRange(sqlParams.ToArray());
                                    cmd.ExecuteNonQuery();
                                    cmd.Parameters.Clear();
                                }
                            }
                        }
                    }
                    else
                    {
                        result = "Error calling 1stPay gateway.";
                    }
                }
                catch (Exception ex)
                {
                    result = ex.Message;
                }
            }
            return(result);
        }
Example #3
0
        //Settle should be run here if site is setup for auth/capture, Payment Module will always be processing a transactions as an Auth
        public override string ProcessCard(int orderNumber, int customerID, Decimal orderTotal, bool useLiveTransactions, TransactionModeEnum transactionMode, Address useBillingAddress, string cardExtraCode, Address useShippingAddress, string CAVV, string ECI, string XID, out string AVSResult, out string authorizationResult, out string authorizationCode, out string authorizationTransID, out string transactionCommandOut, out string transactionResponse)
        {
            Customer ThisCustomer = new Customer(customerID, true);

            authorizationResult = AVSResult = authorizationCode = authorizationTransID = transactionCommandOut = transactionResponse = "";
            string approvalCode            = "";
            string AVSCode                 = AVSResult = "";
            string CVCode                  = "";
            string responseCode            = "";
            string responseError           = "";
            string responseReferenceNumber = "";
            string authResponse            = "";
            string TransID                 = "";
            string TransStatus             = "";
            string result                  = AppLogic.ro_OK;

            if (ThisCustomer != null && ThisCustomer.CustomerID > 0)
            {
                if (ThisCustomer.IsAdminUser && (AppLogic.ExceedsFailedTransactionsThreshold(ThisCustomer) || AppLogic.IPIsRestricted(ThisCustomer.LastIPAddress)))
                {
                    return(AppLogic.GetString("gateway.FailedTransactionThresholdExceeded", ThisCustomer.SkinID, ThisCustomer.LocaleSetting));
                }
            }

            Encoding           encoding           = System.Text.Encoding.GetEncoding(1252);
            FirstPayXmlCommand transactionCommand = new FirstPayXmlCommand(transaction_center_id.ToString(), gateway_id, processor_id);

            if (transactionMode == TransactionModeEnum.authcapture)
            {
                transactionCommand.Settle(XID, Localization.CurrencyStringForGatewayWithoutExchangeRate(orderTotal));
            }
            else
            {
                transactionCommand.Query(orderNumber.ToString(), DateTime.Today.AddDays(-1), DateTime.Today.AddDays(1));
            }

            string rawResponseString = "";
            FirstPayXmlResponse xmlResponse;

            if (GetXmlResponse(transactionCommand.InnerXml, out rawResponseString, out xmlResponse))
            {
                if (xmlResponse.Fields.Count > 0)
                {
                    responseCode            = xmlResponse.Fields.ContainsKey("status1") ? xmlResponse.Fields["status1"] : (xmlResponse.Fields.ContainsKey("trans_status1") ? xmlResponse.Fields["trans_status1"] : "");
                    authResponse            = xmlResponse.Fields.ContainsKey("response1") ? xmlResponse.Fields["response1"] : "";
                    responseError           = xmlResponse.Fields.ContainsKey("error1") ? xmlResponse.Fields["error1"] : (xmlResponse.Fields.ContainsKey("error") ? xmlResponse.Fields["error"] : "");
                    TransStatus             = xmlResponse.Fields.ContainsKey("trans_status1") ? xmlResponse.Fields["trans_status1"] : null;
                    responseReferenceNumber = xmlResponse.Fields.ContainsKey("reference_number1") ? xmlResponse.Fields["reference_number1"] : "";
                }

                // rawResponseString now has gateway response
                transactionResponse = rawResponseString;

                authorizationCode    = approvalCode;
                authorizationResult  = rawResponseString;
                authorizationTransID = TransID;
                AVSResult            = AVSCode;
                if (CVCode.Length > 0)
                {
                    AVSResult += ", CV Result: " + CVCode;
                }
                transactionCommandOut = transactionCommand.InnerXml.Replace(gateway_id, "***");

                if (responseCode == "1" && (string.IsNullOrEmpty(TransStatus) || TransStatus == "1"))
                {
                    result = AppLogic.ro_OK;
                }
                else if (responseCode == "2")
                {
                    result = "DECLINED";
                    if (authResponse.Length > 0)
                    {
                        result += ". " + authResponse;
                    }
                }
                else if (responseCode == "0")
                {
                    result = "Error: " + authResponse + " | " + responseError;
                }
                else
                {
                    result = "System Error: " + rawResponseString;
                }

                if (transactionMode == TransactionModeEnum.authcapture)
                {
                    OrderTransactionCollection transactions = new OrderTransactionCollection(orderNumber);
                    transactions.AddTransaction(AppLogic.ro_TXStateCaptured, transactionCommand.InnerXml.Replace(gateway_id, "***"), rawResponseString, responseReferenceNumber, responseCode, AppLogic.ro_PMCreditCard, DisplayName(ThisCustomer.LocaleSetting), orderTotal);
                }
            }
            else
            {
                result = "Error calling 1stPay gateway.";
            }
            if (result != AppLogic.ro_OK)
            {
                string         IP        = "";
                SqlParameter[] sqlParams = { new SqlParameter("@CustomerID", customerID)
                                             ,                               new SqlParameter("@OrderNumber", orderNumber)
                                             ,                               new SqlParameter("@IP", IP)
                                             ,                               new SqlParameter("@Gateway", DisplayName(ThisCustomer.LocaleSetting))
                                             ,                               new SqlParameter("@PaymentMethod", AppLogic.ro_PMCreditCard)
                                             ,                               new SqlParameter("@Command", transactionCommandOut)
                                             ,                               new SqlParameter("@Result", transactionResponse) };

                if (ThisCustomer != null)
                {
                    IP = ThisCustomer.LastIPAddress;
                }
                string sql = "insert into FailedTransaction(CustomerID,OrderNumber,IPAddress,OrderDate,PaymentGateway,PaymentMethod,TransactionCommand,TransactionResult) "
                             + "values(@CustomerID,@OrderNumber,@IP,getdate(),@Gateway,@PaymentMethod,@Command,@Result)";

                using (SqlConnection dbconn = DB.dbConn())
                {
                    dbconn.Open();
                    using (SqlCommand cmd = new SqlCommand(sql, dbconn))
                    {
                        cmd.Parameters.AddRange(sqlParams.ToArray());
                        cmd.ExecuteNonQuery();
                        cmd.Parameters.Clear();
                    }
                }
            }

            return(result);
        }
Example #4
0
        public override string CaptureOrder(Order order)
        {
            string   result = AppLogic.ro_OK;
            bool     useLiveTransactions = AppLogic.AppConfigBool("UseLiveTransactions");
            Customer ThisCustomer        = new Customer(order.CustomerID, true);

            order.CaptureTXCommand = "";
            order.CaptureTXResult  = "";

            string  TransID           = order.AuthorizationPNREF;
            Decimal OrderTotal        = order.OrderBalance;
            string  AuthorizationCode = order.AuthorizationCode;

            order.CaptureTXCommand = TransID;

            if (string.IsNullOrEmpty(TransID) || TransID.Length == 0 || TransID == "0")
            {
                result = "Invalid or Empty Transaction ID";
            }
            else
            {
                try
                {
                    string[] TXInfo = TransID.Split('|');

                    Encoding           encoding           = System.Text.Encoding.GetEncoding(1252);
                    FirstPayXmlCommand transactionCommand = new FirstPayXmlCommand(transaction_center_id.ToString(), gateway_id, processor_id);

                    transactionCommand.Settle(TXInfo[0], Localization.CurrencyStringForGatewayWithoutExchangeRate(OrderTotal));

                    string rawResponseString = "";
                    FirstPayXmlResponse xmlResponse;

                    if (GetXmlResponse(transactionCommand.InnerXml, out rawResponseString, out xmlResponse))
                    {
                        string responseCode            = "";
                        string responseError           = "";
                        string authResponse            = "";
                        string responseReferenceNumber = "";

                        if (xmlResponse.Fields.Count > 0)
                        {
                            responseCode            = xmlResponse.Fields.ContainsKey("status1") ? xmlResponse.Fields["status1"] : "";
                            authResponse            = xmlResponse.Fields.ContainsKey("response1") ? xmlResponse.Fields["response1"] : "";
                            responseError           = xmlResponse.Fields.ContainsKey("error1") ? xmlResponse.Fields["error1"] : "";
                            responseReferenceNumber = xmlResponse.Fields.ContainsKey("reference_number1") ? xmlResponse.Fields["reference_number1"] : "";
                        }

                        if (responseCode == "1")
                        {
                            result = AppLogic.ro_OK;
                        }
                        else if (responseCode == "2")
                        {
                            result = "REJECTED";
                            if (authResponse.Length > 0)
                            {
                                result += ". " + authResponse;
                            }
                        }
                        else if (responseCode == "0")
                        {
                            result = "Error: " + authResponse + " | " + responseError;
                        }
                        else
                        {
                            result = "System Error: " + rawResponseString;
                        }

                        OrderTransactionCollection transactions = new OrderTransactionCollection(order.OrderNumber);
                        transactions.AddTransaction(AppLogic.ro_TXStateCaptured, transactionCommand.InnerXml.Replace(gateway_id, "***"), rawResponseString, responseReferenceNumber, responseCode, AppLogic.ro_PMCreditCard, DisplayName(ThisCustomer.LocaleSetting), OrderTotal);
                    }
                    else
                    {
                        result = "Error calling 1stPay gateway.";
                    }
                    order.CaptureTXResult  = result;
                    order.CaptureTXCommand = transactionCommand.InnerXml.Replace(gateway_id, "***");
                }
                catch (Exception ex)
                {
                    result = ex.Message;
                }
            }
            return(result);
        }