コード例 #1
0
        // returns true if no errors, and card is enrolled:
        static public bool PreChargeLookup(string cardNumber,
                                           int cardExpirationYear,
                                           int cardExpirationMonth,
                                           int orderNumber,
                                           decimal orderTotal,
                                           string orderDescription,
                                           out string acsUrl,
                                           out string payload,
                                           out string transactionId,
                                           out string cardinalLookupResult)
        {
            var ccRequest     = new CardinalCommerce.CentinelRequest();
            var ccResponse    = new CardinalCommerce.CentinelResponse();
            var numAttempts   = AppLogic.AppConfigUSInt("CardinalCommerce.Centinel.NumRetries");
            var callSucceeded = false;

            payload       = string.Empty;
            acsUrl        = String.Empty;
            transactionId = String.Empty;

            // ==================================================================================
            // Construct the cmpi_lookup message
            // ==================================================================================

            ccRequest.add("MsgType", AppLogic.AppConfig("CardinalCommerce.Centinel.MsgType.Lookup"));
            ccRequest.add("Version", "1.7");
            ccRequest.add("ProcessorId", AppLogic.AppConfig("CardinalCommerce.Centinel.ProcessorID"));
            ccRequest.add("MerchantId", AppLogic.AppConfig("CardinalCommerce.Centinel.MerchantID"));
            ccRequest.add("TransactionPwd", AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionPwd"));
            ccRequest.add("TransactionType", "C");             //C = Credit Card / Debit Card Authentication.
            ccRequest.add("Amount", Localization.CurrencyStringForGatewayWithoutExchangeRate(orderTotal).Replace(",", "").Replace(".", ""));
            ccRequest.add("CurrencyCode", Localization.StoreCurrencyNumericCode());
            ccRequest.add("CardNumber", cardNumber);
            ccRequest.add("CardExpMonth", cardExpirationMonth.ToString().PadLeft(2, '0'));
            ccRequest.add("CardExpYear", cardExpirationYear.ToString().PadLeft(4, '0'));
            ccRequest.add("OrderNumber", orderNumber.ToString());

            // Optional fields
            ccRequest.add("OrderDescription", orderDescription);
            ccRequest.add("UserAgent", CommonLogic.ServerVariables("HTTP_USER_AGENT"));
            ccRequest.add("Recurring", "N");

            if (numAttempts == 0)
            {
                numAttempts = 1;
            }

            for (int i = 1; i <= numAttempts; i++)
            {
                callSucceeded = true;
                try
                {
                    var URL = AppLogic.AppConfigBool("CardinalCommerce.Centinel.IsLive")
                                                ? AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionUrl.Live")
                                                : AppLogic.AppConfig("CardinalCommerce.Centinel.TransactionUrl.Test");

                    ccResponse = ccRequest.sendHTTP(URL, AppLogic.AppConfigUSInt("CardinalCommerce.Centinel.MapsTimeout"));
                }
                catch
                {
                    callSucceeded = false;
                }
                if (callSucceeded)
                {
                    break;
                }
            }

            if (callSucceeded)
            {
                var errorNo  = ccResponse.getValue("ErrorNo");
                var enrolled = ccResponse.getValue("Enrolled");
                payload       = ccResponse.getValue("Payload");
                acsUrl        = ccResponse.getValue("ACSUrl");
                transactionId = ccResponse.getValue("TransactionId");

                cardinalLookupResult = ccResponse.getUnparsedResponse();

                ccRequest  = null;
                ccResponse = null;

                //======================================================================================
                // Assert that there was no error code returned and the Cardholder is enrolled in the
                // Payment Authentication Program prior to starting the Authentication process.
                //======================================================================================

                if (errorNo == "0" && enrolled == "Y")
                {
                    return(true);
                }
                return(false);
            }
            ccRequest            = null;
            ccResponse           = null;
            cardinalLookupResult = AppLogic.GetString("cardinal.cs.1", 1, Localization.GetDefaultLocale());
            return(false);
        }
コード例 #2
0
        /// <summary>
        /// Attaches the Order Options text as Xml element contained in the OrderInfo Node
        /// </summary>
        /// <param name="nav">The XPathNavigator</param>
        private void AttachOrderOptionsXml(XPathNavigator nav)
        {
            XmlNode orderInfoNode = GetXmlNode(nav.SelectSingleNode("Order/OrderInfo"));

            CultureInfo culture = new CultureInfo(ThisCustomer.LocaleSetting);

            try
            {
                XmlNode orderOptionsNode = orderInfoNode.SelectSingleNode("OrderOptions");
                if (null == orderOptionsNode)
                {
                    return;
                }
                XmlDocument doc = orderInfoNode.OwnerDocument;

                string orderOptions = orderOptionsNode.InnerText;

                XmlNode orderOptionsXml = doc.CreateNode(XmlNodeType.Element, "OrderOptionsXml", string.Empty);

                if (!string.IsNullOrEmpty(orderOptions))
                {
                    string[] orderOptionDelimitedValues = orderOptions.Split('^');
                    foreach (string orderOptionDelimitedValue in orderOptionDelimitedValues)
                    {
                        string[] orderOptionValues = orderOptionDelimitedValue.Split('|');
                        if (orderOptionValues != null && orderOptionValues.Length > 0)
                        {
                            int    id       = int.Parse(orderOptionValues[0]);
                            Guid   uniqueID = new Guid(orderOptionValues[1]);
                            string name     = orderOptionValues[2];

                            string priceFormatted = orderOptionValues[3];
                            // NOTE:
                            // Since the order options are attached to the order as a | delimited string
                            // and the price and tax amounts are already hardcoded as strings together
                            // with their currency symbols, we need to extract only the numeric values
                            decimal price = ParseAmount(priceFormatted, culture);
                            // since the order option is saved as one whole string
                            // the price saved here is already converted into the target curency format
                            // we'll need to revert to the original currency setting so to display properly especially on different currencies
                            price = Currency.Convert(price, ThisCustomer.CurrencySetting, Localization.GetPrimaryCurrency());

                            string extPriceFormatted = priceFormatted;

                            bool    withVat      = orderOptionValues.Length >= 4;
                            string  vatFormatted = string.Empty;
                            decimal vat          = decimal.Zero;
                            if (withVat)
                            {
                                vatFormatted = orderOptionValues[4];
                                vat          = ParseAmount(vatFormatted, culture);
                            }

                            XmlNode orderOptionNode = doc.CreateNode(XmlNodeType.Element, "OrderOption", string.Empty);

                            // the details
                            XmlNode idNode       = doc.CreateNode(XmlNodeType.Element, "ID", string.Empty);
                            XmlNode nameNode     = doc.CreateNode(XmlNodeType.Element, "ProductName", string.Empty);
                            XmlNode priceNode    = doc.CreateNode(XmlNodeType.Element, "Price", string.Empty);
                            XmlNode vatNode      = doc.CreateNode(XmlNodeType.Element, "VAT", string.Empty);
                            XmlNode imageUrlNode = doc.CreateNode(XmlNodeType.Element, "ImageUrl", string.Empty);

                            idNode.InnerText    = XmlCommon.XmlEncode(id.ToString());
                            nameNode.InnerXml   = XmlCommon.XmlEncode(name);                           // NOTE: this value may be localized, make sure to call GetMLValue on the xml package!!!
                            priceNode.InnerText = XmlCommon.XmlEncode(price.ToString());
                            vatNode.InnerText   = XmlCommon.XmlEncode(vat.ToString());

                            // get the image info
                            string imgUrl = orderOptionValues[5];

                            if (!string.IsNullOrEmpty(CommonLogic.ServerVariables("HTTP_HOST")))
                            {
                                imgUrl = "http://" + CommonLogic.ServerVariables("HTTP_HOST") + imgUrl;
                            }

                            imageUrlNode.InnerText = XmlCommon.XmlEncode(imgUrl);

                            orderOptionNode.AppendChild(idNode);
                            orderOptionNode.AppendChild(nameNode);
                            orderOptionNode.AppendChild(priceNode);
                            orderOptionNode.AppendChild(vatNode);
                            orderOptionNode.AppendChild(imageUrlNode);

                            orderOptionsXml.AppendChild(orderOptionNode);
                        }
                    }
                }

                orderInfoNode.InsertAfter(orderOptionsXml, orderInfoNode.LastChild);
            }
            catch { }
        }
コード例 #3
0
ファイル: Parser.cs プロジェクト: lulzzz/BrandStore
        // these can change on EVERY page request!!
        public void BuildPageDynamicTokens()
        {
            if (m_DynamicTokens == null)
            {
                // page/customer specific items (that may change every page):
                m_DynamicTokens = new Hashtable();

                if (CommonLogic.GetThisPageName(false).ToLowerInvariant().StartsWith("orderconfirmation.aspx"))
                {
                    m_DynamicTokens.Add("(!GOOGLE_ECOM_TRACKING!)", AppLogic.GetGoogleEComTracking(ThisCustomer));
                }
                else
                {
                    m_DynamicTokens.Add("(!GOOGLE_ECOM_TRACKING!)", String.Empty);
                }

                if (CommonLogic.GetThisPageName(false).ToLowerInvariant().StartsWith("orderconfirmation.aspx"))
                {
                    m_DynamicTokens.Add("(!GOOGLE_ECOM_TRACKING_V2!)", String.Empty);
                }
                else
                {
                    m_DynamicTokens.Add("(!GOOGLE_ECOM_TRACKING_V2!)", AppLogic.GetGoogleEComTrackingV2(ThisCustomer, false));
                }

                if (!AppLogic.VATIsEnabled())
                {
                    m_DynamicTokens.Add("(!VATREGISTRATIONID!)", String.Empty);
                }
                else
                {
                    StringBuilder tmpS2 = new StringBuilder(1024);
                    if (ThisCustomer.HasCustomerRecord)
                    {
                        tmpS2.Append("<span class=\"VATRegistrationIDPrompt\">" + AppLogic.GetString("setvatsetting.aspx.8", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</span><input type=\"text\" style=\"VATRegistrationID\" id=\"VATRegistrationID\" value=\"" + ThisCustomer.VATRegistrationID + "\">");
                    }
                    m_DynamicTokens.Add("(!VATREGISTRATIONID!)", tmpS2.ToString());
                }

                if (AppLogic.NumLocaleSettingsInstalled() < 2)
                {
                    m_DynamicTokens.Add("(!COUNTRYDIVVISIBILITY!)", "hidden");
                    m_DynamicTokens.Add("(!COUNTRYDIVDISPLAY!)", "none");
                    m_DynamicTokens.Add("(!COUNTRYSELECTLIST!)", String.Empty);
                }
                else
                {
                    m_DynamicTokens.Add("(!COUNTRYDIVVISIBILITY!)", "visible");
                    m_DynamicTokens.Add("(!COUNTRYDIVDISPLAY!)", "inline");
                    m_DynamicTokens.Add("(!COUNTRYSELECTLIST!)", AppLogic.GetCountrySelectList(ThisCustomer.LocaleSetting));
                }

                if (Currency.NumPublishedCurrencies() < 2)
                {
                    m_DynamicTokens.Add("(!CURRENCYDIVVISIBILITY!)", "hidden");
                    m_DynamicTokens.Add("(!CURRENCYDIVDISPLAY!)", "none");
                    m_DynamicTokens.Add("(!CURRENCYSELECTLIST!)", String.Empty);
                }
                else
                {
                    m_DynamicTokens.Add("(!CURRENCYDIVVISIBILITY!)", "visible");
                    m_DynamicTokens.Add("(!CURRENCYDIVDISPLAY!)", "inline");
                    m_DynamicTokens.Add("(!CURRENCYSELECTLIST!)", AppLogic.GetCurrencySelectList(ThisCustomer));
                }

                if (AppLogic.VATIsEnabled() && AppLogic.AppConfigBool("VAT.AllowCustomerToChooseSetting"))
                {
                    m_DynamicTokens.Add("(!VATDIVVISIBILITY!)", "visible");
                    m_DynamicTokens.Add("(!VATDIVDISPLAY!)", "inline");
                    m_DynamicTokens.Add("(!VATSELECTLIST!)", AppLogic.GetVATSelectList(ThisCustomer));
                }
                else
                {
                    m_DynamicTokens.Add("(!VATDIVVISIBILITY!)", "hidden");
                    m_DynamicTokens.Add("(!VATDIVDISPLAY!)", "none");
                    m_DynamicTokens.Add("(!VATSELECTLIST!)", String.Empty);
                }

                if (!ThisCustomer.IsRegistered)
                {
                    m_DynamicTokens.Add("(!SUBSCRIPTION_EXPIRATION!)", AppLogic.ro_NotApplicable);
                }
                else
                {
                    if (ThisCustomer.SubscriptionExpiresOn.Equals(System.DateTime.MinValue))
                    {
                        m_DynamicTokens.Add("(!SUBSCRIPTION_EXPIRATION!)", "Expired");
                    }
                    else
                    {
                        m_DynamicTokens.Add("(!SUBSCRIPTION_EXPIRATION!)", Localization.ToThreadCultureShortDateString(ThisCustomer.SubscriptionExpiresOn));
                    }
                }

                m_DynamicTokens.Add("(!PAGEURL!)", HttpContext.Current.Server.UrlEncode(CommonLogic.GetThisPageName(false) + "?" + CommonLogic.ServerVariables("QUERY_STRING")));
                m_DynamicTokens.Add("(!RANDOM!)", CommonLogic.GetRandomNumber(1, 7).ToString());
                m_DynamicTokens.Add("(!HDRID!)", CommonLogic.GetRandomNumber(1, 7).ToString());
                m_DynamicTokens.Add("(!INVOCATION!)", HttpContext.Current.Server.HtmlEncode(CommonLogic.PageInvocation()));
                m_DynamicTokens.Add("(!REFERRER!)", HttpContext.Current.Server.HtmlEncode(CommonLogic.PageReferrer()));

                StringBuilder tmp = new StringBuilder(4096);
                tmp.Append("<!--\n");
                tmp.Append("PAGE INVOCATION: " + HttpContext.Current.Server.HtmlEncode(CommonLogic.PageInvocation()) + "\n");
                tmp.Append("PAGE REFERRER: " + HttpContext.Current.Server.HtmlEncode(CommonLogic.PageReferrer()) + "\n");
                tmp.Append("STORE LOCALE: " + Localization.GetDefaultLocale() + "\n");
                tmp.Append("STORE CURRENCY: " + Localization.GetPrimaryCurrency() + "\n");
                tmp.Append("CUSTOMER ID: " + ThisCustomer.CustomerID.ToString() + "\n");
                tmp.Append("AFFILIATE ID: " + ThisCustomer.AffiliateID.ToString() + "\n");
                tmp.Append("CUSTOMER LOCALE: " + ThisCustomer.LocaleSetting + "\n");
                tmp.Append("CURRENCY SETTING: " + ThisCustomer.CurrencySetting + "\n");
                tmp.Append("CACHE MENUS: " + AppLogic.AppConfigBool("CacheMenus").ToString() + "\n");
                tmp.Append("-->\n");
                m_DynamicTokens.Add("(!PAGEINFO!)", tmp.ToString());

                bool IsRegistered = CommonLogic.IIF(ThisCustomer != null, ThisCustomer.IsRegistered, false);

                String tmpS = String.Empty;

                if (IsRegistered)
                {
                    if (!AppLogic.IsAdminSite)
                    {
                        tmpS = AppLogic.GetString("skinbase.cs.1", SkinID, ThisCustomer.LocaleSetting) + " <a class=\"username\" href=\"account.aspx\">" + ThisCustomer.FullName() + "</a>" + CommonLogic.IIF(ThisCustomer.CustomerLevelID != 0, "&nbsp;(" + ThisCustomer.CustomerLevelName + ")", "");
                    }
                    m_DynamicTokens.Add("(!USER_NAME!)", tmpS);
                    m_DynamicTokens.Add("(!USERNAME!)", tmpS);
                }
                else
                {
                    m_DynamicTokens.Add("(!USER_NAME!)", String.Empty);
                    m_DynamicTokens.Add("(!USERNAME!)", String.Empty);
                }

                m_DynamicTokens.Add("(!USER_MENU_NAME!)", CommonLogic.IIF(!IsRegistered, "my account", ThisCustomer.FullName()));
                m_DynamicTokens.Add("(!USER_MENU!)", AppLogic.GetUserMenu(ThisCustomer.IsRegistered, SkinID, ThisCustomer.LocaleSetting));
                if (AppLogic.MicropayIsEnabled())
                {
                    tmpS = "Your " + AppLogic.GetString("account.aspx.11", SkinID, ThisCustomer.LocaleSetting) + " balance is: " + Localization.DecimalStringForDB(ThisCustomer.MicroPayBalance);
                    m_DynamicTokens.Add("(!MICROPAY_BALANCE!)", tmpS);
                    m_DynamicTokens.Add("(!MICROPAY_BALANCE_RAW!)", Localization.DecimalStringForDB(ThisCustomer.MicroPayBalance));
                    m_DynamicTokens.Add("(!MICROPAY_BALANCE_CURRENCY!)", ThisCustomer.CurrencyString(ThisCustomer.MicroPayBalance));
                }
                tmpS = ShoppingCart.NumItems(ThisCustomer.CustomerID, CartTypeEnum.ShoppingCart).ToString();
                m_DynamicTokens.Add("(!NUM_CART_ITEMS!)", tmpS);
                tmpS = AppLogic.GetString("AppConfig.CartPrompt", SkinID, ThisCustomer.LocaleSetting);
                m_DynamicTokens.Add("(!CARTPROMPT!)", tmpS);
                tmpS = ShoppingCart.NumItems(ThisCustomer.CustomerID, CartTypeEnum.WishCart).ToString();
                m_DynamicTokens.Add("(!NUM_WISH_ITEMS!)", tmpS);
                tmpS = ShoppingCart.NumItems(ThisCustomer.CustomerID, CartTypeEnum.GiftRegistryCart).ToString();
                m_DynamicTokens.Add("(!NUM_GIFT_ITEMS!)", tmpS);
                tmpS = CommonLogic.IIF(!IsRegistered, AppLogic.GetString("skinbase.cs.4", SkinID, ThisCustomer.LocaleSetting), AppLogic.GetString("skinbase.cs.5", SkinID, ThisCustomer.LocaleSetting));
                m_DynamicTokens.Add("(!SIGNINOUT_TEXT!)", tmpS);
                m_DynamicTokens.Add("(!SIGNINOUT_LINK!)", CommonLogic.IIF(!IsRegistered, "signin.aspx", "signout.aspx"));
                String PN = CommonLogic.GetThisPageName(false);
                if (AppLogic.AppConfigBool("ShowMiniCart"))
                {
                    if (PN.StartsWith("shoppingcart", StringComparison.InvariantCultureIgnoreCase) || PN.StartsWith("checkout", StringComparison.InvariantCultureIgnoreCase) || PN.StartsWith("cardinal", StringComparison.InvariantCultureIgnoreCase) || PN.StartsWith("addtocart") || PN.IndexOf("_process", StringComparison.InvariantCultureIgnoreCase) != -1 || PN.StartsWith("lat_", StringComparison.InvariantCultureIgnoreCase))
                    {
                        m_DynamicTokens.Add("(!MINICART!)", String.Empty); // don't show on these pages
                    }
                    else
                    {
                        m_DynamicTokens.Add("(!MINICART!)", ShoppingCart.DisplayMiniCart(ThisCustomer, SkinID, true));
                    }
                    if (PN.StartsWith("shoppingcart", StringComparison.InvariantCultureIgnoreCase) || PN.StartsWith("checkout", StringComparison.InvariantCultureIgnoreCase) || PN.StartsWith("cardinal", StringComparison.InvariantCultureIgnoreCase) || PN.StartsWith("addtocart", StringComparison.InvariantCultureIgnoreCase) || PN.IndexOf("_process", StringComparison.InvariantCultureIgnoreCase) != -1 || PN.StartsWith("lat_", StringComparison.InvariantCultureIgnoreCase))
                    {
                        m_DynamicTokens.Add("(!MINICART_PLAIN!)", String.Empty); // don't show on these pages
                    }
                    else
                    {
                        m_DynamicTokens.Add("(!MINICART_PLAIN!)", ShoppingCart.DisplayMiniCart(ThisCustomer, SkinID, false));
                    }
                }
                m_DynamicTokens.Add("(!CUSTOMERID!)", ThisCustomer.CustomerID.ToString());
            }
        }