protected override void BuildPostForm(Order order, IndividualOrderCollection indOrders, decimal price, decimal shipping, Customer customer)
        {
            var remotePostHelper = new RemotePost { FormName = "AssistForm", Url = GetPaymentServiceUrl() };
            remotePostHelper.Add("Merchant_ID", "706403");
            remotePostHelper.Add("OrderNumber", order.OrderID.ToString());
            remotePostHelper.Add("OrderAmount", Math.Round(price + shipping).ToString());
            remotePostHelper.Add("OrderCurrency", ConvertToUsd ? "USD" : CurrencyId);
            remotePostHelper.Add("TestMode", IsTestMode? "1": "0");
            if (!String.IsNullOrEmpty(customer.BillingAddress.LastName))
            {
                remotePostHelper.Add("Lastname", customer.BillingAddress.LastName);
            }
            if (!String.IsNullOrEmpty(customer.BillingAddress.FirstName))
            {
                remotePostHelper.Add("Firstname", customer.BillingAddress.FirstName);
            }
            if (!String.IsNullOrEmpty(customer.BillingAddress.Email))
            {
                remotePostHelper.Add("Email", customer.BillingAddress.Email);
            }

            remotePostHelper.Add("URL_RETURN_OK", SettingManager.GetSettingValue("PaymentMethod.Assist.OkUrl"));
            remotePostHelper.Add("URL_RETURN_NO", SettingManager.GetSettingValue("PaymentMethod.Assist.NoUrl"));

            remotePostHelper.Post();
        }
Beispiel #2
0
 /// <summary>
 /// Cancels recurring payment
 /// </summary>
 /// <param name="order">Order</param>
 /// <param name="cancelPaymentResult">Cancel payment result</param>
 public static void CancelRecurringPayment(Order order, ref CancelPaymentResult cancelPaymentResult)
 {
     var paymentMethod = PaymentMethodManager.GetPaymentMethodById(order.PaymentMethodId);
     if (paymentMethod == null)
         throw new NopException("Payment method couldn't be loaded");
     var iPaymentMethod = Activator.CreateInstance(Type.GetType(paymentMethod.ClassName)) as IPaymentMethod;
     iPaymentMethod.CancelRecurringPayment(order, ref cancelPaymentResult);
 }
        /// <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 static string PostProcessPayment(Order order)
        {
            //already paid or order.OrderTotal == decimal.Zero
            if (order.PaymentStatus == PaymentStatusEnum.Paid)
                return string.Empty;

            PaymentMethod paymentMethod = PaymentMethodManager.GetPaymentMethodByID(order.PaymentMethodID);
            if (paymentMethod == null)
                throw new NopException("Payment method couldn't be loaded");
            IPaymentMethod iPaymentMethod = Activator.CreateInstance(Type.GetType(paymentMethod.ClassName)) as IPaymentMethod;
            return iPaymentMethod.PostProcessPayment(order);
        }
        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>
        /// 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)
        {
            RemotePost remotePostHelper = new RemotePost();
            remotePostHelper.FormName = "MoneybookersForm";
            remotePostHelper.Url = GetMoneybookersUrl();

            remotePostHelper.Add("pay_to_email", payToEmail);
            remotePostHelper.Add("recipient_description", SettingManager.StoreName);
            remotePostHelper.Add("transaction_id", order.OrderID.ToString());
            remotePostHelper.Add("cancel_url", CommonHelper.GetStoreLocation(false) + "Default.aspx");
            remotePostHelper.Add("status_url", CommonHelper.GetStoreLocation(false) + "MoneybookersReturn.aspx");
            //supported moneybookers languages (EN, DE, ES, FR, IT, PL, GR, RO, RU, TR, CN, CZ or NL)
            //TODO Check if customer working language is supported by Moneybookers.
            remotePostHelper.Add("language", "EN");
            remotePostHelper.Add("amount", order.OrderTotal.ToString(new CultureInfo("en-US", false).NumberFormat));
            //TODO Primary store currency should be set to USD now (3-letter codes)
            remotePostHelper.Add("currency", CurrencyManager.PrimaryStoreCurrency.CurrencyCode);
            remotePostHelper.Add("detail1_description", "Order ID:");
            remotePostHelper.Add("detail1_text", order.OrderID.ToString());

            remotePostHelper.Add("firstname", order.BillingFirstName);
            remotePostHelper.Add("lastname", order.BillingLastName);
            remotePostHelper.Add("address", order.BillingAddress1);
            remotePostHelper.Add("phone_number", order.BillingPhoneNumber);
            remotePostHelper.Add("postal_code", order.BillingZipPostalCode);
            remotePostHelper.Add("city", order.BillingCity);
            StateProvince billingStateProvince = StateProvinceManager.GetStateProvinceByID(order.BillingStateProvinceID);
            if (billingStateProvince != null)
                remotePostHelper.Add("state", billingStateProvince.Abbreviation);
            else
                remotePostHelper.Add("state", order.BillingStateProvince);
            Country billingCountry = CountryManager.GetCountryByID(order.BillingCountryID);
            if (billingCountry != null)
                remotePostHelper.Add("country", billingCountry.ThreeLetterISOCode);
            else
                remotePostHelper.Add("country", order.BillingCountry);
            remotePostHelper.Post();
            return string.Empty;
        }
 /// <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)
 {
     return string.Empty;
 }
 /// <summary>
 /// Cancels recurring payment
 /// </summary>
 /// <param name="order">Order</param>
 /// <param name="cancelPaymentResult">Cancel payment result</param>        
 public void CancelRecurringPayment(Order order, ref CancelPaymentResult cancelPaymentResult)
 {
 }
        /// <summary>
        /// Replaces a message template tokens
        /// </summary>
        /// <param name="order">Order instance</param>
        /// <param name="template">Template</param>
        /// <param name="languageId">Language identifier</param>
        /// <returns>New template</returns>
        public string ReplaceMessageTemplateTokens(Order order,
            string template, int languageId)
        {
            var tokens = new NameValueCollection();
            tokens.Add("Store.Name", IoC.Resolve<ISettingManager>().StoreName);
            tokens.Add("Store.URL", IoC.Resolve<ISettingManager>().StoreUrl);
            tokens.Add("Store.Email", this.DefaultEmailAccount.Email);

            tokens.Add("Order.OrderNumber", order.OrderId.ToString());

            tokens.Add("Order.CustomerFullName", HttpUtility.HtmlEncode(order.BillingFullName));
            tokens.Add("Order.CustomerEmail", HttpUtility.HtmlEncode(order.BillingEmail));

            tokens.Add("Order.BillingFirstName", HttpUtility.HtmlEncode(order.BillingFirstName));
            tokens.Add("Order.BillingLastName", HttpUtility.HtmlEncode(order.BillingLastName));
            tokens.Add("Order.BillingPhoneNumber", HttpUtility.HtmlEncode(order.BillingPhoneNumber));
            tokens.Add("Order.BillingEmail", HttpUtility.HtmlEncode(order.BillingEmail));
            tokens.Add("Order.BillingFaxNumber", HttpUtility.HtmlEncode(order.BillingFaxNumber));
            tokens.Add("Order.BillingCompany", HttpUtility.HtmlEncode(order.BillingCompany));
            tokens.Add("Order.BillingAddress1", HttpUtility.HtmlEncode(order.BillingAddress1));
            tokens.Add("Order.BillingAddress2", HttpUtility.HtmlEncode(order.BillingAddress2));
            tokens.Add("Order.BillingCity", HttpUtility.HtmlEncode(order.BillingCity));
            tokens.Add("Order.BillingStateProvince", HttpUtility.HtmlEncode(order.BillingStateProvince));
            tokens.Add("Order.BillingZipPostalCode", HttpUtility.HtmlEncode(order.BillingZipPostalCode));
            tokens.Add("Order.BillingCountry", HttpUtility.HtmlEncode(order.BillingCountry));

            tokens.Add("Order.ShippingMethod", HttpUtility.HtmlEncode(order.ShippingMethod));

            tokens.Add("Order.ShippingFirstName", HttpUtility.HtmlEncode(order.ShippingFirstName));
            tokens.Add("Order.ShippingLastName", HttpUtility.HtmlEncode(order.ShippingLastName));
            tokens.Add("Order.ShippingPhoneNumber", HttpUtility.HtmlEncode(order.ShippingPhoneNumber));
            tokens.Add("Order.ShippingEmail", HttpUtility.HtmlEncode(order.ShippingEmail));
            tokens.Add("Order.ShippingFaxNumber", HttpUtility.HtmlEncode(order.ShippingFaxNumber));
            tokens.Add("Order.ShippingCompany", HttpUtility.HtmlEncode(order.ShippingCompany));
            tokens.Add("Order.ShippingAddress1", HttpUtility.HtmlEncode(order.ShippingAddress1));
            tokens.Add("Order.ShippingAddress2", HttpUtility.HtmlEncode(order.ShippingAddress2));
            tokens.Add("Order.ShippingCity", HttpUtility.HtmlEncode(order.ShippingCity));
            tokens.Add("Order.ShippingStateProvince", HttpUtility.HtmlEncode(order.ShippingStateProvince));
            tokens.Add("Order.ShippingZipPostalCode", HttpUtility.HtmlEncode(order.ShippingZipPostalCode));
            tokens.Add("Order.ShippingCountry", HttpUtility.HtmlEncode(order.ShippingCountry));

            tokens.Add("Order.TrackingNumber", HttpUtility.HtmlEncode(order.TrackingNumber));
            tokens.Add("Order.VatNumber", HttpUtility.HtmlEncode(order.VatNumber));

            tokens.Add("Order.Product(s)", ProductListToHtmlTable(order, languageId));

            var language = IoC.Resolve<ILanguageService>().GetLanguageById(languageId);
            if (language != null && !String.IsNullOrEmpty(language.LanguageCulture))
            {
                DateTime createdOn = DateTimeHelper.ConvertToUserTime(order.CreatedOn, TimeZoneInfo.Utc, DateTimeHelper.GetCustomerTimeZone(order.Customer));
                tokens.Add("Order.CreatedOn", createdOn.ToString("D", new CultureInfo(language.LanguageCulture)));
            }
            else
            {
                tokens.Add("Order.CreatedOn", order.CreatedOn.ToString("D"));
            }
            tokens.Add("Order.OrderURLForCustomer", string.Format("{0}orderdetails.aspx?orderid={1}", IoC.Resolve<ISettingManager>().StoreUrl, order.OrderId));

            foreach (string token in tokens.Keys)
            {
                template = Replace(template, String.Format(@"%{0}%", token), tokens[token]);
            }

            return template;
        }
        /// <summary>
        /// Sends an order shipped notification to a customer
        /// </summary>
        /// <param name="order">Order instance</param>
        /// <param name="languageId">Message language identifier</param>
        /// <returns>Queued email identifier</returns>
        public int SendOrderShippedCustomerNotification(Order order, int languageId)
        {
            if (order == null)
                throw new ArgumentNullException("order");

            string templateName = "OrderShipped.CustomerNotification";
            LocalizedMessageTemplate localizedMessageTemplate = this.GetLocalizedMessageTemplate(templateName, languageId);
            if(localizedMessageTemplate == null || !localizedMessageTemplate.IsActive)
                return 0;

            var emailAccount = localizedMessageTemplate.EmailAccount;

            string subject = ReplaceMessageTemplateTokens(order, localizedMessageTemplate.Subject, languageId);
            string body = ReplaceMessageTemplateTokens(order, localizedMessageTemplate.Body, languageId);
            string bcc = localizedMessageTemplate.BccEmailAddresses;
            var from = new MailAddress(emailAccount.Email, emailAccount.DisplayName);
            var to = new MailAddress(order.BillingEmail, order.BillingFullName);
            var queuedEmail = InsertQueuedEmail(5, from, to, string.Empty, bcc, subject, body,
                DateTime.UtcNow, 0, null, emailAccount.EmailAccountId);
            return queuedEmail.QueuedEmailId;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (NopContext.Current.User == null)
            {
                string loginURL = SEOHelper.GetLoginPageUrl(true);
                Response.Redirect(loginURL);
            }
            order = OrderManager.GetOrderById(this.OrderId);
            if (order == null || order.Deleted || NopContext.Current.User.CustomerId != order.CustomerId)
            {
                string loginURL = SEOHelper.GetLoginPageUrl(true);
                Response.Redirect(loginURL);
            }

            if (!Page.IsPostBack)
            {
                this.BindData();
            }

            //buttons
            lbPDFInvoice.Visible = SettingManager.GetSettingValueBoolean("Features.SupportPDF");
        }
		/// <summary>
		/// Gets a value indicating whether downloads are allowed
		/// </summary>
		/// <param name="order">Order to check</param>
		/// <returns>True if downloads are allowed; otherwise, false.</returns>
		public static bool AreDownloadsAllowed(Order order)
		{
			if (order == null)
				return false;

			if (order.OrderStatus == OrderStatusEnum.Pending || order.OrderStatus == OrderStatusEnum.Cancelled)
				return false;

			if (order.PaymentStatus == PaymentStatusEnum.Paid)
				return true;

			return false;
		}
Beispiel #12
0
        /// <summary>
        /// Gets a value indicating whether order is delivered
        /// </summary>
        /// <param name="order">Order</param>
        /// <returns>A value indicating whether shipping is delivered</returns>
        public bool CanDeliver(Order order)
        {
            if (order == null)
                return false;

            if (order.OrderStatus == OrderStatusEnum.Cancelled)
                return false;

            if (order.ShippingStatus == ShippingStatusEnum.Shipped)
                return true;

            return false;
        }
Beispiel #13
0
        /// <summary>
        /// Sets an order status
        /// </summary>
        /// <param name="order">Order</param>
        /// <param name="os">New order status</param>
        /// <param name="notifyCustomer">True to notify customer</param>
        protected void SetOrderStatus(Order order,
            OrderStatusEnum os, bool notifyCustomer)
        {
            if (order == null)
                throw new ArgumentNullException("order");

            OrderStatusEnum prevOrderStatus = order.OrderStatus;
            if (prevOrderStatus == os)
                return;

            //set and save new order status
            order.OrderStatusId = (int)os;
            UpdateOrder(order);

            //order notes, notifications
            InsertOrderNote(order.OrderId, string.Format("Order status has been changed to {0}", os.ToString()), false, DateTime.UtcNow);

            if (prevOrderStatus != OrderStatusEnum.Complete &&
                os == OrderStatusEnum.Complete
                && notifyCustomer)
            {
                int orderCompletedCustomerNotificationQueuedEmailId = IoC.Resolve<IMessageService>().SendOrderCompletedCustomerNotification(order, order.CustomerLanguageId);
                if (orderCompletedCustomerNotificationQueuedEmailId > 0)
                {
                    InsertOrderNote(order.OrderId, string.Format("\"Order completed\" email (to customer) has been queued. Queued email identifier: {0}.", orderCompletedCustomerNotificationQueuedEmailId), false, DateTime.UtcNow);
                }
            }

            if (prevOrderStatus != OrderStatusEnum.Cancelled &&
                os == OrderStatusEnum.Cancelled
                && notifyCustomer)
            {
                int orderCancelledCustomerNotificationQueuedEmailId = IoC.Resolve<IMessageService>().SendOrderCancelledCustomerNotification(order, order.CustomerLanguageId);
                if (orderCancelledCustomerNotificationQueuedEmailId > 0)
                {
                    InsertOrderNote(order.OrderId, string.Format("\"Order cancelled\" email (to customer) has been queued. Queued email identifier: {0}.", orderCancelledCustomerNotificationQueuedEmailId), false, DateTime.UtcNow);
                }
            }

            //reward points
            if (this.RewardPointsEnabled)
            {
                if (this.RewardPointsForPurchases_Amount > decimal.Zero)
                {
                    //Ensure that reward points are applied only to registered users
                    if (order.Customer != null && !order.Customer.IsGuest)
                    {
                        int points = (int)Math.Truncate(order.OrderTotal / this.RewardPointsForPurchases_Amount * this.RewardPointsForPurchases_Points);
                        if (points != 0)
                        {
                            if (this.RewardPointsForPurchases_Awarded == order.OrderStatus)
                            {
                                InsertRewardPointsHistory(order.CustomerId,
                                    0, points, decimal.Zero,
                                    decimal.Zero, string.Empty,
                                    string.Format(IoC.Resolve<ILocalizationManager>().GetLocaleResourceString("RewardPoints.Message.EarnedForOrder"), order.OrderId),
                                    DateTime.UtcNow);
                            }

                            if (this.RewardPointsForPurchases_Canceled == order.OrderStatus)
                            {
                               InsertRewardPointsHistory(order.CustomerId,
                                    0, -points, decimal.Zero,
                                    decimal.Zero, string.Empty,
                                    string.Format(IoC.Resolve<ILocalizationManager>().GetLocaleResourceString("RewardPoints.Message.ReducedForOrder"), order.OrderId),
                                    DateTime.UtcNow);
                            }
                        }
                    }
                }
            }

            //gift cards activation
            if (this.GiftCards_Activated.HasValue &&
               this.GiftCards_Activated.Value == order.OrderStatus)
            {
                var giftCards = GetAllGiftCards(order.OrderId, null, null, null, null, null, null, false, string.Empty);
                foreach (var gc in giftCards)
                {
                    bool isRecipientNotified = gc.IsRecipientNotified;
                    switch (gc.PurchasedOrderProductVariant.ProductVariant.GiftCardType)
                    {
                        case (int)GiftCardTypeEnum.Virtual:
                            {
                                //send email for virtual gift card
                                if (!String.IsNullOrEmpty(gc.RecipientEmail) &&
                                    !String.IsNullOrEmpty(gc.SenderEmail))
                                {
                                    Language customerLang = IoC.Resolve<ILanguageService>().GetLanguageById(order.CustomerLanguageId);
                                    if (customerLang == null)
                                        customerLang = NopContext.Current.WorkingLanguage;
                                    int queuedEmailId = IoC.Resolve<IMessageService>().SendGiftCardNotification(gc, customerLang.LanguageId);
                                    if (queuedEmailId > 0)
                                    {
                                        isRecipientNotified = true;
                                    }
                                }
                            }
                            break;
                        case (int)GiftCardTypeEnum.Physical:
                            {
                            }
                            break;
                        default:
                            break;
                    }

                    gc.IsGiftCardActivated = true;
                    gc.IsRecipientNotified = isRecipientNotified;
                    this.UpdateGiftCard(gc);
                }
            }

            //gift cards deactivation
            if (this.GiftCards_Deactivated.HasValue &&
               this.GiftCards_Deactivated.Value == order.OrderStatus)
            {
                var giftCards = GetAllGiftCards(order.OrderId,
                    null, null, null, null, null, null, true, string.Empty);
                foreach (var gc in giftCards)
                {
                    gc.IsGiftCardActivated = false;
                    this.UpdateGiftCard(gc);
                }
            }
        }
Beispiel #14
0
        /// <summary>
        /// Updates the order
        /// </summary>
        /// <param name="order">The order</param>
        public void UpdateOrder(Order order)
        {
            if (order == null)
                throw new ArgumentNullException("order");

            order.TaxRates = CommonHelper.EnsureNotNull(order.TaxRates);
            order.TaxRatesInCustomerCurrency = CommonHelper.EnsureNotNull(order.TaxRatesInCustomerCurrency);
            order.CustomerIP = CommonHelper.EnsureNotNull(order.CustomerIP);
            order.CheckoutAttributeDescription = CommonHelper.EnsureNotNull(order.CheckoutAttributeDescription);
            order.CheckoutAttributesXml = CommonHelper.EnsureNotNull(order.CheckoutAttributesXml);
            order.CardType = CommonHelper.EnsureNotNull(order.CardType);
            order.CardName = CommonHelper.EnsureNotNull(order.CardName);
            order.CardNumber = CommonHelper.EnsureNotNull(order.CardNumber);
            order.MaskedCreditCardNumber = CommonHelper.EnsureNotNull(order.MaskedCreditCardNumber);
            order.CardCvv2 = CommonHelper.EnsureNotNull(order.CardCvv2);
            order.CardExpirationMonth = CommonHelper.EnsureNotNull(order.CardExpirationMonth);
            order.CardExpirationYear = CommonHelper.EnsureNotNull(order.CardExpirationYear);
            order.PaymentMethodName = CommonHelper.EnsureNotNull(order.PaymentMethodName);
            order.AuthorizationTransactionId = CommonHelper.EnsureNotNull(order.AuthorizationTransactionId);
            order.AuthorizationTransactionCode = CommonHelper.EnsureNotNull(order.AuthorizationTransactionCode);
            order.AuthorizationTransactionResult = CommonHelper.EnsureNotNull(order.AuthorizationTransactionResult);
            order.CaptureTransactionId = CommonHelper.EnsureNotNull(order.CaptureTransactionId);
            order.CaptureTransactionResult = CommonHelper.EnsureNotNull(order.CaptureTransactionResult);
            order.SubscriptionTransactionId = CommonHelper.EnsureNotNull(order.SubscriptionTransactionId);
            order.PurchaseOrderNumber = CommonHelper.EnsureNotNull(order.PurchaseOrderNumber);
            order.BillingFirstName = CommonHelper.EnsureNotNull(order.BillingFirstName);
            order.BillingLastName = CommonHelper.EnsureNotNull(order.BillingLastName);
            order.BillingPhoneNumber = CommonHelper.EnsureNotNull(order.BillingPhoneNumber);
            order.BillingEmail = CommonHelper.EnsureNotNull(order.BillingEmail);
            order.BillingFaxNumber = CommonHelper.EnsureNotNull(order.BillingFaxNumber);
            order.BillingCompany = CommonHelper.EnsureNotNull(order.BillingCompany);
            order.BillingAddress1 = CommonHelper.EnsureNotNull(order.BillingAddress1);
            order.BillingAddress2 = CommonHelper.EnsureNotNull(order.BillingAddress2);
            order.BillingCity = CommonHelper.EnsureNotNull(order.BillingCity);
            order.BillingStateProvince = CommonHelper.EnsureNotNull(order.BillingStateProvince);
            order.BillingZipPostalCode = CommonHelper.EnsureNotNull(order.BillingZipPostalCode);
            order.BillingCountry = CommonHelper.EnsureNotNull(order.BillingCountry);
            order.ShippingFirstName = CommonHelper.EnsureNotNull(order.ShippingFirstName);
            order.ShippingLastName = CommonHelper.EnsureNotNull(order.ShippingLastName);
            order.ShippingPhoneNumber = CommonHelper.EnsureNotNull(order.ShippingPhoneNumber);
            order.ShippingEmail = CommonHelper.EnsureNotNull(order.ShippingEmail);
            order.ShippingFaxNumber = CommonHelper.EnsureNotNull(order.ShippingFaxNumber);
            order.ShippingCompany = CommonHelper.EnsureNotNull(order.ShippingCompany);
            order.ShippingAddress1 = CommonHelper.EnsureNotNull(order.ShippingAddress1);
            order.ShippingAddress2 = CommonHelper.EnsureNotNull(order.ShippingAddress2);
            order.ShippingCity = CommonHelper.EnsureNotNull(order.ShippingCity);
            order.ShippingStateProvince = CommonHelper.EnsureNotNull(order.ShippingStateProvince);
            order.ShippingZipPostalCode = CommonHelper.EnsureNotNull(order.ShippingZipPostalCode);
            order.ShippingCountry = CommonHelper.EnsureNotNull(order.ShippingCountry);
            order.ShippingMethod = CommonHelper.EnsureNotNull(order.ShippingMethod);
            order.TrackingNumber = CommonHelper.EnsureNotNull(order.TrackingNumber);
            order.VatNumber = CommonHelper.EnsureNotNull(order.VatNumber);

            order.BillingEmail = order.BillingEmail.Trim();
            order.ShippingEmail = order.ShippingEmail.Trim();

            order.TaxRates = CommonHelper.EnsureMaximumLength(order.TaxRates, 4000);
            order.TaxRatesInCustomerCurrency = CommonHelper.EnsureMaximumLength(order.TaxRatesInCustomerCurrency, 4000);
            order.CustomerIP = CommonHelper.EnsureMaximumLength(order.CustomerIP, 50);
            order.CardType = CommonHelper.EnsureMaximumLength(order.CardType, 100);
            order.CardName = CommonHelper.EnsureMaximumLength(order.CardName, 1000);
            order.CardNumber = CommonHelper.EnsureMaximumLength(order.CardNumber, 100);
            order.MaskedCreditCardNumber = CommonHelper.EnsureMaximumLength(order.MaskedCreditCardNumber, 100);
            order.CardCvv2 = CommonHelper.EnsureMaximumLength(order.CardCvv2, 100);
            order.CardExpirationMonth = CommonHelper.EnsureMaximumLength(order.CardExpirationMonth, 100);
            order.CardExpirationYear = CommonHelper.EnsureMaximumLength(order.CardExpirationYear, 100);
            order.PaymentMethodName = CommonHelper.EnsureMaximumLength(order.PaymentMethodName, 100);
            order.AuthorizationTransactionId = CommonHelper.EnsureMaximumLength(order.AuthorizationTransactionId, 4000);
            order.AuthorizationTransactionCode = CommonHelper.EnsureMaximumLength(order.AuthorizationTransactionCode, 4000);
            order.AuthorizationTransactionResult = CommonHelper.EnsureMaximumLength(order.AuthorizationTransactionResult, 4000);
            order.CaptureTransactionId = CommonHelper.EnsureMaximumLength(order.CaptureTransactionId, 4000);
            order.CaptureTransactionResult = CommonHelper.EnsureMaximumLength(order.CaptureTransactionResult, 4000);
            order.SubscriptionTransactionId = CommonHelper.EnsureMaximumLength(order.SubscriptionTransactionId, 4000);
            order.PurchaseOrderNumber = CommonHelper.EnsureMaximumLength(order.PurchaseOrderNumber, 100);
            order.BillingFirstName = CommonHelper.EnsureMaximumLength(order.BillingFirstName, 100);
            order.BillingLastName = CommonHelper.EnsureMaximumLength(order.BillingLastName, 100);
            order.BillingPhoneNumber = CommonHelper.EnsureMaximumLength(order.BillingPhoneNumber, 50);
            order.BillingEmail = CommonHelper.EnsureMaximumLength(order.BillingEmail, 255);
            order.BillingFaxNumber = CommonHelper.EnsureMaximumLength(order.BillingFaxNumber, 50);
            order.BillingCompany = CommonHelper.EnsureMaximumLength(order.BillingCompany, 100);
            order.BillingAddress1 = CommonHelper.EnsureMaximumLength(order.BillingAddress1, 100);
            order.BillingAddress2 = CommonHelper.EnsureMaximumLength(order.BillingAddress2, 100);
            order.BillingCity = CommonHelper.EnsureMaximumLength(order.BillingCity, 100);
            order.BillingStateProvince = CommonHelper.EnsureMaximumLength(order.BillingStateProvince, 100);
            order.BillingZipPostalCode = CommonHelper.EnsureMaximumLength(order.BillingZipPostalCode, 30);
            order.BillingCountry = CommonHelper.EnsureMaximumLength(order.BillingCountry, 100);
            order.ShippingFirstName = CommonHelper.EnsureMaximumLength(order.ShippingFirstName, 100);
            order.ShippingLastName = CommonHelper.EnsureMaximumLength(order.ShippingLastName, 100);
            order.ShippingPhoneNumber = CommonHelper.EnsureMaximumLength(order.ShippingPhoneNumber, 50);
            order.ShippingEmail = CommonHelper.EnsureMaximumLength(order.ShippingEmail, 255);
            order.ShippingFaxNumber = CommonHelper.EnsureMaximumLength(order.ShippingFaxNumber, 50);
            order.ShippingCompany = CommonHelper.EnsureMaximumLength(order.ShippingCompany, 100);
            order.ShippingAddress1 = CommonHelper.EnsureMaximumLength(order.ShippingAddress1, 100);
            order.ShippingAddress2 = CommonHelper.EnsureMaximumLength(order.ShippingAddress2, 100);
            order.ShippingCity = CommonHelper.EnsureMaximumLength(order.ShippingCity, 100);
            order.ShippingStateProvince = CommonHelper.EnsureMaximumLength(order.ShippingStateProvince, 100);
            order.ShippingZipPostalCode = CommonHelper.EnsureMaximumLength(order.ShippingZipPostalCode, 30);
            order.ShippingCountry = CommonHelper.EnsureMaximumLength(order.ShippingCountry, 100);
            order.ShippingMethod = CommonHelper.EnsureMaximumLength(order.ShippingMethod, 100);
            order.TrackingNumber = CommonHelper.EnsureMaximumLength(order.TrackingNumber, 100);
            order.VatNumber = CommonHelper.EnsureMaximumLength(order.VatNumber, 100);

            if (!_context.IsAttached(order))
                _context.Orders.Attach(order);

            _context.SaveChanges();

            //quickbooks
            if (IoC.Resolve<IQBService>().QBIsEnabled)
            {
                IoC.Resolve<IQBService>().RequestSynchronization(order);
            }

            //raise event
            EventContext.Current.OnOrderUpdated(null,
                new OrderEventArgs() { Order = order });
        }
Beispiel #15
0
        /// <summary>
        /// Gets a value indicating whether capture from admin panel is allowed
        /// </summary>
        /// <param name="order">Order</param>
        /// <returns>A value indicating whether capture from admin panel is allowed</returns>
        public bool CanCapture(Order order)
        {
            if (order == null)
                return false;

            if (order.OrderStatus == OrderStatusEnum.Cancelled ||
                order.OrderStatus == OrderStatusEnum.Pending)
                return false;

            if (order.PaymentStatus == PaymentStatusEnum.Authorized &&
                IoC.Resolve<IPaymentService>().CanCapture(order.PaymentMethodId))
                return true;

            return false;
        }
		/// <summary>
		/// Gets a value indicating whether capture from admin panel is allowed
		/// </summary>
		/// <param name="order">Order</param>
		/// <returns>A value indicating whether capture from admin panel is allowed</returns>
		public static bool CanCapture(Order order)
		{
			if (order == null)
				return false;

			if (order.OrderStatus == OrderStatusEnum.Cancelled ||
				order.OrderStatus == OrderStatusEnum.Pending)
				return false;

			if (order.PaymentStatus == PaymentStatusEnum.Authorized &&
				PaymentManager.CanCapture(order.PaymentMethodID))
				return true;

			return false;
		}
		/// <summary>
		/// Gets a value indicating whether order can be marked as paid
		/// </summary>
		/// <param name="order">Order</param>
		/// <returns>A value indicating whether order can be marked as paid</returns>
		public static bool CanMarkOrderAsPaid(Order order)
		{
			if (order == null)
				return false;

			if (order.OrderStatus == OrderStatusEnum.Cancelled)
				return false;

			if (order.PaymentStatus == PaymentStatusEnum.Paid)
				return false;

			return true;
		}
Beispiel #18
0
        /// <summary>
        /// Gets a value indicating whether order can be marked as authorized
        /// </summary>
        /// <param name="order">Order</param>
        /// <returns>A value indicating whether order can be marked as authorized</returns>
        public bool CanMarkOrderAsAuthorized(Order order)
        {
            if (order == null)
                return false;

            if (order.OrderStatus == OrderStatusEnum.Cancelled)
                return false;

            if (order.PaymentStatus == PaymentStatusEnum.Pending)
                return true;

            return false;
        }
		private static Order DBMapping(DBOrder dbItem)
		{
			if (dbItem == null)
				return null;

			Order item = new Order();
			item.OrderID = dbItem.OrderID;
			item.OrderGUID = dbItem.OrderGUID;
			item.CustomerID = dbItem.CustomerID;
			item.CustomerLanguageID = dbItem.CustomerLanguageID;
			item.CustomerTaxDisplayTypeID = dbItem.CustomerTaxDisplayTypeID;
			item.OrderSubtotalInclTax = dbItem.OrderSubtotalInclTax;
			item.OrderSubtotalExclTax = dbItem.OrderSubtotalExclTax;
			item.OrderShippingInclTax = dbItem.OrderShippingInclTax;
			item.OrderShippingExclTax = dbItem.OrderShippingExclTax;
			item.PaymentMethodAdditionalFeeInclTax = dbItem.PaymentMethodAdditionalFeeInclTax;
			item.PaymentMethodAdditionalFeeExclTax = dbItem.PaymentMethodAdditionalFeeExclTax;
			item.OrderTax = dbItem.OrderTax;
			item.OrderTotal = dbItem.OrderTotal;
			item.OrderDiscount = dbItem.OrderDiscount;
			item.OrderSubtotalInclTaxInCustomerCurrency = dbItem.OrderSubtotalInclTaxInCustomerCurrency;
			item.OrderSubtotalExclTaxInCustomerCurrency = dbItem.OrderSubtotalExclTaxInCustomerCurrency;
			item.OrderShippingInclTaxInCustomerCurrency = dbItem.OrderShippingInclTaxInCustomerCurrency;
			item.OrderShippingExclTaxInCustomerCurrency = dbItem.OrderShippingExclTaxInCustomerCurrency;
			item.PaymentMethodAdditionalFeeInclTaxInCustomerCurrency = dbItem.PaymentMethodAdditionalFeeInclTaxInCustomerCurrency;
			item.PaymentMethodAdditionalFeeExclTaxInCustomerCurrency = dbItem.PaymentMethodAdditionalFeeExclTaxInCustomerCurrency;
			item.OrderTaxInCustomerCurrency = dbItem.OrderTaxInCustomerCurrency;
			item.OrderTotalInCustomerCurrency = dbItem.OrderTotalInCustomerCurrency;
			item.CustomerCurrencyCode = dbItem.CustomerCurrencyCode;
			item.OrderWeight = dbItem.OrderWeight;
			item.AffiliateID = dbItem.AffiliateID;
			item.OrderStatusID = dbItem.OrderStatusID;
			item.AllowStoringCreditCardNumber = dbItem.AllowStoringCreditCardNumber;
			item.CardType = dbItem.CardType;
			item.CardName = dbItem.CardName;
			item.CardNumber = dbItem.CardNumber;
			item.MaskedCreditCardNumber = dbItem.MaskedCreditCardNumber;
			item.CardCVV2 = dbItem.CardCVV2;
			item.CardExpirationMonth = dbItem.CardExpirationMonth;
			item.CardExpirationYear = dbItem.CardExpirationYear;
			item.PaymentMethodID = dbItem.PaymentMethodID;
			item.PaymentMethodName = dbItem.PaymentMethodName;
			item.AuthorizationTransactionID = dbItem.AuthorizationTransactionID;
			item.AuthorizationTransactionCode = dbItem.AuthorizationTransactionCode;
			item.AuthorizationTransactionResult = dbItem.AuthorizationTransactionResult;
			item.CaptureTransactionID = dbItem.CaptureTransactionID;
			item.CaptureTransactionResult = dbItem.CaptureTransactionResult;
			item.PurchaseOrderNumber = dbItem.PurchaseOrderNumber;
			item.PaymentStatusID = dbItem.PaymentStatusID;
			item.BillingFirstName = dbItem.BillingFirstName;
			item.BillingLastName = dbItem.BillingLastName;
			item.BillingPhoneNumber = dbItem.BillingPhoneNumber;
			item.BillingEmail = dbItem.BillingEmail;
			item.BillingFaxNumber = dbItem.BillingFaxNumber;
			item.BillingCompany = dbItem.BillingCompany;
			item.BillingAddress1 = dbItem.BillingAddress1;
			item.BillingAddress2 = dbItem.BillingAddress2;
			item.BillingCity = dbItem.BillingCity;
			item.BillingStateProvince = dbItem.BillingStateProvince;
			item.BillingStateProvinceID = dbItem.BillingStateProvinceID;
			item.BillingZipPostalCode = dbItem.BillingZipPostalCode;
			item.BillingCountry = dbItem.BillingCountry;
			item.BillingCountryID = dbItem.BillingCountryID;
			item.ShippingStatusID = dbItem.ShippingStatusID;
			item.ShippingFirstName = dbItem.ShippingFirstName;
			item.ShippingLastName = dbItem.ShippingLastName;
			item.ShippingPhoneNumber = dbItem.ShippingPhoneNumber;
			item.ShippingEmail = dbItem.ShippingEmail;
			item.ShippingFaxNumber = dbItem.ShippingFaxNumber;
			item.ShippingCompany = dbItem.ShippingCompany;
			item.ShippingAddress1 = dbItem.ShippingAddress1;
			item.ShippingAddress2 = dbItem.ShippingAddress2;
			item.ShippingCity = dbItem.ShippingCity;
			item.ShippingStateProvince = dbItem.ShippingStateProvince;
			item.ShippingStateProvinceID = dbItem.ShippingStateProvinceID;
			item.ShippingZipPostalCode = dbItem.ShippingZipPostalCode;
			item.ShippingCountry = dbItem.ShippingCountry;
			item.ShippingCountryID = dbItem.ShippingCountryID;
			item.ShippingMethod = dbItem.ShippingMethod;
			item.ShippingRateComputationMethodID = dbItem.ShippingRateComputationMethodID;
			item.ShippedDate = dbItem.ShippedDate;
			item.Deleted = dbItem.Deleted;
			item.CreatedOn = dbItem.CreatedOn;

			return item;
		}
Beispiel #20
0
        /// <summary>
        /// Gets a value indicating whether partial refund from admin panel is allowed
        /// </summary>
        /// <param name="order">Order</param>
        /// <param name="amountToRefund">Amount to refund</param>
        /// <returns>A value indicating whether refund from admin panel is allowed</returns>
        public bool CanPartiallyRefund(Order order, decimal amountToRefund)
        {
            if (order == null)
                return false;

            if (order.OrderTotal == decimal.Zero)
                return false;

            if (order.OrderStatus == OrderStatusEnum.Cancelled)
                return false;

            decimal canBeRefunded = order.OrderTotal - order.RefundedAmount;
            if (canBeRefunded <= decimal.Zero)
                return false;

            if (amountToRefund > canBeRefunded)
                return false;

            if ((order.PaymentStatus == PaymentStatusEnum.Paid ||
                order.PaymentStatus == PaymentStatusEnum.PartiallyRefunded) &&
                IoC.Resolve<IPaymentService>().CanPartiallyRefund(order.PaymentMethodId))
                return true;

            return false;
        }
        /// <summary>
        /// Captures payment
        /// </summary>
        /// <param name="order">Order</param>
        /// <param name="processPaymentResult">Process payment result</param>
        public void Capture(Order order, ref ProcessPaymentResult processPaymentResult)
        {
            InitSettings();

            string authorizationID = processPaymentResult.AuthorizationTransactionId;
            DoCaptureReq req = new DoCaptureReq();
            req.DoCaptureRequest = new DoCaptureRequestType();
            req.DoCaptureRequest.Version = this.APIVersion;
            req.DoCaptureRequest.AuthorizationID = authorizationID;
            req.DoCaptureRequest.Amount = new BasicAmountType();
            req.DoCaptureRequest.Amount.Value = order.OrderTotal.ToString("N", new CultureInfo("en-us"));
            req.DoCaptureRequest.Amount.currencyID = PaypalHelper.GetPaypalCurrency(IoC.Resolve<ICurrencyService>().PrimaryStoreCurrency);
            req.DoCaptureRequest.CompleteType = CompleteCodeType.Complete;
            DoCaptureResponseType response = service2.DoCapture(req);

            string error = string.Empty;
            bool Success = PaypalHelper.CheckSuccess(response, out error);
            if (Success)
            {
                processPaymentResult.PaymentStatus = PaymentStatusEnum.Paid;
                processPaymentResult.CaptureTransactionId = response.DoCaptureResponseDetails.PaymentInfo.TransactionID;
                processPaymentResult.CaptureTransactionResult = response.Ack.ToString();
            }
            else
            {
                processPaymentResult.Error = error;
            }
        }
Beispiel #22
0
        /// <summary>
        /// Gets a value indicating whether order can be marked as partially refunded
        /// </summary>
        /// <param name="order">Order</param>
        /// <param name="amountToRefund">Amount to refund</param>
        /// <returns>A value indicating whether order can be marked as partially refunded</returns>
        public bool CanPartiallyRefundOffline(Order order, decimal amountToRefund)
        {
            if (order == null)
                return false;

            if (order.OrderTotal == decimal.Zero)
                return false;

            if (order.OrderStatus == OrderStatusEnum.Cancelled)
                return false;

            decimal canBeRefunded = order.OrderTotal - order.RefundedAmount;
            if (canBeRefunded <= decimal.Zero)
                return false;

            if (amountToRefund > canBeRefunded)
                return false;

            if (order.PaymentStatus == PaymentStatusEnum.Paid ||
                order.PaymentStatus == PaymentStatusEnum.PartiallyRefunded)
                return true;

            return false;
        }
Beispiel #23
0
        /// <summary>
        /// Convert a collection to a HTML table
        /// </summary>
        /// <param name="order">Order</param>
        /// <param name="languageId">Language identifier</param>
        /// <returns>HTML table of products</returns>
        private string ProductListToHtmlTable(Order order, int languageId)
        {
            string result = string.Empty;

            var language = IoC.Resolve<ILanguageService>().GetLanguageById(languageId);
            if (language == null)
            {
                language = NopContext.Current.WorkingLanguage;
                languageId = language.LanguageId;
            }

            var localizationManager = IoC.Resolve<ILocalizationManager>();

            StringBuilder sb = new StringBuilder();
            sb.AppendLine("<table border=\"0\" style=\"width:100%;\">");
            string color1 = IoC.Resolve<ISettingManager>().GetSettingValue("MessageTemplate.Color1", "#b9babe");
            string color2 = IoC.Resolve<ISettingManager>().GetSettingValue("MessageTemplate.Color2", "#ebecee");
            string color3 = IoC.Resolve<ISettingManager>().GetSettingValue("MessageTemplate.Color3", "#dde2e6");

            #region Products
            sb.AppendLine(string.Format("<tr style=\"background-color:{0};text-align:center;\">", color1));
            sb.AppendLine(string.Format("<th>{0}</th>", localizationManager.GetLocaleResourceString("Order.ProductsGrid.Name", languageId)));
            sb.AppendLine(string.Format("<th>{0}</th>", localizationManager.GetLocaleResourceString("Order.ProductsGrid.Price", languageId)));
            sb.AppendLine(string.Format("<th>{0}</th>", localizationManager.GetLocaleResourceString("Order.ProductsGrid.Quantity", languageId)));
            sb.AppendLine(string.Format("<th>{0}</th>", localizationManager.GetLocaleResourceString("Order.ProductsGrid.Total", languageId)));
            sb.AppendLine("</tr>");

            var table = order.OrderProductVariants;
            for (int i = 0; i <= table.Count - 1; i++)
            {
                var opv = table[i];
                var productVariant = opv.ProductVariant;
                if (productVariant == null)
                    continue;

                sb.AppendLine(string.Format("<tr style=\"background-color: {0};text-align: center;\">", color2));
                //product name
                sb.AppendLine("<td style=\"padding: 0.6em 0.4em;text-align: left;\">" + HttpUtility.HtmlEncode(productVariant.GetLocalizedFullProductName(languageId)));
                //download link
                if (IoC.Resolve<IOrderService>().IsDownloadAllowed(opv))
                {
                    string downloadUrl = string.Format("<a class=\"link\" href=\"{0}\" >{1}</a>", IoC.Resolve<IDownloadService>().GetDownloadUrl(opv), localizationManager.GetLocaleResourceString("Order.Download", languageId));
                    sb.AppendLine("&nbsp;&nbsp;(");
                    sb.AppendLine(downloadUrl);
                    sb.AppendLine(")");
                }
                //attributes
                if (!String.IsNullOrEmpty(opv.AttributeDescription))
                {
                    sb.AppendLine("<br />");
                    sb.AppendLine(opv.AttributeDescription);
                }
                //sku
                if (IoC.Resolve<ISettingManager>().GetSettingValueBoolean("Display.Products.ShowSKU"))
                {
                    if (!String.IsNullOrEmpty(opv.ProductVariant.SKU))
                    {
                        sb.AppendLine("<br />");
                        string sku = string.Format(localizationManager.GetLocaleResourceString("MessageToken.OrderProducts.SKU", languageId), HttpUtility.HtmlEncode(opv.ProductVariant.SKU));
                        sb.AppendLine(sku);
                    }
                }
                sb.AppendLine("</td>");

                string unitPriceStr = string.Empty;
                switch (order.CustomerTaxDisplayType)
                {
                    case TaxDisplayTypeEnum.ExcludingTax:
                        unitPriceStr = PriceHelper.FormatPrice(opv.UnitPriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, language, false);
                        break;
                    case TaxDisplayTypeEnum.IncludingTax:
                        unitPriceStr = PriceHelper.FormatPrice(opv.UnitPriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, language, true);
                        break;
                }
                sb.AppendLine(string.Format("<td style=\"padding: 0.6em 0.4em;text-align: right;\">{0}</td>", unitPriceStr));

                sb.AppendLine(string.Format("<td style=\"padding: 0.6em 0.4em;text-align: center;\">{0}</td>",opv.Quantity));

                string priceStr = string.Empty;
                switch (order.CustomerTaxDisplayType)
                {
                    case TaxDisplayTypeEnum.ExcludingTax:
                        priceStr = PriceHelper.FormatPrice(opv.PriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, language, false);
                        break;
                    case TaxDisplayTypeEnum.IncludingTax:
                        priceStr = PriceHelper.FormatPrice(opv.PriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, language, true);
                        break;
                }
                sb.AppendLine(string.Format("<td style=\"padding: 0.6em 0.4em;text-align: right;\">{0}</td>", priceStr));

                sb.AppendLine("</tr>");
            }
            #endregion

            #region Checkout Attributes

            if (!String.IsNullOrEmpty(order.CheckoutAttributeDescription))
            {
                sb.AppendLine("<tr><td style=\"text-align:right;\" colspan=\"1\">&nbsp;</td><td colspan=\"3\" style=\"text-align:right\">");
                sb.AppendLine(order.CheckoutAttributeDescription);
                sb.AppendLine("</td></tr>");
            }

            #endregion

            #region Totals

            string cusSubTotal = string.Empty;
            bool dislaySubTotalDiscount = false;
            string cusSubTotalDiscount = string.Empty;
            string cusShipTotal = string.Empty;
            string cusPaymentMethodAdditionalFee = string.Empty;
            SortedDictionary<decimal, decimal> taxRates = new SortedDictionary<decimal, decimal>();
            string cusTaxTotal = string.Empty;
            string cusDiscount = string.Empty;
            string cusTotal = string.Empty;
            //subtotal, shipping, payment method fee
            switch (order.CustomerTaxDisplayType)
            {
                case TaxDisplayTypeEnum.ExcludingTax:
                    {
                        //subtotal
                        cusSubTotal = PriceHelper.FormatPrice(order.OrderSubtotalExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, language, false);
                        //discount (applied to order subtotal)
                        if (order.OrderSubTotalDiscountExclTaxInCustomerCurrency > decimal.Zero)
                        {
                            cusSubTotalDiscount = PriceHelper.FormatPrice(-order.OrderSubTotalDiscountExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, language, false);
                            dislaySubTotalDiscount = true;
                        }
                        //shipping
                        cusShipTotal = PriceHelper.FormatShippingPrice(order.OrderShippingExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, language, false);
                        //payment method additional fee
                        cusPaymentMethodAdditionalFee = PriceHelper.FormatPaymentMethodAdditionalFee(order.PaymentMethodAdditionalFeeExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, language, false);
                    }
                    break;
                case TaxDisplayTypeEnum.IncludingTax:
                    {
                        //subtotal
                        cusSubTotal = PriceHelper.FormatPrice(order.OrderSubtotalInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, language, true);
                        //discount (applied to order subtotal)
                        if (order.OrderSubTotalDiscountInclTaxInCustomerCurrency > decimal.Zero)
                        {
                            cusSubTotalDiscount = PriceHelper.FormatPrice(-order.OrderSubTotalDiscountInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, language, true);
                            dislaySubTotalDiscount = true;
                        }
                        //shipping
                        cusShipTotal = PriceHelper.FormatShippingPrice(order.OrderShippingInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, language, true);
                        //payment method additional fee
                        cusPaymentMethodAdditionalFee = PriceHelper.FormatPaymentMethodAdditionalFee(order.PaymentMethodAdditionalFeeInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, language, true);
                    }
                    break;
            }

            //shipping
            bool dislayShipping = order.ShippingStatus != ShippingStatusEnum.ShippingNotRequired;

            //payment method fee
            bool displayPaymentMethodFee = true;
            if (order.PaymentMethodAdditionalFeeExclTaxInCustomerCurrency == decimal.Zero)
            {
                displayPaymentMethodFee = false;
            }

            //tax
            bool displayTax = true;
            bool displayTaxRates = true;
            if (IoC.Resolve<ITaxService>().HideTaxInOrderSummary && order.CustomerTaxDisplayType == TaxDisplayTypeEnum.IncludingTax)
            {
                displayTax = false;
                displayTaxRates = false;
            }
            else
            {
                if (order.OrderTax == 0 && IoC.Resolve<ITaxService>().HideZeroTax)
                {
                    displayTax = false;
                    displayTaxRates = false;
                }
                else
                {
                    taxRates = order.TaxRatesDictionaryInCustomerCurrency;

                    displayTaxRates = IoC.Resolve<ITaxService>().DisplayTaxRates && taxRates.Count > 0;
                    displayTax = !displayTaxRates;

                    string taxStr = PriceHelper.FormatPrice(order.OrderTaxInCustomerCurrency, true, order.CustomerCurrencyCode, false);
                    cusTaxTotal = taxStr;
                }
            }

            //discount
            bool dislayDiscount = false;
            if (order.OrderDiscountInCustomerCurrency > decimal.Zero)
            {
                cusDiscount = PriceHelper.FormatPrice(-order.OrderDiscountInCustomerCurrency, true, order.CustomerCurrencyCode, false);
                dislayDiscount = true;
            }

            //total
            cusTotal = PriceHelper.FormatPrice(order.OrderTotalInCustomerCurrency, true, order.CustomerCurrencyCode, false);

            //subtotal
            sb.AppendLine(string.Format("<tr style=\"text-align:right;\"><td>&nbsp;</td><td colspan=\"2\" style=\"background-color: {0};padding:0.6em 0.4 em;\"><strong>{1}</strong></td> <td style=\"background-color: {0};padding:0.6em 0.4 em;\"><strong>{2}</strong></td></tr>", color3, localizationManager.GetLocaleResourceString("Order.Sub-Total", languageId), cusSubTotal));

            //discount (applied to order subtotal)
            if (dislaySubTotalDiscount)
            {
                sb.AppendLine(string.Format("<tr style=\"text-align:right;\"><td>&nbsp;</td><td colspan=\"2\" style=\"background-color: {0};padding:0.6em 0.4 em;\"><strong>{1}</strong></td> <td style=\"background-color: {0};padding:0.6em 0.4 em;\"><strong>{2}</strong></td></tr>", color3, localizationManager.GetLocaleResourceString("Order.Discount", languageId), cusSubTotalDiscount));
            }

            //shipping
            if (dislayShipping)
            {
                sb.AppendLine(string.Format("<tr style=\"text-align:right;\"><td>&nbsp;</td><td colspan=\"2\" style=\"background-color: {0};padding:0.6em 0.4 em;\"><strong>{1}</strong></td> <td style=\"background-color: {0};padding:0.6em 0.4 em;\"><strong>{2}</strong></td></tr>", color3, localizationManager.GetLocaleResourceString("Order.Shipping", languageId), cusShipTotal));
            }

            //payment method fee
            if (displayPaymentMethodFee)
            {
                string paymentMethodFeeTitle = localizationManager.GetLocaleResourceString("Order.PaymentMethodAdditionalFee", languageId);
                sb.AppendLine(string.Format("<tr style=\"text-align:right;\"><td>&nbsp;</td><td colspan=\"2\" style=\"background-color: {0};padding:0.6em 0.4 em;\"><strong>{1}</strong></td> <td style=\"background-color: {0};padding:0.6em 0.4 em;\"><strong>{2}</strong></td></tr>", color3, paymentMethodFeeTitle, cusPaymentMethodAdditionalFee));
            }

            //tax
            if (displayTax)
            {
                sb.AppendLine(string.Format("<tr style=\"text-align:right;\"><td>&nbsp;</td><td colspan=\"2\" style=\"background-color: {0};padding:0.6em 0.4 em;\"><strong>{1}</strong></td> <td style=\"background-color: {0};padding:0.6em 0.4 em;\"><strong>{2}</strong></td></tr>", color3, localizationManager.GetLocaleResourceString("Order.Tax", languageId), cusTaxTotal));
            }
            if (displayTaxRates)
            {
                foreach (var item in taxRates)
                {
                    string taxRate = String.Format(localizationManager.GetLocaleResourceString("Order.Totals.TaxRate"), PriceHelper.FormatTaxRate(item.Key));
                    string taxValue = PriceHelper.FormatPrice(item.Value, true, order.CustomerCurrencyCode, false);
                    sb.AppendLine(string.Format("<tr style=\"text-align:right;\"><td>&nbsp;</td><td colspan=\"2\" style=\"background-color: {0};padding:0.6em 0.4 em;\"><strong>{1}</strong></td> <td style=\"background-color: {0};padding:0.6em 0.4 em;\"><strong>{2}</strong></td></tr>", color3, taxRate, taxValue));
                }
            }

            //discount
            if (dislayDiscount)
            {
                sb.AppendLine(string.Format("<tr style=\"text-align:right;\"><td>&nbsp;</td><td colspan=\"2\" style=\"background-color: {0};padding:0.6em 0.4 em;\"><strong>{1}</strong></td> <td style=\"background-color: {0};padding:0.6em 0.4 em;\"><strong>{2}</strong></td></tr>", color3, localizationManager.GetLocaleResourceString("Order.Discount", languageId), cusDiscount));
            }

            //gift cards
            var gcuhC = IoC.Resolve<IOrderService>().GetAllGiftCardUsageHistoryEntries(null, null, order.OrderId);
            foreach (var giftCardUsageHistory in gcuhC)
            {
                string giftCardText = String.Format(localizationManager.GetLocaleResourceString("Order.GiftCardInfo", languageId), HttpUtility.HtmlEncode(giftCardUsageHistory.GiftCard.GiftCardCouponCode));
                string giftCardAmount = PriceHelper.FormatPrice(-giftCardUsageHistory.UsedValueInCustomerCurrency, true, order.CustomerCurrencyCode, false);
                sb.AppendLine(string.Format("<tr style=\"text-align:right;\"><td>&nbsp;</td><td colspan=\"2\" style=\"background-color: {0};padding:0.6em 0.4 em;\"><strong>{1}</strong></td> <td style=\"background-color: {0};padding:0.6em 0.4 em;\"><strong>{2}</strong></td></tr>", color3, giftCardText, giftCardAmount));
            }

            //reward points
            if (order.RedeemedRewardPoints != null)
            {
                string rpTitle = string.Format(localizationManager.GetLocaleResourceString("Order.Totals.RewardPoints", languageId), -order.RedeemedRewardPoints.Points);
                string rpAmount = PriceHelper.FormatPrice(-order.RedeemedRewardPoints.UsedAmountInCustomerCurrency, true, order.CustomerCurrencyCode, false);
                sb.AppendLine(string.Format("<tr style=\"text-align:right;\"><td>&nbsp;</td><td colspan=\"2\" style=\"background-color: {0};padding:0.6em 0.4 em;\"><strong>{1}</strong></td> <td style=\"background-color: {0};padding:0.6em 0.4 em;\"><strong>{2}</strong></td></tr>", color3, rpTitle, rpAmount));
            }

            //total
            sb.AppendLine(string.Format("<tr style=\"text-align:right;\"><td>&nbsp;</td><td colspan=\"2\" style=\"background-color: {0};padding:0.6em 0.4 em;\"><strong>{1}</strong></td> <td style=\"background-color: {0};padding:0.6em 0.4 em;\"><strong>{2}</strong></td></tr>", color3, localizationManager.GetLocaleResourceString("Order.OrderTotal", languageId), cusTotal));
            #endregion

            sb.AppendLine("</table>");
            result = sb.ToString();
            return result;
        }
Beispiel #24
0
        /// <summary>
        /// Gets a value indicating whether void from admin panel is allowed
        /// </summary>
        /// <param name="order">Order</param>
        /// <returns>A value indicating whether void from admin panel is allowed</returns>
        public bool CanVoid(Order order)
        {
            if (order == null)
                return false;

            if (order.OrderTotal == decimal.Zero)
                return false;

            if (order.OrderStatus == OrderStatusEnum.Cancelled)
                return false;

            if (order.PaymentStatus == PaymentStatusEnum.Authorized &&
                IoC.Resolve<IPaymentService>().CanVoid(order.PaymentMethodId))
                return true;

            return false;
        }
 protected string GetOrderTotal(Order order)
 {
     string orderTotalStr = PriceHelper.FormatPrice(order.OrderTotalInCustomerCurrency, true, order.CustomerCurrencyCode, false);
     return orderTotalStr;
 }
Beispiel #26
0
        /// <summary>
        /// Gets a value indicating whether order can be marked as voided
        /// </summary>
        /// <param name="order">Order</param>
        /// <returns>A value indicating whether order can be marked as voided</returns>
        public bool CanVoidOffline(Order order)
        {
            if (order == null)
                return false;

            if (order.OrderTotal == decimal.Zero)
                return false;

            if (order.OrderStatus == OrderStatusEnum.Cancelled)
                return false;

            if (order.PaymentStatus == PaymentStatusEnum.Authorized)
                return true;

            return false;
        }
 /// <summary>
 /// Captures payment
 /// </summary>
 /// <param name="order">Order</param>
 /// <param name="processPaymentResult">Process payment result</param>
 public void Capture(Order order, ref ProcessPaymentResult processPaymentResult)
 {
     throw new NopException("Capture method not supported");
 }
		/// <summary>
		/// Gets a value indicating whether shipping is allowed
		/// </summary>
		/// <param name="order">Order</param>
		/// <returns>A value indicating whether shipping is allowed</returns>
		public static bool CanShip(Order order)
		{
			if (order == null)
				return false;

			if (order.OrderStatus == OrderStatusEnum.Cancelled)
				return false;

			if (order.ShippingStatus == ShippingStatusEnum.NotYetShipped)
				return true;

			return false;
		}
 /// <summary>
 /// Voids payment
 /// </summary>
 /// <param name="order">Order</param>
 /// <param name="cancelPaymentResult">Cancel payment result</param>        
 public void Void(Order order, ref CancelPaymentResult cancelPaymentResult)
 {
     throw new NopException("Void method not supported");
 }
		/// <summary>
		/// Gets a value indicating whether cancel is allowed
		/// </summary>
		/// <param name="order">Order</param>
		/// <returns>A value indicating whether cancel is allowed</returns>
		public static bool CanCancelOrder(Order order)
		{
			if (order == null)
				return false;

			if (order.OrderStatus == OrderStatusEnum.Cancelled)
				return false;

			return true;
		}