Ejemplo n.º 1
0
        public ActionResult PaymentFormPopup(CustomerPaymentModel Model)
        {
            if (!ModelState.IsValid)
            {
                return(null);
            }
            //first check if the customer has an address, otherwise first address form will be shown

            if (_workContext.CurrentCustomer.Addresses.Count == 0)
            {
                return(AddressFormPopup(Model));
            }
            var BattleId     = Model.BattleId;
            var BattleType   = Model.BattleType;
            var PurchaseType = Model.PurchaseType;

            //TODO: Remove comment when picture battles are ready
            var battle = _videoBattleService.GetById(BattleId); // Model.BattleType == BattleType.Video ? _videoBattleService.GetById(Model.BattleId) : null;

            var model = new CustomerPaymentPublicModel
            {
                IsAmountVariable     = PurchaseType == PurchaseType.SponsorPass || battle.CanVoterIncreaseVotingCharge,
                MinimumPaymentAmount = PurchaseType == PurchaseType.SponsorPass ? battle.MinimumSponsorshipAmount : battle.MinimumVotingCharge,
                PurchaseType         = Model.PurchaseType
            };

            //if purchase type is sponsor and customer is already a sponsor, he should not have a minimum amount criteria
            if (PurchaseType == PurchaseType.SponsorPass)
            {
                var sponsorshipOrders = _sponsorPassService.GetSponsorPassOrders(_workContext.CurrentCustomer.Id, BattleId, BattleType);
                if (sponsorshipOrders.Any())
                {
                    model.MinimumPaymentAmount = 1;
                }
            }

            IList <Order> orders;

            if (PurchaseType == PurchaseType.VoterPass)
            {
                //also check if there are any paid orders which haven't been used for voting yet?
                var passes = _voterPassService.GetPurchasedVoterPasses(_workContext.CurrentCustomer.Id, PassStatus.NotUsed);
                orders = passes.Count > 0
                    ? _orderService.GetOrdersByIds(passes.Select(x => x.VoterPassOrderId).ToArray())
                    : null;
            }
            else
            {
                //also check if there are any paid orders which haven't been used for sponsorship yet?
                var passes = _sponsorPassService.GetPurchasedSponsorPasses(_workContext.CurrentCustomer.Id, PassStatus.NotUsed);
                orders = passes.Count > 0 ? _orderService.GetOrdersByIds(passes.Select(x => x.SponsorPassOrderId).ToArray()) : null;
            }


            if (orders != null)
            {
                foreach (var order in orders)
                {
                    model.CustomerPendingOrders.Add(new SelectListItem()
                    {
                        Text  = "Order#" + order.Id + " (" + order.OrderTotal + ")",
                        Value = order.Id.ToString()
                    });
                }
            }

            //let's get the payment methods for the logged in user
            var paymentMethods = _paymentMethodService.GetCustomerPaymentMethods(_workContext.CurrentCustomer.Id);

            foreach (var pm in paymentMethods)
            {
                model.CustomerPaymentMethods.Add(new SelectListItem()
                {
                    Text  = pm.NameOnCard + " (" + pm.CardNumberMasked + ")",
                    Value = pm.Id.ToString()
                });
            }
            //battle should not be complete before payment form can be opened
            return(battle.VideoBattleStatus == VideoBattleStatus.Complete ? null : PartialView("mobSocial/Payment/PaymentFormPopup", model));
        }
Ejemplo n.º 2
0
        public IHttpActionResult SaveSponsor(SponsorModel Model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { Success = false, Message = "Invalid Data" }));
            }

            var battle = _videoBattleService.GetById(Model.BattleId); //todo: query picture battles when ready

            if (battle == null)
            {
                return(Json(new { Success = false, Message = "Invalid Battle" }));
            }

            var isProductOnlySponsorship = Model.SponsorshipType == SponsorshipType.OnlyProducts;

            var customerId = _workContext.CurrentCustomer.Id;

            SponsorPass sponsorPass = null;
            Order       order       = null;

            if (!isProductOnlySponsorship)
            {
                //because somebody wants to be a sponsor, let's first query the sponsorship pass
                sponsorPass = _sponsorPassService.GetSponsorPassByOrderId(Model.SponsorPassId);

                //the sponsor pass must belong to the person in question && it shouldn't have been used
                if (sponsorPass == null || sponsorPass.CustomerId != customerId || sponsorPass.Status == PassStatus.Used)
                {
                    return(Json(new { Success = false, Message = "Unauthorized" }));
                }
            }

            //lets find the associated order
            order = isProductOnlySponsorship ? null : _orderService.GetOrderById(sponsorPass.SponsorPassOrderId);

            //there is a possibility that a sponsor is increasing the sponsorship amount. In that case, the new order status will automatically
            //be of same status as that of previous one for the same battle
            //lets find if the sponsor already exist for this battle?
            var existingSponsors = _sponsorService.GetSponsors(customerId, Model.BattleId, Model.BattleType, null);

            var newSponsorStatus = SponsorshipStatus.Pending;

            //so is the current customer already an sponsor for this battle?
            if (existingSponsors.Any())
            {
                newSponsorStatus = existingSponsors.First().SponsorshipStatus;
            }


            //create the sponsor and set the status to pending or an existing status as determined above. (the status will be marked accepted or rejected or cancelled by battle owner)
            var sponsor = new Sponsor()
            {
                BattleId          = Model.BattleId,
                BattleType        = Model.BattleType,
                SponsorshipAmount = isProductOnlySponsorship ? 0 : order.OrderTotal,
                CustomerId        = customerId,
                SponsorshipStatus = newSponsorStatus,
                DateCreated       = DateTime.UtcNow,
                DateUpdated       = DateTime.UtcNow
            };

            //save the sponsor
            _sponsorService.Insert(sponsor);

            if (!isProductOnlySponsorship)
            {
                //if it's already approved sponsor, it's better to immediately capture the order
                if (newSponsorStatus == SponsorshipStatus.Accepted)
                {
                    var captureResult = _paymentProcessingService.CapturePayment(order);
                    if (!captureResult.Success)
                    {
                        return(Json(new { Success = false, Message = "Failed to capture order" }));
                    }
                    order.PaymentStatus            = captureResult.NewPaymentStatus;
                    order.CaptureTransactionId     = captureResult.CaptureTransactionId;
                    order.CaptureTransactionResult = captureResult.CaptureTransactionResult;
                    _orderService.UpdateOrder(order);
                }
                //and mark the sponsor pass used by this battle
                _sponsorPassService.MarkSponsorPassUsed(sponsorPass.SponsorPassOrderId, Model.BattleId, Model.BattleType);
            }
            else
            {
                //save the prizes only sponsorship prizes
                SaveSponsorProductPrizes(Model.Prizes);
            }


            var battleOwner = _customerService.GetCustomerById(battle.ChallengerId);

            var sponsorCustomer = _customerService.GetCustomerById(customerId);

            //send notification to battle owner
            _mobSocialMessageService.SendSponsorAppliedNotificationToBattleOwner(battleOwner, sponsorCustomer, battle,
                                                                                 _workContext.WorkingLanguage.Id, _storeContext.CurrentStore.Id);

            return(Json(new { Success = true }));
        }
Ejemplo n.º 3
0
        private TimelinePostDisplayModel PrepareTimelinePostDisplayModel(TimelinePost post)
        {
            //total likes for this post
            var totalLikes = _customerLikeService.GetLikeCount <TimelinePost>(post.Id);
            //the like status for current customer
            var likeStatus =
                _customerLikeService.GetCustomerLike <TimelinePost>(_workContext.CurrentCustomer.Id, post.Id) == null
                    ? 0
                    : 1;

            var totalComments = _customerCommentService.GetCommentsCount(post.Id, typeof(TimelinePost).Name);
            var postModel     = new TimelinePostDisplayModel()
            {
                Id                       = post.Id,
                DateCreatedUtc           = post.DateCreated,
                DateUpdatedUtc           = post.DateUpdated,
                DateCreated              = _dateTimeHelper.ConvertToUserTime(post.DateCreated, DateTimeKind.Utc),
                DateUpdated              = _dateTimeHelper.ConvertToUserTime(post.DateUpdated, DateTimeKind.Utc),
                OwnerId                  = post.OwnerId,
                OwnerEntityType          = post.OwnerEntityType,
                PostTypeName             = post.PostTypeName,
                IsSponsored              = post.IsSponsored,
                Message                  = post.Message,
                AdditionalAttributeValue = post.AdditionalAttributeValue,
                CanDelete                = post.OwnerId == _workContext.CurrentCustomer.Id || _workContext.CurrentCustomer.IsAdmin(),
                TotalLikes               = totalLikes,
                LikeStatus               = likeStatus,
                TotalComments            = totalComments
            };

            if (post.OwnerEntityType == TimelinePostOwnerTypeNames.Customer)
            {
                //get the customer to retrieve info such a profile image, profile url etc.
                var customer = _customerService.GetCustomerById(post.OwnerId);

                postModel.OwnerName     = customer.GetFullName();
                postModel.OwnerImageUrl =
                    _pictureService.GetPictureUrl(
                        customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId),
                        _mediaSettings.AvatarPictureSize, true);

                postModel.OwnerProfileUrl = Url.RouteUrl("CustomerProfileUrl", new RouteValueDictionary()
                {
                    { "SeName", customer.GetSeName(_workContext.WorkingLanguage.Id, true, false) }
                });
            }
            //depending on the posttype, we may need to extract additional data e.g. in case of autopublished posts, we may need to query the linked entity
            switch (post.PostTypeName)
            {
            case TimelineAutoPostTypeNames.VideoBattle.Publish:
            case TimelineAutoPostTypeNames.VideoBattle.BattleStart:
            case TimelineAutoPostTypeNames.VideoBattle.BattleComplete:
                //we need to query the video battle
                if (post.LinkedToEntityId != 0)
                {
                    var battle = _videoBattleService.GetById(post.LinkedToEntityId);
                    if (battle == null)
                    {
                        break;
                    }
                    var battleUrl = Url.RouteUrl("VideoBattlePage",
                                                 new RouteValueDictionary()
                    {
                        { "SeName", battle.GetSeName(_workContext.WorkingLanguage.Id, true, false) }
                    });

                    //create a dynamic object for battle, we'll serialize this object to json and store as additional attribute value
                    //todo: to see if we have some better way of doing this
                    var coverImageUrl = "";
                    if (battle.CoverImageId.HasValue)
                    {
                        coverImageUrl = _pictureService.GetPictureUrl(battle.CoverImageId.Value);
                    }
                    var obj = new {
                        Name             = battle.Name,
                        Url              = battleUrl,
                        Description      = battle.Description,
                        VotingStartDate  = battle.VotingStartDate,
                        VotingEndDate    = battle.VotingEndDate,
                        CoverImageUrl    = coverImageUrl,
                        RemainingSeconds = battle.GetRemainingSeconds(),
                        Status           = battle.VideoBattleStatus.ToString()
                    };

                    postModel.AdditionalAttributeValue = JsonConvert.SerializeObject(obj);
                }
                break;
            }

            return(postModel);
        }
Ejemplo n.º 4
0
        public ActionResult SaveSponsor(SponsorModel Model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { Success = false, Message = "Invalid Data" }));
            }

            var battle = _videoBattleService.GetById(Model.BattleId); //todo: query picture battles when ready

            if (battle == null)
            {
                return(Json(new { Success = false, Message = "Invalid Battle" }));
            }

            //because somebody wants to be a sponsor, let's first query the sponsorship pass
            var sponsorPass = _sponsorPassService.GetSponsorPassByOrderId(Model.SponsorPassId);

            //the sponsor pass must belong to the person in question && it shouldn't have been used
            if (sponsorPass == null || sponsorPass.CustomerId != _workContext.CurrentCustomer.Id || sponsorPass.Status == PassStatus.Used)
            {
                return(Json(new { Success = false, Message = "Unauthorized" }));
            }

            //lets find the associated order
            var order = _orderService.GetOrderById(sponsorPass.SponsorPassOrderId);

            //there is a possibility that a sponsor is increasing the sponsorship amount. In that case, the new order status will automatically
            //be of same status as that of previous one for the same battle
            //lets find if the sponsor already exist for this battle?
            var existingSponsors = _sponsorService.GetSponsors(order.CustomerId, Model.BattleId, Model.BattleType, null);

            var newSponsorStatus = SponsorshipStatus.Pending;

            //so is the current customer already an sponsor for this battle?
            if (existingSponsors.Any())
            {
                newSponsorStatus = existingSponsors.First().SponsorshipStatus;
            }


            //create the sponsor and set the status to pending or an existing status as determined above. (the status will be marked accepted or rejected or cancelled by battle owner)
            var sponsor = new Sponsor()
            {
                BattleId          = Model.BattleId,
                BattleType        = Model.BattleType,
                SponsorshipAmount = order.OrderTotal,
                CustomerId        = sponsorPass.CustomerId,
                SponsorshipStatus = newSponsorStatus
            };

            //save the sponsor
            _sponsorService.Insert(sponsor);

            //and mark the sponsor pass used by this battle
            _sponsorPassService.MarkSponsorPassUsed(sponsorPass.SponsorPassOrderId, Model.BattleId, Model.BattleType);


            var battleOwner = _customerService.GetCustomerById(battle.ChallengerId);

            var sponsorCustomer = _customerService.GetCustomerById(sponsorPass.CustomerId);

            //send notification to battle owner
            _mobSocialMessageService.SendSponsorAppliedNotificationToBattleOwner(battleOwner, sponsorCustomer, battle,
                                                                                 _workContext.WorkingLanguage.Id, _storeContext.CurrentStore.Id);

            return(Json(new { Success = true }));
        }