예제 #1
0
        public override string GetTemplate(NBrightInfo cartInfo)
        {
            var info  = ProviderUtils.GetProviderSettings("manualpayment");
            var templ = ProviderUtils.GetTemplateData(info.GetXmlProperty("genxml/textbox/checkouttemplate"), info);

            return(templ);
        }
예제 #2
0
        public override Double CalculateItemTax(NBrightInfo cartItemInfo)
        {
            var info    = ProviderUtils.GetProviderSettings("tax");
            var taxtype = info.GetXmlProperty("genxml/radiobuttonlist/taxtype");

            if (taxtype == "3")
            {
                return(0);
            }

            var rateDic = GetRates();

            if (!rateDic.Any())
            {
                return(0);
            }

            // loop through each item and calc the tax for each.
            Double taxtotal = 0;

            var totalcost = cartItemInfo.GetXmlPropertyDouble("genxml/totalcost");

            // check if dealer and if dealertotal cost exists. ()
            if (cartItemInfo.GetXmlPropertyBool("genxml/isdealer"))
            {
                totalcost = cartItemInfo.GetXmlPropertyDouble("genxml/dealercost");
            }
            var taxratecode = cartItemInfo.GetXmlProperty("genxml/taxratecode");

            if (!Utils.IsNumeric(taxratecode))
            {
                taxratecode = "0";
            }
            if (!rateDic.ContainsKey(taxratecode))
            {
                taxratecode = "0";
            }
            Double taxrate = 0;

            if (rateDic.ContainsKey(taxratecode))
            {
                taxrate = rateDic[taxratecode]; // Can happen is no default tax added.
            }
            if (taxtype == "1")                 // included in unit price
            {
                taxtotal += totalcost - ((totalcost / (100 + taxrate)) * 100);
            }
            if (taxtype == "2") // NOT included in unit price
            {
                taxtotal += (totalcost / 100) * taxrate;
            }

            return(Math.Round(taxtotal, 2));
        }
예제 #3
0
        public override string GetTemplate(NBrightInfo cartInfo)
        {
            var templ        = "";
            var info         = ProviderUtils.GetProviderSettings("manualpayment");
            var templateName = info.GetXmlProperty("genxml/textbox/checkouttemplate");

            if (templateName.EndsWith(".html"))
            {
                templ = ProviderUtils.GetTemplateData(templateName, info);
            }
            else
            {
                templ = NBrightBuyUtils.RazorTemplRender(templateName, 0, "", info, "/DesktopModules/NBright/NBrightBuy/Providers/ManualPaymentProvider", "config", Utils.GetCurrentCulture(), StoreSettings.Current.Settings());
            }

            return(templ);
        }
예제 #4
0
        override protected void OnInit(EventArgs e)
        {
            base.OnInit(e);

            try
            {
                _ctrlkey = "tax";
                _info    = ProviderUtils.GetProviderSettings(_ctrlkey);
                var rpDataHTempl = ProviderUtils.GetTemplateData("settings.html");
                rpDataH.ItemTemplate = NBrightBuyUtils.GetGenXmlTemplate(rpDataHTempl, StoreSettings.Current.Settings(), PortalSettings.HomeDirectory);
            }
            catch (Exception exc)
            {
                //display the error on the template (don;t want to log it here, prefer to deal with errors directly.)
                var l = new Literal();
                l.Text = exc.ToString();
                Controls.Add(l);
            }
        }
예제 #5
0
        public override Dictionary <string, double> GetRates()
        {
            var info   = ProviderUtils.GetProviderSettings("tax");
            var rtnDic = new Dictionary <string, double>();

            var rate = info.GetXmlProperty("genxml/textbox/taxdefault").Replace("%", "").Trim();

            if (Utils.IsNumeric(rate))
            {
                rtnDic.Add("0", Convert.ToDouble(rate, CultureInfo.GetCultureInfo("en-US")));
            }

            rate = info.GetXmlProperty("genxml/textbox/rate1").Replace("%", "").Trim();
            if (Utils.IsNumeric(rate))
            {
                rtnDic.Add("1", Convert.ToDouble(rate, CultureInfo.GetCultureInfo("en-US")));
            }
            rate = info.GetXmlProperty("genxml/textbox/rate2").Replace("%", "").Trim();
            if (Utils.IsNumeric(rate))
            {
                rtnDic.Add("2", Convert.ToDouble(rate, CultureInfo.GetCultureInfo("en-US")));
            }
            rate = info.GetXmlProperty("genxml/textbox/rate3").Replace("%", "").Trim();
            if (Utils.IsNumeric(rate))
            {
                rtnDic.Add("3", Convert.ToDouble(rate, CultureInfo.GetCultureInfo("en-US")));
            }
            rate = info.GetXmlProperty("genxml/textbox/rate4").Replace("%", "").Trim();
            if (Utils.IsNumeric(rate))
            {
                rtnDic.Add("4", Convert.ToDouble(rate, CultureInfo.GetCultureInfo("en-US")));
            }
            rate = info.GetXmlProperty("genxml/textbox/rate5").Replace("%", "").Trim();
            if (Utils.IsNumeric(rate))
            {
                rtnDic.Add("5", Convert.ToDouble(rate, CultureInfo.GetCultureInfo("en-US")));
            }

            return(rtnDic);
        }
예제 #6
0
        public override Dictionary <string, string> GetName()
        {
            var info   = ProviderUtils.GetProviderSettings("tax");
            var rtnDic = new Dictionary <string, string>();

            var rate = info.GetXmlProperty("genxml/textbox/taxdefault").Replace("%", "").Trim();

            if (Utils.IsNumeric(rate))
            {
                rtnDic.Add("0", rate + "%");
            }
            rate = info.GetXmlProperty("genxml/textbox/rate1").Replace("%", "").Trim();
            if (Utils.IsNumeric(rate))
            {
                rtnDic.Add("1", info.GetXmlProperty("genxml/textbox/name1"));
            }
            rate = info.GetXmlProperty("genxml/textbox/rate2").Replace("%", "").Trim();
            if (Utils.IsNumeric(rate))
            {
                rtnDic.Add("2", info.GetXmlProperty("genxml/textbox/name2"));
            }
            rate = info.GetXmlProperty("genxml/textbox/rate3").Replace("%", "").Trim();
            if (Utils.IsNumeric(rate))
            {
                rtnDic.Add("3", info.GetXmlProperty("genxml/textbox/name3"));
            }
            rate = info.GetXmlProperty("genxml/textbox/rate4").Replace("%", "").Trim();
            if (Utils.IsNumeric(rate))
            {
                rtnDic.Add("4", info.GetXmlProperty("genxml/textbox/name4"));
            }
            rate = info.GetXmlProperty("genxml/textbox/rate5").Replace("%", "").Trim();
            if (Utils.IsNumeric(rate))
            {
                rtnDic.Add("5", info.GetXmlProperty("genxml/textbox/name5"));
            }

            return(rtnDic);
        }
예제 #7
0
        public override string RedirectForPayment(OrderData orderData)
        {
            var info           = ProviderUtils.GetProviderSettings("manualpayment");
            var settings       = info.ToDictionary();
            var neworderstatus = "020";

            if (settings.ContainsKey("orderstatus"))
            {
                neworderstatus = settings["orderstatus"];
            }
            if (neworderstatus == "")
            {
                neworderstatus = "020";
            }
            orderData.OrderStatus = neworderstatus;
            orderData.SavePurchaseData();
            var param = new string[3];

            param[0] = "orderid=" + orderData.PurchaseInfo.ItemID.ToString("D");
            param[1] = "status=1";
            return(Globals.NavigateURL(StoreSettings.Current.PaymentTabId, "", param));
        }
예제 #8
0
        /// <summary>
        /// This function needs to process and returned message from the bank.
        /// This processing may vary widely between banks.
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            var info = ProviderUtils.GetProviderSettings();

            var            objEventLog    = new EventLogController();
            PortalSettings portalsettings = new PortalSettings();

            try
            {
                var debugMode = info.GetXmlPropertyBool("genxml/checkbox/debugmode");
                var debugMsg  = "START CALL" + DateTime.Now.ToString("s") + " </br>";
                var rtnMsg    = "version=2" + Environment.NewLine + "cdr=1";

                var orderid = Utils.RequestQueryStringParam(context, "orderid");

                debugMsg += "orderid: " + orderid + "</br>";


                if (Utils.IsNumeric(orderid))
                {
                    var orderData = new OrderData(Convert.ToInt32(orderid));

                    PaymentResponse paymentClientResult = ProviderUtils.GetOrderPaymentResponse(orderData, "OS_MollieNotify.ProcessRequest");

                    objEventLog.AddLog("Mollie Webhook call for orderid: " + orderid, "Status: " + paymentClientResult.Status, portalsettings, -1, EventLogController.EventLogType.ADMIN_ALERT);

                    //Waiting for Payment 060
                    //Payment OK 040
                    //Incomplete 010
                    //Cancelled 030

                    switch (paymentClientResult.Status.ToString().ToLower())
                    {
                    case "paid":
                        orderData.PaymentOk("040", true);
                        rtnMsg = "OK";
                        break;

                    case "failed":
                        orderData.PaymentFail("010");
                        rtnMsg = "OK";
                        break;

                    case "canceled":
                        orderData.PaymentFail("030");
                        rtnMsg = "OK";
                        break;

                    case "expired":
                        orderData.PaymentFail("010");
                        rtnMsg = "OK";
                        break;

                    default:
                        orderData.PaymentFail("010");
                        rtnMsg = "OK";
                        break;
                    }
                }
                if (debugMode)
                {
                    debugMsg += "Return Message: " + rtnMsg;
                    info.SetXmlProperty("genxml/debugmsg", debugMsg);
                    var modCtrl = new NBrightBuyController();
                    modCtrl.Update(info);
                }

                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.Write(rtnMsg);
                HttpContext.Current.Response.ContentType  = "text/plain";
                HttpContext.Current.Response.CacheControl = "no-cache";
                HttpContext.Current.Response.Expires      = -1;
                HttpContext.Current.Response.End();
            }
            catch (Exception ex)
            {
                objEventLog.AddLog("Mollie Webhook call failed", ex.Message + " " + ex.InnerException, portalsettings, -1, EventLogController.EventLogType.ADMIN_ALERT);

                if (!ex.ToString().StartsWith("System.Threading.ThreadAbortException")) // we expect a thread abort from the End response.
                {
                    info.SetXmlProperty("genxml/debugmsg", "OS_Mollie ERROR: " + ex.ToString());
                    var modCtrl = new NBrightBuyController();
                    modCtrl.Update(info);
                }
            }
        }
예제 #9
0
        public override NBrightInfo Calculate(NBrightInfo cartInfo)
        {
            var info    = ProviderUtils.GetProviderSettings("tax");
            var taxtype = info.GetXmlProperty("genxml/radiobuttonlist/taxtype");

            if (taxtype == "3") // no tax
            {
                cartInfo.SetXmlPropertyDouble("genxml/taxcost", 0);
                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0);
                return(cartInfo);
            }


            var rateDic = GetRates();

            if (!rateDic.Any())
            {
                return(cartInfo);
            }

            // loop through each item and calc the tax for each.
            var nodList = cartInfo.XMLDoc.SelectNodes("genxml/items/*");

            if (nodList != null)
            {
                Double taxtotal = 0;

                foreach (XmlNode nod in nodList)
                {
                    var nbi = new NBrightInfo();
                    nbi.XMLData = nod.OuterXml;
                    taxtotal   += CalculateItemTax(nbi);
                }

                cartInfo.SetXmlPropertyDouble("genxml/taxcost", taxtotal);
                if (taxtype == "1")
                {
                    cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0);                 // tax already in total, so don't apply any more tax.
                }
                if (taxtype == "2")
                {
                    cartInfo.SetXmlPropertyDouble("genxml/appliedtax", taxtotal);
                }


                var taxcountry            = cartInfo.GetXmlProperty("genxml/billaddress/genxml/dropdownlist/country");
                var storecountry          = StoreSettings.Current.Get("storecountry");
                var valideutaxcountrycode = info.GetXmlProperty("genxml/textbox/valideutaxcountrycode");
                var isvalidEU             = false;
                valideutaxcountrycode = "," + valideutaxcountrycode.ToUpper().Replace(" ", "") + ",";
                if ((valideutaxcountrycode.Contains("," + taxcountry.ToUpper().Replace(" ", "") + ",")))
                {
                    isvalidEU = true;
                }

                // Check for EU tax number.
                var enabletaxnumber = info.GetXmlPropertyBool("genxml/checkbox/enabletaxnumber");
                if (enabletaxnumber)
                {
                    var taxnumber      = cartInfo.GetXmlProperty("genxml/extrainfo/genxml/textbox/taxnumber");
                    var storetaxnumber = StoreSettings.Current.Get("storetaxnumber");
                    if (storetaxnumber.Length >= 2)
                    {
                        storetaxnumber = storetaxnumber.Substring(0, 2).ToUpper();
                    }
                    if (taxnumber.Length >= 2)
                    {
                        taxnumber = taxnumber.Substring(0, 2).ToUpper();
                    }
                    if (taxnumber != storetaxnumber && taxnumber != "")
                    {
                        // not matching merchant country, so remove tax
                        if (taxtype == "1")
                        {
                            cartInfo.SetXmlPropertyDouble("genxml/taxcost", taxtotal * -1);
                            cartInfo.SetXmlPropertyDouble("genxml/appliedtax", taxtotal * -1);
                        }
                        if (taxtype == "2")
                        {
                            cartInfo.SetXmlPropertyDouble("genxml/taxcost", 0);
                            cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0);
                        }
                    }
                }

                // Check for country.
                var enabletaxcountry = info.GetXmlPropertyBool("genxml/checkbox/enabletaxcountry");
                if (enabletaxcountry)
                {
                    if (taxcountry != "")
                    {
                        if (taxcountry != storecountry && !isvalidEU)
                        {
                            // not matching merchant country, so remove tax
                            if (taxtype == "1")
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/taxcost", taxtotal * -1);
                                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", taxtotal * -1);
                            }
                            if (taxtype == "2")
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/taxcost", 0);
                                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0);
                            }
                        }
                    }
                }

                // check for region exempt (in same country)
                var taxexemptregions = info.GetXmlProperty("genxml/textbox/taxexemptregions");
                if (taxexemptregions != "" && taxcountry == storecountry)
                {
                    taxexemptregions = "," + taxexemptregions.ToUpper().Replace(" ", "") + ",";
                    var taxregioncode = cartInfo.GetXmlProperty("genxml/billaddress/genxml/dropdownlist/region");
                    if (taxregioncode == "")
                    {
                        taxregioncode = cartInfo.GetXmlProperty("genxml/billaddress/genxml/textbox/txtregion");
                    }
                    if (taxregioncode != "")
                    {
                        if (!taxexemptregions.Contains("," + taxregioncode.ToUpper().Replace(" ", "") + ","))
                        {
                            // not matching merchant region, so remove tax
                            if (taxtype == "1")
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/taxcost", taxtotal * -1);
                                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", taxtotal * -1);
                            }
                            if (taxtype == "2")
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/taxcost", 0);
                                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0);
                            }
                        }
                    }
                }
            }


            return(cartInfo);
        }
예제 #10
0
 static TaxProvider()
 {
     _info    = ProviderUtils.GetProviderSettings("tax");
     _taxType = _info.GetXmlProperty("genxml/radiobuttonlist/taxtype");
 }