Exemplo n.º 1
0
        /// <summary>
        /// Captures the order.
        /// </summary>
        /// <param name="o">The sales order.</param>
        /// <returns> Status of the transaction </returns>
        public override String CaptureOrder(Order o)
        {
            // merchant account
            string token      = AppLogic.AppConfig("NETAXEPT.Merchant_Token");
            string merchantID = AppLogic.AppConfig("NETAXEPT.Merchant_Id");

            string responseText = string.Empty;
            string responseCode = string.Empty;

            // get the transaction string that was created of calling setup in the GetHTMLTicket
            string transactionString = Customer.Current.ThisCustomerSession["Nextaxept_TransactionString"];

            string sql = string.Format("SELECT TransactionCommand FROM Orders WHERE OrderNumber = {0}", o.OrderNumber.ToString());

            using (SqlConnection conn = new SqlConnection(DB.GetDBConn()))
            {
                conn.Open();
                using (IDataReader rs = DB.GetRS(sql, conn))
                {
                    if (rs.Read())
                    {
                        transactionString = DB.RSField(rs, "TransactionCommand");
                    }
                }
            }
            // This is the transaction string needed for capture
            string transID = o.AuthorizationPNREF;

            TokenService service = new TokenService();

            // the server url
            string url = string.Empty;

            if (AppLogic.AppConfigBool("UseLiveTransactions"))
            {
                url = AppLogic.AppConfig("NETAXEPT.Live_Server"); // use live
            }
            else
            {
                url = AppLogic.AppConfig("NETAXEPT.Test_Server"); // use test
            }

            service.Url = url;

            try
            {
                Result result     = null;
                Result authResult = null;

                result = service.ProcessSetup(token, merchantID, transactionString);

                if (result.ResponseCode.Equals("OK", StringComparison.OrdinalIgnoreCase))
                {
                    authResult = service.Capture(token, merchantID, transID, string.Empty, RemoveSeperatorFromAmount(o.OrderBalance), string.Empty);
                }

                // ResponseCode is the response from BBS or issuer
                o.CaptureTXResult = authResult.ResponseCode;
            }
            catch (Exception ex)
            {
                SoapException se = ex as SoapException;

                if (se != null)
                {
                    GetStatusCodeMessage(se, out responseText, out responseCode);
                    o.CaptureTXResult = responseCode;

                    if (!string.IsNullOrEmpty(responseText))
                    {
                        return(responseText);
                    }
                }

                return(ex.Message);
            }

            return(AppLogic.ro_OK);
        }