Beispiel #1
0
        protected void BindProductInfo(Order order)
        {
            if (order == null)
            {
                return;
            }

            OrderProductVariantCollection orderProductVariants = order.OrderProductVariants;

            this.gvOrderProductVariants.DataSource = orderProductVariants;
            this.gvOrderProductVariants.DataBind();
        }
        /// <summary>
        /// Sends POST request to the DIBS server with order info
        /// </summary>
        /// <param name="order">Order</param>
        /// <returns>String.Empty</returns>
        public string PostProcessPayment(Order order)
        {
            RemotePost post = new RemotePost();

            post.FormName = "FlexWin";
            post.Url      = FlexWinSettings.GatewayUrl;
            if (FlexWinSettings.UseSandbox)
            {
                post.Add("test", "yes");
            }
            post.Add("uniqueoid", "yes");

            Language lang       = LanguageManager.GetLanguageById(order.CustomerLanguageId);
            int      currency   = DibsHelper.GetCurrencyNumberByCode(CurrencyManager.PrimaryStoreCurrency.CurrencyCode);
            int      amount     = (int)((double)order.OrderTotal * 100);
            int      merhcantID = FlexWinSettings.MerchantId;

            post.Add("lang", DibsHelper.GetLanguageCodeByLanguageCulture(lang.LanguageCulture));
            post.Add("currency", currency.ToString());
            post.Add("color", FlexWinSettings.ColorTheme);
            post.Add("decorator", FlexWinSettings.Decorator);
            post.Add("merchant", merhcantID.ToString());
            post.Add("orderid", order.OrderId.ToString());
            post.Add("amount", amount.ToString());
            post.Add("md5key", FlexWinHelper.CalcMD5Key(merhcantID, order.OrderId, currency, amount));
            post.Add("accepturl", String.Format("{0}DibsFlexWinReturn.aspx?x={1}", CommonHelper.GetStoreHost(false), order.OrderId));
            post.Add("cancelurl", String.Format("{0}shoppingcart.aspx", CommonHelper.GetStoreHost(false)));
            post.Add("delivery1.Name", order.ShippingFullName);
            post.Add("delivery2.Address", order.ShippingAddress1);

            post.Add("ordline0-1", "SKU");
            post.Add("ordline0-2", "Description");
            post.Add("ordline0-3", "Quantity");
            post.Add("ordline0-4", "Price");

            OrderProductVariantCollection products = order.OrderProductVariants;

            for (int i = 0; i < products.Count; i++)
            {
                string         lineName = String.Format("ordline{0}", (i + 1));
                ProductVariant pv       = products[i].ProductVariant;

                post.Add(lineName + "-1", HttpUtility.HtmlEncode(pv.SKU));
                post.Add(lineName + "-2", HttpUtility.HtmlEncode(pv.Name));
                post.Add(lineName + "-3", HttpUtility.HtmlEncode(products[i].Quantity.ToString()));
                post.Add(lineName + "-4", pv.Price.ToString(NumberFormatInfo.CurrentInfo));
            }

            post.Post();

            return(String.Empty);
        }
        protected override decimal CalculateTotalOrderServiceFee(OrderProductVariantCollection orderProducts, List<ProductVariant> prodVars, Order order, out object shippingPrice)
        {
            decimal retVal = ConvertToUsd
                                 ? prodVars.Sum(prodVar => (Math.Round(PriceConverter.ToUsd(AddServiceFee(prodVar.Price, ConvertToUsd)))*
                                      orderProducts.First(op => op.ProductVariantID == prodVar.ProductVariantID).Quantity))
                                 : prodVars.Sum(prodVar =>(AddServiceFee(prodVar.Price, ConvertToUsd)*
                                      orderProducts.First(op => op.ProductVariantID == prodVar.ProductVariantID).Quantity));
            if (ShoppingCartRequiresShipping)
            {
                decimal shippingBlr = AddServiceFee(((FreeShippingEnabled && retVal > FreeShippingBorder) ? 0 : ShippingRate), 
                                                ConvertToUsd);
                shippingPrice = ConvertToUsd ? Math.Round(PriceConverter.ToUsd(shippingBlr)) : shippingBlr;
            }
            else
            {
                shippingPrice = (decimal) 0;
            }

            return retVal;
        }
        protected override decimal CalculateTotalOrderServiceFee(OrderProductVariantCollection orderProducts, List <ProductVariant> prodVars, Order order, out object shippingPrice)
        {
            decimal retVal = ConvertToUsd
                                 ? prodVars.Sum(prodVar => (Math.Round(PriceConverter.ToUsd(AddServiceFee(prodVar.Price, ConvertToUsd))) *
                                                            orderProducts.First(op => op.ProductVariantID == prodVar.ProductVariantID).Quantity))
                                 : prodVars.Sum(prodVar => (AddServiceFee(prodVar.Price, ConvertToUsd) *
                                                            orderProducts.First(op => op.ProductVariantID == prodVar.ProductVariantID).Quantity));

            if (ShoppingCartRequiresShipping)
            {
                decimal shippingBlr = AddServiceFee(((FreeShippingEnabled && retVal > FreeShippingBorder) ? 0 : ShippingRate),
                                                    ConvertToUsd);
                shippingPrice = ConvertToUsd ? Math.Round(PriceConverter.ToUsd(shippingBlr)) : shippingBlr;
            }
            else
            {
                shippingPrice = (decimal)0;
            }

            return(retVal);
        }
        /// <summary>
        /// Builds the query string and redirect user to Svea payment gateway
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        public string PostProcessPayment(Order order)
        {
            StringBuilder sb = new StringBuilder(HostedPaymentSettings.GatewayUrl);
            OrderProductVariantCollection opvCollection = order.OrderProductVariants;
            Customer customer = order.Customer;

            sb.AppendFormat("?Username={0}&", HostedPaymentSettings.Username);

            int rowNumber = 1;

            //items
            for (int i = 0; i < opvCollection.Count; i++, rowNumber++)
            {
                OrderProductVariant opv = opvCollection[i];
                ProductVariant      pv  = opv.ProductVariant;

                sb.AppendFormat("Row{0}AmountExVAT={1}&", rowNumber, opv.UnitPriceExclTax);
                sb.AppendFormat("Row{0}Description={1}&", rowNumber, HttpUtility.UrlEncode(pv.FullProductName, Encoding.UTF8));
                sb.AppendFormat("Row{0}Quantity={1}&", rowNumber, opv.Quantity);

                string errStr = String.Empty;
                sb.AppendFormat("Row{0}VATPercentage={1}&", rowNumber, (int)TaxManager.GetTaxRate(pv, customer, ref errStr));
            }

            //discount
            if (order.OrderDiscount != Decimal.Zero)
            {
                sb.AppendFormat("Row{0}AmountExVAT={1}&", rowNumber, -order.OrderDiscount);
                sb.AppendFormat("Row{0}Description=Discount&", rowNumber);
                sb.AppendFormat("Row{0}Quantity=1&", rowNumber);
                sb.AppendFormat("Row{0}VATPercentage=0&", rowNumber);

                rowNumber++;
            }

            //shipping
            if (order.OrderShippingExclTax != decimal.Zero)
            {
                sb.AppendFormat("Row{0}AmountExVAT={1}&", rowNumber, order.OrderShippingExclTax);
                sb.AppendFormat("Row{0}Description=Shipping&", rowNumber);
                sb.AppendFormat("Row{0}Quantity=1&", rowNumber);
                sb.AppendFormat("Row{0}VATPercentage={1}&", rowNumber, (int)(((order.OrderShippingInclTax - order.OrderShippingExclTax) / order.OrderShippingExclTax) * 100));

                rowNumber++;
            }

            //payment method fee
            if (order.PaymentMethodAdditionalFeeInclTax != Decimal.Zero)
            {
                sb.AppendFormat("Row{0}AmountExVAT={1}&", rowNumber, order.PaymentMethodAdditionalFeeExclTax);
                sb.AppendFormat("Row{0}Description=Additional&", rowNumber);
                sb.AppendFormat("Row{0}Quantity=1&", rowNumber);
                sb.AppendFormat("Row{0}VATPercentage={1}&", rowNumber, (int)(((order.PaymentMethodAdditionalFeeInclTax - order.PaymentMethodAdditionalFeeExclTax) / order.PaymentMethodAdditionalFeeExclTax) * 100));

                rowNumber++;
            }

            //gift cards
            var gcuhC = OrderManager.GetAllGiftCardUsageHistoryEntries(null, null, order.OrderId);

            foreach (var gcuh in gcuhC)
            {
                sb.AppendFormat("Row{0}AmountExVAT={1}&", rowNumber, -gcuh.UsedValue);
                sb.AppendFormat("Row{0}Description=GiftCard-{1}&", rowNumber, gcuh.GiftCard.GiftCardCouponCode);
                sb.AppendFormat("Row{0}Quantity=1&", rowNumber);
                sb.AppendFormat("Row{0}VATPercentage={1}&", rowNumber, 0);

                rowNumber++;
            }

            //reward points
            if (order.RedeemedRewardPoints != null)
            {
                sb.AppendFormat("Row{0}AmountExVAT={1}&", rowNumber, -order.RedeemedRewardPoints.UsedAmount);
                sb.AppendFormat("Row{0}Description={1}-RewardPoints&", rowNumber, -order.RedeemedRewardPoints.Points);
                sb.AppendFormat("Row{0}Quantity=1&", rowNumber);
                sb.AppendFormat("Row{0}VATPercentage={1}&", rowNumber, 0);

                rowNumber++;
            }

            sb.AppendFormat("{0}={1}&", "OrderId", order.OrderId);
            sb.AppendFormat("{0}={1}&", "PaymentMethod", HostedPaymentSettings.PaymentMethod);
            sb.AppendFormat("{0}={1}&", "ResponseURL", HttpUtility.UrlEncode(String.Format("{0}SveaHostedPaymentReturn.aspx", CommonHelper.GetStoreHost(false)), Encoding.UTF8));
            sb.AppendFormat("{0}={1}&", "CancelURL", HttpUtility.UrlEncode(String.Format("{0}Checkout.aspx", CommonHelper.GetStoreHost(false)), Encoding.UTF8));
            sb.AppendFormat("{0}={1}&", "TestMode", HostedPaymentSettings.UseSandbox);
            sb.AppendFormat("{0}={1}&", "Language", "SV");
            sb.AppendFormat("{0}={1}&", "Country", "SE");
            sb.AppendFormat("{0}={1}", "Currency", CurrencyManager.PrimaryStoreCurrency.CurrencyCode);

            sb.AppendFormat("&{0}={1}", "MD5", HostedPaymentHelper.CalcMd5Hash(sb.ToString() + HostedPaymentSettings.Password));

            HttpContext.Current.Response.Redirect(sb.ToString());

            return(String.Empty);
        }
		private static OrderProductVariantCollection DBMapping(DBOrderProductVariantCollection dbCollection)
		{
			if (dbCollection == null)
				return null;

			OrderProductVariantCollection collection = new OrderProductVariantCollection();
			foreach (DBOrderProductVariant dbItem in dbCollection)
			{
				OrderProductVariant item = DBMapping(dbItem);
				collection.Add(item);
			}

			return collection;
		}
Beispiel #7
0
        /// <summary>
        /// Print packaging slips to PDF
        /// </summary>
        /// <param name="orderCollection">Order collection</param>
        /// <param name="filePath">File path</param>
        public static void PrintPackagingSlipsToPdf(OrderCollection orderCollection,
                                                    string filePath)
        {
            if (String.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }

            Document doc     = new Document();
            Section  section = doc.AddSection();

            int ordCount = orderCollection.Count;
            int ordNum   = 0;

            foreach (var order in orderCollection)
            {
                Paragraph p1 = section.AddParagraph(String.Format("{0} #{1}", LocalizationManager.GetLocaleResourceString("PdfPackagingSlip.Order"), order.OrderId));
                p1.Format.Font.Bold      = true;
                p1.Format.Font.Color     = Colors.Black;
                p1.Format.Font.Underline = Underline.None;

                section.AddParagraph();

                section.AddParagraph(order.ShippingFullName);
                section.AddParagraph(order.ShippingAddress1);
                section.AddParagraph(String.Format("{0}, {1}", order.ShippingCity, order.ShippingZipPostalCode));

                section.AddParagraph();

                Table productTable = section.AddTable();
                productTable.Borders.Visible = true;
                productTable.AddColumn(Unit.FromCentimeter(4));
                productTable.AddColumn(Unit.FromCentimeter(10));
                productTable.AddColumn(Unit.FromCentimeter(4));

                Row header = productTable.AddRow();
                header.Shading.Color = Colors.LightGray;

                header.Cells[0].Format.Alignment = ParagraphAlignment.Center;
                header.Cells[0].AddParagraph(LocalizationManager.GetLocaleResourceString("PdfPackagingSlip.QTY"));

                header.Cells[1].Format.Alignment = ParagraphAlignment.Center;
                header.Cells[1].AddParagraph(LocalizationManager.GetLocaleResourceString("PdfPackagingSlip.ProductName"));

                header.Cells[2].Format.Alignment = ParagraphAlignment.Center;
                header.Cells[2].AddParagraph(LocalizationManager.GetLocaleResourceString("PdfPackagingSlip.SKU"));

                OrderProductVariantCollection opvc = order.OrderProductVariants;
                foreach (var orderProductVariant in opvc)
                {
                    Row row = productTable.AddRow();

                    row.Cells[0].Format.Alignment = ParagraphAlignment.Center;
                    row.Cells[0].AddParagraph(orderProductVariant.Quantity.ToString());

                    string name = String.Format("Not available. ID={0}", orderProductVariant.ProductVariantId);
                    var    pv   = ProductManager.GetProductVariantById(orderProductVariant.ProductVariantId);
                    if (pv != null)
                    {
                        name = pv.FullProductName;
                    }
                    row.Cells[1].Format.Alignment = ParagraphAlignment.Left;
                    row.Cells[1].AddParagraph(name);
                    Paragraph p2 = row.Cells[1].AddParagraph(HtmlHelper.ConvertHtmlToPlainText(orderProductVariant.AttributeDescription, true));
                    p2.Format.Font.Italic = true;

                    row.Cells[2].Format.Alignment = ParagraphAlignment.Center;
                    row.Cells[2].AddParagraph(orderProductVariant.ProductVariant.SKU);
                }

                ordNum++;

                if (ordNum < ordCount)
                {
                    section.AddPageBreak();
                }
            }

            PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);

            renderer.Document = doc;
            renderer.RenderDocument();
            renderer.PdfDocument.Save(filePath);
        }
        private void BindData()
        {
            this.lnkPrint.NavigateUrl = Page.ResolveUrl("~/PrintOrderDetails.aspx?OrderID=" + this.OrderID);
            this.lblOrderID.Text      = order.OrderID.ToString();
            this.lblCreatedOn.Text    = DateTimeHelper.ConvertToUserTime(order.CreatedOn).ToString("D");
            this.lblOrderStatus.Text  = OrderManager.GetOrderStatusName(order.OrderStatusID);

            if (order.ShippingStatus != ShippingStatusEnum.ShippingNotRequired)
            {
                this.pnlShipping.Visible       = true;
                this.lShippingFirstName.Text   = Server.HtmlEncode(order.ShippingFirstName);
                this.lShippingLastName.Text    = Server.HtmlEncode(order.ShippingLastName);
                this.lShippingPhoneNumber.Text = Server.HtmlEncode(order.ShippingPhoneNumber);
                this.lShippingEmail.Text       = Server.HtmlEncode(!string.IsNullOrEmpty(NopContext.Current.User.BillingAddress.Email) ? NopContext.Current.User.BillingAddress.Email : NopContext.Current.User.Email);
                this.lShippingFaxNumber.Text   = Server.HtmlEncode(order.ShippingFaxNumber);
                if (!String.IsNullOrEmpty(order.ShippingCompany))
                {
                    this.lShippingCompany.Text = Server.HtmlEncode(order.ShippingCompany);
                }
                else
                {
                    pnlShippingCompany.Visible = false;
                }
                this.lShippingAddress1.Text = Server.HtmlEncode(order.ShippingAddress1);
                if (!String.IsNullOrEmpty(order.ShippingAddress2))
                {
                    this.lShippingAddress2.Text = Server.HtmlEncode(order.ShippingAddress2);
                }
                else
                {
                    pnlShippingAddress2.Visible = false;
                }
                this.lShippingCity.Text          = Server.HtmlEncode(order.ShippingCity);
                this.lShippingStateProvince.Text = Server.HtmlEncode(order.ShippingStateProvince);
                this.lShippingZipPostalCode.Text = Server.HtmlEncode(order.ShippingZipPostalCode);
                if (!String.IsNullOrEmpty(order.ShippingCountry))
                {
                    this.lShippingCountry.Text = Server.HtmlEncode(order.ShippingCountry);
                }
                else
                {
                    pnlShippingCountry.Visible = false;
                }

                this.lblShippingMethod.Text = Server.HtmlEncode(order.ShippingMethod);
                this.lblOrderWeight.Text    = string.Format("{0} [{1}]", order.OrderWeight, MeasureManager.BaseWeightIn.Name);

                //TODO use order.ShippingStatus
                if (order.ShippedDate.HasValue)
                {
                    this.lblShippedDate.Text = DateTimeHelper.ConvertToUserTime(order.ShippedDate.Value).ToString();
                }
                else
                {
                    this.lblShippedDate.Text = GetLocaleResourceString("Order.NotYetShipped");
                }
            }
            else
            {
                this.pnlShipping.Visible = false;
            }

            this.lBillingFirstName.Text   = Server.HtmlEncode(order.BillingFirstName);
            this.lBillingLastName.Text    = Server.HtmlEncode(order.BillingLastName);
            this.lBillingPhoneNumber.Text = Server.HtmlEncode(order.BillingPhoneNumber);
            this.lBillingEmail.Text       = Server.HtmlEncode(!string.IsNullOrEmpty(NopContext.Current.User.BillingAddress.Email) ? NopContext.Current.User.BillingAddress.Email : NopContext.Current.User.Email);
            this.lBillingFaxNumber.Text   = Server.HtmlEncode(order.BillingFaxNumber);
            if (!String.IsNullOrEmpty(order.BillingCompany))
            {
                this.lBillingCompany.Text = Server.HtmlEncode(order.BillingCompany);
            }
            else
            {
                pnlBillingCompany.Visible = false;
            }
            this.lBillingAddress1.Text = Server.HtmlEncode(order.BillingAddress1);
            if (!String.IsNullOrEmpty(order.BillingAddress2))
            {
                this.lBillingAddress2.Text = Server.HtmlEncode(order.BillingAddress2);
            }
            else
            {
                pnlBillingAddress2.Visible = false;
            }
            this.lBillingCity.Text          = Server.HtmlEncode(order.BillingCity);
            this.lBillingStateProvince.Text = Server.HtmlEncode(order.BillingStateProvince);
            this.lBillingZipPostalCode.Text = Server.HtmlEncode(order.BillingZipPostalCode);
            if (!String.IsNullOrEmpty(order.BillingCountry))
            {
                this.lBillingCountry.Text = Server.HtmlEncode(order.BillingCountry);
            }
            else
            {
                pnlBillingCountry.Visible = false;
            }


            PaymentMethod paymentMethod = PaymentMethodManager.GetPaymentMethodByID(order.PaymentMethodID);

            if (paymentMethod != null)
            {
                this.lPaymentMethod.Text = paymentMethod.VisibleName;
            }
            else
            {
                this.lPaymentMethod.Text = order.PaymentMethodName;
            }

            switch (order.CustomerTaxDisplayType)
            {
            case TaxDisplayTypeEnum.ExcludingTax:
            {
                this.lblOrderSubtotal.Text = PriceHelper.FormatPrice(order.OrderSubtotalExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, NopContext.Current.WorkingLanguage, false);
                this.lblOrderShipping.Text = PriceHelper.FormatShippingPrice(order.OrderShippingExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, NopContext.Current.WorkingLanguage, false);
                this.lblPaymentMethodAdditionalFee.Text = PriceHelper.FormatPaymentMethodAdditionalFee(order.PaymentMethodAdditionalFeeExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, NopContext.Current.WorkingLanguage, false);
            }
            break;

            case TaxDisplayTypeEnum.IncludingTax:
            {
                this.lblOrderSubtotal.Text = PriceHelper.FormatPrice(order.OrderSubtotalInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, NopContext.Current.WorkingLanguage, true);
                this.lblOrderShipping.Text = PriceHelper.FormatShippingPrice(order.OrderShippingInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, NopContext.Current.WorkingLanguage, true);
                this.lblPaymentMethodAdditionalFee.Text = PriceHelper.FormatPaymentMethodAdditionalFee(order.PaymentMethodAdditionalFeeInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, NopContext.Current.WorkingLanguage, true);
            }
            break;
            }

            bool displayPaymentMethodFee = true;

            if (order.PaymentMethodAdditionalFeeExclTaxInCustomerCurrency == decimal.Zero)
            {
                displayPaymentMethodFee = false;
            }
            phPaymentMethodAdditionalFee.Visible = displayPaymentMethodFee;

            bool displayTax = true;

            if (TaxManager.HideTaxInOrderSummary && order.CustomerTaxDisplayType == TaxDisplayTypeEnum.IncludingTax)
            {
                displayTax = false;
            }
            else
            {
                if (order.OrderTax == 0 && TaxManager.HideZeroTax)
                {
                    displayTax = false;
                }
                else
                {
                    string taxStr = PriceHelper.FormatPrice(order.OrderTaxInCustomerCurrency, true, order.CustomerCurrencyCode, false);
                    this.lblOrderTax.Text = taxStr;
                }
            }
            phTaxTotal.Visible = displayTax;

            string orderTotalStr = PriceHelper.FormatPrice(order.OrderTotalInCustomerCurrency, true, order.CustomerCurrencyCode, false);

            this.lblOrderTotal.Text  = orderTotalStr;
            this.lblOrderTotal2.Text = orderTotalStr;

            OrderProductVariantCollection orderProductVariants = order.OrderProductVariants;
            bool hasDownloadableItems = false;

            foreach (OrderProductVariant orderProductVariant in orderProductVariants)
            {
                ProductVariant productVariant = orderProductVariant.ProductVariant;
                if (productVariant != null)
                {
                    if (productVariant.IsDownload && OrderManager.AreDownloadsAllowed(order))
                    {
                        hasDownloadableItems = true;
                        break;
                    }
                }
            }
            gvOrderProductVariants.Columns[2].Visible = hasDownloadableItems;
            gvOrderProductVariants.DataSource         = orderProductVariants;
            gvOrderProductVariants.DataBind();
        }
Beispiel #9
0
        /// <summary>
        /// Post process payment (payment gateways that require redirecting)
        /// </summary>
        /// <param name="order">Order</param>
        /// <returns>The error status, or String.Empty if no errors</returns>
        public string PostProcessPayment(Order order)
        {
            string returnURL = CommonHelper.GetStoreLocation(false) + "TwoCheckoutReturn.aspx";

            RemotePost remotePostHelper = new RemotePost();

            remotePostHelper.FormName = "TwoCheckoutForm";
            remotePostHelper.Url      = serverURL;

            remotePostHelper.Add("id_type", "1");

            OrderProductVariantCollection orderProductVariants = order.OrderProductVariants;

            for (int i = 0; i < orderProductVariants.Count; i++)
            {
                int pNum = i + 1;
                OrderProductVariant opv     = orderProductVariants[i];
                ProductVariant      pv      = orderProductVariants[i].ProductVariant;
                Product             product = pv.Product;

                string c_prod       = string.Format("c_prod_{0}", pNum);
                string c_prod_value = string.Format("{0},{1}", pv.SKU, opv.Quantity);
                remotePostHelper.Add(c_prod, c_prod_value);
                string c_name       = string.Format("c_name_{0}", pNum);
                string c_name_value = pv.FullProductName;
                string c_attributes = opv.AttributeDescription;
                if (!String.IsNullOrEmpty(c_attributes))
                {
                    c_name_value += c_attributes;
                    c_name_value  = c_name_value.Replace("<br />", ". ");
                }
                remotePostHelper.Add(c_name, c_name_value);

                string c_description       = string.Format("c_description_{0}", pNum);
                string c_description_value = pv.FullProductName;
                c_description_value = c_description_value.Replace("<br />", ". ");
                remotePostHelper.Add(c_description, c_description_value);

                string c_price       = string.Format("c_price_{0}", pNum);
                string c_price_value = opv.UnitPriceInclTax.ToString("####.00", new CultureInfo("en-US", false).NumberFormat);
                remotePostHelper.Add(c_price, c_price_value);

                string c_tangible       = string.Format("c_tangible_{0}", pNum);
                string c_tangible_value = "Y";
                if (pv.IsDownload)
                {
                    c_tangible_value = "N";
                }
                remotePostHelper.Add(c_tangible, c_tangible_value);
            }

            remotePostHelper.Add("x_login", vendorID);
            remotePostHelper.Add("x_amount", order.OrderTotal.ToString("####.00", new CultureInfo("en-US", false).NumberFormat));
            //TODO add primary store currency to parameters
            remotePostHelper.Add("x_invoice_num", order.OrderID.ToString());
            //remotePostHelper.Add("x_receipt_link_url", returnURL);
            //remotePostHelper.Add("x_return_url", returnURL);
            //remotePostHelper.Add("x_return", returnURL);
            if (useSandBox)
            {
                remotePostHelper.Add("demo", "Y");
            }
            remotePostHelper.Add("x_First_Name", order.BillingFirstName);
            remotePostHelper.Add("x_Last_Name", order.BillingLastName);
            remotePostHelper.Add("x_Address", order.BillingAddress1);
            remotePostHelper.Add("x_City", order.BillingCity);
            StateProvince billingStateProvince = StateProvinceManager.GetStateProvinceByID(order.BillingStateProvinceID);

            if (billingStateProvince != null)
            {
                remotePostHelper.Add("x_State", billingStateProvince.Abbreviation);
            }
            else
            {
                remotePostHelper.Add("x_State", order.BillingStateProvince);
            }
            remotePostHelper.Add("x_Zip", order.BillingZipPostalCode);
            Country billingCountry = CountryManager.GetCountryByID(order.BillingCountryID);

            if (billingCountry != null)
            {
                remotePostHelper.Add("x_Country", billingCountry.ThreeLetterISOCode);
            }
            else
            {
                remotePostHelper.Add("x_Country", order.BillingCountry);
            }

            remotePostHelper.Add("x_EMail", order.BillingEmail);
            remotePostHelper.Add("x_Phone", order.BillingPhoneNumber);
            remotePostHelper.Post();
            return(string.Empty);
        }
Beispiel #10
0
        /// <summary>
        /// Checks requirements for customer
        /// </summary>
        /// <param name="customer">Customer</param>
        /// <returns>Value indicating whether all requirements are met</returns>
        public bool CheckDiscountRequirements(Customer customer)
        {
            switch (this.DiscountRequirement)
            {
            case DiscountRequirementEnum.None:
            {
                return(true);
            }
            break;

            case DiscountRequirementEnum.MustBeAssignedToCustomerRole:
            {
                if (customer != null)
                {
                    CustomerRoleCollection customerRoles = customer.CustomerRoles;
                    CustomerRoleCollection assignedRoles = this.CustomerRoles;
                    foreach (CustomerRole _customerRole in customerRoles)
                    {
                        foreach (CustomerRole _assignedRole in assignedRoles)
                        {
                            if (_customerRole.Name == _assignedRole.Name)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            break;

            case DiscountRequirementEnum.HadPurchasedAllOfTheseProductVariants:
            {
                if (customer != null)
                {
                    ProductVariantCollection      restrictedProductVariants = ProductManager.GetProductVariantsRestrictedByDiscountId(this.DiscountId);
                    OrderProductVariantCollection purchasedProductVariants  = OrderManager.GetAllOrderProductVariants(null, customer.CustomerId, null, null, OrderStatusEnum.Complete, null, null);

                    bool allFound = true;
                    foreach (ProductVariant restrictedPV in restrictedProductVariants)
                    {
                        bool found1 = false;
                        foreach (OrderProductVariant purchasedPV in purchasedProductVariants)
                        {
                            if (restrictedPV.ProductVariantId == purchasedPV.ProductVariantId)
                            {
                                found1 = true;
                                break;
                            }
                        }

                        if (!found1)
                        {
                            allFound = false;
                            break;
                        }
                    }

                    if (allFound)
                    {
                        return(true);
                    }
                }
            }
            break;

            case DiscountRequirementEnum.HadPurchasedOneOfTheseProductVariants:
            {
                if (customer != null)
                {
                    ProductVariantCollection      restrictedProductVariants = ProductManager.GetProductVariantsRestrictedByDiscountId(this.DiscountId);
                    OrderProductVariantCollection purchasedProductVariants  = OrderManager.GetAllOrderProductVariants(null, customer.CustomerId, null, null, OrderStatusEnum.Complete, null, null);

                    bool found = false;
                    foreach (ProductVariant restrictedPV in restrictedProductVariants)
                    {
                        foreach (OrderProductVariant purchasedPV in purchasedProductVariants)
                        {
                            if (restrictedPV.ProductVariantId == purchasedPV.ProductVariantId)
                            {
                                found = true;
                                break;
                            }
                        }

                        if (found)
                        {
                            break;
                        }
                    }

                    if (found)
                    {
                        return(true);
                    }
                }
            }
            break;

            default:
                break;
            }
            return(false);
        }
Beispiel #11
0
 protected abstract decimal CalculateTotalOrderServiceFee(OrderProductVariantCollection orderProductVariants,
                                                          List <ProductVariant> prodVars, Order order,
                                                          out object shippingPrice);
Beispiel #12
0
        /// <summary>
        /// Post process payment (payment gateways that require redirecting)
        /// </summary>
        /// <param name="order">Order</param>
        /// <returns>The error status, or String.Empty if no errors</returns>
        public string PostProcessPayment(Order order)
        {
            string returnURL = CommonHelper.GetStoreLocation(false) + "TwoCheckoutReturn.aspx";

            StringBuilder builder = new StringBuilder();

            builder.AppendFormat("{0}?id_type=1", serverURL);

            //products
            OrderProductVariantCollection orderProductVariants = order.OrderProductVariants;

            for (int i = 0; i < orderProductVariants.Count; i++)
            {
                int pNum = i + 1;
                OrderProductVariant opv     = orderProductVariants[i];
                ProductVariant      pv      = orderProductVariants[i].ProductVariant;
                Product             product = pv.Product;

                string c_prod       = string.Format("c_prod_{0}", pNum);
                string c_prod_value = string.Format("{0},{1}", pv.SKU, opv.Quantity);
                builder.AppendFormat("&{0}={1}", c_prod, c_prod_value);
                string c_name       = string.Format("c_name_{0}", pNum);
                string c_name_value = pv.FullProductName;
                builder.AppendFormat("&{0}={1}", HttpUtility.UrlEncode(c_name), HttpUtility.UrlEncode(c_name_value));

                string c_description       = string.Format("c_description_{0}", pNum);
                string c_description_value = pv.FullProductName;
                if (!String.IsNullOrEmpty(opv.AttributeDescription))
                {
                    c_description_value = c_description_value + ". " + opv.AttributeDescription;
                    c_description_value = c_description_value.Replace("<br />", ". ");
                }
                builder.AppendFormat("&{0}={1}", HttpUtility.UrlEncode(c_description), HttpUtility.UrlEncode(c_description_value));

                string c_price       = string.Format("c_price_{0}", pNum);
                string c_price_value = opv.UnitPriceInclTax.ToString("0.00", CultureInfo.InvariantCulture);
                builder.AppendFormat("&{0}={1}", c_price, c_price_value);

                string c_tangible       = string.Format("c_tangible_{0}", pNum);
                string c_tangible_value = "Y";
                if (pv.IsDownload)
                {
                    c_tangible_value = "N";
                }
                builder.AppendFormat("&{0}={1}", c_tangible, c_tangible_value);
            }

            builder.AppendFormat("&x_login={0}", vendorID);
            builder.AppendFormat("&x_amount={0}", order.OrderTotal.ToString("0.00", CultureInfo.InvariantCulture));
            builder.AppendFormat("&x_invoice_num={0}", order.OrderId);
            //("x_receipt_link_url", returnURL);
            //("x_return_url", returnURL);
            //("x_return", returnURL);
            if (useSandBox)
            {
                builder.AppendFormat("&demo=Y");
            }
            builder.AppendFormat("&x_First_Name={0}", HttpUtility.UrlEncode(order.BillingFirstName));
            builder.AppendFormat("&x_Last_Name={0}", HttpUtility.UrlEncode(order.BillingLastName));
            builder.AppendFormat("&x_Address={0}", HttpUtility.UrlEncode(order.BillingAddress1));
            builder.AppendFormat("&x_City={0}", HttpUtility.UrlEncode(order.BillingCity));
            StateProvince billingStateProvince = StateProvinceManager.GetStateProvinceById(order.BillingStateProvinceId);

            if (billingStateProvince != null)
            {
                builder.AppendFormat("&x_State={0}", HttpUtility.UrlEncode(billingStateProvince.Abbreviation));
            }
            else
            {
                builder.AppendFormat("&x_State={0}", HttpUtility.UrlEncode(order.BillingStateProvince));
            }
            builder.AppendFormat("&x_Zip={0}", HttpUtility.UrlEncode(order.BillingZipPostalCode));
            Country billingCountry = CountryManager.GetCountryById(order.BillingCountryId);

            if (billingCountry != null)
            {
                builder.AppendFormat("&x_Country={0}", HttpUtility.UrlEncode(billingCountry.ThreeLetterIsoCode));
            }
            else
            {
                builder.AppendFormat("&x_Country={0}", HttpUtility.UrlEncode(order.BillingCountry));
            }
            builder.AppendFormat("&x_EMail={0}", HttpUtility.UrlEncode(order.BillingEmail));
            builder.AppendFormat("&x_Phone={0}", HttpUtility.UrlEncode(order.BillingPhoneNumber));
            HttpContext.Current.Response.Redirect(builder.ToString());
            return(string.Empty);
        }
Beispiel #13
0
        /// <summary>
        /// Print an order to PDF
        /// </summary>
        /// <param name="order">Order</param>
        /// <param name="LanguageID">Language identifier</param>
        /// <param name="FilePath">File path</param>
        public static void PrintOrderToPDF(Order order, int LanguageID, string FilePath)
        {
            if (order == null)
            {
                throw new ArgumentNullException("order");
            }

            if (String.IsNullOrEmpty(FilePath))
            {
                throw new ArgumentNullException("FilePath");
            }

            Document doc = new Document();

            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(FilePath, FileMode.Create));

            doc.Open();

            doc.Add(new Paragraph(String.Format(LocalizationManager.GetLocaleResourceString("PDFInvoice.Order#", LanguageID), order.OrderID)));
            doc.Add(new Paragraph(String.Format(LocalizationManager.GetLocaleResourceString("PDFInvoice.OrderDate", LanguageID), order.CreatedOn)));

            //billing info
            doc.Add(new Paragraph(" "));
            doc.Add(new Paragraph(LocalizationManager.GetLocaleResourceString("PDFInvoice.BillingInformation", LanguageID)));
            doc.Add(new Paragraph("   " + String.Format(LocalizationManager.GetLocaleResourceString("PDFInvoice.Name", LanguageID), order.BillingFullName)));
            doc.Add(new Paragraph("   " + String.Format(LocalizationManager.GetLocaleResourceString("PDFInvoice.Phone", LanguageID), order.BillingPhoneNumber)));
            if (!String.IsNullOrEmpty(order.BillingFaxNumber))
            {
                doc.Add(new Paragraph("   " + String.Format(LocalizationManager.GetLocaleResourceString("PDFInvoice.Fax", LanguageID), order.BillingFaxNumber)));
            }
            doc.Add(new Paragraph("   " + String.Format(LocalizationManager.GetLocaleResourceString("PDFInvoice.Address", LanguageID), order.BillingAddress1)));
            if (!String.IsNullOrEmpty(order.BillingAddress2))
            {
                doc.Add(new Paragraph("   " + String.Format(LocalizationManager.GetLocaleResourceString("PDFInvoice.Address2", LanguageID), order.BillingAddress2)));
            }
            doc.Add(new Paragraph("   " + String.Format("{0}, {1}", order.BillingCountry, order.BillingStateProvince)));
            doc.Add(new Paragraph("   " + String.Format("{0}, {1}", order.BillingCity, order.BillingZipPostalCode)));
            doc.Add(new Paragraph(" "));

            //shipping info
            if (order.ShippingStatus != ShippingStatusEnum.ShippingNotRequired)
            {
                doc.Add(new Paragraph(" "));
                doc.Add(new Paragraph(LocalizationManager.GetLocaleResourceString("PDFInvoice.ShippingInformation", LanguageID)));
                doc.Add(new Paragraph("   " + String.Format(LocalizationManager.GetLocaleResourceString("PDFInvoice.Name", LanguageID), order.ShippingFullName)));
                doc.Add(new Paragraph("   " + String.Format(LocalizationManager.GetLocaleResourceString("PDFInvoice.Phone", LanguageID), order.ShippingPhoneNumber)));
                if (!String.IsNullOrEmpty(order.ShippingFaxNumber))
                {
                    doc.Add(new Paragraph("   " + String.Format(LocalizationManager.GetLocaleResourceString("PDFInvoice.Fax", LanguageID), order.ShippingFaxNumber)));
                }
                doc.Add(new Paragraph("   " + String.Format(LocalizationManager.GetLocaleResourceString("PDFInvoice.Address", LanguageID), order.ShippingAddress1)));
                if (!String.IsNullOrEmpty(order.ShippingAddress2))
                {
                    doc.Add(new Paragraph("   " + String.Format(LocalizationManager.GetLocaleResourceString("PDFInvoice.Address2", LanguageID), order.ShippingAddress2)));
                }
                doc.Add(new Paragraph("   " + String.Format("{0}, {1}", order.ShippingCountry, order.ShippingStateProvince)));
                doc.Add(new Paragraph("   " + String.Format("{0}, {1}", order.ShippingCity, order.ShippingZipPostalCode)));
                doc.Add(new Paragraph(" "));
            }



            //products
            doc.Add(new Paragraph(LocalizationManager.GetLocaleResourceString("PDFInvoice.Product(s)", LanguageID)));
            doc.Add(new Paragraph(" "));

            OrderProductVariantCollection productCollection = order.OrderProductVariants;
            Table tbl = new Table(4, productCollection.Count + 1);

            tbl.AutoFillEmptyCells = true;
            tbl.Cellpadding        = 2f;
            tbl.SetWidths(new int[4] {
                40, 25, 10, 25
            });

            Cell c1 = new Cell(LocalizationManager.GetLocaleResourceString("PDFInvoice.ProductName", LanguageID));

            c1.Header = true;
            c1.HorizontalAlignment = Element.ALIGN_CENTER;
            c1.VerticalAlignment   = Element.ALIGN_MIDDLE;
            tbl.AddCell(c1, 0, 0);

            Cell c2 = new Cell(LocalizationManager.GetLocaleResourceString("PDFInvoice.ProductPrice", LanguageID));

            c2.Header = true;
            c2.HorizontalAlignment = Element.ALIGN_CENTER;
            c2.VerticalAlignment   = Element.ALIGN_MIDDLE;
            tbl.AddCell(c2, 0, 1);

            Cell c3 = new Cell(LocalizationManager.GetLocaleResourceString("PDFInvoice.ProductQuantity", LanguageID));

            c3.Header = true;
            c3.HorizontalAlignment = Element.ALIGN_CENTER;
            c3.VerticalAlignment   = Element.ALIGN_MIDDLE;
            tbl.AddCell(c3, 0, 2);

            Cell c4 = new Cell(LocalizationManager.GetLocaleResourceString("PDFInvoice.ProductTotal", LanguageID));

            c4.Header = true;
            c4.HorizontalAlignment = Element.ALIGN_CENTER;
            c4.VerticalAlignment   = Element.ALIGN_MIDDLE;
            tbl.AddCell(c4, 0, 3);

            tbl.Width = 90f;

            for (int i = 0; i < productCollection.Count; i++)
            {
                OrderProductVariant orderProductVariant = productCollection[i];
                int row = i + 1;

                string         name = String.Format("Not available. ID={0}", orderProductVariant.ProductVariantID);
                ProductVariant pv   = ProductManager.GetProductVariantByID(orderProductVariant.ProductVariantID);
                if (pv != null)
                {
                    name = pv.FullProductName;
                }
                tbl.AddCell(new Cell(name), row, 0);

                string unitPrice = string.Empty;
                switch (order.CustomerTaxDisplayType)
                {
                case TaxDisplayTypeEnum.ExcludingTax:
                    unitPrice = PriceHelper.FormatPrice(orderProductVariant.UnitPriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, NopContext.Current.WorkingLanguage, false);
                    break;

                case TaxDisplayTypeEnum.IncludingTax:
                    unitPrice = PriceHelper.FormatPrice(orderProductVariant.UnitPriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, NopContext.Current.WorkingLanguage, true);
                    break;
                }

                tbl.AddCell(new Cell(unitPrice), row, 1);

                tbl.AddCell(new Cell(orderProductVariant.Quantity.ToString()), row, 2);

                string subTotal = string.Empty;
                switch (order.CustomerTaxDisplayType)
                {
                case TaxDisplayTypeEnum.ExcludingTax:
                    subTotal = PriceHelper.FormatPrice(orderProductVariant.PriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, NopContext.Current.WorkingLanguage, false);
                    break;

                case TaxDisplayTypeEnum.IncludingTax:
                    subTotal = PriceHelper.FormatPrice(orderProductVariant.PriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, NopContext.Current.WorkingLanguage, true);
                    break;
                }
                tbl.AddCell(new Cell(subTotal), row, 3);
            }

            doc.Add(tbl);



            //subtotal
            doc.Add(new Paragraph(" "));
            Paragraph p1 = null;

            switch (order.CustomerTaxDisplayType)
            {
            case TaxDisplayTypeEnum.ExcludingTax:
            {
                string orderSubtotalExclTaxStr = PriceHelper.FormatPrice(order.OrderSubtotalExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, NopContext.Current.WorkingLanguage, false);
                p1 = new Paragraph(String.Format("{0} {1}", LocalizationManager.GetLocaleResourceString("PDFInvoice.Sub-Total", LanguageID), orderSubtotalExclTaxStr));
            }
            break;

            case TaxDisplayTypeEnum.IncludingTax:
            {
                string orderSubtotalInclTaxStr = PriceHelper.FormatPrice(order.OrderSubtotalInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, NopContext.Current.WorkingLanguage, true);
                p1 = new Paragraph(String.Format("{0} {1}", LocalizationManager.GetLocaleResourceString("PDFInvoice.Sub-Total", LanguageID), orderSubtotalInclTaxStr));
            }
            break;
            }
            if (p1 != null)
            {
                p1.Alignment = Element.ALIGN_RIGHT;
                doc.Add(p1);
            }

            //shipping
            Paragraph p2 = null;

            switch (order.CustomerTaxDisplayType)
            {
            case TaxDisplayTypeEnum.ExcludingTax:
            {
                string orderShippingExclTaxStr = PriceHelper.FormatShippingPrice(order.OrderShippingExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, NopContext.Current.WorkingLanguage, false);
                p2 = new Paragraph(String.Format("{0} {1}", LocalizationManager.GetLocaleResourceString("PDFInvoice.Shipping", LanguageID), orderShippingExclTaxStr));
            }
            break;

            case TaxDisplayTypeEnum.IncludingTax:
            {
                string orderShippingInclTaxStr = PriceHelper.FormatShippingPrice(order.OrderShippingInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, NopContext.Current.WorkingLanguage, true);
                p2 = new Paragraph(String.Format("{0} {1}", LocalizationManager.GetLocaleResourceString("PDFInvoice.Shipping", LanguageID), orderShippingInclTaxStr));
            }
            break;
            }

            if (p2 != null)
            {
                p2.Alignment = Element.ALIGN_RIGHT;
                doc.Add(p2);
            }

            //payment fee
            bool displayPaymentMethodFee = true;

            if (order.PaymentMethodAdditionalFeeExclTaxInCustomerCurrency == decimal.Zero)
            {
                displayPaymentMethodFee = false;
            }
            if (displayPaymentMethodFee)
            {
                Paragraph p3 = null;
                switch (order.CustomerTaxDisplayType)
                {
                case TaxDisplayTypeEnum.ExcludingTax:
                {
                    string paymentMethodAdditionalFeeExclTaxStr = PriceHelper.FormatPaymentMethodAdditionalFee(order.PaymentMethodAdditionalFeeExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, NopContext.Current.WorkingLanguage, false);
                    p3 = new Paragraph(String.Format("{0} {1}", LocalizationManager.GetLocaleResourceString("PDFInvoice.PaymentMethodAdditionalFee", LanguageID), paymentMethodAdditionalFeeExclTaxStr));
                }
                break;

                case TaxDisplayTypeEnum.IncludingTax:
                {
                    string paymentMethodAdditionalFeeInclTaxStr = PriceHelper.FormatPaymentMethodAdditionalFee(order.PaymentMethodAdditionalFeeInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, NopContext.Current.WorkingLanguage, true);
                    p3 = new Paragraph(String.Format("{0} {1}", LocalizationManager.GetLocaleResourceString("PDFInvoice.PaymentMethodAdditionalFee", LanguageID), paymentMethodAdditionalFeeInclTaxStr));
                }
                break;
                }
                if (p3 != null)
                {
                    p3.Alignment = Element.ALIGN_RIGHT;
                    doc.Add(p3);
                }
            }

            string taxStr     = string.Empty;
            bool   displayTax = true;

            if (TaxManager.HideTaxInOrderSummary && order.CustomerTaxDisplayType == TaxDisplayTypeEnum.IncludingTax)
            {
                displayTax = false;
            }
            else
            {
                if (order.OrderTax == 0 && TaxManager.HideZeroTax)
                {
                    displayTax = false;
                }
                else
                {
                    taxStr = string.Format("{0} ({1})", order.OrderTaxInCustomerCurrency.ToString("N"), order.CustomerCurrencyCode);
                }
            }
            if (displayTax)
            {
                Paragraph p4 = new Paragraph(String.Format("{0} {1}", LocalizationManager.GetLocaleResourceString("PDFInvoice.Tax", LanguageID), taxStr));
                p4.Alignment = Element.ALIGN_RIGHT;
                doc.Add(p4);
            }

            string    totalStr = string.Format("{0} ({1})", order.OrderTotalInCustomerCurrency.ToString("N"), order.CustomerCurrencyCode);
            Paragraph p5       = new Paragraph(String.Format("{0} {1}", LocalizationManager.GetLocaleResourceString("PDFInvoice.OrderTotal", LanguageID), totalStr));

            p5.Alignment = Element.ALIGN_RIGHT;
            doc.Add(p5);

            doc.Close();
        }