Esempio n. 1
0
        private IEnumerable <PriceViewModel> GetCampaignFirstProductPrices(
            IEnumerable <SearchCampaignItem> searchCampaignItems)
        {
            var currencies = _currencyRepository.Table.ToList();

            var prices = new List <PriceViewModel>();

            foreach (var searchCampaignItem in searchCampaignItems)
            {
                var currencyFrom = currencies.First(c => c.Id == searchCampaignItem.CampaignCurrencyId);

                var price = _priceConversionService
                            .ConvertPrice(searchCampaignItem.CampaignFirstProductPrice, currencyFrom);

                var priceViewModel = new PriceViewModel
                {
                    Price        = price.Value,
                    CurrencyCode = price.Currency.Code
                };

                prices.Add(priceViewModel);
            }

            return(prices);
        }
Esempio n. 2
0
        public string GetXmlToSend(Models.OrderRecord rec, Models.CreditCardInfo cCardInfo)
        {
            //var currency = "MYR";
            var total    = ((rec.TotalPriceWithPromo > 0 ? rec.TotalPriceWithPromo : rec.TotalPrice) + rec.Delivery);
            var currency = rec.Campaign.CurrencyRecord.Code;

            if (!string.IsNullOrWhiteSpace(rec.selectedCurrency))
            {
                currency = rec.selectedCurrency;
                total    = _priceConversation.ConvertPrice(total, rec.Campaign.CurrencyRecord, currency).Value;
            }
            var xmlToSend = "<card-transaction xmlns=\"http://ws.plimus.com\">" +
                            "<card-transaction-type>AUTH_CAPTURE</card-transaction-type>" +
                            "<recurring-transaction>ECOMMERCE</recurring-transaction>" +
                            "<soft-descriptor>DescTest</soft-descriptor>" +
                            "<amount>" + total.ToString("0.00") + "</amount>" +
                            "<currency>" + currency + "</currency>" +
                            "<card-holder-info>" +
                            "<first-name>" + rec.FirstName + "</first-name>" +
                            "<last-name>" + rec.LastName + "</last-name>" +
                            "</card-holder-info>" +
                            "<credit-card>" +
                            "<encrypted-card-number>" + cCardInfo.CardNumber + "</encrypted-card-number>" +
                            "<encrypted-security-code>" + cCardInfo.SecurityCode + "</encrypted-security-code>" +
                            "<expiration-month>" + cCardInfo.ExpirationMonth + "</expiration-month>" +
                            "<expiration-year>" + cCardInfo.ExpirationYear + "</expiration-year>" +
                            "<card-last-four-digits>" + cCardInfo.CardLastFour + "</card-last-four-digits>" +
                            "</credit-card>" +
                            "</card-transaction>";

            return(xmlToSend);
        }
Esempio n. 3
0
        //
        // GET: /Campaign/
        public ActionResult Index(string campaignName, string promo)
        {
            if (string.IsNullOrWhiteSpace(campaignName))
            {
                return(View("NotFound", Request.UrlReferrer != null ? Request.UrlReferrer.PathAndQuery : ""));
            }

            var campaign = _campaignService.GetCampaignByAlias(campaignName);

            if (campaign == null)
            {
                return(View("NotFound", Request.UrlReferrer != null ? Request.UrlReferrer.PathAndQuery : ""));
            }

            var user          = _wca.GetContext().CurrentUser;
            var teeyootUserId = -1;

            if (user != null)
            {
                teeyootUserId = user.ContentItem.Get(typeof(TeeyootUserPart)).Id;
            }

            if (!campaign.IsApproved &&
                !Services.Authorizer.Authorize(Permissions.ApproveCampaigns) &&
                teeyootUserId != campaign.TeeyootUserId)
            {
                return(View("NotFound", Request.UrlReferrer != null ? Request.UrlReferrer.PathAndQuery : ""));
            }

            //TODO: (auth:keinlekan) Удалить код, если больше не пригодиться. Переход сайта на культуру компании
            //string campaignCulture = campaign.CampaignCulture;
            //if (campaignCulture != cultureUsed)
            //{
            //    _cookieCultureService.SetCulture(campaignCulture);
            //}

            if ((Services.Authorizer.Authorize(Permissions.ApproveCampaigns) || teeyootUserId == campaign.TeeyootUserId) &&
                campaign.Rejected)
            {
                var infoMessage = T("Your campaign have been rejected!");
                _notifier.Add(NotifyType.Information, infoMessage);
            }
            else
            {
                if ((Services.Authorizer.Authorize(Permissions.ApproveCampaigns) ||
                     teeyootUserId == campaign.TeeyootUserId) && campaign.IsApproved == false)
                {
                    var infoMessage =
                        T(
                            "Your campaign is awaiting approval. This should take less than 1 hour during office hours.");
                    _notifier.Add(NotifyType.Information, infoMessage);
                }
            }

            var model = new CampaignIndexViewModel(_priceConversionService)
            {
                Campaign = campaign
            };

            model.FBDescription = model.Campaign.Description;
            model.FBDescription = Regex.Replace(model.FBDescription, @"<br>", " ").Trim();
            model.FBDescription = Regex.Replace(model.FBDescription, @"<[^>]+>", "").Trim();
            model.FBDescription = Regex.Replace(model.FBDescription, @"&nbsp;", " ").Trim();


            //Add User Pixel
            var ____user = _userRepository.Get(campaign.Seller.Id);

            if (____user != null)
            {
                model.SellerFbPixel = !string.IsNullOrWhiteSpace(campaign.FBPixelId) ? campaign.FBPixelId : ____user.DefaultFBPixelId;
                model.FacebookCustomAudiencePixel = !string.IsNullOrWhiteSpace(campaign.FBPixelId) ? campaign.FBPixelId : ____user.DefaultFacebookCustomAudiencePixel;
            }
            else
            {
                model.SellerFbPixel = campaign.FBPixelId;
            }


            model.Prices = new Dictionary <int, Dictionary <string, double> >();

            foreach (var p in campaign.Products)
            {
                Dictionary <string, double> productPrices = new Dictionary <string, double>();
                foreach (var c in _currencyRepository.Table)
                {
                    productPrices.Add(c.Code, _priceConversionService.ConvertPrice(p.Price, campaign.CurrencyRecord, c).Value);
                }
                model.Prices.Add(p.Id, productPrices);
            }
            model.currency = _imulticountryservice.GetCurrency().Code;


            model.exchangeRate = Newtonsoft.Json.JsonConvert.SerializeObject(_currencyExchangeRepository.Table.Select(aa => new { From = aa.CurrencyFrom.Code, To = aa.CurrencyTo.Code, RateForSeller = aa.RateForSeller, RateForBuyer = aa.RateForBuyer }));



            if (campaign.ProductCountSold >= campaign.ProductMinimumGoal && campaign.IsActive)
            {
                var infoMessage =
                    T(
                        "Yippee! The minimum order for this campaign is {0}, but we have already sold {1}. The item will definitely go to print once the campaign ends.",
                        campaign.ProductMinimumGoal, campaign.ProductCountSold);
                _notifier.Add(NotifyType.Information, infoMessage);
            }
            //if (campaign.IsApproved && campaign.ProductCountSold < campaign.ProductMinimumGoal &&
            //    campaign.IsActive)
            //{
            //    var infoMessage = T(
            //        string.Format(
            //            "{0} orders have been made. We need {1} more for this campaign to proceed.",
            //            campaign.ProductCountSold,
            //            campaign.ProductMinimumGoal - campaign.ProductCountSold));
            //    _notifier.Add(NotifyType.Information, infoMessage);
            //}
            if (!campaign.IsActive && campaign.IsApproved && !campaign.IsArchived)
            {
                var cntRequests = _campaignService.GetCountOfReservedRequestsOfCampaign(campaign.Id);
                model.CntRequests = 10 - (cntRequests >= 10 ? 10 : cntRequests);
                if (cntRequests >= 10)
                {
                    var infoMessage = T("This campaign is likely to be re-activated soon.");
                    _notifier.Add(NotifyType.Information, infoMessage);
                }
                else
                {
                    var infoMessage = T(
                        string.Format("Only {0} more requests for the campaign to be re-activated",
                                      10 - (cntRequests >= 10 ? 10 : cntRequests)));
                    _notifier.Add(NotifyType.Information, infoMessage);
                }
            }

            if (promo == null)
            {
                return(View("Index2", model));
            }

            try
            {
                var promotion = _promotionService.GetPromotionByPromoId(promo);

                var localizationInfo = _multiCountryService.GetCountry();  //LocalizationInfoFactory.GetCurrentLocalizationInfo();
                var currency         = _multiCountryService.GetCurrency(); //_countryService.GetCurrency(localizationInfo, LocalizationInfoFactory.GetCurrency());

                if (promotion.Status &&
                    promotion.Expiration > DateTime.UtcNow &&
                    promotion.UserId == campaign.TeeyootUserId
                    /*campaign.ProductCountSold >= campaign.ProductMinimumGoal*/)
                {
                    if (promotion.AmountType == "%")
                    {
                        FillViewModelWithPromo(model, promotion);
                    }
                    else
                    {
                        var promotionCurrency = _currencyRepository.Table
                                                .First(c => c.Code == promotion.AmountType);

                        if (promotionCurrency == currency)
                        {
                            FillViewModelWithPromo(model, promotion);
                        }
                        else
                        {
                            var infoMessage = T(
                                "Oh no! The requested promotion is currently not available for this campaign. But you can still buy at the normal price!");
                            _notifier.Add(NotifyType.Information, infoMessage);
                        }
                    }
                }
                else
                {
                    var infoMessage = T(
                        "Oh no! The requested promotion is currently not available for this campaign. But you can still buy at the normal price!");
                    _notifier.Add(NotifyType.Information, infoMessage);
                }

                //foreach (var product in campaign.Products)
                //{
                //    model.Prices.Add()
                //}
                return(View("Index2", model));
            }
            catch (Exception)
            {
                var infoMessage = T(
                    "Oh no! The requested promotion is currently not available for this campaign. But you can still buy at the normal price!");
                _notifier.Add(NotifyType.Information, infoMessage);

                return(View("Index2", model));
            }
        }
        protected override DriverResult Display(FeaturedCampaignsWidgetPart part, string displayType, dynamic shapeHelper)
        {
            var culture = _workContextAccessor.GetContext().CurrentCulture.Trim();

            var campaignsInFeatured = _campaignsService.GetAllCampaigns().Where(c => c.IsFeatured && !c.IsPrivate && c.IsActive && c.IsApproved).OrderByDescending(c => c.ProductCountSold).ToList();
            var featuredCampaigns   = new List <CampaignRecord>();

            if (campaignsInFeatured.Count >= 8)
            {
                featuredCampaigns = campaignsInFeatured;
            }
            else
            {
                featuredCampaigns = campaignsInFeatured;
                int countTopCamp     = 8 - campaignsInFeatured.Count;
                var ordersFromOneDay = _featuredCampaignsService.GetOrderForOneDay().Where(c => c.Products != null && c.Products.Count > 0).ToList();
                if (ordersFromOneDay != null && ordersFromOneDay.Count > 0)
                {
                    int[] ordersIdFromOneDay = ordersFromOneDay.Select(c => c.Id).ToArray();
                    Dictionary <CampaignRecord, int> campaignsFromOrderForDay = _featuredCampaignsService.GetCampaignsFromOrderForOneDay(ordersIdFromOneDay);

                    int take = campaignsFromOrderForDay.Count > 16 ? 16 : campaignsFromOrderForDay.Count;
                    campaignsFromOrderForDay = campaignsFromOrderForDay.OrderByDescending(c => c.Value).OrderBy(c => c.Key.Title).Skip(0).Take(take).ToDictionary(p => p.Key, p => p.Value);

                    Random rand       = new Random();
                    int    insertCamp = campaignsFromOrderForDay.Count() <= countTopCamp?campaignsFromOrderForDay.Count() : countTopCamp;

                    for (int i = 0; i < insertCamp; i++)
                    {
                        var campNum = rand.Next(take);
                        var campKey = campaignsFromOrderForDay.ElementAt(campNum).Key;
                        if (!featuredCampaigns.Contains(campKey))
                        {
                            featuredCampaigns.Add(campKey);
                        }
                    }
                }

                if (featuredCampaigns.Count() < 8)
                {
                    countTopCamp = 8 - featuredCampaigns.Count();
                    var otherCampaigns = _campaignsService.GetAllCampaigns().Where(c => !c.IsPrivate && c.IsActive && c.IsApproved).ToList();
                    foreach (var camp in campaignsInFeatured)
                    {
                        if (otherCampaigns.Exists(c => c.Id == camp.Id))
                        {
                            otherCampaigns.Remove(camp);
                        }
                    }
                    int max = otherCampaigns.Count();
                    if ((max + featuredCampaigns.Count()) < 8)
                    {
                        featuredCampaigns.AddRange(otherCampaigns.ToArray());
                    }
                    else
                    {
                        Random rand = new Random();
                        for (int i = 0; i < countTopCamp; i++)
                        {
                            var res = false;
                            while (!res)
                            {
                                var camp = otherCampaigns.ElementAt(rand.Next(max));
                                if (!featuredCampaigns.Exists(c => c.Id == camp.Id))
                                {
                                    featuredCampaigns.Add(camp);

                                    res = true;
                                }
                            }
                        }
                    }
                }
            }
            var currenciesandprices = new Dictionary <int, Dictionary <string, double> >();

            foreach (var c in featuredCampaigns)
            {
                Dictionary <string, double> prices = new Dictionary <string, double>();
                foreach (var item in _currencies.Table)
                {
                    var price = c.Products.First().Price;
                    prices.Add(item.Code, _priceconvertorservice.ConvertPrice(price, c.CurrencyRecord, item).Value);
                }


                currenciesandprices.Add(c.Id, prices);
            }
            return(ContentShape("Parts_FeaturedCampaignsWidget", () =>
                                shapeHelper.Parts_FeaturedCampaignsWidget(Campaigns: featuredCampaigns, currency: _countries.GetDefaultCurrecny().Code, prices: currenciesandprices)));
        }
Esempio n. 5
0
        public Payment CreatePayment(OrderRecord order, string cancelUrl, string returnUrl)
        {
            var currency = (order.CurrencyRecord == null) ? "MYR" : order.CurrencyRecord.Code;

            currency = order.selectedCurrency == null ? currency : order.selectedCurrency;


            Amount amount    = CreateAmount(order);
            var    item_list = new ItemList();

            item_list.items = new List <Item>();
            foreach (var item in order.Products)
            {
                item_list.items.Add(new Item()
                {
                    currency    = currency,
                    description = item.CampaignProductRecord.ProductRecord.Details,
                    name        = item.CampaignProductRecord.ProductRecord.Name,
                    quantity    = item.Count.ToString(),
                    price       = _priceConverationService.ConvertPrice(item.Count * item.CampaignProductRecord.Price, order.Campaign.CurrencyRecord, currency).Value.ToString("0.00").Replace(",", ".")
                });
            }
            if (order.TotalPriceWithPromo > 0)
            {
                item_list.items.Add(new Item()
                {
                    currency    = currency,
                    description = "Promotion",
                    name        = "Promotion",
                    quantity    = "1",
                    price       = _priceConverationService.ConvertPrice(order.TotalPriceWithPromo - order.TotalPrice, order.Campaign.CurrencyRecord, currency).Value.ToString("0.00").Replace(",", ".")
                });
            }

            var payment = new Payment
            {
                transactions = new List <Transaction>
                {
                    new Transaction
                    {
                        amount         = amount,
                        description    = "Purchase From Teeyoot.com, Amount:" + amount.total,
                        invoice_number = order.Id.ToString(),
                        item_list      = item_list,
                    }
                },
                intent = "sale",
                payer  = new Payer
                {
                    payment_method = "paypal",
                    payer_info     = new PayerInfo()
                    {
                        first_name = order.FirstName,
                        //email = order.Email,
                        last_name       = order.LastName,
                        billing_address = new Address()
                        {
                            line1        = order.StreetAddress,
                            city         = order.City,
                            postal_code  = order.PostalCode,
                            state        = order.State,
                            country_code = "US"
                        }
                    }
                },
                redirect_urls = new RedirectUrls
                {
                    cancel_url = cancelUrl,
                    return_url = returnUrl
                }
            };

            payment = payment.Create(GetAPIContext());
            return(payment);
        }