Exemple #1
0
    protected void BuyOrUpgradePlan(PurchaseBalances balance)
    {
        try
        {
            var plan        = new InvestmentPlatformPlan(int.Parse(PlansDropDownList.SelectedValue));
            var activePlans = CurrentMode == InvestmentPlatformMode.Levels ? 0 : userActivePlans.Count;

            if (AppSettings.InvestmentPlatform.LevelsEnabled)
            {
                InvestmentLevelsManager.CanUserDepositOnLevel(plan, User);
            }

            if (plan.MaxPrice > Money.Zero)
            {
                if (AppSettings.InvestmentPlatform.InvestmentPlatformPlansPolicy == PlansPolicy.OneUpgradedPlan)
                {
                    throw new MsgException(U6012.CANTUPGRADERANGEPLAN);
                }

                var targetPrice = Money.Parse(RangePriceTextBox.Text);
                if (plan.CheckPlanPrice(targetPrice))
                {
                    InvestmentPlatformManager.BuyOrUpgradePlan(Member.Current, balance, plan, targetPrice);
                }
                else
                {
                    throw new MsgException(U6012.TYPECORRECTPRICE);
                }
            }
            else
            {
                InvestmentPlatformManager.BuyOrUpgradePlan(Member.Current, balance, plan);
            }

            //IF activePlans = 1, MEANS THAT WE UPGRADE PLAN (ON PlansPolicy.OneUpgradedPlan)
            if (AppSettings.InvestmentPlatform.InvestmentPlatformPlansPolicy == PlansPolicy.OneUpgradedPlan && activePlans == 1)
            {
                SuccessTextLiteral.Text = string.Format(U6011.SUCCESSUPGRADEPLAN, plan.Name);
            }
            else
            {
                SuccessTextLiteral.Text = string.Format(U6006.SUCCESBOUGHTPLAN, plan.Name);
            }

            SuccessPanel.Visible = true;

            availablePlans = InvestmentPlatformManager.GetAllAvailablePlansForUser(User.Id);
            InitBuyViewControls();
            InitPlans();
        }
        catch (Exception ex)
        {
            ErrorPanel.Visible    = true;
            ErrorTextLiteral.Text = ex.Message;
            if (!(ex is MsgException))
            {
                ErrorLogger.Log(ex);
            }
        }
    }
Exemple #2
0
    private void upgradeMembershipFromBalance(PurchaseBalances balanceType)
    {
        SuccMessagePanel.Visible  = false;
        ErrorMessagePanel.Visible = false;

        try
        {
            AppSettings.DemoCheck();

            MembershipPack pack = new MembershipPack(Int32.Parse(ddlOptions.SelectedValue));
            Member         user = Member.Current;

            Membership.BuyPack(user, pack, balanceType);

            Response.Redirect("~/status.aspx?type=upgradeok");
        }
        catch (MsgException ex)
        {
            ErrorMessagePanel.Visible = true;

            if (!TitanFeatures.IsRofriqueWorkMines)
            {
                ErrorMessage.Text = ex.Message;
            }
            else
            {
                ErrorMessage.Text = "YOU DONT HAVE ENOUGH FUNDS IN YOUR CASH BALANCE. PLEASE CLICK ON DEPOSIT FUNDS TO TOP UP YOUR CASH BALANCE.";
            }
        }
        catch (Exception ex)
        {
            ErrorLogger.Log(ex);
            throw ex;
        }
    }
Exemple #3
0
        public static void Buy(Member user, PTCOfferWallPack pack, PurchaseBalances targetBalance, List <UserUrl> userUrls,
                               string title, string description, GeolocationUnit geoUnit, bool pcAllowed, bool mobileAllowed,
                               bool autosurfEnabled, int maxSingleUserDailyViews)
        {
            if (pack.Adverts != userUrls.Count)
            {
                throw new MsgException(string.Format(U6002.NUMBEROFURLSERROR, pack.Adverts));
            }

            if (userUrls.Any(u => u.Status != AdvertStatus.Active))
            {
                throw new MsgException("Fraud! Only active urls are permitted.");
            }

            PurchaseOption.ChargeBalance(user, pack.Price, PurchaseOption.Features.PtcOfferWall.ToString(), targetBalance, "PTC OfferWall");

            var offerWall = new PTCOfferWall(user.Id, pack, title, description, pcAllowed, mobileAllowed, autosurfEnabled, maxSingleUserDailyViews);

            if (geoUnit != null)
            {
                offerWall.AddGeolocation(geoUnit);
            }

            offerWall.Save();
            offerWall.MapWithUrls(userUrls);

            MatrixBase.TryAddMemberAndCredit(user, pack.Price, AdvertType.PTCOfferWall);
        }
Exemple #4
0
        public static void BuyPack(Member user, MembershipPack pack, PurchaseBalances targetBalance)
        {
            Money packPrice = pack.Price;

            PurchaseOption.ChargeBalance(user, pack.GetPrice(user), PurchaseOption.Features.Upgrade.ToString(), targetBalance, "Upgrade");

            AddPack(user, pack);
        }
    public RepresentativesTransferManager(int userId, int representativeUserId)
    {
        if (userId == representativeUserId)
        {
            throw new MsgException("You can't send money to yourself.");
        }

        RepresentativeUserId = representativeUserId;
        User              = new Member(userId);
        targetBalance     = AppSettings.Payments.CashBalanceEnabled ? PurchaseBalances.Cash : PurchaseBalances.Purchase;
        targetBalanceName = targetBalance == PurchaseBalances.Cash ? "Cash Balance" : "Purchase Balance";
    }
Exemple #6
0
 private InTextAdvert(int userId, InTextAdvertPack pack, string title, string description, string url, PurchaseBalances targetBalance)
 {
     UserId         = userId;
     ClicksBought   = pack.Clicks;
     ClicksReceived = 0;
     PricePaid      = pack.Price;
     Title          = title;
     Description    = description;
     Url            = url;
     Status         = AdvertStatus.Active;
     TargetBalance  = targetBalance;
 }
Exemple #7
0
        public static BalanceType GetBalanceType(PurchaseBalances balance)
        {
            if (balance == PurchaseBalances.Purchase)
            {
                return(BalanceType.PurchaseBalance);
            }
            if (balance == PurchaseBalances.Cash)
            {
                return(BalanceType.CashBalance);
            }

            return(BalanceType.PurchaseBalance);
        }
 private ExternalBannerAdvert(int userId, string url, int categoryId, ExternalBannerAdvertPack pack, Banner image, PurchaseBalances targetBalance)
 {
     UserId = userId;
     Url    = url;
     Status = AdvertStatus.WaitingForAcceptance;
     PublishersWebsiteCategoryId = categoryId;
     ExternalBannerAdvertPackId  = pack.Id;
     Image          = image;
     ClicksReceived = 0;
     ClicksBought   = pack.Clicks;
     PricePaid      = pack.Price;
     MoneyPerClick  = PricePaid / ClicksBought;
     TargetBalance  = targetBalance;
 }
Exemple #9
0
        public static void BuyOrUpgradePlan(Member user, PurchaseBalances targetBalance, InvestmentPlatformPlan newPlan, Money targetPrice = null)
        {
            var userActivePlans = GetUserActivePlans(user.Id);
            var moneyDiff       = Money.Zero;

            //UPGRADE
            if (AppSettings.InvestmentPlatform.InvestmentPlatformPlansPolicy == PlansPolicy.OneUpgradedPlan && userActivePlans.Count == 1)
            {
                var activePlan = userActivePlans[0];
                moneyDiff = newPlan.Price - new InvestmentPlatformPlan(activePlan.PlanId).Price;

                activePlan.Finish();
            }

            BuyPlan(user, targetBalance, newPlan, moneyDiff, targetPrice);
        }
Exemple #10
0
        public Money CreditReferer(Money money, PurchaseBalances targetBalance)
        {
            if (targetBalance == PurchaseBalances.Purchase)
            {
                TargetAdBalance = true;
            }
            else
            {
                TargetAdBalance = false;
            }

            Money moneySpent        = CreditReferersMainBalance(money, "AdPack /ref/ " + User.Name, BalanceLogType.AdPackRefPurchase);
            Money moneyLeftForPools = money - moneySpent;

            return(money - moneySpent);
        }
Exemple #11
0
        private static void ChargeBalance(Member user, Money amount, PurchaseBalances balance, string note, string feature = null, BalanceLogType balanceLogType = BalanceLogType.Other)
        {
            if (feature != null)
            {
                Features targetFeature = GetFeatureFromString(feature);
                ValidateChosenBalance(targetFeature, balance);
            }

            switch (balance)
            {
            case PurchaseBalances.Cash:
                if (amount > user.CashBalance)
                {
                    throw new MsgException(L1.NOTENOUGHFUNDS);
                }
                user.SubtractFromCashBalance(amount, note, balanceLogType);
                break;

            case PurchaseBalances.Purchase:
                if (amount > user.PurchaseBalance)
                {
                    throw new MsgException(L1.NOTENOUGHFUNDS);
                }
                user.SubtractFromPurchaseBalance(amount, note, balanceLogType);
                break;

            case PurchaseBalances.Traffic:
                if (amount > user.TrafficBalance)
                {
                    throw new MsgException(L1.NOTENOUGHFUNDS);
                }
                user.SubtractFromTrafficBalance(amount, note, balanceLogType);
                break;

            case PurchaseBalances.LoginAdsCredits:
                if (amount.AsPoints() > user.LoginAdsCredits)
                {
                    throw new MsgException(L1.NOTENOUGHFUNDS);
                }
                user.SubstractFromLoginAdsCredits(amount.AsPoints(), note, balanceLogType);
                break;
            }

            user.SaveBalances();
        }
        protected override ApiResultMessage HandleRequest(object args)
        {
            string token = ((JObject)args)["token"].ToString();
            ApiJackpotTicketPurchaseData data = ((JObject)args).ToObject <ApiJackpotTicketPurchaseData>();

            int userId = ApiAccessToken.ValidateAndGetUserId(token);

            if (!AppSettings.TitanFeatures.MoneyJackpotEnabled)
            {
                throw new MsgException("Jackpot are disabled.");
            }

            Member  user    = new Member(userId);
            Jackpot jackpot = new Jackpot(data.jackpotId);

            if (data.tickets <= 0)
            {
                throw new MsgException(U5003.INVALIDNUMBEROFTICKETS);
            }

            PurchaseBalances balance       = (PurchaseBalances)data.balance;
            BalanceType      targetBalance = PurchaseOption.GetBalanceType(balance);

            var purchaseOption = PurchaseOption.Get(PurchaseOption.Features.Jackpot);

            if (balance == PurchaseBalances.Purchase && !purchaseOption.PurchaseBalanceEnabled)
            {
                throw new MsgException("You can't purchase with that balance.");
            }

            if (balance == PurchaseBalances.Cash && !purchaseOption.CashBalanceEnabled)
            {
                throw new MsgException("You can't purchase with that balance.");
            }

            JackpotManager.BuyTickets(jackpot, user, data.tickets, targetBalance);

            return(new ApiResultMessage
            {
                success = true,
                message = U5003.TICKETPURCHASESUCCESS.Replace("%n%", data.tickets.ToString()),
                data = null
            });
        }
Exemple #13
0
        private static void ValidateChosenBalance(Features feature, PurchaseBalances balance)
        {
            try
            {
                var purchaseOption = Get(feature);

                switch (balance)
                {
                case PurchaseBalances.Purchase:
                    if (!purchaseOption.PurchaseBalanceEnabled)
                    {
                        throw new ArgumentException("Chosen balance is invalid.", balance.ToString());
                    }
                    break;

                case PurchaseBalances.Cash:
                    if (!purchaseOption.CashBalanceEnabled || !AppSettings.Payments.CashBalanceEnabled)
                    {
                        throw new ArgumentException("Chosen balance is invalid.", balance.ToString());
                    }
                    break;

                default: throw new ArgumentException("Chosen balance is invalid.", balance.ToString());
                }
            }
            catch (Exception ex)
            {
                if (ex is ArgumentException)
                {
                    throw new MsgException(ex.Message);
                }
                else
                {
                    ErrorLogger.Log(ex);
                    throw new MsgException("Chosen balance is invalid.");
                }
            }
        }
Exemple #14
0
        /// <summary>
        /// Saves balances.
        /// </summary>
        private static void CreditBalance(Member user, PurchaseBalances balance, Money amount, string note)
        {
            switch (balance)
            {
            case PurchaseBalances.Purchase:
                user.AddToPurchaseBalance(amount, note);
                break;

            case PurchaseBalances.Cash:
                user.AddToCashBalance(amount, note);
                break;

            case PurchaseBalances.LoginAdsCredits:
                user.AddToLoginAdsCredits(amount.AsPoints(), note);
                break;

            case PurchaseBalances.Traffic:
                user.AddToTrafficBalance(amount, note);
                break;
            }

            user.SaveBalances();
        }
Exemple #15
0
        public static void BuyPack(DirectReferralPack pack, Member user, PurchaseBalances targetBalance)
        {
            if (user.DirectReferralLimit < user.GetDirectReferralsCount() + pack.NumberOfRefs)
            {
                throw new MsgException(L1.ER_RENT_LIMIT);
            }

            var membersWithoutRefs = GetUsersWithoutReferer(pack.NumberOfRefs, user.Id, pack.MembershipId);

            if (membersWithoutRefs.Count < pack.NumberOfRefs)
            {
                throw new MsgException(U5007.NOTENOUGHREFSAVAILABLE);
            }

            PurchaseOption.ChargeBalance(user, pack.Price, PurchaseOption.Features.DirectReferral.ToString(),
                                         targetBalance, "Direct ref purchase", BalanceLogType.DirectRefPurchase);

            foreach (Member member in membersWithoutRefs)
            {
                member.TryAddReferer(user, true, AppSettings.ServerTime.AddDays(pack.Days));
                member.CameFromUrl = "Purchase";
                member.Save();
            }
        }
Exemple #16
0
        public static void Buy(Member user, InTextAdvertPack pack, string title, string description, string url, PurchaseBalances targetBalance, List <string> tags)
        {
            if (tags.Count > pack.MaxNumberOfTags)
            {
                throw new MsgException(string.Format(U6002.TOOMANYTAGS, pack.MaxNumberOfTags));
            }

            if (tags.Count == 0)
            {
                throw new MsgException(U6002.MUSTADDTAGS);
            }

            PurchaseOption.ChargeBalance(user, pack.Price, PurchaseOption.Features.InTextAds.ToString(), targetBalance, "InText Ad");
            var ad = new InTextAdvert(user.Id, pack, title, description, url, targetBalance);

            ad.Save();

            MapTags(ad.Id, tags);

            MatrixBase.TryAddMemberAndCredit(user, pack.Price, AdvertType.InText);
        }
Exemple #17
0
    public static void BuySurfAds(int adPacksAdvertId, Member user, SurfAdsPack surfAdsPack, PurchaseBalances targetBalance)
    {
        var availablePacks = SurfAdsPack.GetAllActivePacks();

        if (surfAdsPack.Status != SurfAdsPackStatus.Active)
        {
            throw new MsgException("Selected Surf Ads Pack is unavailable");
        }

        //BUY ADPACKS
        var totalPrice = surfAdsPack.Price;

        PurchaseOption.ChargeBalance(user, totalPrice, PurchaseOption.Features.SurfAd.ToString(), targetBalance, string.Format("{0} purchase", U5004.SURFADS));

        AdPacksAdvert ad = new AdPacksAdvert(adPacksAdvertId);

        AdPack pack = new AdPack();

        pack.MoneyReturned   = new Money(0);
        pack.AdPacksAdvertId = adPacksAdvertId;
        pack.TotalConstantBannerImpressions = pack.ConstantBannerImpressionsBought = 0;
        pack.NormalBannerImpressionsBought  = pack.TotalNormalBannerImpressions = 0;
        pack.ClicksBought         = surfAdsPack.Clicks;
        pack.PurchaseDate         = DateTime.Now;
        pack.MoneyToReturn        = pack.MoneyReturned = new Money(0);
        pack.UserCustomGroupId    = -1;
        pack.UserId               = user.Id;
        pack.DistributionPriority = new Decimal(0);
        pack.AdPackTypeId         = -1;
        pack.DisplayTime          = surfAdsPack.DisplayTime;
        pack.Save();

        //Pools
        PoolDistributionManager.AddProfit(ProfitSource.SurfAds, totalPrice);
    }
    public static void Buy(Member user, string url, int categoryId, Banner image, ExternalBannerAdvertPack pack, PurchaseBalances targetBalance)
    {
        PurchaseOption.ChargeBalance(user, pack.Price, PurchaseOption.Features.ExternalBanner.ToString(), targetBalance, "External Banner advertisement");

        var banner = new ExternalBannerAdvert(user.Id, url, categoryId, pack, image, targetBalance);

        banner.Save();

        History.AddPurchase(user.Name, pack.Price, "Banner campaign");

        MatrixBase.TryAddMemberAndCredit(user, pack.Price, AdvertType.ExternalBanner);
    }
Exemple #19
0
 public static void ChargeBalance(Member user, Money amount, PurchaseBalances balance, string note, BalanceLogType balanceLogType = BalanceLogType.Other)
 {
     ChargeBalance(user, amount, balance, note, null, balanceLogType);
 }
Exemple #20
0
    public static void BuyPacks(int numberOfPacks, int adPacksAdvertId, Member user, AdPackType adPackType, PurchaseBalances targetBalance,
                                int?userGroupIdNullable = null, int?groupIdNullable = null, bool forcePurchaseWithoutDeducingFunds = false, Member adPackOwner = null)
    {
        if (!TitanFeatures.IsClickmyad && !AppSettings.RevShare.AdPack.EnableAdvertChange && adPacksAdvertId == -1 && AppSettings.RevShare.AdPacksPolicy != AppSettings.AdPacksPolicy.HYIP)
        {
            throw new MsgException(U6000.CANNOTBUYADPACKS);
        }

        AdPacksForOtherUsers record = null;
        string note = string.Format("{0} purchase", AppSettings.RevShare.AdPack.AdPackName);

        //Buying AdPacks for oneself
        if (adPackOwner == null)
        {
            if (!user.HasThisMembershipOrHigher(adPackType.RequiredMembership))
            {
                throw new MsgException(String.Format(U5006.YOUNEEDMEMBERSHIP, Membership.SelectName(adPackType.RequiredMembership)));
            }

            int numberOfUsersAdPacks = GetNumberOfUsersAdPacks(user.Id, true, adPackType.Id);

            if (numberOfUsersAdPacks + numberOfPacks > adPackType.MaxInstances)
            {
                throw new MsgException(U5004.TOOMANYADPACKOFTYPE.Replace("%a%", AppSettings.RevShare.AdPack.AdPackNamePlural)
                                       .Replace("%b%", (adPackType.MaxInstances - numberOfUsersAdPacks).ToString()));
            }

            int numberOfAllUsersAdpacks = GetNumberOfAllUsersAdPacks(user.Id, adPackType.Id);

            if (numberOfAllUsersAdpacks + numberOfPacks > adPackType.MaxInstancesOfAllAdpacks)
            {
                throw new MsgException(U5004.TOOMANYADPACKOFTYPE.Replace("%a%", AppSettings.RevShare.AdPack.AdPackNamePlural)
                                       .Replace("%b%", (adPackType.MaxInstancesOfAllAdpacks - numberOfAllUsersAdpacks).ToString()));
            }

            var availableTypes = AdPackTypeManager.GetAllActiveTypesForUser(user);

            if (!availableTypes.Any(el => el.Id == adPackType.Id) || adPackType.Status != AdPackTypeStatus.Active)
            {
                throw new MsgException("You cannot buy AdPacks of selected type.");
            }

            adPackOwner = user;
        }
        else
        {
            AdPacksForOtherUsers.Validate(user.Id, adPackOwner.Id, numberOfPacks, out record);
            note += " for " + adPackOwner.Name;
        }

        //BUY ADPACKS
        var totalPrice = GetAdPacksPrice(adPackType, numberOfPacks);

        if (!forcePurchaseWithoutDeducingFunds)
        {
            PurchaseOption.ChargeBalance(user, totalPrice, PurchaseOption.Features.AdPack.ToString(), targetBalance, note, BalanceLogType.AdPackPurchase);
        }

        if (user != adPackOwner)
        {
            AdPacksForOtherUsers.AddOrUpdate(record, user.Id, adPackOwner.Id, numberOfPacks);
        }


        Money totalTrafficExchangeSurfCredits = Money.Zero;
        int   totalLoginAdsCredits            = 0;

        for (int i = 0; i < numberOfPacks; i++)
        {
            AdPack pack = new AdPack();
            pack.MoneyReturned   = new Money(0);
            pack.AdPacksAdvertId = adPacksAdvertId;
            pack.TotalConstantBannerImpressions  = 0;
            pack.TotalNormalBannerImpressions    = 0;
            pack.ConstantBannerImpressionsBought = adPackType.ConstantBannerImpressions;
            pack.NormalBannerImpressionsBought   = adPackType.NormalBannerImpressions;
            pack.ClicksBought         = adPackType.Clicks;
            pack.PurchaseDate         = DateTime.Now;
            pack.MoneyReturned        = new Money(0);
            pack.MoneyToReturn        = Money.MultiplyPercent(adPackType.Price, adPackType.PackReturnValuePercentage + adPackOwner.Membership.ROIEnlargedByPercentage);
            pack.UserCustomGroupId    = -1;
            pack.UserId               = adPackOwner.Id;
            pack.DistributionPriority = new Decimal(1);
            pack.AdPackTypeId         = adPackType.Id;
            pack.DisplayTime          = adPackType.DisplayTime;
            pack.BalanceBoughtType    = targetBalance;
            pack.Save();

            totalTrafficExchangeSurfCredits += adPackType.TrafficExchangeSurfCredits;
            totalLoginAdsCredits            += adPackType.LoginAdsCredits;
        }

        if (AppSettings.TitanFeatures.AdvertTrafficExchangeEnabled)
        {
            adPackOwner.AddToTrafficBalance(totalTrafficExchangeSurfCredits, "Traffic Exchange Surf Credits", BalanceLogType.Other);
        }

        adPackOwner.AddToLoginAdsCredits(totalLoginAdsCredits, note);
        adPackOwner.SaveBalances();

        Money moneyLeftForPools;

        if (TitanFeatures.isAri)
        {
            AriRevShareDistribution.AdPackAriCrediter crediter = new AriRevShareDistribution.AdPackAriCrediter(user);
            moneyLeftForPools = crediter.CreditReferer(totalPrice, targetBalance);
        }
        else
        {
            AdPackCrediter crediter = new AdPackCrediter(user);
            moneyLeftForPools = crediter.CreditReferer(totalPrice);
        }

        //Pools
        if (TitanFeatures.StringSawSundayPool.HasValue && AppSettings.ServerTime.DayOfWeek == DayOfWeek.Sunday)
        {
            PoolDistributionManager.AddProfitToSundayPool(moneyLeftForPools);
        }
        else
        {
            PoolDistributionManager.AddProfit(ProfitSource.AdPacks, moneyLeftForPools);
        }

        //Matrix
        MatrixBase.TryAddMemberAndCredit(user, totalPrice, AdvertType.AdPack);

        var purchasedItem = PurchasedItem.Create(user.Id, adPackType.Price, numberOfPacks,
                                                 adPackType.Name + " " + AppSettings.RevShare.AdPack.AdPackName, PurchasedItemType.AdPack);

        if (TitanFeatures.isAri)
        {
            HtmlInvoiceGenerator generator = new HtmlInvoiceGenerator(purchasedItem);
            generator.SendPdfViaEmail();
        }

        //LeadershipSystem
        var list = new List <RestrictionKind>();

        list.Add(RestrictionKind.ActiveAdPacks);
        list.Add(RestrictionKind.ActiveAdPacksPrice);
        list.Add(RestrictionKind.DirectReferralsActiveAdPacks);
        list.Add(RestrictionKind.DirectReferralsActiveAdPacksPrice);
        LeadershipSystem.CheckSystem(list, user, 1);
    }
Exemple #21
0
        private static void BuyPlan(Member user, PurchaseBalances targetBalance, InvestmentPlatformPlan plan, Money planDiff, Money targetPrice = null)
        {
            var price = planDiff == Money.Zero ? plan.Price : planDiff;
            var note  = string.Format("{0} purchase", plan.Name);

            if (targetPrice != null)
            {
                price = targetPrice;
            }

            //IF TARGET BALANCE != (AR || CASH) IT MEANS THAT WE BUY/UPGRADE FROM PAYMENT BUTTONS
            if (targetBalance == PurchaseBalances.Cash || targetBalance == PurchaseBalances.Purchase)
            {
                PurchaseOption.ChargeBalance(user, price, PurchaseOption.Features.InvestmentPlatform.ToString(), targetBalance, note, BalanceLogType.InvestmentPlatformPlanPurchase);
            }
            else
            {
                targetBalance = PurchaseBalances.PaymentProcessor;
            }

            if (AppSettings.InvestmentPlatform.LevelsEnabled)
            {
                InvestmentLevelsManager.CanUserDepositOnLevel(plan, user);
            }

            var userPlan = new InvestmentUsersPlans
            {
                PlanId             = plan.Id,
                UserId             = user.Id,
                Price              = price,
                Status             = PlanStatus.Active,
                BalanceBoughtType  = targetBalance,
                PurchaseDate       = DateTime.Now,
                MoneyReturned      = Money.Zero,
                MoneyToReturn      = Money.MultiplyPercent(price, plan.Roi),
                CurrentMonthPayout = Money.Zero
            };

            userPlan.Save();

            InvestmentLevelsManager.DepositOnLevel(plan, userPlan.Id, user);

            if (AppSettings.InvestmentPlatform.ProofsEnabled)
            {
                HtmlInvestmentProofGenerator proof;

                if (AppSettings.InvestmentPlatform.LevelsEnabled)
                {
                    proof = new HtmlInvestmentProofGenerator(InvestmentTicket.GetTicket(user.Id, userPlan.Id));
                }
                else
                {
                    proof = new HtmlInvestmentProofGenerator(userPlan);
                }

                proof.SendPdfViaEmail();
            }

            MatrixBase.TryAddMemberAndCredit(user, price, AdvertType.InvestmentPlan);

            InvestmentPlanCrediter Crediter = new InvestmentPlanCrediter(user);

            Crediter.CreditStructure(price);

            if (user.HasReferer)
            {
                TryToSpeedUpReferrer(user.ReferrerId, price, user.Name);

                Crediter.CreditReferer(price);
            }
        }