示例#1
0
        public ActionResult GetSponsorTransactions(SponsorTransactionRequestModel Model)
        {
            //only battle owner or sponsor should be able to see transactions
            //todo: get picture battle when ready
            var battle = Model.BattleType == BattleType.Video ? _videoBattleService.GetById(Model.BattleId) : null;

            if (battle == null)
            {
                return(Json(new { Success = false, Message = "Battle doesn't exist" }));
            }


            if (battle.ChallengerId != _workContext.CurrentCustomer.Id &&
                Model.CustomerId != _workContext.CurrentCustomer.Id)
            {
                return(Json(new { Success = false, Message = "Unauthorized" }));
            }

            var orders = _sponsorPassService.GetSponsorPassOrders(Model.CustomerId, Model.BattleId, Model.BattleType);
            var model  = new List <SponsorTransactionModel>();

            foreach (var order in orders)
            {
                var orderTotalInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTotal, order.CurrencyRate);
                model.Add(new SponsorTransactionModel()
                {
                    OrderId                    = order.Id,
                    TransactionDate            = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc).ToString(),
                    TransactionAmount          = order.OrderTotal,
                    TransactionAmountFormatted = _priceFormatter.FormatPrice(orderTotalInCustomerCurrency, true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage)
                });
            }

            return(Json(new { Success = true, Orders = model }));
        }
示例#2
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));
        }
示例#3
0
        public IHttpActionResult UpdateSponsor(UpdateSponsorModel Model)
        {
            //here we update or reject the status of battle
            if (!ModelState.IsValid)
            {
                return(Json(new { Success = false, Message = "Invalid Data" }));
            }

            //because a sponsor may have performed multiple transactions for a battle, we'd update all of them at once

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

            //only battle owner should be able to accept or reject the sponsorship
            if (battle.ChallengerId != _workContext.CurrentCustomer.Id && Model.SponsorshipStatus != SponsorshipStatus.Cancelled)
            {
                return(Json(new { Success = false, Message = "Unauthorized" }));
            }

            //similarly only the sponsor should be able to withdraw it
            if (Model.SponsorCustomerId != _workContext.CurrentCustomer.Id && Model.SponsorshipStatus == SponsorshipStatus.Cancelled)
            {
                return(Json(new { Success = false, Message = "Unauthorized" }));
            }

            var captureVoidSuccess = true;
            //now depending on whether it's being approved or rejected, the transaction will be either captured or voided
            //get all the orders and capture/void the transactions
            var orders = _sponsorPassService.GetSponsorPassOrders(Model.SponsorCustomerId, Model.BattleId, Model.BattleType).Where(x => x.PaymentStatus == PaymentStatus.Authorized);

            if (Model.SponsorshipStatus == SponsorshipStatus.Accepted)
            {
                foreach (var order in orders)
                {
                    var captureResult = _paymentProcessingService.CapturePayment(order);
                    if (captureResult.Success)
                    {
                        order.PaymentStatus            = captureResult.NewPaymentStatus;
                        order.CaptureTransactionId     = captureResult.CaptureTransactionId;
                        order.CaptureTransactionResult = captureResult.CaptureTransactionResult;
                        _orderService.UpdateOrder(order);
                    }
                    else
                    {
                        captureVoidSuccess = false;
                    }
                }
            }
            else if (Model.SponsorshipStatus == SponsorshipStatus.Cancelled || Model.SponsorshipStatus == SponsorshipStatus.Rejected)
            {
                foreach (var order in orders)
                {
                    var voidResult = _paymentProcessingService.VoidPayment(order);
                    if (voidResult.Success)
                    {
                        order.PaymentStatus = voidResult.NewPaymentStatus;
                        _orderService.UpdateOrder(order);
                    }
                    else
                    {
                        captureVoidSuccess = false;
                    }
                }
            }
            //only if all transactions are captured/void
            if (captureVoidSuccess)
            {
                //so lets update all the sponsors for this battle and this user
                _sponsorService.UpdateSponsorStatus(Model.SponsorCustomerId, Model.BattleId, Model.BattleType,
                                                    Model.SponsorshipStatus);

                //send sponsorship update status to battle owner and admin
                var customer = _customerService.GetCustomerById(Model.SponsorshipStatus == SponsorshipStatus.Cancelled ? battle.ChallengerId : Model.SponsorCustomerId);

                //send notification
                _mobSocialMessageService.SendSponsorshipStatusChangeNotification(customer, Model.SponsorshipStatus,
                                                                                 battle, _workContext.WorkingLanguage.Id, _storeContext.CurrentStore.Id);
                return(Json(new { Success = true }));
            }
            else
            {
                return(Json(new { Success = false, Message = "Failed to capture or void the payment" }));
            }
        }