コード例 #1
0
 static public String GetSqlServerLocale()
 {
     if (SqlServerLocale.Length == 0)
     {
         SqlServerLocale  = CommonLogic.Application("DBSQLServerLocaleSetting");
         SqlServerCulture = new CultureInfo(SqlServerLocale);
     }
     return(SqlServerLocale);
 }
コード例 #2
0
        /// <summary>
        /// Precompute the line item vat and discounts and attach it inside the order info node
        /// </summary>
        /// <param name="nav">The XPathNavigator</param>
        private void PreComputeLineItemIntrinsics(XPathNavigator nav)
        {
            XmlNode           orderInfoNode        = GetXmlNode(nav.SelectSingleNode("Order/OrderInfo"));
            XPathNodeIterator lineItemNodeIterator = nav.Select("OrderItems/Item");
            CultureInfo       cultureInfo;
            var orderCultureInfo = CommonLogic.Application("DBSQLServerLocaleSetting");

            cultureInfo = string.IsNullOrEmpty(orderCultureInfo)
                                ? CultureInfo.InvariantCulture
                                : new CultureInfo(orderCultureInfo);

            decimal allLineItemDiscounts = decimal.Zero;

            while (lineItemNodeIterator.MoveNext())
            {
                XmlNode lineItemNode = GetXmlNode(lineItemNodeIterator.Current);

                bool isAKit = XmlCommon.XmlFieldBool(lineItemNode, "IsAKit");

                int quantity = 1;
                int.TryParse(XmlCommon.XmlField(lineItemNode, "Quantity"), out quantity);

                decimal price = 0;
                Decimal.TryParse(XmlCommon.XmlField(lineItemNode, "OrderedProductRegularPrice"), NumberStyles.AllowDecimalPoint, cultureInfo, out price);

                decimal orderedExtendedPrice = 0;
                Decimal.TryParse(XmlCommon.XmlField(lineItemNode, "OrderedProductPrice"), NumberStyles.AllowDecimalPoint, cultureInfo, out orderedExtendedPrice);

                decimal taxRate = Decimal.Parse(XmlCommon.XmlField(lineItemNode, "TaxRate"), NumberStyles.AllowDecimalPoint, cultureInfo);

                decimal vatAmount         = decimal.Zero;
                decimal extendedVatAmount = decimal.Zero;

                bool applyVat = AppLogic.AppConfigBool("VAT.Enabled") == true &&
                                XmlCommon.XmlFieldBool(orderInfoNode, "LevelHasNoTax") == false &&
                                XmlCommon.XmlFieldBool(lineItemNode, "IsTaxable") == true &&
                                string.IsNullOrEmpty(XmlCommon.XmlField(orderInfoNode, "VATRegistrationID"));

                if (applyVat)
                {
                    if (AppLogic.AppConfigBool("VAT.RoundPerItem"))
                    {
                        vatAmount         = (((price / quantity) * taxRate) / 100M) * quantity;
                        extendedVatAmount = (((orderedExtendedPrice / quantity) * taxRate) / 100M) * quantity;
                    }
                    else
                    {
                        vatAmount         = (price * taxRate) / 100M;
                        extendedVatAmount = (orderedExtendedPrice * taxRate) / 100M;
                    }

                    if (isAKit)
                    {
                        vatAmount = extendedVatAmount / quantity;
                    }
                }
                // let's save these as decimal values, leave out formatting on a later call
                XmlNode vatAmountNode = lineItemNode.OwnerDocument.CreateNode(XmlNodeType.Element, "VatAmount", string.Empty);
                vatAmountNode.InnerText = XmlCommon.XmlEncode(vatAmount.ToString(cultureInfo));

                XmlNode extVatAmountNode = lineItemNode.OwnerDocument.CreateNode(XmlNodeType.Element, "ExtVatAmount", string.Empty);
                extVatAmountNode.InnerText = XmlCommon.XmlEncode(extendedVatAmount.ToString(cultureInfo));

                // insert these nodes on the bottom
                lineItemNode.InsertAfter(vatAmountNode, lineItemNode.LastChild);
                lineItemNode.InsertAfter(extVatAmountNode, lineItemNode.LastChild);

                decimal regularExtendedPrice = decimal.Zero;
                decimal discount             = decimal.Zero;

                // kit products don't save the regular price only the sales price
                // we won't be supporting line item discounts on these item types then
                if (isAKit)
                {
                    regularExtendedPrice = decimal.Zero;
                    discount             = decimal.Zero;

                    price = orderedExtendedPrice / quantity;
                }
                else
                {
                    // make sure to round to 2 decimal places
                    price = Math.Round(price, 2, MidpointRounding.AwayFromZero);
                    regularExtendedPrice = price * quantity;
                    discount             = (regularExtendedPrice - orderedExtendedPrice);
                }

                bool showPriceVatInclusive = ThisCustomer.VATSettingReconciled == VATSettingEnum.ShowPricesInclusiveOfVAT;

                decimal displayPrice = price;
                if (applyVat && showPriceVatInclusive)
                {
                    displayPrice += vatAmount;
                }

                decimal displayExtPrice = orderedExtendedPrice;
                if (applyVat && showPriceVatInclusive)
                {
                    displayExtPrice += extendedVatAmount;
                }

                // let's save these as decimal values, leave out formatting on a later call
                XmlNode extRegularPriceNode = lineItemNode.OwnerDocument.CreateNode(XmlNodeType.Element, "ExtendedRegularPrice", string.Empty);
                extRegularPriceNode.InnerText = XmlCommon.XmlEncode(regularExtendedPrice.ToString(cultureInfo));
                // insert these nodes on the bottom
                lineItemNode.InsertAfter(extRegularPriceNode, lineItemNode.LastChild);

                XmlNode discountNode = lineItemNode.OwnerDocument.CreateNode(XmlNodeType.Element, "DiscountAmount", string.Empty);
                discountNode.InnerText = XmlCommon.XmlEncode(discount.ToString(cultureInfo));
                // insert these nodes on the bottom
                lineItemNode.InsertAfter(discountNode, lineItemNode.LastChild);

                // price column
                XmlNode priceNode = lineItemNode.OwnerDocument.CreateNode(XmlNodeType.Element, "Price", string.Empty);
                priceNode.InnerText = XmlCommon.XmlEncode(price.ToString(cultureInfo));
                // insert these nodes on the bottom
                lineItemNode.InsertAfter(priceNode, lineItemNode.LastChild);

                XmlNode displayPriceNode = lineItemNode.OwnerDocument.CreateNode(XmlNodeType.Element, "DisplayPrice", string.Empty);
                displayPriceNode.InnerText = XmlCommon.XmlEncode(displayPrice.ToString(cultureInfo));
                // insert these nodes on the bottom
                lineItemNode.InsertAfter(displayPriceNode, lineItemNode.LastChild);

                XmlNode displayExtPriceNode = lineItemNode.OwnerDocument.CreateNode(XmlNodeType.Element, "DisplayExtPrice", string.Empty);
                displayExtPriceNode.InnerText = XmlCommon.XmlEncode(displayExtPrice.ToString(cultureInfo));
                // insert these nodes on the bottom
                lineItemNode.InsertAfter(displayExtPriceNode, lineItemNode.LastChild);

                XmlNode discountWithVATNode = lineItemNode.OwnerDocument.CreateNode(XmlNodeType.Element, "DiscountWithVAT", string.Empty);
                discountWithVATNode.InnerText = XmlCommon.XmlEncode((displayPrice - displayExtPrice).ToString(cultureInfo));
                // insert these nodes on the bottom
                lineItemNode.InsertAfter(discountWithVATNode, lineItemNode.LastChild);

                // store the line item discounts
                allLineItemDiscounts += XmlCommon.XmlFieldNativeDecimal(lineItemNode, "DiscountAmount");
            }

            bool hasLineItemDiscounts = false;

            hasLineItemDiscounts = allLineItemDiscounts > decimal.Zero;

            XmlNode hasLineItemDiscountsNode = orderInfoNode.OwnerDocument.CreateNode(XmlNodeType.Element, "HasLineItemDiscounts", string.Empty);

            hasLineItemDiscountsNode.InnerText = XmlCommon.XmlEncode(hasLineItemDiscounts.ToString(cultureInfo));
            orderInfoNode.InsertAfter(hasLineItemDiscountsNode, orderInfoNode.LastChild);
        }
コード例 #3
0
        public static String GetEncryptParam(String ParamName)
        {
            var param = string.Empty;

            if (ParamName == "EncryptKey")
            {
                // Pull the encryption key from appsettings.
                param = CommonLogic.Application(ParamName);

                // The EncryptKey AppSetting will either be plain text from a merchant manually setting the value
                //  or it will be encrypted from setting it via the Change Encrypt Key in admin. If it was set through
                //  the admin, a KEK and a TEK will have been generated. Bypass decryption if neither are set.
                var keyEncryptionKeyConfig = GlobalConfig.GetGlobalConfig(KeyEncryptionKeyName);
                var tertiaryEncryptionKey  = ConfigurationManager.AppSettings[TertiaryEncryptionKeyName];

                if (keyEncryptionKeyConfig != null &&
                    !string.IsNullOrWhiteSpace(keyEncryptionKeyConfig.ConfigValue) &&
                    !string.IsNullOrWhiteSpace(tertiaryEncryptionKey))
                {
                    var encryptIterations    = AppLogic.AppConfigNativeInt("EncryptIterations");
                    var hashAlgorithm        = AppLogic.AppConfig("HashAlgorithm");
                    var initializationVector = AppLogic.AppConfig("InitializationVector");
                    var keySize = AppLogic.AppConfigNativeInt("KeySize");

                    // We found the KEK and the TEK, decrypt the KEK using the TEK.
                    var decryptedKEK = Security.UnmungeString(keyEncryptionKeyConfig.ConfigValue, string.Empty, new Security.SecurityParams
                    {
                        EncryptIterations    = encryptIterations,
                        EncryptKey           = tertiaryEncryptionKey,
                        HashAlgorithm        = hashAlgorithm,
                        InitializationVector = initializationVector,
                        KeySize = keySize
                    });

                    // Decrypt the Encrypt Key using the decrypted KEK.
                    param = Security.UnmungeString(param, string.Empty, new Security.SecurityParams
                    {
                        EncryptIterations    = encryptIterations,
                        EncryptKey           = decryptedKEK,
                        HashAlgorithm        = hashAlgorithm,
                        InitializationVector = initializationVector,
                        KeySize = keySize
                    });
                }
            }
            else
            {
                param = AppLogic.AppConfig(ParamName);
            }

            // now do validation!
            if (ParamName == "EncryptKey")
            {
                if (param.Length == 0 || param == "WIZARD" ||
                    param == AppLogic.ro_TBD)
                {
                    throw new ArgumentException("You must enter your EncryptKey in the /AppSettings.config file!!! Review documentation for instructions.");
                }
            }

            if (ParamName == "EncryptIterations")
            {
                if (param.Length == 0 && !CommonLogic.IsInteger(param) && Convert.ToInt32(param) >= 1 &&
                    Convert.ToInt32(param) <= 4)
                {
                    throw new ArgumentException("The EncryptIterations parameter must be an integer value between 1 and 4.");
                }
            }

            if (ParamName == "InitializationVector")
            {
                if (param.Length == 0 || param == AppLogic.ro_TBD ||
                    param.Length != 16)
                {
                    throw new ArgumentException("You MUST set your InitializationVector in the AppConfig manager in the admin site! it MUST be exactly 16 characters/digits long. This is required for security reasons.");
                }
            }

            if (ParamName == "KeySize")
            {
                if (param.Length == 0 || param == "0" ||
                    (param != "128" && param != "192" && param != "256"))
                {
                    throw new ArgumentException("You MUST set your KeySize value in the AppConfig manager in the admin site to an allowed valid value! This is required for security reasons.");
                }
            }

            if (ParamName == "HashAlgorithm")
            {
                if (param.Length == 0 ||
                    (param != "MD5" && param != "SHA1"))
                {
                    throw new ArgumentException("You MUST set your HashAlgorithm in the AppConfig manager in the admin site to an allowed valid value! This is required for security reasons.");
                }
            }

            return(param);
        }
コード例 #4
0
        public static String GetEncryptParam(String ParamName)
        {
            String param = string.Empty;

            if (ParamName == "EncryptKey")
            {
                param = CommonLogic.Application(ParamName);
            }
            else
            {
                param = AppLogic.AppConfig(ParamName);
            }

            // now do validation!
            if (ParamName == "EncryptKey")
            {
                if (param.Length == 0 || param == "WIZARD" ||
                    param == AppLogic.ro_TBD)
                {
                    throw new ArgumentException("You must enter your EncryptKey in the /web.config file!!! Open that file in Notepad, and see the instructions.");
                }
            }

            if (ParamName == "EncryptIterations")
            {
                if (param.Length == 0 && !CommonLogic.IsInteger(param) && Convert.ToInt32(param) >= 1 &&
                    Convert.ToInt32(param) <= 4)
                {
                    throw new ArgumentException("The EncryptIterations parameter must be an integer value between 1 and 4.");
                }
            }

            if (ParamName == "InitializationVector")
            {
                if (param.Length == 0 || param == AppLogic.ro_TBD ||
                    param.Length != 16)
                {
                    throw new ArgumentException("You MUST set your InitializationVector in the AppConfig manager in the admin site! it MUST be exactly 16 characters/digits long. This is required for security reasons.");
                }
            }

            if (ParamName == "KeySize")
            {
                if (param.Length == 0 || param == "0" ||
                    (param != "128" && param != "192" && param != "256"))
                {
                    throw new ArgumentException("You MUST set your KeySize value in the AppConfig manager in the admin site to an allowed valid value! This is required for security reasons.");
                }
            }

            if (ParamName == "HashAlgorithm")
            {
                if (param.Length == 0 ||
                    (param != "MD5" && param != "SHA1"))
                {
                    throw new ArgumentException("You MUST set your HashAlgorithm in the AppConfig manager in the admin site to an allowed valid value! This is required for security reasons.");
                }
            }

            return(param);
        }