Ejemplo n.º 1
0
        public void PaymentOk(String orderStatus = "040", Boolean sendEmails = true)
        {
            NBrightBuyUtils.ProcessEventProvider(EventActions.BeforePaymentOK, PurchaseInfo);

            if (!PurchaseInfo.GetXmlPropertyBool("genxml/stopprocess"))
            {
                // only process this on waiting for bank, incomplete or cancelled.  Cancel might be sent back from bank if client fails on first payment try.
                if (OrderStatus == "020" || OrderStatus == "010" || OrderStatus == "030")
                {
                    var discountprov = DiscountCodeInterface.Instance();
                    if (discountprov != null)
                    {
                        PurchaseInfo = discountprov.UpdatePercentUsage(PortalId, UserId, PurchaseInfo);
                        PurchaseInfo = discountprov.UpdateVoucherAmount(PortalId, UserId, PurchaseInfo);
                    }

                    PurchaseTypeCode = "ORDER";
                    CreatedDate      = DateTime.Now.ToString("O");
                    ApplyModelTransQty();
                    OrderStatus = orderStatus;
                    SavePurchaseData();

                    // Send emails
                    if (sendEmails)
                    {
                        NBrightBuyUtils.SendOrderEmail("OrderCreatedClient", PurchaseInfo.ItemID, "ordercreatedemailsubject");
                    }
                }
            }
            NBrightBuyUtils.ProcessEventProvider(EventActions.AfterPaymentOK, PurchaseInfo);
        }
Ejemplo n.º 2
0
        public void ValidateCart(Boolean removeZeroQtyItems = false)
        {
            PurchaseInfo = NBrightBuyUtils.ProcessEventProvider(EventActions.ValidateCartBefore, PurchaseInfo);

            var    itemList          = GetCartItemList();
            Double subtotalcost      = 0;
            Double totaldealerbonus  = 0;
            Double totaldiscount     = 0;
            Double totalsalediscount = 0;
            Double totalqty          = 0;
            Double totalweight       = 0;
            Double totalunitcost     = 0;

            // Calculate Promotions
            // Calculate first, so if we add items the price is calculated
            if (PromoInterface.Instance() != null)
            {
                var promol = PromoInterface.ProviderList;
                foreach (var p in promol)
                {
                    PurchaseInfo = PromoInterface.Instance(p.Key).CalculatePromotion(PortalId, PurchaseInfo);
                    itemList     = GetCartItemList(); // get any new items
                }
            }

            var strXml = "<items>";

            foreach (var info in itemList)
            {
                // check product still exists and remove if deleted, altered or disabled.

                var cartItem = ValidateCartItem(PortalId, UserId, info, removeZeroQtyItems);
                if (cartItem != null)
                {
                    strXml            += cartItem.XMLData;
                    totalunitcost     += info.GetXmlPropertyDouble("genxml/unitcost");
                    subtotalcost      += info.GetXmlPropertyDouble("genxml/totalcost");
                    totaldealerbonus  += info.GetXmlPropertyDouble("genxml/totaldealerbonus");
                    totaldiscount     += info.GetXmlPropertyDouble("genxml/totaldiscount");
                    totalsalediscount += info.GetXmlPropertyDouble("genxml/salediscount");
                    totalqty          += info.GetXmlPropertyDouble("genxml/qty");
                    totalweight       += info.GetXmlPropertyDouble("genxml/totalweight");
                }
            }
            strXml += "</items>";
            PurchaseInfo.RemoveXmlNode("genxml/items");
            PurchaseInfo.AddXmlNode(strXml, "items", "genxml");
            PopulateItemList(); // put changed items and prices back into base class for saving to DB

            // calculate totals

            var promototaldiscount = (totaldiscount - totalsalediscount);

            PurchaseInfo.SetXmlPropertyDouble("genxml/totalqty", totalqty);
            PurchaseInfo.SetXmlPropertyDouble("genxml/totalweight", totalweight);
            PurchaseInfo.SetXmlPropertyDouble("genxml/totalunitcost", totalunitcost);
            PurchaseInfo.SetXmlPropertyDouble("genxml/subtotalcost", subtotalcost);
            PurchaseInfo.SetXmlPropertyDouble("genxml/subtotal", subtotalcost);
            PurchaseInfo.SetXmlPropertyDouble("genxml/appliedsubtotal", (subtotalcost + totalsalediscount));


            // calc any voucher amounts
            var    discountcode    = PurchaseInfo.GetXmlProperty("genxml/extrainfo/genxml/textbox/promocode");
            Double voucherDiscount = 0;

            if (DiscountCodeInterface.Instance() != null)
            {
                PurchaseInfo    = DiscountCodeInterface.Instance().CalculateVoucherAmount(PortalId, UserId, PurchaseInfo, discountcode);
                voucherDiscount = PurchaseInfo.GetXmlPropertyDouble("genxml/voucherdiscount");
            }
            promototaldiscount += voucherDiscount;
            totaldiscount      += voucherDiscount;

            PurchaseInfo.SetXmlPropertyDouble("genxml/applieddiscount", totaldiscount);

            PurchaseInfo.SetXmlPropertyDouble("genxml/totaldealerbonus", totaldealerbonus);

            PurchaseInfo.SetXmlPropertyDouble("genxml/totaldiscount", totaldiscount);
            PurchaseInfo.SetXmlPropertyDouble("genxml/totalsalediscount", totalsalediscount);


            //add shipping
            Double shippingcost       = 0;
            Double shippingdealercost = 0;
            var    shippingkey        = PurchaseInfo.GetXmlProperty("genxml/extrainfo/genxml/radiobuttonlist/shippingprovider");
            var    currentcartstage   = PurchaseInfo.GetXmlProperty("genxml/currentcartstage");

            if (currentcartstage == "cartaddress" || currentcartstage == "cartsummary") // can only calc shipping on this stage.
            {
                ShippingInterface shipprov = null;
                shipprov = ShippingInterface.Instance(shippingkey);
                if (shipprov != null)
                {
                    PurchaseInfo       = shipprov.CalculateShipping(PurchaseInfo);
                    shippingcost       = PurchaseInfo.GetXmlPropertyDouble("genxml/shippingcost");
                    shippingdealercost = PurchaseInfo.GetXmlPropertyDouble("genxml/shippingdealercost");
                }
                PurchaseInfo.SetXmlPropertyDouble("genxml/appliedshipping", AppliedCost(shippingcost, shippingdealercost));
            }
            else
            {
                // clear the provider if not cartshipping stage
                PurchaseInfo.SetXmlProperty("genxml/extrainfo/genxml/radiobuttonlist/shippingprovider", "");
            }


            //add tax
            Double appliedtax     = 0;
            var    taxproviderkey = PurchaseInfo.GetXmlProperty("genxml/extrainfo/genxml/hidden/taxproviderkey");
            var    taxprov        = TaxInterface.Instance(taxproviderkey);

            if (taxprov != null)
            {
                PurchaseInfo = taxprov.Calculate(PurchaseInfo);
                appliedtax   = PurchaseInfo.GetXmlPropertyDouble("genxml/appliedtax");
            }

            //cart full total
            var total = (subtotalcost + shippingcost + appliedtax) - promototaldiscount;

            if (total < 0)
            {
                total = 0;
            }
            PurchaseInfo.SetXmlPropertyDouble("genxml/total", total);
            PurchaseInfo.SetXmlPropertyDouble("genxml/appliedtotal", total);

            if (PurchaseInfo.GetXmlProperty("genxml/clientmode") == "True")
            {
                // user not editor, so stop edit mode.
                if (!UserController.Instance.GetCurrentUserInfo().IsInRole("Administrators") && !UserController.Instance.GetCurrentUserInfo().IsInRole(StoreSettings.ManagerRole) && !UserController.Instance.GetCurrentUserInfo().IsInRole(StoreSettings.EditorRole))
                {
                    PurchaseInfo.SetXmlProperty("genxml/clientmode", "False");
                }
            }

            PurchaseInfo = NBrightBuyUtils.ProcessEventProvider(EventActions.ValidateCartAfter, PurchaseInfo);

            SavePurchaseData();
        }
Ejemplo n.º 3
0
        override protected void OnInit(EventArgs e)
        {
            base.OnInit(e);

            if (ModSettings.Get("themefolder") == "")  // if we don't have module setting jump out
            {
                rpPaymentGateways.ItemTemplate = new GenXmlTemplate("NO MODULE SETTINGS");
                return;
            }

            try
            {
                var pluginData = new PluginData(PortalSettings.Current.PortalId);
                _provList = pluginData.GetPaymentProviders();
                _cartInfo = new CartData(PortalId);

                var orderid     = Utils.RequestQueryStringParam(Context, "orderid");
                var templOk     = ModSettings.Get("paymentoktemplate");
                var templFail   = ModSettings.Get("paymentfailtemplate");
                var templHeader = "";
                var templFooter = "";
                var templText   = "";

                if ((_provList.Count == 0 || _cartInfo.PurchaseInfo.GetXmlPropertyDouble("genxml/appliedtotal") <= 0) && orderid == "")
                {
                    #region "No Payment providers, so process as a ordering system"

                    var displayTempl = templOk;
                    if (!_cartInfo.IsValidated())
                    {
                        displayTempl = templFail;
                    }

                    rpDetailDisplay.ItemTemplate = NBrightBuyUtils.GetGenXmlTemplate(ModCtrl.GetTemplateData(ModSettings, displayTempl, Utils.GetCurrentCulture(), DebugMode), ModSettings.Settings(), PortalSettings.HomeDirectory);
                    _templateHeader = (GenXmlTemplate)rpDetailDisplay.ItemTemplate;

                    // we may have voucher discounts that give a zero appliedtotal, so process.
                    var discountprov = DiscountCodeInterface.Instance();
                    if (discountprov != null)
                    {
                        discountprov.UpdatePercentUsage(PortalId, UserId, _cartInfo.PurchaseInfo);
                        discountprov.UpdateVoucherAmount(PortalId, UserId, _cartInfo.PurchaseInfo);
                    }

                    #endregion
                }
                else
                {
                    #region "Payment Details"

                    // display the payment method by default
                    templHeader = ModSettings.Get("paymentordersummary");
                    templFooter = ModSettings.Get("paymentfooter");
                    var templPaymentText = "";
                    var msg = "";
                    if (Utils.IsNumeric(orderid))
                    {
                        // orderid exists, so must be return from bank; Process it!!
                        _orderData = new OrderData(PortalId, Convert.ToInt32(orderid));
                        _prov      = PaymentsInterface.Instance(_orderData.PaymentProviderKey);

                        msg = _prov.ProcessPaymentReturn(Context);
                        if (msg == "")                                                      // no message so successful
                        {
                            _orderData = new OrderData(PortalId, Convert.ToInt32(orderid)); // get the updated order.
                            _orderData.PaymentOk("050");
                            templText = templOk;
                        }
                        else
                        {
                            _orderData = new OrderData(PortalId, Convert.ToInt32(orderid)); // reload the order, becuase the status and typecode may have changed by the payment provider.
                            _orderData.AddAuditMessage(msg, "paymsg", "payment.ascx", "False");
                            _orderData.Save();
                            templText = templFail;
                        }
                        templFooter = ""; // return from bank, hide footer
                    }
                    else
                    {
                        // not returning from bank, so display list of payment providers.
                        rpPaymentGateways.ItemTemplate = NBrightBuyUtils.GetGenXmlTemplate(GetPaymentProviderTemplates(), ModSettings.Settings(), PortalSettings.HomeDirectory);
                    }

                    if (templText == "")
                    {
                        templText = templHeader;                  // if we are NOT returning from bank, then display normal header summary template
                    }
                    templPaymentText = ModCtrl.GetTemplateData(ModSettings, templText, Utils.GetCurrentCulture(), DebugMode);

                    rpDetailDisplay.ItemTemplate = NBrightBuyUtils.GetGenXmlTemplate(templPaymentText, ModSettings.Settings(), PortalSettings.HomeDirectory);
                    _templateHeader = (GenXmlTemplate)rpDetailDisplay.ItemTemplate;

                    if (templFooter != "")
                    {
                        var templPaymentFooterText = ModCtrl.GetTemplateData(ModSettings, templFooter, Utils.GetCurrentCulture(), DebugMode);
                        rpDetailFooter.ItemTemplate = NBrightBuyUtils.GetGenXmlTemplate(templPaymentFooterText, ModSettings.Settings(), PortalSettings.HomeDirectory);
                    }

                    #endregion
                }


                // insert page header text
                NBrightBuyUtils.IncludePageHeaders(ModCtrl, ModuleId, Page, _templateHeader, ModSettings.Settings(), null, DebugMode);
            }
            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();
                phData.Controls.Add(l);
            }
        }