示例#1
0
        protected void repGateways_ItemCommand(object sender, RepeaterCommandEventArgs e)
        {
            if (!e.CommandName.EqualsIgnoreCase("ShowConfiguration"))
            {
                return;
            }

            GatewayProcessor gp = GatewayLoader.GetProcessor(e.CommandArgument as string);

            if (gp == null)
            {
                return;
            }

            HiddenField hfGatewayIdentifier = e.Item.FindControl("hfGatewayIdentifier") as HiddenField;

            if (hfGatewayIdentifier != null && hfGatewayIdentifier.Value == "PayFlowPro")
            {
                HiddenField hfGatewayProductIdentifier = e.Item.FindControl("hfGatewayProductIdentifier") as HiddenField;
                LaunchGatewayConfiguration(gp, String.Format("Gateway.{0}.ConfigAtom.xml", hfGatewayProductIdentifier.Value.Replace(" ", "").Replace("�", "")));
            }
            else
            {
                LaunchGatewayConfiguration(gp);
            }
        }
示例#2
0
        protected void repGateways_DataBinding(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
            {
                return;
            }

            var rb = e.Item.FindControl("rbGateway") as RadioButton;
            var btnConfigureGateway = e.Item.FindControl("btnConfigureGateway") as LinkButton;
            var imgPayPal           = e.Item.FindControl("imgPayPal") as Image;

            var item = e.Item.DataItem as GatewayData;

            var trGateway = e.Item.FindControl("trGateway");

            if (trGateway != null)
            {
                trGateway.Visible = IsPaymentOptionAvailable(item.DisplayName, ddlCountries.SelectedValue);
            }

            if (item.DisplayName.Contains("PayPal"))
            {
                imgPayPal.Visible = true;
            }

            if (item.DisplayName.ToUpper().Contains("PAYFLOW"))
            {
                imgPayPal.ImageUrl = "images/PayPal_OnBoarding_PayFlow.png";
            }

            if (AppLogic.AppConfig("PaymentGateway", 0, false).EqualsIgnoreCase("PayFlowPro"))
            {
                var payFlowProProduct = AppConfigManager.GetAppConfig("PayFlowPro.Product");
                rb.Checked = item.DisplayName == payFlowProProduct.ConfigValue;
            }
            else
            {
                rb.Checked = AppLogic.AppConfig("PaymentGateway", 0, false).EqualsIgnoreCase(item.GatewayIdentifier);
            }

            if (item.IsInstalled)
            {
                var gp = GatewayLoader.GetProcessor(item.GatewayIdentifier);
                if (gp != null)
                {
                    var atom = gp.GetConfigurationAtom();
                    rb.Enabled = atom == null || atom.IsConfigured(0) || atom.IsConfigured(AppLogic.StoreID());
                }
            }
            else
            {
                rb.Enabled = false;
                btnConfigureGateway.Visible = false;
            }

            if (item.GatewayIdentifier != null && item.GatewayIdentifier.EqualsIgnoreCase("manual"))
            {
                btnConfigureGateway.Visible = false;
            }
        }
示例#3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.CacheControl = "private";
            Response.Expires      = 0;
            Response.AddHeader("pragma", "no-cache");

            dtLastRun = Localization.ParseDBDateTime(AppLogic.AppConfig("Recurring.GatewayLastImportedDate"));
            if (dtLastRun > System.DateTime.MinValue)
            {
                lblLastRun.Text = "Last import was from " + Localization.ToThreadCultureShortDateString(dtLastRun) + "  ";
            }

            m_GW = AppLogic.ActivePaymentGatewayCleaned();
            btnGetGatewayStatus.Text = String.Format(AppLogic.GetString("GetAutoBillStatusFile", SkinID, LocaleSetting), CommonLogic.IIF(dtLastRun > System.DateTime.MinValue, AppLogic.GetString("admin.recurringimport.Next", SkinID, LocaleSetting), AppLogic.GetString("admin.recurringimport.Todays", SkinID, LocaleSetting)), m_GW);
            if (!IsPostBack)
            {
                if (dtLastRun.AddDays((double)1.0) >= DateTime.Today)
                {
                    txtInputFile.Text           = AppLogic.GetString("admin.recurringimport.NothingToProcess", SkinID, LocaleSetting);
                    btnGetGatewayStatus.Enabled = false;
                }

                if (!AppLogic.ThereAreRecurringGatewayAutoBillOrders())
                {
                    pnlMain.Visible         = false;
                    pnlNotSupported.Visible = true;
                }
                else
                {
                    GatewayProcessor GWActual = GatewayLoader.GetProcessor(m_GW);
                    if (GWActual != null && GWActual.RecurringSupportType() == RecurringSupportType.Normal)
                    {
                        btnGetGatewayStatus.Visible = true;
                        pnlMain.Visible             = true;
                        pnlNotSupported.Visible     = false;
                    }
                    else if (GWActual != null && GWActual.RecurringSupportType() == RecurringSupportType.Extended)
                    {
                        btnGetGatewayStatus.Visible = false;
                        btnProcessFile.Visible      = true;
                        pnlMain.Visible             = true;
                        pnlNotSupported.Visible     = false;
                        PastePromptLabel.Text       = PastePromptLabel.Text + "<br />" + AppLogic.GetString("admin.recurringimport.RawTextContents", SkinID, LocaleSetting);
                    }
                    else
                    {
                        pnlMain.Visible         = false;
                        pnlNotSupported.Visible = true;
                    }
                }
            }
            else
            {
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                var gateway = GatewayLoader.GetProcessor("Moneybookers");

                if (gateway == null)
                {
                    throw new Exception("Skrill (Moneybookers) Quick Checkout requires the Moneybookers gateway.");
                }

                var quickCheckout = ((IExternalPaymentMethodProvider)gateway).GetExternalPaymentMethod("Quick Checkout");

                if (quickCheckout == null)
                {
                    throw new Exception("The installed version of the Skrill (Moneybookers) gateway does not support Quick Checkout.");
                }

                string responseData = context.Request.Form["response"];

                if (responseData == null)
                {
                    context.Response.Write("No response parameter present. Aborting.");
                    return;
                }

                responseData = HttpUtility.UrlDecode(responseData);

                // If payment method is VA, then
                var result = quickCheckout.ProcessCallback(new Dictionary <string, string>
                {
                    { "response", responseData }
                });
                context.Response.Write(result.RedirectUrl);

                // otherwise
            }
            catch
            {
                string errorMessage = AspDotNetStorefrontCore.AppLogic.GetString("checkoutpayment.aspx.34", AspDotNetStorefrontCore.Customer.Current.SkinID, AspDotNetStorefrontCore.Customer.Current.LocaleSetting);
                if (errorMessage == String.Empty)
                {
                    errorMessage = "There was an error processing your payment. Please try again.";
                }

                context.Response.Write(AspDotNetStorefrontCore.AppLogic.GetStoreHTTPLocation(false) + "shoppingcart.aspx?ErrorMsg=" + HttpUtility.UrlEncode(errorMessage));
            }
        }
示例#5
0
        public String ProcessAutoBillStatusFile(String GW, String StatusFile, out String Results)
        {
            String Status = AppLogic.ro_OK;

            Results = String.Empty;
            StringBuilder tmpS = new StringBuilder(4096);

            GatewayProcessor GWActual = GatewayLoader.GetProcessor(GW);

            if (GWActual != null)
            {
                string gwresults;
                Status = GWActual.ProcessAutoBillStatusFile(GW, StatusFile, out gwresults, this);
                tmpS.Append(gwresults);
            }

            tmpS.Append("\nEND_OF_FILE");
            Results = tmpS.ToString();
            return(Status);
        }
示例#6
0
        public String ProcessAutoBillAddressUpdate(int OriginalRecurringOrderNumber, Address UseNewBillingInfo)
        {
            // update subscription to use new billing info
            String Status = AppLogic.ro_OK;
            String GW     = AppLogic.ActivePaymentGatewayCleaned();
            String RecurringSubscriptionID = AppLogic.GetRecurringSubscriptionIDFromOrder(OriginalRecurringOrderNumber);

            if (RecurringSubscriptionID.Length != 0)
            {
                // dynamically load the gateway processor class via the name
                GatewayProcessor processor = GatewayLoader.GetProcessor(GW);
                if (processor != null)
                {
                    Status = processor.RecurringBillingAddressUpdate(RecurringSubscriptionID,
                                                                     OriginalRecurringOrderNumber,
                                                                     UseNewBillingInfo);
                }
                else
                {
                    if (GW == Gateway.ro_GWPAYFLOWPRO)
                    {
                        GatewayProcessor pfp = GatewayLoader.GetProcessor(Gateway.ro_GWPAYFLOWPRO);

                        Status = pfp.RecurringBillingAddressUpdate(RecurringSubscriptionID, OriginalRecurringOrderNumber, UseNewBillingInfo);
                    }
                    else
                    {
                        Status = "Invalid Gateway";
                    }
                }
            }

            if (AppLogic.AppConfigBool("AuditLog.Enabled"))
            {
                StringBuilder sbDetails = new StringBuilder("Result=" + Status);
                sbDetails.Append(", RecurringSubscriptionID=" + RecurringSubscriptionID);
                sbDetails.Append(", New Address=" + UseNewBillingInfo.DisplayHTML(true));
                AppLogic.AuditLogInsert(0, 0, OriginalRecurringOrderNumber, "ProcessAutoBillAddressUpdate", sbDetails.ToString(), CommonLogic.GetThisPageName(true), "RecurringOrderMgr");
            }
            return(Status);
        }
示例#7
0
        public String GetAutoBillStatusFile(String GW, out String StatusFile)
        {
            String Status = AppLogic.ro_OK;

            StatusFile = String.Empty;

            if (GW == Gateway.ro_GWPAYFLOWPRO)
            {
                StatusFile = GatewayLoader.GetProcessor(Gateway.ro_GWPAYFLOWPRO).RecurringBillingGetStatusFile();
                return(Status);
            }

            GatewayProcessor GWActual = GatewayLoader.GetProcessor(GW);

            if (GW != null)
            {
                StatusFile = GWActual.RecurringBillingGetStatusFile();
            }

            return(Status);
        }
        private void SetupPageDisplay()
        {
            if (LastImportDate > System.DateTime.MinValue)
            {
                LastRunPanel.Visible = true;
                lblLastRun.Text      = String.Format(AppLogic.GetString("admin.recurringimport.LastImport", LocaleSetting), Localization.ToThreadCultureShortDateString(LastImportDate));
            }

            btnGetGatewayStatus.Text = String.Format(AppLogic.GetString("admin.recurringimport.GetAutoBillStatusFile", LocaleSetting),
                                                     LastImportDate > System.DateTime.MinValue
                                ? AppLogic.GetString("admin.recurringimport.Next", LocaleSetting)
                                : AppLogic.GetString("admin.recurringimport.Todays", SkinID, LocaleSetting),
                                                     RecurringGateway);

            if (LastImportDate.AddDays(1) >= DateTime.Today)
            {
                txtInputFile.Text           = AppLogic.GetString("admin.recurringimport.NothingToProcess", SkinID, LocaleSetting);
                btnGetGatewayStatus.Enabled = false;
            }

            GatewayProcessor GWActual = GatewayLoader.GetProcessor(RecurringGateway);

            if (GWActual != null && GWActual.RecurringSupportType() == RecurringSupportType.Normal)
            {
                btnGetGatewayStatus.Visible = true;
                pnlMain.Visible             = true;
            }
            else if (GWActual != null && GWActual.RecurringSupportType() == RecurringSupportType.Extended)
            {
                btnGetGatewayStatus.Visible = false;
                btnProcessFile.Visible      = true;
                pnlMain.Visible             = true;
                PastePromptLabel.Text       = PastePromptLabel.Text + "<br />" + AppLogic.GetString("admin.recurringimport.RawTextContents", SkinID, LocaleSetting);
            }
            else
            {
                DisablePageDisplay(AppLogic.GetString("admin.recurringimport.NotSupported", LocaleSetting));
                return;
            }
        }
示例#9
0
        private void SetGatewayRBEnabled()
        {
            foreach (RepeaterItem e in repGateways.Items)
            {
                RadioButton rb = e.FindControl("rbGateway") as RadioButton;
                LinkButton  btnConfigureGateway = e.FindControl("btnConfigureGateway") as LinkButton;
                HiddenField hfGatewayIdentifier = e.FindControl("hfGatewayIdentifier") as HiddenField;

                try
                {
                    GatewayProcessor gp = GatewayLoader.GetProcessor(hfGatewayIdentifier.Value);

                    IConfigurationAtom atom = gp.GetConfigurationAtom();
                    rb.Enabled = atom == null || atom.IsConfigured(0) || atom.IsConfigured(AppLogic.StoreID());
                }
                catch // the gateway doesn't exist.
                {
                    rb.Enabled = false;
                    btnConfigureGateway.Visible = false;
                }
            }
        }
示例#10
0
        public ActionResult CreditCard()
        {
            var customer = HttpContext.GetCustomer();

            if (!PaymentOptionProvider.PaymentMethodSelectionIsValid(AppLogic.ro_PMCreditCard, customer))
            {
                NoticeProvider.PushNotice(
                    message: "Invalid payment method!  Please choose another.",
                    type: NoticeType.Failure);
                return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
            }

            //Decide which form to display
            if (AppLogic.ActivePaymentGatewayCleaned() == Gateway.ro_GWBRAINTREE)
            {
                var processor = GatewayLoader.GetProcessor(Gateway.ro_GWBRAINTREE);

                var clientToken = processor.ObtainBraintreeToken();

                if (string.IsNullOrEmpty(clientToken))
                {
                    NoticeProvider.PushNotice("Our credit card processor is currently excperiencing difficulties.  Please try another payment method or contact us for assistance.", NoticeType.Failure);
                    return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
                }

                var braintreeModel = new BraintreeViewModel(token: clientToken,
                                                            scriptUrl: AppLogic.AppConfig("Braintree.ScriptUrl"));

                return(View(ViewNames.BraintreeCreditCard, braintreeModel));
            }
            else
            {
                var ccModel = BuildCheckoutCreditCardViewModel(customer);
                return(View(ViewNames.CreditCard, ccModel));
            }
        }
        public ActionResult CreditCard()
        {
            var customer = HttpContext.GetCustomer();

            if (!PaymentOptionProvider.PaymentMethodSelectionIsValid(AppLogic.ro_PMCreditCard, customer))
            {
                NoticeProvider.PushNotice(
                    message: AppLogic.GetString("checkout.paymentmethodnotallowed"),
                    type: NoticeType.Failure);
                return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
            }

            //Decide which form to display
            if (AppLogic.ActivePaymentGatewayCleaned() == Gateway.ro_GWBRAINTREE)
            {
                var processor = GatewayLoader.GetProcessor(Gateway.ro_GWBRAINTREE);

                var clientToken = processor.ObtainBraintreeToken();

                if (string.IsNullOrEmpty(clientToken))
                {
                    NoticeProvider.PushNotice(AppLogic.GetString("braintree.creditcardunavailable"), NoticeType.Failure);
                    return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
                }

                var braintreeModel = new BraintreeViewModel(token: clientToken,
                                                            scriptUrl: AppLogic.AppConfig("Braintree.ScriptUrl"));

                return(View(ViewNames.BraintreeCreditCard, braintreeModel));
            }
            else if (AppLogic.ActivePaymentGatewayCleaned() == Gateway.ro_GWACCEPTJS)
            {
                var liveMode = AppLogic.AppConfigBool("UseLiveTransactions");
                var cart     = CachedShoppingCartProvider.Get(customer, CartTypeEnum.ShoppingCart, AppLogic.StoreID());

                var acceptJsModel = new AcceptJsViewModel(
                    clientKey: liveMode
                                                ? AppLogic.AppConfig("AcceptJs.Live.ClientKey")
                                                : AppLogic.AppConfig("AcceptJs.Test.ClientKey"),
                    apiLoginId: liveMode
                                                ? AppLogic.AppConfig("AcceptJs.Live.ApiLoginId")
                                                : AppLogic.AppConfig("AcceptJs.Test.ApiLoginId"),
                    scriptUrlHostedForm: liveMode
                                                ? AppLogic.AppConfig("AcceptJs.Form.Hosted.Live.Url")
                                                : AppLogic.AppConfig("AcceptJs.Form.Hosted.Test.Url"),
                    scriptUrlOwnForm: liveMode
                                                ? AppLogic.AppConfig("AcceptJs.Form.Own.Live.Url")
                                                : AppLogic.AppConfig("AcceptJs.Form.Own.Test.Url"));


                return(View(ViewNames.AcceptJsCreditCard, acceptJsModel));
            }
            else if (AppLogic.ActivePaymentGatewayCleaned() == Gateway.ro_GWSAGEPAYPI)
            {
                var processor = (ISagePayPiGatewayProcessor)GatewayLoader.GetProcessor(Gateway.ro_GWSAGEPAYPI);

                var clientMerchantSessionKey = processor.ObtainSagePayPiMerchantSessionKey();

                if (string.IsNullOrEmpty(clientMerchantSessionKey))
                {
                    NoticeProvider.PushNotice(AppLogic.GetString("sagepaypi.creditcardunavailable"), NoticeType.Failure);
                    return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
                }

                var sagePayPiModel = new SagePayPiViewModel(merchantSessionKey: clientMerchantSessionKey,
                                                            scriptUrl: AppLogic.AppConfigBool("UseLiveTransactions")
                                                ? AppLogic.AppConfig("SagePayPi.LiveScriptUrl")
                                                : AppLogic.AppConfig("SagePayPi.TestScriptUrl"),
                                                            validateCreditCardNumber: AppLogic.AppConfigBool("ValidateCreditCardNumbers"));

                return(View(ViewNames.SagePayPiCreditCard, sagePayPiModel));
            }
            else
            {
                var ccModel = BuildCheckoutCreditCardViewModel(customer);
                return(View(ViewNames.CreditCard, ccModel));
            }
        }
示例#12
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.CacheControl = "private";
            Response.Expires      = 0;
            Response.AddHeader("pragma", "no-cache");

            /****************************************************************************/
            // * WARNING TO DEVELOPERS
            // * The redirect below is a SAFETY feature.  Removing the redirect will not
            // * enable ML-only features on a lower version of AspDotNetStorefront.
            // * Attempting to do so can very easily result in a partially implemented
            // * feature, invalid or incomplete data in your DB, and other serious
            // * conditions that will cause your store to be non-functional.
            // *
            // * If you break your store attempting to enable ML-only features in PRO or
            // * Standard, our staff cannot help you fix it, and it will also invalidate
            // * your AspDotNetStorefront License.
            /***************************************************************************/

            if (!AppLogic.m_ProductIsML())
            {
                AppLogic.AdminLinkUrl("restrictedfeature.aspx");
            }

            dtLastRun = Localization.ParseDBDateTime(AppLogic.AppConfig("Recurring.GatewayLastImportedDate"));
            if (dtLastRun > System.DateTime.MinValue)
            {
                lblLastRun.Text = "Last import was from " + Localization.ToThreadCultureShortDateString(dtLastRun) + "&nbsp;&nbsp;";
            }

            m_GW = AppLogic.ActivePaymentGatewayCleaned();
            btnGetGatewayStatus.Text = String.Format(AppLogic.GetString("GetAutoBillStatusFile", SkinID, LocaleSetting), CommonLogic.IIF(dtLastRun > System.DateTime.MinValue, AppLogic.GetString("admin.recurringimport.Next", SkinID, LocaleSetting), AppLogic.GetString("admin.recurringimport.Todays", SkinID, LocaleSetting)), m_GW);
            if (!IsPostBack)
            {
                if (dtLastRun.AddDays((double)1.0) >= DateTime.Today)
                {
                    txtInputFile.Text           = AppLogic.GetString("admin.recurringimport.NothingToProcess", SkinID, LocaleSetting);
                    btnGetGatewayStatus.Enabled = false;
                }

                if (!AppLogic.ThereAreRecurringGatewayAutoBillOrders())
                {
                    pnlMain.Visible         = false;
                    pnlNotSupported.Visible = true;
                }
                else
                {
                    GatewayProcessor GWActual = GatewayLoader.GetProcessor(m_GW);
                    if (GWActual != null && GWActual.RecurringSupportType() == RecurringSupportType.Normal)
                    {
                        btnGetGatewayStatus.Visible = true;
                        pnlMain.Visible             = true;
                        pnlNotSupported.Visible     = false;
                    }
                    else if (GWActual != null && GWActual.RecurringSupportType() == RecurringSupportType.Extended)
                    {
                        btnGetGatewayStatus.Visible = false;
                        btnProcessFile.Visible      = true;
                        pnlMain.Visible             = true;
                        pnlNotSupported.Visible     = false;
                        PastePromptLabel.Text       = PastePromptLabel.Text + "<br />" + AppLogic.GetString("admin.recurringimport.RawTextContents", SkinID, LocaleSetting);
                    }
                    else
                    {
                        pnlMain.Visible         = false;
                        pnlNotSupported.Visible = true;
                    }
                }
            }
            else
            {
            }
        }
示例#13
0
        public void BuildGatewayList()
        {
            String GW = AppLogic.ActivePaymentGatewayCleaned();

            List <GatewayData> ds           = new List <GatewayData>();
            String             downloadLink = "<br /><a href=\"{1}\" onclick=\"showGatewayDirections('{2}');\">{0}</a>";

            if (repGateways.DataSource == null)
            {
                Dictionary <String, List <AssetServerAsset> > serverAssets = AssetServer.AssetServerAsset.GetAssetServerAssets();
                IEnumerable <string> availibleGateways = GatewayLoader.GetAvailableGatewayNames();

                foreach (String s in availibleGateways)
                {
                    GatewayProcessor GWActual = GatewayLoader.GetProcessor(s);
                    GatewayData      gd       = new GatewayData();
                    gd.DisplayName = GWActual.DisplayName(ThisCustomer.LocaleSetting);
                    gd.AdministratorSetupPrompt = GWActual.AdministratorSetupPrompt;
                    if (serverAssets.ContainsKey(GWActual.TypeName))
                    {
                        if (serverAssets[GWActual.TypeName].Count == 0)
                        {
                            return;
                        }

                        AssetServer.AssetVersion dllVersion       = new AssetVersion(GWActual.Version);
                        AssetServer.AssetVersion availibleVersion = new AssetVersion(serverAssets[GWActual.TypeName][0].Version);

                        if (availibleVersion.CompareTo(dllVersion) > 0)
                        {
                            gd.AdministratorSetupPrompt += "<b>Download Update</b>";
                            foreach (AssetServerAsset asa in serverAssets[GWActual.TypeName])
                            {
                                gd.AdministratorSetupPrompt += String.Format(downloadLink, asa.Title + " (" + asa.Version + ")", asa.Link, CommonLogic.IIF(String.IsNullOrEmpty(asa.DownloadInstructions), String.Empty, HttpContext.Current.Server.HtmlEncode(asa.DownloadInstructions)));
                            }
                        }

                        serverAssets.Remove(GWActual.TypeName);
                    }
                    gd.IsInstalled       = true;
                    gd.GatewayIdentifier = s;
                    ds.Add(gd);
                }
                //
                foreach (KeyValuePair <String, List <AssetServerAsset> > sa in serverAssets)
                {
                    if (sa.Value.Count == 0)
                    {
                        break;
                    }
                    GatewayData gd = new GatewayData();
                    gd.DisplayName = sa.Value[0].Title;
                    gd.IsInstalled = false;
                    StringBuilder setupPrompt = new StringBuilder();
                    setupPrompt.Append("<b>Download</b>");
                    foreach (AssetServerAsset asa in sa.Value)
                    {
                        setupPrompt.AppendFormat(downloadLink, asa.Title, asa.Link, CommonLogic.IIF(String.IsNullOrEmpty(asa.DownloadInstructions), String.Empty, HttpContext.Current.Server.HtmlEncode(asa.DownloadInstructions)));
                    }
                    gd.AdministratorSetupPrompt = setupPrompt.ToString();
                    ds.Add(gd);
                }

                ds.Add(CreateGatewayData("PayPal Payflow Link", "PayFlowPro", "(also enables PayPal Express Checkout) - See <a href=\"http://www.aspdotnetstorefront.com/linkmanager.aspx?topic=paypalpayflowlink&type=manual\" target=\"_blank\">Manual</a>."));
                ds.Add(CreateGatewayData("PayPal Payments Advanced", "PayFlowPro", "(also enables PayPal Express Checkout) - See <a href=\"http://www.aspdotnetstorefront.com/linkmanager.aspx?topic=paypalpaymentsadvanced&type=manual\" target=\"_blank\">Manual</a>."));

                ds = ds.Where(gd => IsPaymentOptionAvailable(gd.DisplayName, ddlCountries.SelectedValue)).ToList();

                ds = SortGatewayList(ds);

                repGateways.DataSource = ds;
                repGateways.DataBind();
            }
        }
示例#14
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            StringBuilder writer = new StringBuilder();

            Response.CacheControl = "private";
            Response.Expires      = 0;
            Response.AddHeader("pragma", "no-cache");

            int ONX = CommonLogic.QueryStringUSInt("OrderNumber");

            Customer ThisCustomer          = Context.GetCustomer();
            int      OrderCustomerID       = 0;
            String   OriginalTransactionID = String.Empty;
            String   PM = String.Empty;

            using (var dbconn = new SqlConnection(DB.GetDBConn()))
            {
                dbconn.Open();
                using (var rs = DB.GetRS(String.Format("select CustomerID,AuthorizationPNREF,PaymentMethod from Orders with (NOLOCK) where OrderNumber={0}", ONX.ToString()), dbconn))
                {
                    if (rs.Read())
                    {
                        OrderCustomerID       = DB.RSFieldInt(rs, "CustomerID");
                        OriginalTransactionID = DB.RSField(rs, "AuthorizationPNREF");
                        PM = AppLogic.CleanPaymentMethod(DB.RSField(rs, "PaymentMethod"));
                    }
                }
            }

            Customer OrderCustomer = new Customer(OrderCustomerID, true);

            String GW = AppLogic.ActivePaymentGatewayCleaned();

            if (PM == AppLogic.ro_PMPayPalExpress)
            {
                GW = Gateway.ro_GWPAYPAL;
            }

            bool GatewayRequiresCC = GatewayLoader.GetProcessor(GW).RequiresCCForFurtherProcessing();

            writer.Append("<div class=\"white-ui-box\">");
            if (!ThisCustomer.IsAdminUser)
            {
                writer.Append("<b><font color=red>" + AppLogic.GetString("admin.common.PermissionDeniedUC", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</b></font>");
            }
            else
            {
                if (ONX == 0 || OrderCustomerID == 0)
                {
                    writer.Append("<div class=\"alert alert-danger\">" + AppLogic.GetString("adhoccharge.aspx.1", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</div>");
                    writer.Append("<p><a href=\"javascript:self.close();\">" + AppLogic.GetString("admin.common.Close", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</a></p>");
                }
                else
                {
                    Address BillingAddress = new Address();
                    BillingAddress.LoadFromDB(OrderCustomer.PrimaryBillingAddressID);

                    if (CommonLogic.FormBool("IsSubmit") && CommonLogic.FormCanBeDangerousContent("OrderTotal").Trim().Length != 0)
                    {
                        Decimal OrderTotal       = CommonLogic.FormNativeDecimal("OrderTotal");
                        String  OrderDescription = CommonLogic.FormCanBeDangerousContent("Description");
                        AppLogic.TransactionTypeEnum OrderType = (AppLogic.TransactionTypeEnum)Enum.Parse(typeof(AppLogic.TransactionTypeEnum), CommonLogic.FormCanBeDangerousContent("OrderType"), true);
                        int NewOrderNumber = 0;
                        if (OrderType == AppLogic.TransactionTypeEnum.CHARGE)
                        {
                            if (CommonLogic.FormCanBeDangerousContent("CardNumber").Length < 4)
                            {
                                Security.LogEvent(AppLogic.GetString("admin.common.ViewedCreditCard.Success", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), String.Format(AppLogic.GetString("admin.adhoccharge.ViewedCardNumber", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), CommonLogic.FormCanBeDangerousContent("CardNumber").Replace("*", "").Substring(CommonLogic.FormCanBeDangerousContent("CardNumber").Replace("*", "").Length).PadLeft(CommonLogic.FormCanBeDangerousContent("CardNumber").Replace("*", "").Length, '*'), ONX.ToString()), OrderCustomer.CustomerID, ThisCustomer.CustomerID, Convert.ToInt32(ThisCustomer.CurrentSessionID));
                            }
                            else
                            {
                                Security.LogEvent(AppLogic.GetString("admin.common.ViewedCreditCard.Success", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), String.Format(AppLogic.GetString("admin.adhoccharge.ViewedCardNumber", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), CommonLogic.FormCanBeDangerousContent("CardNumber").Replace("*", "").Substring(CommonLogic.FormCanBeDangerousContent("CardNumber").Replace("*", "").Length - 4).PadLeft(CommonLogic.FormCanBeDangerousContent("CardNumber").Replace("*", "").Length, '*'), ONX.ToString()), OrderCustomer.CustomerID, ThisCustomer.CustomerID, Convert.ToInt32(ThisCustomer.CurrentSessionID));
                            }
                        }
                        // use the billing info in the form, as the store admin may have overridden what was in the db
                        // NOTE: we are NOT going to save this new updated billing info however, it is really up to the customer
                        // to change their billing info, or the store admin should edit their billing address in the customers account page area
                        BillingAddress.CardName = CommonLogic.FormCanBeDangerousContent("CardName");
                        // NOTE, this could be last4 at this point!! not a full CC #! that is ok, as this address will never be stored to the db anyway!
                        BillingAddress.CardNumber          = CommonLogic.FormCanBeDangerousContent("CardNumber").Replace("*", "");
                        BillingAddress.CardType            = CommonLogic.FormCanBeDangerousContent("CardType");
                        BillingAddress.CardExpirationMonth = CommonLogic.FormCanBeDangerousContent("CardExpirationMonth");
                        BillingAddress.CardExpirationYear  = CommonLogic.FormCanBeDangerousContent("CardExpirationYear");
                        BillingAddress.CardStartDate       = CommonLogic.FormCanBeDangerousContent("CardStartDate").Trim().Replace(" ", "").Replace("/", "").Replace("\\", "");
                        BillingAddress.CardIssueNumber     = CommonLogic.FormCanBeDangerousContent("CardIssueNumber");
                        String CardExtraCode = CommonLogic.FormCanBeDangerousContent("CardExtraCode");

                        String Status = Gateway.MakeAdHocOrder(AppLogic.ActivePaymentGatewayCleaned(), ONX, OriginalTransactionID, OrderCustomer, BillingAddress, CardExtraCode, OrderTotal, OrderType, OrderDescription, out NewOrderNumber);

                        //PABP Required cleanup of in-memory objects
                        CardExtraCode = "11111";
                        CardExtraCode = "00000";
                        CardExtraCode = "11111";
                        CardExtraCode = String.Empty;

                        if (Status == AppLogic.ro_OK)
                        {
                            Response.Redirect(AppLogic.AdminLinkUrl("adhocchargecomplete.aspx") + "?ordernumber=" + NewOrderNumber.ToString());
                        }
                        else
                        {
                            Response.Write("<div class=\"alert alert-danger\">" + AppLogic.GetString("adhoccharge.aspx.3", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "<br/>" + Status + "</div>");
                        }
                        Response.Write("<p><a href=\"javascript:self.close();\">" + AppLogic.GetString("admin.common.Close", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</a></p>");
                    }
                    else
                    {
                        writer.Append("<script type=\"text/javascript\">\n");
                        writer.Append("var GatewayRequiresCC=" + CommonLogic.IIF(GatewayRequiresCC, "1", "0") + ";\n");
                        writer.Append("function getSelectedRadio(buttonGroup) {\n");
                        writer.Append("   // returns the array number of the selected radio button or -1 if no button is selected\n");
                        writer.Append("   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)\n");
                        writer.Append("      for (var i=0; i<buttonGroup.length; i++) {\n");
                        writer.Append("         if (buttonGroup[i].checked) {\n");
                        writer.Append("            return i\n");
                        writer.Append("         }\n");
                        writer.Append("      }\n");
                        writer.Append("   } else {\n");
                        writer.Append("      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero\n");
                        writer.Append("   }\n");
                        writer.Append("   // if we get to this point, no radio button is selected\n");
                        writer.Append("   return -1;\n");
                        writer.Append("}");
                        writer.Append("\n");
                        writer.Append("function getSelectedRadioValue(buttonGroup) {\n");
                        writer.Append("   // returns the value of the selected radio button or '' if no button is selected\n");
                        writer.Append("   var i = getSelectedRadio(buttonGroup);\n");
                        writer.Append("   if (i == -1) {\n");
                        writer.Append("      return '';\n");
                        writer.Append("   } else {\n");
                        writer.Append("      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)\n");
                        writer.Append("         return buttonGroup[i].value;\n");
                        writer.Append("      } else { // The button group is just the one button, and it is checked\n");
                        writer.Append("         return buttonGroup.value;\n");
                        writer.Append("      }\n");
                        writer.Append("   }\n");
                        writer.Append("}");
                        writer.Append("\n");
                        writer.Append("function AdHocOrderTypeChanged()\n");
                        writer.Append("{\n");
                        writer.Append("	if(GatewayRequiresCC == 1 || getSelectedRadioValue(theForm.OrderType) == '" + AppLogic.TransactionTypeEnum.CHARGE.ToString() + "')\n");
                        writer.Append("    {\n");
                        writer.Append("        CCDiv.style.display = 'block';\n");
                        writer.Append("    }\n");
                        writer.Append("    else\n");
                        writer.Append("    {\n");
                        writer.Append("        CCDiv.style.display = 'none';\n");
                        writer.Append("    }\n");
                        writer.Append("}\n");
                        writer.Append("function AdHocChargeOrRefundForm_Validator(theForm)\n");
                        writer.Append("{\n");
                        writer.Append("	submitonce(theForm);\n");
                        writer.Append("	if(theForm.Description.value == '')\n");
                        writer.Append("	{\n");
                        writer.Append("		alert('"+ AppLogic.GetString("adhoccharge.aspx.4", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "');\n");
                        writer.Append("		theForm.Description.focus();\n");
                        writer.Append("		submitenabled(theForm);\n");
                        writer.Append("		return (false);\n");
                        writer.Append("	}\n");
                        writer.Append("	if((getSelectedRadioValue(theForm.OrderType) == '" + AppLogic.TransactionTypeEnum.CHARGE.ToString() + "') || (GatewayRequiresCC == 1 && getSelectedRadioValue(theForm.OrderType) == '" + AppLogic.TransactionTypeEnum.CREDIT.ToString() + "'))\n");
                        writer.Append("    {\n");
                        writer.Append("        if(theForm.CardName.value == '')\n");
                        writer.Append("	    {\n");
                        writer.Append("		    alert('"+ String.Format(AppLogic.GetString("adhoccharge.aspx.22", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), "Name On Card") + "');\n");
                        writer.Append("		    theForm.CardName.focus();\n");
                        writer.Append("		    submitenabled(theForm);\n");
                        writer.Append("		    return (false);\n");
                        writer.Append("	    }\n");
                        writer.Append("        if(theForm.CardNumber.value == '')\n");
                        writer.Append("	    {\n");
                        writer.Append("		    alert('"+ String.Format(AppLogic.GetString("adhoccharge.aspx.22", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), "Card Number") + "');\n");
                        writer.Append("		    theForm.CardNumber.focus();\n");
                        writer.Append("		    submitenabled(theForm);\n");
                        writer.Append("		    return (false);\n");
                        writer.Append("	    }\n");
                        writer.Append("        if(isNaN(theForm.CardNumber.value))\n");
                        writer.Append("	    {\n");
                        writer.Append("		    alert('"+ AppLogic.GetString("adhoccharge.aspx.28", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "');\n");
                        writer.Append("		    theForm.CardNumber.focus();\n");
                        writer.Append("		    submitenabled(theForm);\n");
                        writer.Append("		    return (false);\n");
                        writer.Append("	    }\n");
                        writer.Append("        if(theForm.CardExpirationMonth.value == '')\n");
                        writer.Append("	    {\n");
                        writer.Append("		    alert('"+ String.Format(AppLogic.GetString("adhoccharge.aspx.22", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), "Card Expiration Month") + "');\n");
                        writer.Append("		    theForm.CardExpirationMonth.focus();\n");
                        writer.Append("		    submitenabled(theForm);\n");
                        writer.Append("		    return (false);\n");
                        writer.Append("	    }\n");
                        writer.Append("        if(theForm.CardExpirationYear.value == '')\n");
                        writer.Append("	    {\n");
                        writer.Append("		    alert('"+ String.Format(AppLogic.GetString("adhoccharge.aspx.22", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), "Card Expiration Year") + "');\n");
                        writer.Append("		    theForm.CardExpirationYear.focus();\n");
                        writer.Append("		    submitenabled(theForm);\n");
                        writer.Append("		    return (false);\n");
                        writer.Append("	    }\n");
                        writer.Append("        if(theForm.CardType.selectedIndex < 1)\n");
                        writer.Append("	    {\n");
                        writer.Append("		    alert('"+ String.Format(AppLogic.GetString("adhoccharge.aspx.22", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), "Card Type") + "');\n");
                        writer.Append("		    theForm.CardType.focus();\n");
                        writer.Append("		    submitenabled(theForm);\n");
                        writer.Append("		    return (false);\n");
                        writer.Append("	    }\n");
                        writer.Append("	}\n");
                        writer.Append("	submitenabled(theForm);\n");
                        writer.Append("	return (true);\n");
                        writer.Append("}\n");
                        writer.Append("</script>\n");
                        writer.Append(String.Format(AppLogic.GetString("adhoccharge.aspx.5", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), ONX.ToString()));
                        writer.Append("<p>" + AppLogic.GetString("adhoccharge.aspx.6", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</p>");

                        String CNM       = BillingAddress.CardName;
                        String CN        = BillingAddress.CardNumber;
                        String Last4     = String.Empty;
                        String CExpMonth = BillingAddress.CardExpirationMonth;
                        String CExpYear  = BillingAddress.CardExpirationYear;
                        String CardType  = BillingAddress.CardType;
                        if (CN.Length == 0)
                        {
                            // try to pull it from order record:
                            using (var dbconn = new SqlConnection(DB.GetDBConn()))
                            {
                                dbconn.Open();
                                using (var rs2 = DB.GetRS(String.Format("SELECT CardNumber, CardName, Last4, CardExpirationMonth, CardExpirationYear, CardNumber, CardType, {0} FROM Orders WHERE OrderNumber = {1}", AppLogic.AppConfig("OrdersCCSaltField"), ONX), dbconn))
                                {
                                    if (rs2.Read())
                                    {
                                        CN        = DB.RSField(rs2, "CardNumber");
                                        CNM       = DB.RSField(rs2, "CardName");
                                        Last4     = DB.RSField(rs2, "Last4");
                                        CExpMonth = DB.RSField(rs2, "CardExpirationMonth");
                                        CExpYear  = DB.RSField(rs2, "CardExpirationYear");
                                        CN        = DB.RSField(rs2, "CardNumber");
                                        CN        = Security.UnmungeString(CN, DB.RSField(rs2, AppLogic.AppConfig("OrdersCCSaltField")));
                                        if (CN.StartsWith(Security.ro_DecryptFailedPrefix, StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            CN = DB.RSField(rs2, "CardNumber");
                                        }
                                        CardType = DB.RSField(rs2, "CardType");
                                    }
                                }
                            }
                        }

                        if (AppLogic.AppConfigBool("StoreCCInDB") && OrderCustomer.StoreCCInDB && CN.Length > 0)
                        {
                            Security.LogEvent(AppLogic.GetString("admin.common.ViewedCreditCard.Success", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), String.Format(AppLogic.GetString("admin.adhoccharge.ViewedCardNumber", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), CN.Replace("*", "").Substring(CN.Replace("*", "").Length - 4).PadLeft(CN.Replace("*", "").Length, '*'), ONX.ToString()), OrderCustomer.CustomerID, ThisCustomer.CustomerID, Convert.ToInt32(ThisCustomer.CurrentSessionID));
                        }

                        if (GatewayRequiresCC)
                        {
                            writer.Append("<div class=\"alert alert-info\">" + AppLogic.GetString("adhoccharge.aspx.11", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</div>");
                        }
                        else
                        {
                            writer.Append("<div class=\"alert alert-info\">" + AppLogic.GetString("adhoccharge.aspx.12", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</div>");
                        }

                        if (!OrderCustomer.StoreCCInDB)
                        {
                            writer.Append("<div class=\"alert alert-danger\">" + AppLogic.GetString("adhoccharge.aspx.13", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</div>");
                        }

                        if (CN.Length == 0 || CN == AppLogic.ro_CCNotStoredString)
                        {
                            writer.Append("<div class=\"alert alert-danger\">" + AppLogic.GetString("adhoccharge.aspx.14", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</div>");
                        }

                        if (OrderCustomer.PrimaryBillingAddressID == 0)
                        {
                            writer.Append("<div class=\"alert alert-danger\">" + AppLogic.GetString("adhoccharge.aspx.7", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</div>");
                        }
                        else if (CN.Length == 0 && Last4.Length == 0 && GW != Gateway.ro_GWPAYPAL)
                        {
                            writer.Append("<div class=\"alert alert-danger\">" + AppLogic.GetString("adhoccharge.aspx.8", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</div>");
                        }
                        else
                        {
                            if (CommonLogic.FormBool("IsSubmit") && CommonLogic.FormCanBeDangerousContent("OrderTotal").Trim().Length == 0)
                            {
                                writer.Append("<div class=\"alert alert-danger\">Please enter a valid charge amount</div>\n");
                            }
                            writer.Append("<form id=\"AdHocChargeOrRefundForm\" name=\"AdHocChargeOrRefundForm\" method=\"POST\" action=\"" + AppLogic.AdminLinkUrl("adhoccharge.aspx") + "?OrderNumber=" + ONX.ToString() + "\" >");
                            writer.Append("	<div class=\"item-action-bar\">");
                            writer.Append("	<input type=\"button\" value=\"" + AppLogic.GetString("admin.common.Close", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "\" name=\"B2\" onClick=\"javascript:self.close()\" class=\"btn btn-default\">");
                            writer.Append("	<input type=\"submit\" value=\"" + AppLogic.GetString("adhoccharge.aspx.21", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "\" name=\"B1\" class=\"btn btn-primary\">");
                            writer.Append("	</div>");
                            writer.Append("<input type=\"hidden\" name=\"IsSubmit\" value=\"true\">\n");
                            writer.Append("<table class=\"table\">");
                            writer.Append("<tr><td>" + AppLogic.GetString("adhoccharge.aspx.9", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + " </td><td>" + OriginalTransactionID.ToString() + "</td></tr>");
                            writer.Append("<tr><td>" + AppLogic.GetString("admin.label.CustomerID", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + " </td><td>" + OrderCustomer.CustomerID.ToString() + "</td></tr>");
                            writer.Append("<tr><td>" + AppLogic.GetString("admin.label.CustomerName", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + " </td><td>" + OrderCustomer.FullName() + "</td></tr>");
                            writer.Append("<tr><td>" + AppLogic.GetString("adhoccharge.aspx.27", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + " </td><td>" + BillingAddress.Phone + "</td></tr>");
                            writer.Append("<tr><td>" + AppLogic.GetString("adhoccharge.aspx.16", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + " </td><td>");
                            writer.Append("<input onClick=\"AdHocOrderTypeChanged()\" type=\"radio\" value=\"" + AppLogic.TransactionTypeEnum.CHARGE.ToString() + "\" id=\"ChargeOrderType\" name=\"OrderType\">" + AppLogic.GetString("adhoccharge.aspx.17", ThisCustomer.SkinID, ThisCustomer.LocaleSetting));
                            writer.Append("&nbsp;&nbsp;&nbsp;&nbsp;");
                            writer.Append("<input onClick=\"AdHocOrderTypeChanged()\" type=\"radio\" value=\"" + AppLogic.TransactionTypeEnum.CREDIT.ToString() + "\" id=\"RefundOrderType\" name=\"OrderType\" checked>" + AppLogic.GetString("adhoccharge.aspx.18", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</td></tr>");
                            writer.Append("<tr><td>" + AppLogic.GetString("adhoccharge.aspx.19", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + " </td><td><input type=\"text\" name=\"OrderTotal\" size=\"7\"><input type=\"hidden\" name=\"OrderTotal_vldt\" value=\"[req][number][blankalert=" + AppLogic.GetString("adhoccharge.aspx.26", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "][invalidalert=" + AppLogic.GetString("admin.common.ValidDollarAmountPrompt", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "]\"> (xx.xx format)</td></tr>");
                            writer.Append("<tr><td colspan=\"2\">");
                            writer.Append("<div id=\"CCDiv\" name=\"CCDiv\" style=\"display:" + CommonLogic.IIF(GatewayRequiresCC, "block", "none") + ";\">");
                            writer.Append("<table class=\"table\">");
                            writer.Append("<tr>");
                            writer.Append("<td align=\"right\">" + AppLogic.GetString("address.cs.31", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</td>");
                            writer.Append("<td>\n");
                            writer.Append("<select size=\"1\" name=\"CardType\" id=\"CardType\">");
                            writer.Append("<option value=\"\">" + AppLogic.GetString("address.cs.32", ThisCustomer.SkinID, ThisCustomer.LocaleSetting));
                            using (var dbconn = new SqlConnection(DB.GetDBConn()))
                            {
                                dbconn.Open();
                                using (var rsCard = DB.GetRS("select * from creditcardtype  with (NOLOCK)  where Accepted=1 order by CardType", dbconn))
                                {
                                    while (rsCard.Read())
                                    {
                                        writer.Append("<option value=\"" + DB.RSField(rsCard, "CardType") + "\" " + CommonLogic.IIF(CardType == DB.RSField(rsCard, "CardType"), " selected ", "") + ">" + DB.RSField(rsCard, "CardType") + "</option>\n");
                                    }
                                }
                            }
                            writer.Append("</select>\n");
                            writer.Append("</td>");
                            writer.Append("</tr>");
                            writer.Append("<tr><td align=\"right\">" + AppLogic.GetString("adhoccharge.aspx.10", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + " </td><td><input size=\"20\" maxlength=\"100\" type=\"text\" name=\"CardName\" id=\"CardName\" value=\"" + CNM + "\"></td></tr>");
                            writer.Append("<tr><td align=\"right\">" + AppLogic.GetString("adhoccharge.aspx.24", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + " </td><td><input size=\"20\" maxlength=\"19\" type=\"text\" autocomplete=\"off\" name=\"CardNumber\" id=\"CardNumber\" value=\"" + CN + "\">&nbsp;" + String.Format(AppLogic.GetString("admin.adhoccharge.OriginalOrderLastFour", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), Last4) + ")</td></tr>");
                            writer.Append("<tr><td align=\"right\">" + AppLogic.GetString("adhoccharge.aspx.15", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + " </td><td><input size=\"4\" maxlength=\"4\" type=\"text\" autocomplete=\"off\" name=\"CardExtraCode\" id=\"CardExtraCode\">");
                            writer.Append("<tr><td align=\"right\">" + AppLogic.GetString("adhoccharge.aspx.25", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + " </td><td><input type=\"text\" size=\"2\" maxlength=\"2\" name=\"CardExpirationMonth\" id=\"CardExpirationMonth\" value=\"" + CExpMonth + "\"> / <input size=\"4\" maxlength=\"4\" type=\"text\" name=\"CardExpirationYear\" id=\"CardExpirationYear\" value=\"" + CExpYear + "\"> (MM/YYYY)</td></tr>");
                            if (AppLogic.AppConfigBool("ShowCardStartDateFields"))
                            {
                                writer.Append("<tr><td align=\"right\">" + AppLogic.GetString("address.cs.59", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</td><td><input type=\"text\" autocomplete=\"off\" name=\"CardStartDate\" id=\"CardStartDate\" size=\"5\" maxlength=\"20\"> " + AppLogic.GetString("address.cs.64", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</td></tr>");
                                writer.Append("<tr><td align=\"right\">" + AppLogic.GetString("address.cs.61", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</td><td><input type=\"text\" autocomplete=\"off\" name=\"CardIssueNumber\" id=\"CardIssueNumber\" size=\"25\" maxlength=\"25\"> " + AppLogic.GetString("address.cs.63", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</td></tr>");
                            }
                            writer.Append("</table>");
                            writer.Append("</div>");
                            writer.Append("</td></tr>");
                            writer.Append("</table>");
                            writer.Append("	<p>" + AppLogic.GetString("adhoccharge.aspx.20", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + " </p>");
                            writer.Append("	<p><textarea class=\"text-multiline\" id=\"Description\" name=\"Description\" style=\"width: 90%\"></textarea></p>");
                            writer.Append("	<div class=\"item-action-bar\">");
                            writer.Append("	<input type=\"button\" value=\"" + AppLogic.GetString("admin.common.Close", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "\" name=\"B2\" onClick=\"javascript:self.close()\" class=\"btn btn-default\">");
                            writer.Append("	<input type=\"submit\" value=\"" + AppLogic.GetString("adhoccharge.aspx.21", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "\" name=\"B1\" onClick=\"return AdHocChargeOrRefundForm_Validator(this.form);\" class=\"btn btn-primary\">");
                            writer.Append("	</div>");
                            writer.Append("</form>");
                        }
                    }
                }
            }
            writer.Append("</div>");
            ltContent.Text = writer.ToString();
        }
        protected void Page_Load(object sender, System.EventArgs e)
        {
            StringBuilder writer = new StringBuilder();

            Response.CacheControl = "private";
            Response.Expires      = 0;
            Response.AddHeader("pragma", "no-cache");

            /****************************************************************************/
            // * WARNING TO DEVELOPERS
            // * The redirect below is a SAFETY feature.  Removing the redirect will not
            // * enable ML-only features on a lower version of AspDotNetStorefront.
            // * Attempting to do so can very easily result in a partially implemented
            // * feature, invalid or incomplete data in your DB, and other serious
            // * conditions that will cause your store to be non-functional.
            // *
            // * If you break your store attempting to enable ML-only features in PRO or
            // * Standard, our staff cannot help you fix it, and it will also invalidate
            // * your AspDotNetStorefront License.
            /***************************************************************************/

            if (!AppLogic.m_ProductIsML() && !AppLogic.ProductIsMLExpress())
            {
                Response.Redirect(AppLogic.AdminLinkUrl("restrictedfeature.aspx"));
            }

            int ONX = CommonLogic.QueryStringUSInt("OrderNumber");

            Customer ThisCustomer          = ((AspDotNetStorefrontPrincipal)Context.User).ThisCustomer;
            int      OrderCustomerID       = 0;
            String   OriginalTransactionID = String.Empty;
            String   PM = String.Empty;

            using (SqlConnection dbconn = new SqlConnection(DB.GetDBConn()))
            {
                dbconn.Open();
                using (IDataReader rs = DB.GetRS(String.Format("select CustomerID,AuthorizationPNREF,PaymentMethod from Orders with (NOLOCK) where OrderNumber={0}", ONX.ToString()), dbconn))
                {
                    if (rs.Read())
                    {
                        OrderCustomerID       = DB.RSFieldInt(rs, "CustomerID");
                        OriginalTransactionID = DB.RSField(rs, "AuthorizationPNREF");
                        PM = AppLogic.CleanPaymentMethod(DB.RSField(rs, "PaymentMethod"));
                    }
                }
            }

            Customer OrderCustomer = new Customer(OrderCustomerID, true);

            String GW = AppLogic.ActivePaymentGatewayCleaned();

            if (PM == AppLogic.ro_PMPayPal || PM == AppLogic.ro_PMPayPalExpress)
            {
                GW = Gateway.ro_GWPAYPAL;
            }

            bool GatewayRequiresCC = GatewayLoader.GetProcessor(GW).RequiresCCForFurtherProcessing();

            writer.Append("<div style=\"margin-left: 10px;\" align=\"left\">");
            if (!ThisCustomer.IsAdminUser)
            {
                writer.Append("<b><font color=red>" + AppLogic.GetString("admin.common.PermissionDeniedUC", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</b></font>");
            }
            else
            {
                if (ONX == 0 || OrderCustomerID == 0)
                {
                    writer.Append("<p><b><font color=red>" + AppLogic.GetString("adhoccharge.aspx.1", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</font></b></p>");
                    writer.Append("<p><a href=\"javascript:self.close();\">" + AppLogic.GetString("admin.common.Close", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</a></p>");
                }
                else
                {
                    Address BillingAddress = new Address();
                    BillingAddress.LoadFromDB(OrderCustomer.PrimaryBillingAddressID);

                    if (CommonLogic.FormBool("IsSubmit"))
                    {
                        if (CommonLogic.FormCanBeDangerousContent("OrderTotal").Trim().Length != 0)
                        {
                            Decimal OrderTotal       = CommonLogic.FormNativeDecimal("OrderTotal");
                            String  OrderDescription = CommonLogic.FormCanBeDangerousContent("Description");
                            AppLogic.TransactionTypeEnum OrderType = (AppLogic.TransactionTypeEnum)Enum.Parse(typeof(AppLogic.TransactionTypeEnum), CommonLogic.FormCanBeDangerousContent("OrderType"), true);
                            int NewOrderNumber = 0;
                            if (OrderType == AppLogic.TransactionTypeEnum.CHARGE)
                            {
                                if (CommonLogic.FormCanBeDangerousContent("CardNumber").Length < 4)
                                {
                                    Security.LogEvent(AppLogic.GetString("admin.common.ViewedCreditCard", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), String.Format(AppLogic.GetString("admin.adhoccharge.ViewedCardNumber", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), CommonLogic.FormCanBeDangerousContent("CardNumber").Replace("*", "").Substring(CommonLogic.FormCanBeDangerousContent("CardNumber").Replace("*", "").Length).PadLeft(CommonLogic.FormCanBeDangerousContent("CardNumber").Replace("*", "").Length, '*'), ONX.ToString()), OrderCustomer.CustomerID, ThisCustomer.CustomerID, Convert.ToInt32(ThisCustomer.CurrentSessionID));
                                }
                                else
                                {
                                    Security.LogEvent(AppLogic.GetString("admin.common.ViewedCreditCard", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), String.Format(AppLogic.GetString("admin.adhoccharge.ViewedCardNumber", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), CommonLogic.FormCanBeDangerousContent("CardNumber").Replace("*", "").Substring(CommonLogic.FormCanBeDangerousContent("CardNumber").Replace("*", "").Length - 4).PadLeft(CommonLogic.FormCanBeDangerousContent("CardNumber").Replace("*", "").Length, '*'), ONX.ToString()), OrderCustomer.CustomerID, ThisCustomer.CustomerID, Convert.ToInt32(ThisCustomer.CurrentSessionID));
                                }
                            }
                            // use the billing info in the form, as the store admin may have overridden what was in the db
                            // NOTE: we are NOT going to save this new updated billing info however, it is really up to the customer
                            //       to change their billing info, or the store admin should edit their billing address in the customers account page area
                            BillingAddress.CardName = CommonLogic.FormCanBeDangerousContent("CardName");
                            // NOTE, this could be last4 at this point!! not a full CC #! that is ok, as this address will never be stored to the db anyway!
                            BillingAddress.CardNumber          = CommonLogic.FormCanBeDangerousContent("CardNumber").Replace("*", "");
                            BillingAddress.CardType            = CommonLogic.FormCanBeDangerousContent("CardType");
                            BillingAddress.CardExpirationMonth = CommonLogic.FormCanBeDangerousContent("CardExpirationMonth");
                            BillingAddress.CardExpirationYear  = CommonLogic.FormCanBeDangerousContent("CardExpirationYear");
                            BillingAddress.CardStartDate       = CommonLogic.FormCanBeDangerousContent("CardStartDate").Trim().Replace(" ", "").Replace("/", "").Replace("\\", "");
                            BillingAddress.CardIssueNumber     = CommonLogic.FormCanBeDangerousContent("CardIssueNumber");
                            String CardExtraCode = CommonLogic.FormCanBeDangerousContent("CardExtraCode");

                            String Status = Gateway.MakeAdHocOrder(AppLogic.ActivePaymentGatewayCleaned(), ONX, OriginalTransactionID, OrderCustomer, BillingAddress, CardExtraCode, OrderTotal, OrderType, OrderDescription, out NewOrderNumber);

                            //PABP Required cleanup of in-memory objects
                            CardExtraCode = "11111";
                            CardExtraCode = "00000";
                            CardExtraCode = "11111";
                            CardExtraCode = String.Empty;

                            if (Status == AppLogic.ro_OK)
                            {
                                DB.ExecuteSQL("update orders set IsNew=0 where ParentOrderNumber IS NOT NULL"); // any "ad hoc" orders should not be new. so this is a safety check to force that.

                                Response.Redirect(AppLogic.AdminLinkUrl("adhocchargecomplete.aspx") + "?ordernumber=" + NewOrderNumber.ToString());
                            }
                            else
                            {
                                Response.Write("<p><b><font color=red>" + AppLogic.GetString("adhoccharge.aspx.3", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "<br/>" + Status + "</font></b></p>");
                            }
                            Response.Write("<p><a href=\"javascript:self.close();\">" + AppLogic.GetString("admin.common.Close", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</a></p>");
                        }
                    }
                    else
                    {
                        writer.Append("<script type=\"text/javascript\">\n");
                        writer.Append("var GatewayRequiresCC=" + CommonLogic.IIF(GatewayRequiresCC, "1", "0") + ";\n");
                        writer.Append("function getSelectedRadio(buttonGroup) {\n");
                        writer.Append("   // returns the array number of the selected radio button or -1 if no button is selected\n");
                        writer.Append("   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)\n");
                        writer.Append("      for (var i=0; i<buttonGroup.length; i++) {\n");
                        writer.Append("         if (buttonGroup[i].checked) {\n");
                        writer.Append("            return i\n");
                        writer.Append("         }\n");
                        writer.Append("      }\n");
                        writer.Append("   } else {\n");
                        writer.Append("      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero\n");
                        writer.Append("   }\n");
                        writer.Append("   // if we get to this point, no radio button is selected\n");
                        writer.Append("   return -1;\n");
                        writer.Append("}");
                        writer.Append("\n");
                        writer.Append("function getSelectedRadioValue(buttonGroup) {\n");
                        writer.Append("   // returns the value of the selected radio button or '' if no button is selected\n");
                        writer.Append("   var i = getSelectedRadio(buttonGroup);\n");
                        writer.Append("   if (i == -1) {\n");
                        writer.Append("      return '';\n");
                        writer.Append("   } else {\n");
                        writer.Append("      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)\n");
                        writer.Append("         return buttonGroup[i].value;\n");
                        writer.Append("      } else { // The button group is just the one button, and it is checked\n");
                        writer.Append("         return buttonGroup.value;\n");
                        writer.Append("      }\n");
                        writer.Append("   }\n");
                        writer.Append("}");
                        writer.Append("\n");
                        writer.Append("function getSelectedCheckbox(buttonGroup) {\n");
                        writer.Append("   // Go through all the check boxes. return an array of all the ones\n");
                        writer.Append("   // that are selected (their position numbers). if no boxes were checked,\n");
                        writer.Append("   // returned array will be empty (length will be zero)\n");
                        writer.Append("   var retArr = new Array();\n");
                        writer.Append("   var lastElement = 0;\n");
                        writer.Append("   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)\n");
                        writer.Append("      for (var i=0; i<buttonGroup.length; i++) {\n");
                        writer.Append("         if (buttonGroup[i].checked) {\n");
                        writer.Append("            retArr.length = lastElement;\n");
                        writer.Append("            retArr[lastElement] = i;\n");
                        writer.Append("            lastElement++;\n");
                        writer.Append("         }\n");
                        writer.Append("      }\n");
                        writer.Append("   } else { // There is only one check box (it's not an array)\n");
                        writer.Append("      if (buttonGroup.checked) { // if the one check box is checked\n");
                        writer.Append("         retArr.length = lastElement;\n");
                        writer.Append("         retArr[lastElement] = 0; // return zero as the only array value\n");
                        writer.Append("      }\n");
                        writer.Append("   }\n");
                        writer.Append("   return retArr;\n");
                        writer.Append("}");
                        writer.Append("\n");
                        writer.Append("function getSelectedCheckboxValue(buttonGroup) {\n");
                        writer.Append("   // return an array of values selected in the check box group. if no boxes\n");
                        writer.Append("   // were checked, returned array will be empty (length will be zero)\n");
                        writer.Append("   var retArr = new Array(); // set up empty array for the return values\n");
                        writer.Append("   var selectedItems = getSelectedCheckbox(buttonGroup);\n");
                        writer.Append("   if (selectedItems.length != 0) { // if there was something selected\n");
                        writer.Append("      retArr.length = selectedItems.length;\n");
                        writer.Append("      for (var i=0; i<selectedItems.length; i++) {\n");
                        writer.Append("         if (buttonGroup[selectedItems[i]]) { // Make sure it's an array\n");
                        writer.Append("            retArr[i] = buttonGroup[selectedItems[i]].value;\n");
                        writer.Append("         } else { // It's not an array (there's just one check box and it's selected)\n");
                        writer.Append("            retArr[i] = buttonGroup.value;// return that value\n");
                        writer.Append("         }\n");
                        writer.Append("      }\n");
                        writer.Append("   }\n");
                        writer.Append("   return retArr;\n");
                        writer.Append("}");
                        writer.Append("function AdHocOrderTypeChanged(theForm)\n");
                        writer.Append("{\n");
                        writer.Append("	if(GatewayRequiresCC == 1 || getSelectedRadioValue(theForm.OrderType) == '" + AppLogic.TransactionTypeEnum.CHARGE.ToString() + "')\n");
                        writer.Append("    {\n");
                        writer.Append("        CCDiv.style.display = 'block';\n");
                        writer.Append("    }\n");
                        writer.Append("    else\n");
                        writer.Append("    {\n");
                        writer.Append("        CCDiv.style.display = 'none';\n");
                        writer.Append("    }\n");
                        writer.Append("}\n");
                        writer.Append("function AdHocChargeOrRefundForm_Validator(theForm)\n");
                        writer.Append("{\n");
                        writer.Append("	submitonce(theForm);\n");
                        writer.Append("	if(theForm.Description.value == '')\n");
                        writer.Append("	{\n");
                        writer.Append("		alert('"+ AppLogic.GetString("adhoccharge.aspx.4", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "');\n");
                        writer.Append("		theForm.Description.focus();\n");
                        writer.Append("		submitenabled(theForm);\n");
                        writer.Append("		return (false);\n");
                        writer.Append("	}\n");
                        writer.Append("	if((getSelectedRadioValue(theForm.OrderType) == '" + AppLogic.TransactionTypeEnum.CHARGE.ToString() + "') || (GatewayRequiresCC == 1 && getSelectedRadioValue(theForm.OrderType) == '" + AppLogic.TransactionTypeEnum.CREDIT.ToString() + "'))\n");
                        writer.Append("    {\n");
                        writer.Append("        if(theForm.CardName.value == '')\n");
                        writer.Append("	    {\n");
                        writer.Append("		    alert('"+ String.Format(AppLogic.GetString("adhoccharge.aspx.22", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), "Name On Card") + "');\n");
                        writer.Append("		    theForm.CardName.focus();\n");
                        writer.Append("		    submitenabled(theForm);\n");
                        writer.Append("		    return (false);\n");
                        writer.Append("	    }\n");
                        writer.Append("        if(theForm.CardNumber.value == '')\n");
                        writer.Append("	    {\n");
                        writer.Append("		    alert('"+ String.Format(AppLogic.GetString("adhoccharge.aspx.22", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), "Card Number") + "');\n");
                        writer.Append("		    theForm.CardNumber.focus();\n");
                        writer.Append("		    submitenabled(theForm);\n");
                        writer.Append("		    return (false);\n");
                        writer.Append("	    }\n");
                        writer.Append("        if(isNaN(theForm.CardNumber.value))\n");
                        writer.Append("	    {\n");
                        writer.Append("		    alert('"+ AppLogic.GetString("adhoccharge.aspx.28", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "');\n");
                        writer.Append("		    theForm.CardNumber.focus();\n");
                        writer.Append("		    submitenabled(theForm);\n");
                        writer.Append("		    return (false);\n");
                        writer.Append("	    }\n");
                        writer.Append("        if(document.getElementById(\"CardNumber\").value.length <15)\n");
                        writer.Append("	    {\n");
                        writer.Append("		    alert('"+ AppLogic.GetString("adhoccharge.aspx.29", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "');\n");
                        writer.Append("		    theForm.CardNumber.focus();\n");
                        writer.Append("		    submitenabled(theForm);\n");
                        writer.Append("		    return (false);\n");
                        writer.Append("	    }\n");
                        writer.Append("        if(theForm.CardExpirationMonth.value == '')\n");
                        writer.Append("	    {\n");
                        writer.Append("		    alert('"+ String.Format(AppLogic.GetString("adhoccharge.aspx.22", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), "Card Expiration Month") + "');\n");
                        writer.Append("		    theForm.CardExpirationMonth.focus();\n");
                        writer.Append("		    submitenabled(theForm);\n");
                        writer.Append("		    return (false);\n");
                        writer.Append("	    }\n");
                        writer.Append("        if(theForm.CardExpirationYear.value == '')\n");
                        writer.Append("	    {\n");
                        writer.Append("		    alert('"+ String.Format(AppLogic.GetString("adhoccharge.aspx.22", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), "Card Expiration Year") + "');\n");
                        writer.Append("		    theForm.CardExpirationYear.focus();\n");
                        writer.Append("		    submitenabled(theForm);\n");
                        writer.Append("		    return (false);\n");
                        writer.Append("	    }\n");
                        writer.Append("        if(theForm.CardType.selectedIndex < 1)\n");
                        writer.Append("	    {\n");
                        writer.Append("		    alert('"+ String.Format(AppLogic.GetString("adhoccharge.aspx.22", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), "Card Type") + "');\n");
                        writer.Append("		    theForm.CardType.focus();\n");
                        writer.Append("		    submitenabled(theForm);\n");
                        writer.Append("		    return (false);\n");
                        writer.Append("	    }\n");
                        writer.Append("	}\n");
                        writer.Append("	submitenabled(theForm);\n");
                        writer.Append("	return (true);\n");
                        writer.Append("}\n");
                        writer.Append("</script>\n");
                        writer.Append(String.Format(AppLogic.GetString("adhoccharge.aspx.5", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), ONX.ToString()));
                        writer.Append("<p>" + AppLogic.GetString("adhoccharge.aspx.6", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</p>");

                        String CNM       = BillingAddress.CardName;
                        String CN        = BillingAddress.CardNumber;
                        String Last4     = String.Empty;
                        String CExpMonth = BillingAddress.CardExpirationMonth;
                        String CExpYear  = BillingAddress.CardExpirationYear;
                        String CardType  = BillingAddress.CardType;
                        if (CN.Length == 0)
                        {
                            // try to pull it from order record:
                            using (SqlConnection dbconn = new SqlConnection(DB.GetDBConn()))
                            {
                                dbconn.Open();
                                using (IDataReader rs2 = DB.GetRS("select * from Orders  with (NOLOCK)  where OrderNumber=" + ONX.ToString(), dbconn))
                                {
                                    if (rs2.Read())
                                    {
                                        CN        = DB.RSField(rs2, "CardNumber");
                                        CNM       = DB.RSField(rs2, "CardName");
                                        Last4     = DB.RSField(rs2, "Last4");
                                        CExpMonth = DB.RSField(rs2, "CardExpirationMonth");
                                        CExpYear  = DB.RSField(rs2, "CardExpirationYear");
                                        CN        = DB.RSField(rs2, "CardNumber");
                                        CN        = Security.UnmungeString(CN, DB.RSField(rs2, AppLogic.AppConfig("OrdersCCSaltField")));
                                        if (CN.StartsWith(Security.ro_DecryptFailedPrefix, StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            CN = DB.RSField(rs2, "CardNumber");
                                        }
                                        CardType = DB.RSField(rs2, "CardType");
                                    }
                                }
                            }
                        }


                        if (AppLogic.ProductIsMLExpress() == false)
                        {
                            if (AppLogic.AppConfigBool("StoreCCInDB") && OrderCustomer.StoreCCInDB && CN.Length > 0)
                            {
                                Security.LogEvent(AppLogic.GetString("admin.common.ViewedCreditCard", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), String.Format(AppLogic.GetString("admin.adhoccharge.ViewedCardNumber", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), CN.Replace("*", "").Substring(CN.Replace("*", "").Length - 4).PadLeft(CN.Replace("*", "").Length, '*'), ONX.ToString()), OrderCustomer.CustomerID, ThisCustomer.CustomerID, Convert.ToInt32(ThisCustomer.CurrentSessionID));
                            }
                        }

                        if (GatewayRequiresCC)
                        {
                            writer.Append("<p><b><font color=blue>" + AppLogic.GetString("adhoccharge.aspx.11", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</font></b></p>");
                        }
                        else
                        {
                            writer.Append("<p><b><font color=blue>" + AppLogic.GetString("adhoccharge.aspx.12", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</font></b></p>");
                        }

                        if (!OrderCustomer.StoreCCInDB)
                        {
                            writer.Append("<p><b><font color=red>" + AppLogic.GetString("adhoccharge.aspx.13", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</font></b></p>");
                        }

                        if (CN.Length == 0 || CN == AppLogic.ro_CCNotStoredString)
                        {
                            writer.Append("<p><b><font color=red>" + AppLogic.GetString("adhoccharge.aspx.14", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</font></b></p>");
                        }

                        if (OrderCustomer.PrimaryBillingAddressID == 0)
                        {
                            writer.Append("<p><b><font color=red>" + AppLogic.GetString("adhoccharge.aspx.7", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</font></b></p>");
                        }
                        else if (CN.Length == 0 && Last4.Length == 0 && GW != Gateway.ro_GWPAYPAL)
                        {
                            writer.Append("<p><b><font color=red>" + AppLogic.GetString("adhoccharge.aspx.8", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</font></b></p>");
                        }
                        else
                        {
                            writer.Append("<form id=\"AdHocChargeOrRefundForm\" name=\"AdHocChargeOrRefundForm\" method=\"POST\" action=\"" + AppLogic.AdminLinkUrl("adhoccharge.aspx") + "?OrderNumber=" + ONX.ToString() + "\" onsubmit=\"return (validateForm(this) && AdHocChargeOrRefundForm_Validator(this))\" >");
                            writer.Append("<input type=\"hidden\" name=\"IsSubmit\" value=\"true\">\n");
                            writer.Append("<table cellpadding=\"2\" cellspacing=\"0\" border=\"0\" width=\"100%\">");
                            writer.Append("<tr><td width=\"40%\" valign=\"middle\" align=\"right\">" + AppLogic.GetString("adhoccharge.aspx.9", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + " </td><td>" + OriginalTransactionID.ToString() + "</td></tr>");
                            writer.Append("<tr><td valign=\"middle\" align=\"right\">" + AppLogic.GetString("admin.label.CustomerID", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + " </td><td>" + OrderCustomer.CustomerID.ToString() + "</td></tr>");
                            writer.Append("<tr><td valign=\"middle\" align=\"right\">" + AppLogic.GetString("admin.label.CustomerName", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + " </td><td>" + OrderCustomer.FullName() + "</td></tr>");
                            writer.Append("<tr><td valign=\"middle\" align=\"right\">" + AppLogic.GetString("adhoccharge.aspx.27", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + " </td><td>" + BillingAddress.Phone + "</td></tr>");
                            writer.Append("<tr><td valign=\"middle\" align=\"right\">" + AppLogic.GetString("adhoccharge.aspx.16", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + " </td><td>");
                            writer.Append("<input onClick=\"AdHocOrderTypeChanged(AdHocChargeOrRefundForm)\" type=\"radio\" value=\"" + AppLogic.TransactionTypeEnum.CHARGE.ToString() + "\" id=\"ChargeOrderType\" name=\"OrderType\">" + AppLogic.GetString("adhoccharge.aspx.17", ThisCustomer.SkinID, ThisCustomer.LocaleSetting));
                            writer.Append("&nbsp;&nbsp;&nbsp;&nbsp;");
                            writer.Append("<input onClick=\"AdHocOrderTypeChanged(AdHocChargeOrRefundForm)\" type=\"radio\" value=\"" + AppLogic.TransactionTypeEnum.CREDIT.ToString() + "\" id=\"RefundOrderType\" name=\"OrderType\" checked>" + AppLogic.GetString("adhoccharge.aspx.18", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</td></tr>");
                            writer.Append("<tr><td valign=\"middle\" align=\"right\">" + AppLogic.GetString("adhoccharge.aspx.19", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + " </td><td><input type=\"text\" name=\"OrderTotal\" size=\"7\"><input type=\"hidden\" name=\"OrderTotal_vldt\" value=\"[req][number][blankalert=" + AppLogic.GetString("adhoccharge.aspx.26", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "][invalidalert=" + AppLogic.GetString("admin.common.ValidDollarAmountPrompt", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "]\"> (xx.xx format)</td></tr>");
                            writer.Append("<tr><td colspan=\"2\">");
                            writer.Append("<div id=\"CCDiv\" name=\"CCDiv\" style=\"display:" + CommonLogic.IIF(GatewayRequiresCC, "block", "none") + ";\">");
                            writer.Append("<table cellpadding=\"2\" cellspacing=\"0\" border=\"0\" width=\"100%\">");
                            writer.Append("<tr>");
                            writer.Append("<td width=\"40%\" align=\"right\" valign=\"middle\">" + AppLogic.GetString("address.cs.31", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</td>");
                            writer.Append("<td align=\"left\" valign=\"middle\">\n");
                            writer.Append("<select size=\"1\" name=\"CardType\" id=\"CardType\">");
                            writer.Append("<option value=\"\">" + AppLogic.GetString("address.cs.32", ThisCustomer.SkinID, ThisCustomer.LocaleSetting));
                            using (SqlConnection dbconn = new SqlConnection(DB.GetDBConn()))
                            {
                                dbconn.Open();
                                using (IDataReader rsCard = DB.GetRS("select * from creditcardtype  with (NOLOCK)  where Accepted=1 order by CardType", dbconn))
                                {
                                    while (rsCard.Read())
                                    {
                                        writer.Append("<option value=\"" + DB.RSField(rsCard, "CardType") + "\" " + CommonLogic.IIF(CardType == DB.RSField(rsCard, "CardType"), " selected ", "") + ">" + DB.RSField(rsCard, "CardType") + "</option>\n");
                                    }
                                }
                            }
                            writer.Append("</select>\n");
                            writer.Append("</td>");
                            writer.Append("</tr>");
                            writer.Append("<tr><td width=\"40%\" valign=\"middle\" align=\"right\">" + AppLogic.GetString("adhoccharge.aspx.10", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + " </td><td><input size=\"20\" maxlength=\"100\" type=\"text\" name=\"CardName\" id=\"CardName\" value=\"" + CNM + "\"></td></tr>");
                            writer.Append("<tr><td valign=\"middle\" align=\"right\">" + AppLogic.GetString("adhoccharge.aspx.24", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + " </td><td><input size=\"20\" maxlength=\"16\" type=\"text\" autocomplete=\"off\" name=\"CardNumber\" id=\"CardNumber\" value=\"" + CN + "\">&nbsp;" + String.Format(AppLogic.GetString("admin.adhoccharge.OriginalOrderLastFour", ThisCustomer.SkinID, ThisCustomer.LocaleSetting), Last4) + ")</td></tr>");
                            writer.Append("<tr><td valign =\"middle\" align=\"right\">" + AppLogic.GetString("adhoccharge.aspx.15", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + " </td><td><input size=\"4\" maxlength=\"4\" type=\"text\" autocomplete=\"off\" name=\"CardExtraCode\" id=\"CardExtraCode\">");
                            writer.Append("<tr><td valign=\"middle\" align=\"right\">" + AppLogic.GetString("adhoccharge.aspx.25", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + " </td><td><input type=\"text\" size=\"2\" maxlength=\"2\" name=\"CardExpirationMonth\" id=\"CardExpirationMonth\" value=\"" + CExpMonth + "\"> / <input size=\"4\" maxlength=\"4\" type=\"text\" name=\"CardExpirationYear\" id=\"CardExpirationYear\" value=\"" + CExpYear + "\"> (MM/YYYY)</td></tr>");
                            if (AppLogic.AppConfigBool("ShowCardStartDateFields"))
                            {
                                writer.Append("<tr><td valign=\"middle\" align=\"right\">" + AppLogic.GetString("address.cs.59", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</td><td><input type=\"text\" autocomplete=\"off\" name=\"CardStartDate\" id=\"CardStartDate\" size=\"5\" maxlength=\"20\"> " + AppLogic.GetString("address.cs.64", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</td></tr>");
                                writer.Append("<tr><td valign=\"middle\" align=\"right\">" + AppLogic.GetString("address.cs.61", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</td><td><input type=\"text\" autocomplete=\"off\" name=\"CardIssueNumber\" id=\"CardIssueNumber\" size=\"2\" maxlength=\"2\"> " + AppLogic.GetString("address.cs.63", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</td></tr>");
                            }
                            writer.Append("</table>");
                            writer.Append("</div>");
                            writer.Append("</td></tr>");
                            writer.Append("</table>");
                            writer.Append("	<p>" + AppLogic.GetString("adhoccharge.aspx.20", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + " </p>");
                            writer.Append("	<p><textarea rows=\"8\" id=\"Description\" name=\"Description\" style=\"width: 90%\"></textarea></p>");
                            writer.Append("	<p align=\"center\"><input type=\"submit\" value=\"" + AppLogic.GetString("adhoccharge.aspx.21", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "\" name=\"B1\" class=\"normalButtons\">&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"button\" value=\"" + AppLogic.GetString("admin.common.Cancel", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "\" name=\"B2\" onClick=\"javascript:self.close()\" class=\"normalButtons\"></p>");
                            writer.Append("</form>");
                        }
                    }
                }
            }
            writer.Append("</div>");
            ltContent.Text = writer.ToString();
        }
示例#16
0
        /// <summary>
        /// This will check for an existing AutoBill order for the CustomerID and
        /// return the number of days left on that order's subscription, if any.
        /// The existing AutoBill order will be canceled and the items deleted
        /// from the cart.
        /// This should only be used with AppConfig Recurring.LimitCustomerToOneOrder=TRUE
        /// </summary>
        /// <param name="CustomerID"></param>
        /// <returns>Number of subscription days to migrate from existing order. If not a subscription we return zero.</returns>
        public static int ProcessAutoBillMigrateExisting(int CustomerID)
        {
            // This should only be used with AppConfig Recurring.LimitCustomerToOneOrder=TRUE

            int    MigrateDays = 0;
            int    OriginalRecurringOrderNumber = 0;
            bool   IsSubscription          = false;
            String Status                  = AppLogic.ro_OK;
            String RecurringSubscriptionID = String.Empty;

            using (SqlConnection dbconn = new SqlConnection(DB.GetDBConn()))
            {
                dbconn.Open();
                using (IDataReader rs = DB.GetRS("Select top 1 OriginalRecurringOrderNumber, RecurringInterval from ShoppingCart  with (NOLOCK)  where RecurringSubscriptionID<>'' and CustomerID=" + CustomerID.ToString() + " order by OriginalRecurringOrderNumber desc", dbconn))
                {
                    if (rs.Read())
                    {
                        OriginalRecurringOrderNumber = DB.RSFieldInt(rs, "OriginalRecurringOrderNumber");
                        IsSubscription = (DB.RSFieldInt(rs, "RecurringInterval") > 0);
                    }
                }
            }

            if (OriginalRecurringOrderNumber != 0)
            {
                if (IsSubscription && !AppLogic.AppConfigBool("SubscriptionExtensionOccursFromOrderDate"))
                {
                    // get customer's current subscription expiration and compute days remaining
                    using (SqlConnection dbconn = new SqlConnection(DB.GetDBConn()))
                    {
                        dbconn.Open();
                        using (IDataReader rsCust = DB.GetRS("Select SubscriptionExpiresOn from customer  with (NOLOCK)  where CustomerID=" + CustomerID.ToString(), dbconn))
                        {
                            if (rsCust.Read())
                            {
                                TimeSpan TimeRemaining = DB.RSFieldDateTime(rsCust, "SubscriptionExpiresOn").Subtract(DateTime.Today);
                                // Only carry forward if Expires in future
                                if (TimeRemaining.Days > 0)
                                {
                                    MigrateDays = TimeRemaining.Days;
                                }
                            }
                        }
                    }
                }

                RecurringSubscriptionID = AppLogic.GetRecurringSubscriptionIDFromOrder(OriginalRecurringOrderNumber);

                if (RecurringSubscriptionID.Length != 0)
                {
                    // cancel the existing gateway billing
                    String GW = AppLogic.ActivePaymentGatewayCleaned();
                    if (RecurringSubscriptionID.Length != 0)
                    {
                        if (GW == Gateway.ro_GWPAYFLOWPRO)
                        {
                            GatewayProcessor             pfp = GatewayLoader.GetProcessor(Gateway.ro_GWPAYFLOWPRO);
                            IDictionary <string, string> transactionContext = new Dictionary <string, string>();

                            if (RecurringSubscriptionID.ToUpper().StartsWith("B-"))
                            {
                                transactionContext.Add("TENDER", "P");
                            }

                            Status = pfp.RecurringBillingCancelSubscription(RecurringSubscriptionID, OriginalRecurringOrderNumber, transactionContext);
                        }
                        else
                        {
                            Status = "Invalid Gateway";
                        }
                    }
                }

                // now clean up the original order from the cart
                DB.ExecuteSQL(String.Format("delete from kitcart where OriginalRecurringOrderNumber={0}", OriginalRecurringOrderNumber.ToString()));
                DB.ExecuteSQL(String.Format("delete from ShoppingCart where OriginalRecurringOrderNumber={0}", OriginalRecurringOrderNumber.ToString()));
            }
            else
            {
                Status = "OriginalRecurringOrderNumber Not Found.";
            }

            if (AppLogic.AppConfigBool("AuditLog.Enabled"))
            {
                StringBuilder sbDetails = new StringBuilder("Result=" + Status);
                sbDetails.Append(", RecurringSubscriptionID=" + RecurringSubscriptionID);
                sbDetails.Append(", MigrateDays=" + MigrateDays.ToString());
                AppLogic.AuditLogInsert(0, CustomerID, OriginalRecurringOrderNumber, "ProcessAutoBillMigrateExisting", sbDetails.ToString(), CommonLogic.GetThisPageName(true), "RecurringOrderMgr");
            }
            return(MigrateDays);
        }
示例#17
0
        // main routine to cancel any active recurring order (can be subscription autobill or in-cart):
        public String CancelRecurringOrder(int OriginalRecurringOrderNumber)
        {
            String Status = AppLogic.ro_OK;

            if (OriginalRecurringOrderNumber != 0)
            {
                String RecurringSubscriptionID = AppLogic.GetRecurringSubscriptionIDFromOrder(OriginalRecurringOrderNumber);

                if (RecurringSubscriptionID.Length != 0)
                {
                    // a Gateway AutoBill order, so cancel the gateway billing first:
                    String GW = AppLogic.ActivePaymentGatewayCleaned();
                    if (RecurringSubscriptionID.Length != 0)
                    {
                        // dynamically load the gateway processor class via the name
                        GatewayProcessor processor = GatewayLoader.GetProcessor(GW);

                        IDictionary <string, string> transactionContext = new Dictionary <string, string>();

                        if (RecurringSubscriptionID.ToUpper().StartsWith("B-"))
                        {
                            transactionContext.Add("TENDER", "P");
                        }

                        if (processor != null)
                        {
                            Status = processor.RecurringBillingCancelSubscription(RecurringSubscriptionID, OriginalRecurringOrderNumber, transactionContext);
                        }
                        else
                        {
                            if (GW == Gateway.ro_GWPAYFLOWPRO)
                            {
                                GatewayProcessor pfp = GatewayLoader.GetProcessor(Gateway.ro_GWPAYFLOWPRO);

                                Status = pfp.RecurringBillingCancelSubscription(RecurringSubscriptionID, OriginalRecurringOrderNumber, transactionContext);
                            }
                            else
                            {
                                Status = "Invalid Gateway";
                            }
                        }
                    }
                }

                int ProcessCustomerID = Order.GetOrderCustomerID(OriginalRecurringOrderNumber);

                if (Status == AppLogic.ro_OK)
                {
                    // now clean it up in the cart only if it cannot be restarted/reactivated
                    DB.ExecuteSQL(String.Format("delete from kitcart where OriginalRecurringOrderNumber={0}", OriginalRecurringOrderNumber.ToString()));
                    DB.ExecuteSQL(String.Format("delete from ShoppingCart where OriginalRecurringOrderNumber={0}", OriginalRecurringOrderNumber.ToString()));

                    // now notify customer of cancellation:
                    Customer ProcessCustomer = new Customer(ProcessCustomerID, true);

                    try
                    {
                        // send email notification to customer
                        string emailSubject = String.Format("{0} - Recurring Order Canceled", AppLogic.AppConfig("StoreName"));
                        string emailBody    = String.Format("Your recurring order has been canceled. The original order number was: {0}", OriginalRecurringOrderNumber.ToString());
                        AppLogic.SendMail(subject: emailSubject,
                                          body: emailBody + AppLogic.AppConfig("MailFooter"),
                                          useHtml: true,
                                          fromAddress: AppLogic.AppConfig("ReceiptEMailFrom"),
                                          fromName: AppLogic.AppConfig("ReceiptEMailFromName"),
                                          toAddress: ProcessCustomer.EMail,
                                          toName: ProcessCustomer.EMail,
                                          bccAddresses: String.Empty,
                                          server: AppLogic.MailServer());


                        // send email notification to admin
                        if (AppLogic.AppConfig("GotOrderEMailTo").Length != 0 && !AppLogic.AppConfigBool("TurnOffStoreAdminEMailNotifications"))
                        {
                            String SendToList = AppLogic.AppConfig("GotOrderEMailTo").Replace(",", ";");
                            if (SendToList.IndexOf(';') != -1)
                            {
                                foreach (String s in SendToList.Split(';'))
                                {
                                    AppLogic.SendMail(subject: emailSubject,
                                                      body: emailBody + AppLogic.AppConfig("MailFooter"),
                                                      useHtml: true,
                                                      fromAddress: AppLogic.AppConfig("GotOrderEMailFrom"),
                                                      fromName: AppLogic.AppConfig("GotOrderEMailFromName"),
                                                      toAddress: s.Trim(),
                                                      toName: s.Trim(),
                                                      bccAddresses: String.Empty,
                                                      server: AppLogic.MailServer());
                                }
                            }
                            else
                            {
                                AppLogic.SendMail(subject: emailSubject,
                                                  body: emailBody + AppLogic.AppConfig("MailFooter"),
                                                  useHtml: true,
                                                  fromAddress: AppLogic.AppConfig("GotOrderEMailFrom"),
                                                  fromName: AppLogic.AppConfig("GotOrderEMailFromName"),
                                                  toAddress: SendToList,
                                                  toName: SendToList,
                                                  bccAddresses: String.Empty,
                                                  server: AppLogic.MailServer());
                            }
                        }
                    }
                    catch { }
                }

                if (AppLogic.AppConfigBool("AuditLog.Enabled"))
                {
                    StringBuilder sbDetails = new StringBuilder("Result=" + Status);
                    sbDetails.Append(", RecurringSubscriptionID=" + RecurringSubscriptionID);
                    AppLogic.AuditLogInsert(0, ProcessCustomerID, OriginalRecurringOrderNumber, "CancelRecurringOrder", sbDetails.ToString(), CommonLogic.GetThisPageName(true), "RecurringOrderMgr");
                }
            }
            return(Status);
        }