Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Request.IsSecureConnection)
            {
                AuthNetSettings settings = new AuthNetSettings(StoreSettings.GatewaySettings);
                if (!settings.IsTest)
                {
                    throw new ApplicationException(Localization.GetString("ErrorNotSecured", LocalResourceFile));
                }
            }

            if (!Page.IsPostBack)
            {
                btnProcess.Attributes.Add("OnClick", ScriptAvoidDoubleClick(btnProcess, Localization.GetString("Processing", LocalResourceFile)));
                string message = Localization.GetString("lblConfirmMessage", LocalResourceFile);
                lblConfirmMessage.Text = string.Format(message, PortalSettings.PortalName);
                for (int i = DateTime.Now.Year; i < DateTime.Now.Year + 10; i++)
                {
                    ddlYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
                }
                ddlMonth.Items.FindByValue(DateTime.Now.Month.ToString("00")).Selected = true;
            }
        }
Ejemplo n.º 2
0
        public TransactionResult ProcessTransaction(IAddressInfo shipping, IAddressInfo billing, OrderInfo orderInfo, TransactionDetails trans)
        {
            TransactionResult result = new TransactionResult();

            CultureInfo ciEnUs = new CultureInfo("en-US");

            // Check data before performing transaction
            AuthNetSettings settings = new AuthNetSettings(_gatewaySettings);

            if (!settings.IsValid())
            {
                result.Succeeded  = false;
                result.ResultCode = -3;

                return(result);
            }

            if (billing == null)
            {
                result.Succeeded  = false;
                result.ResultCode = -4;

                return(result);
            }

            if (trans == null || !trans.IsValid())
            {
                result.Succeeded  = false;
                result.ResultCode = -5;

                return(result);
            }

            // Gather transaction information
            string url = settings.GatewayURL;
            NameValueCollection NVCol = new NameValueCollection
            {
                // Merchant infos
                { "x_login", settings.Username },    //Req
                { "x_tran_key", settings.Password }, //Req
                { "x_version", settings.Version },   //Req
                { "x_test_request", settings.IsTest.ToString().ToUpper() },
                // Init infos
                { "x_delim_data", "TRUE" },
                { "x_delim_char", "|" },
                { "x_encap_char", "" },
                { "x_relay_response", "FALSE" }, //Req
                                                 //New in Store 3.1.10, added by Authorize in February 2014
                { "x_market_type", "0" },        // 0=eCommerce, 1 MOTO, 2 Retail
                                                 // Billing infos
                { "x_first_name", billing.FirstName },
                { "x_last_name", billing.LastName },
                { "x_company", "" },
                { "x_address", (billing.Address1 + " " + billing.Address2).Trim() },
                { "x_city", billing.City },
                { "x_state", billing.RegionCode },
                { "x_zip", billing.PostalCode },
                { "x_country", billing.CountryCode },
                { "x_phone", billing.Phone1 },
                // Shipping infos
                { "x_ship_to_first_name", shipping.FirstName },
                { "x_ship_to_last_name", shipping.LastName },
                { "x_ship_to_company", "" },
                { "x_ship_to_address", (shipping.Address1 + " " + shipping.Address2).Trim() },
                { "x_ship_to_city", shipping.City },
                { "x_ship_to_state", shipping.RegionCode },
                { "x_ship_to_zip", shipping.PostalCode },
                { "x_ship_to_country", shipping.CountryCode },
                // Customer infos
                { "x_cust_id", billing.UserID.ToString() },
                { "x_customer_ip", HttpContext.Current.Request.UserHostAddress },
                // Order infos
                { "x_invoice_num", orderInfo.OrderID.ToString() },
                { "x_amount", orderInfo.GrandTotal.ToString("0.00", ciEnUs) },//Req
                { "x_tax", orderInfo.TaxTotal.ToString("0.00", ciEnUs) },
                { "x_freight", orderInfo.ShippingCost.ToString("0.00", ciEnUs) },
                // Transaction infos
                { "x_method", "CC" },                      //CC=Credit Card could be also ECHECK
                { "x_type", settings.Capture.ToString() }, //Req
                { "x_recurring_billing", "NO" },
                { "x_card_num", trans.CardNumber },        //Req
                { "x_card_code", trans.VerificationCode },
                { "x_exp_date", trans.ExpirationMonth.ToString("00") + "/" + trans.ExpirationYear }//Req
            };
            // Order details
            string                 fieldSep        = "<|>";
            OrderController        orderController = new OrderController();
            List <OrderDetailInfo> orderDetails    = orderController.GetOrderDetails(orderInfo.OrderID);
            ArrayList              items           = new ArrayList(orderDetails.Count);

            foreach (OrderDetailInfo detail in orderDetails)
            {
                string modelNumber = detail.ModelNumber;
                if (modelNumber.Length > 31)
                {
                    modelNumber = modelNumber.Substring(0, 31);
                }

                string modelName = detail.ModelName;
                if (modelName.Length > 31)
                {
                    modelName = modelName.Substring(0, 31);
                }

                items.Add(modelNumber + fieldSep + modelName + fieldSep + fieldSep + detail.Quantity +
                          fieldSep + detail.UnitCost.ToString("0.00", ciEnUs) + fieldSep + "Y");
            }
            // Perform transaction
            try
            {
                Encoding     enc = Encoding.GetEncoding(1252);
                StreamReader loResponseStream = new StreamReader(PostEx(url, NVCol, items).GetResponseStream(), enc);

                string lcHtml = loResponseStream.ReadToEnd();
                loResponseStream.Close();

                string[] resultArray = lcHtml.Split('|');

                result.Succeeded  = (resultArray[0] == "1");
                result.ResultCode = int.Parse(resultArray[0]);
                result.ReasonCode = int.Parse(resultArray[2]);
                result.Message    = resultArray[3];
            }
            catch (Exception ex)
            {
                result.Succeeded  = false;
                result.ResultCode = -2;
                result.Message    = ex.Message;
            }

            return(result);
        }