示例#1
0
    public static void TryBuyAdPackForTokens(int numberOfPacks, int advertId, Member user, AdPackType adPackType,
                                             int?userGroupIdNullable = null, int?groupIdNullable = null, bool forcePurchaseWithoutDeducingFunds = false, Member adPackOwner = null)
    {
        var TokenCryptocurrency = CryptocurrencyFactory.Get(CryptocurrencyType.ERC20Token);

        //Check all basic values
        Money   TotalPriceForAdPacks = AdPackManager.GetAdPacksPrice(adPackType, numberOfPacks);
        Money   TokenValue           = TokenCryptocurrency.GetValue();
        Decimal TokenNumberNeeded    = TotalPriceForAdPacks.ToDecimal() / TokenValue.ToDecimal();

        if (TokenValue <= Money.Zero)
        {
            throw new MsgException("Amount of tokens can not be <= 0");
        }

        if (TokenNumberNeeded > user.GetCryptocurrencyBalance(CryptocurrencyType.ERC20Token).ToDecimal())
        {
            throw new MsgException(String.Format(U6012.NOFUNDSINWALLET, TokenCryptocurrency.Code));
        }

        try
        {
            //Funds ok, lets proceed with tokens transfer
            user.SubtractFromCryptocurrencyBalance(CryptocurrencyType.ERC20Token, TokenNumberNeeded, "Purchase transfer", BalanceLogType.PurchaseTransfer);
            user.AddToPurchaseBalance(TotalPriceForAdPacks, "Purchase transfer", BalanceLogType.PurchaseTransfer);

            AdPackManager.BuyPacks(numberOfPacks, advertId, user, adPackType, PurchaseBalances.Purchase, adPackOwner: adPackOwner);
        }
        catch (MsgException ex)
        {
            user.AddToCryptocurrencyBalance(CryptocurrencyType.ERC20Token, TokenNumberNeeded, "Reversed Purchase transfer", BalanceLogType.ReversedPurchaseTransfer);
            user.SubtractFromPurchaseBalance(TotalPriceForAdPacks, "Reversed Purchase transfer", BalanceLogType.ReversedPurchaseTransfer);
            throw new MsgException("<br />" + ex.Message);
        }
    }
示例#2
0
    public static void Apply(CustomGroup type, UserCustomGroup userCustomGroup)
    {
        //Temporary (for better performance)
        List <AdPackType> typesList     = TableHelper.SelectAllRows <AdPackType>();
        AdPack            creatorAdPack = null;
        var types = new Dictionary <int, AdPackType>();

        foreach (var typeList in typesList)
        {
            types.Add(typeList.Id, typeList);
        }

        Random     random    = new Random();
        List <int> adPackIds = new List <int>();

        //Value of purchases
        Money memberPurchasesAmount  = Money.Zero;
        Money creatorPurchasesAmount = Money.Zero;
        var   adpacks = AdPackManager.GetAllAdPacksInCustomGroup(userCustomGroup.Id);

        foreach (var adpack in adpacks)
        {
            if (adpack.UserId != userCustomGroup.CreatorUserId)
            {
                memberPurchasesAmount += types[adpack.AdPackTypeId].Price;
                adPackIds.Add(adpack.Id);
            }
            else
            {
                creatorPurchasesAmount += types[adpack.AdPackTypeId].Price;
            }
        }

        //Reward for creator
        var    creatorReward = Money.MultiplyPercent(memberPurchasesAmount, type.CreatorRewardBonusPercent);
        Member GroupCreator  = new Member(userCustomGroup.CreatorUserId);

        GroupCreator.AddToPurchaseBalance(creatorReward, "Custom Group creator bonus");
        GroupCreator.SaveBalances();

        //Prize1
        var    prize1Reward    = Money.MultiplyPercent(memberPurchasesAmount, type.FirstRewardPercent);
        int    wonPrize1Ticket = random.Next(0, adPackIds.Count);
        Member Prize1Winner    = new Member((new AdPack(adPackIds[wonPrize1Ticket])).UserId);

        Prize1Winner.AddToPurchaseBalance(prize1Reward, "Custom Group 1st prize");
        Prize1Winner.SaveBalances();

        //Prize2
        var    prize2Reward    = Money.MultiplyPercent(creatorPurchasesAmount, type.SecondRewardPercent);
        int    wonPrize2Ticket = random.Next(0, adPackIds.Count);
        Member Prize2Winner    = new Member((new AdPack(adPackIds[wonPrize2Ticket])).UserId);

        Prize2Winner.AddToPurchaseBalance(prize2Reward, "Custom Group 2nd prize");
        Prize2Winner.SaveBalances();

        userCustomGroup.BonusExtraInformation =
            String.Format("Creator username: <b>{0}</b>, reward: <b>{1}</b>, 1st prize winner: <b>{2}</b> ({3}), 2nd prize winner: <b>{4}</b> ({5}).",
                          GroupCreator.Name, creatorReward.ToString(), Prize1Winner.Name, prize1Reward.ToString(), Prize2Winner.Name, prize2Reward.ToString());
    }
示例#3
0
        private void DepositCryptocurrency(Member user, decimal amountInCryptocurrency)
        {
            Money   moneyAmount = ConvertToMoney(amountInCryptocurrency);
            LogType LogType     = ErrorLoggerHelper.GetTypeFromProcessor(DepositApiProcessor);

            user.Reload();

            if (DepositTarget == DepositTargetBalance.PurchaseBalance)
            {
                user.AddToPurchaseBalance(moneyAmount, Code + " deposit", BalanceLogType.Other);
                user.SaveBalances();
            }
            if (DepositTarget == DepositTargetBalance.CashBalance)
            {
                user.AddToCashBalance(moneyAmount, Code + " deposit", BalanceLogType.Other);
                user.SaveBalances();

                //Referral commission for sponsors when user does Cash Balance deposit
                CashBalanceCrediter Crediter = (CashBalanceCrediter)CrediterFactory.Acquire(user, CreditType.CashBalanceDeposit);
                Crediter.TryCreditReferer(moneyAmount);
            }
            if (DepositTarget == DepositTargetBalance.Wallet)
            {
                user.AddToCryptocurrencyBalance(Type, amountInCryptocurrency, Code + " Wallet deposit", BalanceLogType.WalletDeposit);
            }

            PaymentProportionsManager.MemberPaidIn(moneyAmount, CryptocurrencyTypeHelper.ConvertToPaymentProcessor(Type), user);
            History.AddTransfer(user.Name, moneyAmount, Code + " deposit", DepositTarget.ToString());

            ContestManager.IMadeAnAction(ContestType.Transfer, user.Name, moneyAmount, 0);
        }
示例#4
0
    public static void CreditAriRevShareDistribution()
    {
        try
        {
            var balanceLogsList = TableHelper.GetListFromRawQuery <BalanceLog>("SELECT * FROM BalanceLogs WHERE balancelogtype = 6 AND DateOccured IN (SELECT MAX(DateOccured) FROM BalanceLogs WHERE balancelogtype = 6) AND balance = 1");

            foreach (var log in balanceLogsList)
            {
                var referrerId = GerReferrerID(log.UserId);
                if (CheckReferalCondition(referrerId))
                {
                    var member           = new Member(referrerId);
                    var memberWhoMatched = new Member(log.UserId);

                    member.AddToMainBalance(new Money(log.Amount), "Matching bonus from " + memberWhoMatched.Name);
                    member.AddToPurchaseBalance(new Money(log.Amount), "Matching bonus from " + memberWhoMatched.Name);

                    member.IncreaseAdPackEarningsFromDR(2 * new Money(log.Amount));
                    member.IncreaseEarningsFromDirectReferral(2 * new Money(log.Amount));

                    member.Save();
                }
            }
        }
        catch (Exception ex)
        {
            ErrorLogger.Log(ex);
        }
    }
示例#5
0
 private static void RefundBid(BannerBid bid)
 {
     if (bid != null)
     {
         Member user = new Member(bid.Username);
         user.AddToPurchaseBalance(Money.MultiplyPercent(bid.BidValue, AppSettings.BannerAdverts.LostBidsReturnPercent), "Bid refund");
         user.SaveBalances();
     }
 }
示例#6
0
    private static void CreditWinner(Jackpot jackpot, JackpotWinningTicket winningTicket, Member winner)
    {
        var prizeType = GetPrizeType(jackpot, winner);

        switch (prizeType)
        {
        case JackpotPrize.MainBalance:
            var mainBalancePrize = jackpot.MainBalancePrize / jackpot.NumberOfWinningTickets;
            winner.AddToMainBalance(mainBalancePrize, "Jackpot win", BalanceLogType.Other);
            winner.SaveBalances();
            History.AddJackpotWin(winner.Name, string.Format("{0} - {1}", L1.MAINBALANCE, mainBalancePrize.ToString()), winningTicket.WinningTicketNumber.ToString(), jackpot.Name);
            PoolDistributionManager.SubtractProfit(ProfitSource.Jackpots, mainBalancePrize);
            break;

        case JackpotPrize.AdBalance:
            var adBalancePrize = jackpot.AdBalancePrize / jackpot.NumberOfWinningTickets;
            winner.AddToPurchaseBalance(adBalancePrize, "Jackpot win", BalanceLogType.Other);
            winner.SaveBalances();
            History.AddJackpotWin(winner.Name, string.Format("{0} - {1}", U6012.PURCHASEBALANCE, adBalancePrize.ToString()), winningTicket.WinningTicketNumber.ToString(), jackpot.Name);
            PoolDistributionManager.SubtractProfit(ProfitSource.Jackpots, adBalancePrize);
            break;

        case JackpotPrize.LoginAdsCredits:
            var loginAdsCreditsPrize = jackpot.LoginAdsCreditsPrize / jackpot.NumberOfWinningTickets;
            winner.AddToLoginAdsCredits(loginAdsCreditsPrize, "Jackpot win");
            winner.SaveBalances();
            History.AddJackpotWin(winner.Name, string.Format("{0} - {1}", U5008.LOGINADSCREDITS, loginAdsCreditsPrize.ToString()), winningTicket.WinningTicketNumber.ToString(), jackpot.Name);
            break;

        case JackpotPrize.Upgrade:
            var upgradeMembershipDaysPrize = jackpot.UpgradeDaysPrize / jackpot.NumberOfWinningTickets;

            if (winner.MembershipId == Membership.Standard.Id)
            {
                winner.Upgrade(new Membership(jackpot.UpgradeIdPrize), new TimeSpan(upgradeMembershipDaysPrize, 0, 0, 0));
            }
            else
            {
                winner.Upgrade(new Membership(jackpot.UpgradeIdPrize), winner.MembershipExpires.HasValue
                            ? winner.MembershipExpires.Value.AddDays(upgradeMembershipDaysPrize)
                            : AppSettings.ServerTime.AddDays(upgradeMembershipDaysPrize));
            }
            History.AddJackpotWin(winner.Name, string.Format("{0} - {1}", U5008.UPGRADED, winner.Membership.Name), winningTicket.WinningTicketNumber.ToString(), jackpot.Name);
            break;

        default: break;
        }
        JackpotTicketPrize prize = new JackpotTicketPrize();

        prize.JackpotId = jackpot.Id;
        prize.PrizeType = prizeType;
        prize.Save();
    }
示例#7
0
        public static void AddPack(Member user, MembershipPack pack, Money paidAmountToValidate = null)
        {
            Money PackPrice = pack.GetPrice(user);

            if (paidAmountToValidate != null && paidAmountToValidate < PackPrice)
            {
                throw new MsgException(string.Format("{0} is not enough to buy the chosen Membership ({1} - {2})", paidAmountToValidate, pack.Membership.Name, PackPrice));
            }

            user.Upgrade(pack);

            //Add history entry
            History.AddUpgradePurchase(user.Name, pack.Membership.Name, PackPrice);

            //Update pack stats
            pack.CopiesBought++;
            pack.Save();

            //Credit Balances Bonuses
            var AdBalanceBonus      = pack.Membership.AdBalanceBonusForUpgrade;
            var CashBalanceBonus    = pack.Membership.CashBalanceBonusForUpgrade;
            var TrafficBalanceBonus = pack.Membership.TrafficBalanceBonusForUpgrade;

            if (AdBalanceBonus > Money.Zero)
            {
                user.AddToPurchaseBalance(AdBalanceBonus, "Bonus from Upgrade");
            }

            if (AppSettings.Payments.CashBalanceEnabled && CashBalanceBonus > Money.Zero)
            {
                user.AddToCashBalance(CashBalanceBonus, "Bonus from Upgrade");
            }

            if (AppSettings.TitanFeatures.EarnTrafficExchangeEnabled && TrafficBalanceBonus > Money.Zero)
            {
                user.AddToTrafficBalance(TrafficBalanceBonus, "Bonus from Upgrade");
            }

            var moneyLeftForPools = PackPrice;

            Titan.UpgradeCrediter Crediter = (Titan.UpgradeCrediter)Titan.CrediterFactory.Acquire(user, Titan.CreditType.Upgrade);
            moneyLeftForPools = Crediter.CreditReferer(PackPrice);

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

            list.Add(RestrictionKind.RequiredMembership);
            LeadershipSystem.CheckSystem(list, user);

            //Pools
            PoolDistributionManager.AddProfit(ProfitSource.Memberships, moneyLeftForPools);
        }
示例#8
0
        private static void ConfirmIPN(MarketplaceIPN ipn)
        {
            MarketplaceProduct product = new MarketplaceProduct(ipn.ProductId);
            Member             seller  = new Member(product.SellerId);

            if (ipn.Status == MarketplaceIPNStatus.Pending)
            {
                ipn.Status = MarketplaceIPNStatus.Confirmed;
                ipn.Save();

                seller.AddToPurchaseBalance(ipn.ProductQuantity * product.Price, "Marketplace sale", BalanceLogType.MarketplaceSale);
                seller.SaveBalances();
            }
        }
    public void TryCancelDeposit(string username, ConversationMessage transactionMessage)
    {
        Member RepresentativeUser = new Member(RepresentativeUserId);

        if (targetBalance == PurchaseBalances.Cash)
        {
            RepresentativeUser.AddToCashBalance(transactionMessage.RepresentativeTransferAmount, "Return for representative deposit cancellation");
            RepresentativeUser.SaveBalances();
        }

        if (targetBalance == PurchaseBalances.Purchase)
        {
            RepresentativeUser.AddToPurchaseBalance(transactionMessage.RepresentativeTransferAmount, "Return for representative deposit cancellation");
            RepresentativeUser.SaveBalances();
        }
    }
示例#10
0
        private static void GivePrizesToWinner(Member user)
        {
            var note = U6010.ROLLDICELOTTERYWINNER;

            if (MainBalancePrize > Money.Zero)
            {
                user.AddToMainBalance(MainBalancePrize, note);
            }
            if (AdBalancePrize > Money.Zero)
            {
                user.AddToPurchaseBalance(AdBalancePrize, note);
            }
            if (PointsPrize > 0)
            {
                user.AddToPointsBalance(PointsPrize, note);
            }

            user.SaveBalances();
        }
示例#11
0
    public static void AcceptRequest(int creditLineRequestId)
    {
        Money maxLoan = GlobalPool.Get(PoolsHelper.GetBuiltInProfitPoolId(Pools.CreditLine)).SumAmount;

        CreditLineRequest request = new CreditLineRequest(creditLineRequestId);

        if (request.LoanRequested > maxLoan)
        {
            request.Status = CreditLineRequestStatus.Rejected;
            request.Save();
            throw new MsgException("There is not enough money in the pool. The request has been rejected.");
        }

        request.Status = CreditLineRequestStatus.Accepted;
        request.Save();

        Member         user = new Member(request.UserId);
        DateTime       now  = AppSettings.ServerTime;
        CreditLineLoan loan = new CreditLineLoan();

        loan.UserId                    = user.Id;
        loan.Loaned                    = request.LoanRequested;
        loan.FirstDeadline             = now.AddDays(AppSettings.CreditLine.FirstDeadlineDays);
        loan.SecondDeadline            = now.AddDays(AppSettings.CreditLine.SecondDeadlineDays);
        loan.FinalDeadline             = now.AddDays(AppSettings.CreditLine.FinalDeadlineDays);
        loan.AmounBeforeFirstDeadline  = Money.MultiplyPercent(request.LoanRequested, AppSettings.CreditLine.FirstRepayPercent);
        loan.AmounBeforeSecondDeadline = Money.MultiplyPercent(request.LoanRequested, AppSettings.CreditLine.SecondRepayPercent);
        loan.BorrowDate                = now;
        loan.Repaid                    = Money.Zero;
        loan.Save();

        var moneyWithoutFee = Money.MultiplyPercent(request.LoanRequested, 100 - AppSettings.CreditLine.Fee);

        GlobalPoolManager.SubtractFromPool(PoolsHelper.GetBuiltInProfitPoolId(Pools.CreditLine), moneyWithoutFee);

        user.AddToPurchaseBalance(moneyWithoutFee, "Credit Line", BalanceLogType.CreditLine);
        user.SaveBalances();

        Mailer.SendNewCreditLineMessage(user.Email, request.LoanRequested);
    }
示例#12
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();
        }
示例#13
0
    public static void TryBuyAdPackFromAnotherBalance(int numberOfPacks, int advertId, Member user, AdPackType adPackType, BalanceType targetType,
                                                      int?userGroupIdNullable = null, int?groupIdNullable = null, bool forcePurchaseWithoutDeducingFunds = false, Member adPackOwner = null)
    {
        Money TotalPriceForAdPacks = AdPackManager.GetAdPacksPrice(adPackType, numberOfPacks);

        if (TotalPriceForAdPacks <= Money.Zero)
        {
            throw new MsgException("Value can not be <= 0");
        }


        if (targetType == BalanceType.CommissionBalance)
        {
            if (TotalPriceForAdPacks > user.CommissionBalance)
            {
                throw new MsgException(L1.NOTENOUGHFUNDS);
            }

            try
            {
                //Funds ok, lets proceed with tokens transfer
                user.SubtractFromCommissionBalance(TotalPriceForAdPacks, "Purchase transfer", BalanceLogType.PurchaseTransfer);
                user.AddToPurchaseBalance(TotalPriceForAdPacks, "Purchase transfer", BalanceLogType.PurchaseTransfer);
                AdPackManager.BuyPacks(numberOfPacks, advertId, user, adPackType, PurchaseBalances.Purchase, adPackOwner: adPackOwner);
            }
            catch (MsgException ex)
            {
                user.SubtractFromPurchaseBalance(TotalPriceForAdPacks, "Reversed Purchase transfer", BalanceLogType.ReversedPurchaseTransfer);
                user.AddToPurchaseBalance(TotalPriceForAdPacks, "Purchase transfer", BalanceLogType.PurchaseTransfer);
                throw new MsgException("<br />" + ex.Message);
            }
        }
        else if (targetType == BalanceType.MainBalance)
        {
            if (TotalPriceForAdPacks > user.MainBalance)
            {
                throw new MsgException(L1.NOTENOUGHFUNDS);
            }

            try
            {
                //Funds ok, lets proceed with tokens transfer
                user.SubtractFromMainBalance(TotalPriceForAdPacks, "Purchase transfer", BalanceLogType.PurchaseTransfer);
                user.AddToPurchaseBalance(TotalPriceForAdPacks, "Purchase transfer", BalanceLogType.PurchaseTransfer);
                AdPackManager.BuyPacks(numberOfPacks, advertId, user, adPackType, PurchaseBalances.Purchase, adPackOwner: adPackOwner);
            }
            catch (MsgException ex)
            {
                user.SubtractFromPurchaseBalance(TotalPriceForAdPacks, "Reversed Purchase transfer", BalanceLogType.ReversedPurchaseTransfer);
                user.AddToMainBalance(TotalPriceForAdPacks, "Purchase transfer", BalanceLogType.PurchaseTransfer);
                throw new MsgException("<br />" + ex.Message);
            }
        }
        else if (targetType == BalanceType.BTC)
        {
            Money   BTCValue        = CryptocurrencyFactory.Get(CryptocurrencyType.BTC).GetValue();
            Decimal BTCAmountNeeded = TotalPriceForAdPacks.ToDecimal() / BTCValue.ToDecimal();

            if (BTCAmountNeeded > user.GetCryptocurrencyBalance(CryptocurrencyType.BTC).ToDecimal())
            {
                throw new MsgException(String.Format(U6012.NOFUNDSINWALLET, "BTC"));
            }

            try
            {
                //Funds ok, lets proceed with tokens transfer
                user.SubtractFromCryptocurrencyBalance(CryptocurrencyType.BTC, BTCAmountNeeded, "Purchase transfer", BalanceLogType.PurchaseTransfer);
                user.AddToPurchaseBalance(TotalPriceForAdPacks, "Purchase transfer", BalanceLogType.PurchaseTransfer);
                AdPackManager.BuyPacks(numberOfPacks, advertId, user, adPackType, PurchaseBalances.Purchase, adPackOwner: adPackOwner);
            }
            catch (MsgException ex)
            {
                user.SubtractFromPurchaseBalance(TotalPriceForAdPacks, "Reversed Purchase transfer", BalanceLogType.ReversedPurchaseTransfer);
                user.AddToCryptocurrencyBalance(CryptocurrencyType.BTC, BTCAmountNeeded, "Purchase transfer", BalanceLogType.PurchaseTransfer);
                throw new MsgException("<br />" + ex.Message);
            }
        }
        else
        {
            throw new MsgException("Not implemented transaction");
        }
    }
示例#14
0
        public static void TransferToBalance(string username, Money money, string from, string transId, string targetBalance,
                                             bool isViaRepresentative = false, string cryptoCurrencyInfo = "")
        {
            Exceptions.HandleNonMsgEx(() =>
            {
                //Add income to stats
                if (!isViaRepresentative)
                {
                    Statistics.Statistics.AddToCashflow(money);
                }

                bool successful = (money >= AppSettings.Payments.MinimumTransferAmount);

                PaymentProcessor paymentProcessor = PaymentAccountDetails.GetFromStringType(from);
                Money moneyWithoutFee             = money;

                if (!isViaRepresentative &&
                    (targetBalance == "Purchase Balance" || targetBalance == "Cash Balance" || targetBalance == "Marketplace Balance"))
                {
                    moneyWithoutFee = PaymentAccountDetails.GetAmountWithoutFee(from, money);
                }

                if (successful)
                {
                    Member user = new Member(username);
                    if (targetBalance == "Purchase Balance")
                    {
                        user.AddToPurchaseBalance(moneyWithoutFee, from + " transfer");
                    }
                    else if (targetBalance == "Cash Balance")
                    {
                        user.AddToCashBalance(moneyWithoutFee, from + " transfer");
                    }
                    else if (targetBalance == "Traffic Balance")
                    {
                        user.AddToTrafficBalance(money, from + " transfer");
                    }
                    else if (targetBalance == "Marketplace Balance")
                    {
                        user.AddToMarketplaceBalance(moneyWithoutFee, from + " transfer");
                    }
                    else if (targetBalance == "Points Balance")
                    {
                        user.AddToPointsBalance(moneyWithoutFee.ConvertToPoints(), from + " transfer");
                    }
                    user.SaveBalances();

                    if (targetBalance == "Purchase Balance" || targetBalance == "Cash Balance" || targetBalance == "Marketplace Balance")
                    {
                        //Update payment proportions
                        PaymentProportionsManager.MemberPaidIn(moneyWithoutFee, paymentProcessor, user);
                    }

                    //Add history
                    History.AddTransfer(username, moneyWithoutFee, from, targetBalance);

                    //TryAchievement
                    bool shouldBeSaved = user.TryToAddAchievements(
                        Achievements.Achievement.GetProperAchievements(
                            Achievements.AchievementType.AfterTransferringOnceAmount, moneyWithoutFee.GetTotals()));

                    if (shouldBeSaved)
                    {
                        user.Save();
                    }

                    //Check the contests
                    Contests.ContestManager.IMadeAnAction(Contests.ContestType.Transfer, user.Name, moneyWithoutFee, 0);
                    PurchasedItem.Create(user.Id, moneyWithoutFee, 1, "Transfer to " + targetBalance, PurchasedItemType.Transfer);

                    //Referral commission for sponsors when user does Cash Balance deposit
                    Titan.CashBalanceCrediter Crediter = (Titan.CashBalanceCrediter)Titan.CrediterFactory.Acquire(user, Titan.CreditType.CashBalanceDeposit);
                    Crediter.TryCreditReferer(moneyWithoutFee);
                }

                //AddLog
                if (!isViaRepresentative)
                {
                    CompletedPaymentLog.Create(paymentProcessor, "Transfer to " + targetBalance, transId, false, username, moneyWithoutFee,
                                               money - moneyWithoutFee, successful, cryptoCurrencyInfo);
                }
            });
        }
示例#15
0
    public static string TryInvokeTransfer(string transferFrom, string transferTo, Money amount, Member user, ref bool htmlResponse)
    {
        var TokenCryptocurrency = CryptocurrencyFactory.Get(CryptocurrencyType.ERC20Token);

        //Anti-Injection Fix
        if (amount <= new Money(0))
        {
            throw new MsgException(L1.ERROR);
        }

        if (!TransferHelper.IsAllowed(transferFrom, transferTo))
        {
            throw new MsgException("This transfer is not allowed.");
        }

        if (transferFrom == "MPesa" && String.IsNullOrWhiteSpace(user.GetPaymentAddress(PaymentProcessor.MPesa)))
        {
            throw new MsgException(U6010.ACCOUNTIDREQUIRED);
        }

        AppSettings.DemoCheck();
        htmlResponse = false;

        if (transferFrom == "Main balance")
        {
            // Option 1: From Main Balance (always available)

            if (amount > user.MainBalance)
            {
                throw new MsgException(L1.NOTENOUGHFUNDS);
            }

            user.SubtractFromMainBalance(amount, "Transfer from Main Balance");
            user.MoneyTransferredFromMainBalance += amount;

            if (transferTo == "Traffic balance")
            {
                user.AddToTrafficBalance(amount, "Transfer from Main Balance");
            }

            else if (transferTo == "Purchase balance" && AppSettings.Payments.TransferMainInAdBalanceEnabled)
            {
                user.AddToPurchaseBalance(amount, "Transfer from Main Balance");
            }

            else if (transferTo == "Cash balance")
            {
                user.AddToCashBalance(amount, "Transfer from Main Balance");
            }

            else if (transferTo == TokenCryptocurrency.Code + " Wallet" && AppSettings.Payments.TransferFromMainBalanceToTokenWalletEnabled)
            {
                //Let's calculate transfer amount using current token rate
                decimal tokenValue = CryptocurrencyFactory.Get(CryptocurrencyType.ERC20Token).ConvertFromMoney(amount);
                user.AddToCryptocurrencyBalance(CryptocurrencyType.ERC20Token, tokenValue, "Transfer from Main Balance");
            }

            else
            {
                throw new MsgException("You must select your target account / this transfer is not available.");
            }

            user.Save();
            AddHistoryAndTryAchievement(amount, user, "Main balance", transferTo);
            return(U3501.TRANSFEROK);
        }
        else if (transferFrom == "Cash balance")
        {
            if (AppSettings.Payments.CashBalanceEnabled && AppSettings.Payments.CashToAdBalanceEnabled)
            {
                if (amount > user.CashBalance)
                {
                    throw new MsgException(L1.NOTENOUGHFUNDS);
                }

                user.SubtractFromCashBalance(amount, "Transfer from Cash Balance");

                if (transferTo == "Purchase balance")
                {
                    user.AddToPurchaseBalance(amount, "Transfer from Cash Balance");
                }

                user.SaveBalances();
                return(U3501.TRANSFEROK);
            }
            else
            {
                throw new MsgException("You cannot transfer from Cash Balance");
            }
        }
        else if (transferFrom == "Commission Balance")
        {
            if (((AppSettings.Payments.CommissionToMainBalanceEnabled) ||
                 (TitanFeatures.UserCommissionToMainBalanceEnabled && user.CommissionToMainBalanceEnabled) ||
                 (AppSettings.Payments.CommissionToAdBalanceEnabled) || TitanFeatures.isAri) && user.CheckAccessCustomizeTradeOwnSystem)
            {
                if (amount > user.CommissionBalance)
                {
                    throw new MsgException(L1.NOTENOUGHFUNDS);
                }

                user.SubtractFromCommissionBalance(amount, "Transfer from Commission Balance");

                if (transferTo == "Main balance")
                {
                    Money amountWithFee = TransferManager.GetAmountWithFee(amount, TransferFeeType.SameUserCommissionToMain, user);
                    user.AddToMainBalance(amountWithFee, "Transfer from Commission Balance");

                    //Pools
                    Money moneyLeft = amount - amountWithFee;
                    PoolDistributionManager.AddProfit(ProfitSource.TransferFees, moneyLeft);
                }
                else if (transferTo == "Purchase balance")
                {
                    user.AddToPurchaseBalance(amount, "Transfer from Commission Balance");
                }
                else if (transferTo == "Cash balance")
                {
                    user.AddToCashBalance(amount, "Transfer from Purchase Balance");
                }

                user.SaveBalances();
                return(U3501.TRANSFEROK);
            }
            else
            {
                throw new MsgException("You cannot transfer from Commission Balance");
            }
        }
        else if (transferFrom == "Purchase balance")
        {
            if (!TitanFeatures.IsRevolca)
            {
                throw new MsgException("You cannot transfer from Purchase Balance");
            }

            if (amount > user.MainBalance)
            {
                throw new MsgException(L1.NOTENOUGHFUNDS);
            }

            user.SubtractFromPurchaseBalance(amount, "Transfer from Purchase Balance");
            user.AddToMainBalance(amount, "Transfer from Purchase Balance");
            user.SaveBalances();
            return(U3501.TRANSFEROK);
        }
        else
        {
            htmlResponse = true;
            return(TryInvokeProcessorTransfer(transferFrom, transferTo, amount, user));
        }
    }
示例#16
0
    protected void btnTransferPoints_Click(object sender, EventArgs e)
    {
        string amount = SliderSinglePointsTextBox.Text;
        int    Points;

        try
        {
            AppSettings.DemoCheck();

            Points = Int32.Parse(amount);
            Member User = Member.Current;

            Money Amount = Titan.PointsConverter.ToMoney(Points);

            //Anti-Injection Fix
            if (Amount <= new Money(0))
            {
                throw new MsgException(L1.ERROR);
            }

            if (PointsFrom.SelectedValue == "Points")
            {
                if (Points > User.PointsBalance)
                {
                    throw new MsgException(L1.NOTENOUGHFUNDS);
                }

                User.SubtractFromPointsBalance(Points, "Transfer from " + AppSettings.PointsName + " balance", BalanceLogType.Other, setMinPoints: false);

                if (PointsTo.SelectedValue == "Traffic balance")
                {
                    User.AddToTrafficBalance(Amount, "Transfer from  " + AppSettings.PointsName + "  balance");
                }
                else if (PointsTo.SelectedValue == "Purchase balance")
                {
                    User.AddToPurchaseBalance(Amount, "Transfer from  " + AppSettings.PointsName + "  balance");
                }
                else if (PointsTo.SelectedValue == "Main balance")
                {
                    User.AddToMainBalance(Amount, "Transfer from  " + AppSettings.PointsName + "  balance");
                    User.TotalEarned += Amount;
                }

                else
                {
                    throw new MsgException("You must select your target account");
                }

                User.SaveBalances();
                Response.Redirect("../status.aspx?type=transferok");
            }
        }
        catch (MsgException ex)
        {
            ShowErrorMessage(ex.Message);
        }
        catch (Exception ex)
        {
            ErrorLogger.Log(ex);
            ShowErrorMessage(ex.Message);
        }
    }