public Money Credit(PtcAdvert ad) { Money calculated = ad.MoneyToClaimAsCashLink; user.AddToMainBalance(calculated, "CashLink", BalanceLogType.CashLinkClick); user.IncreaseEarnings(calculated); //OK mark as watched and credit List <int> av = user.AdsViewed; av.Add(ad.Id); user.AdsViewed = av; user.LastActive = DateTime.Now; Money NewTotalEarned = (user.TotalEarned + calculated); user.TryToAddAchievements( Prem.PTC.Achievements.Achievement.GetProperAchievements( Prem.PTC.Achievements.AchievementType.AfterEarning, NewTotalEarned.GetRealTotals())); user.IncreaseUserStatClicks(1); user.IncreaseStatClicks(1); user.IncreaseCashLinksEarnings(calculated); user.Save(); DailyPoolManager.AddToPool(PoolsHelper.GetBuiltInProfitPoolId(Pools.AdPackRevenueReturn), DateTime.Now, calculated); AdPackProfitDistributionHistory.Add(calculated); return(calculated); }
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); } }
public static void TryDivest(Money amountToDivest, int?kelly, Member user) { Money _amountToDivest; Money totalInvestment; if (amountToDivest == null || kelly == null) { _amountToDivest = totalInvestment = GetInvestments(user, null); } else { if (kelly <= 0 || kelly > AppSettings.DiceGame.MaxKellyLevel) { throw new MsgException(U4200.KELLYERROR + ' ' + AppSettings.DiceGame.MaxKellyLevel); } _amountToDivest = amountToDivest; totalInvestment = GetInvestments(user, kelly); } if (totalInvestment == Money.Zero || _amountToDivest > totalInvestment) { throw new MsgException(U4200.DIVESTTOOHIGH); } else if (_amountToDivest <= Money.Zero) { throw new MsgException(U4200.DIVESTTOOLOW); } user.AddToMainBalance(_amountToDivest, "Dice Game Divestment", BalanceLogType.Other); var siteInvestments = SiteInvestment.GetAll(user.Id); int i = 0; while (_amountToDivest > Money.Zero && i < siteInvestments.Count) { if (kelly == null || kelly == siteInvestments[i].KellyInt) { if (_amountToDivest > siteInvestments[i].Amount) { siteInvestments[i].Amount -= siteInvestments[i].Amount; _amountToDivest -= siteInvestments[i].Amount; } else { siteInvestments[i].Amount -= _amountToDivest; _amountToDivest = Money.Zero; } siteInvestments[i].OperationDate = DateTime.Now; siteInvestments[i].Save(); if (siteInvestments[i].Amount == Money.Zero) { siteInvestments[i].Delete(); } } i++; } user.SaveBalances(); }
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(); }
private void CreditAncestor(Member ancestor, Money servicePrice, decimal percentage) { if (percentage <= 0) { return; } if (!TitanFeatures.IsRevolca || ancestor.RevenueShareAdsWatchedYesterday >= ancestor.Membership.AdPackDailyRequiredClicks) { ancestor.AddToMainBalance(Money.MultiplyPercent(servicePrice, percentage), "Matrix Reward"); ancestor.SaveBalances(); } }
public void RejectWithdrawal(ConversationMessage transactionMessage) { Money fullAmount = transactionMessage.RepresentativeTransferAmount / ((100 - AppSettings.Representatives.RepresentativesHelpWithdrawalFee) / 100); User.AddToMainBalance(fullAmount, "Representative payout rejected"); User.SaveBalances(); //Check & subtract from the represenative Member RepresentativeUser = new Member(RepresentativeUserId); RepresentativeUser.SubtractFromMainBalance(fullAmount, "Representative payout rejected"); RepresentativeUser.SaveBalances(); }
public void InceaseClicks() { ClicksDelivered++; if (ClicksDelivered / 1000 > CreditedCPM) { CreditedCPM++; var user = new Member(UserId); user.AddToMainBalance(AppSettings.PaidToPromote.CostPerMillePrice, "PaidToPromote CPM"); user.SaveBalances(); } Save(); }
private void HandleOwnerUser(Member OwnerUser, TrafficExchangeAdvert Ad, bool FiredByDirectReferral = false) { bool CreditMoney = OwnerUser.HasClickedEnoughToProfitFromReferrals(); if (CreditMoney) { var Earnings = TrafficExchangeAdvert.CalculateEarningsFromDirectReferralTE(OwnerUser, Ad); OwnerUser.AddToMainBalance(Earnings, "TE /ref/" + Username, BalanceLogType.Other); bool isFullSaveRequired1 = false; bool isFullSaveRequired2 = false; string inter = (OwnerUser.TotalEarned + Earnings).ToClearString(); Decimal tempMoney = Decimal.Parse(inter, new System.Globalization.CultureInfo("en-US")); isFullSaveRequired2 = OwnerUser.TryToAddAchievements( Prem.PTC.Achievements.Achievement.GetProperAchievements( Prem.PTC.Achievements.AchievementType.AfterEarning, Convert.ToInt32(tempMoney))); OwnerUser.IncreaseEarnings(Earnings); //OwnerUser.IncreaseStatClicks(1); //if (FiredByDirectReferral) // OwnerUser.IncreaseDRClicks(); //else // OwnerUser.IncreaseRRClicks(); if (isFullSaveRequired1 || isFullSaveRequired2) { OwnerUser.Save(); } else { OwnerUser.SaveBalances(); } } else { //OwnerUser.IncreaseStatClicks(1); //if (FiredByDirectReferral) // OwnerUser.IncreaseDRClicks(); //else // OwnerUser.IncreaseRRClicks(); //OwnerUser.SaveBalances(); } }
public void InvokeWithdrawal(Money amount, string message) { User.SubtractFromMainBalance(amount, "Payout via representative"); User.SaveBalances(); Money fees = GetWithdrawalFees(amount); //Check & add to the represenative Member RepresentativeUser = new Member(RepresentativeUserId); RepresentativeUser.AddToMainBalance(amount, "Payout via representative"); RepresentativeUser.SaveBalances(); User.SendMessage(RepresentativeUserId, message, MessageType.RepresentativeWithdrawalRequest, RepresentativeRequestStatus.Pending, amount - fees); }
public string TryConfirmDeposit(ConversationMessage transactionMessage) { //Make the deposit Money CommissionFee = GetWithdrawalFees(transactionMessage.RepresentativeTransferAmount); DepositHelper.TransferToBalance(User.Name, transactionMessage.RepresentativeTransferAmount - CommissionFee, "ViaRepresentative", String.Empty, targetBalanceName, true); //Deposit fee for Representative Member RepresentativeUser = new Member(RepresentativeUserId); RepresentativeUser.AddToMainBalance(CommissionFee, "Payout fee for representative deposit"); RepresentativeUser.SaveBalances(); //Send message to the user RepresentativeUser.SendMessage(User.Id, String.Format(U6010.DEPOSITSUCCESSFULLMESSAGE, transactionMessage.RepresentativeTransferAmount - CommissionFee, User.Name)); return(String.Format(U6010.DEPOSITSUCCESSFULLINFO, transactionMessage.RepresentativeTransferAmount - CommissionFee, User.Name)); }
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(); }
public void BuyViaProcessor(string username, int quantity, string emailAddress, string deliveryAddress, Money paidAmount, int?promotorId) { Money totalAmount = this.Price * quantity; if (totalAmount <= Money.Zero) { throw new MsgException(U5006.AMOUNTEQUALZERO); } if (paidAmount < totalAmount) { throw new MsgException(L1.NOTENOUGHFUNDS); } MarketplaceMember mBuyer; if (Member.Exists(username)) { Member user = new Member(username); mBuyer = new MarketplaceMember(emailAddress, deliveryAddress, user.Name, user.Id); } else { mBuyer = new MarketplaceMember(emailAddress, deliveryAddress); } if (promotorId != null) { Member promotor = new Member((int)promotorId); var amount = totalAmount * AppSettings.Marketplace.MarketplacePromoteCommission / 100; promotor.AddToMainBalance(amount, "Marketplace commission"); promotor.SaveBalances(); } MarketplaceIPN.Create(mBuyer, quantity, this); this.Quantity -= quantity; this.Sold += quantity; this.Save(); History.AddPurchase(mBuyer.Name, totalAmount, "Marketplace purchase"); }
public void Reject() { this.Status = WithdrawRequestStatus.Rejected; this.Save(); var user = new Member(UserId); if (WithdrawalSourceBalance == WithdrawalSourceBalance.MainBalance) { user.MoneyCashout -= AmountWithFee; user.AddToMainBalance(AmountWithFee, CryptocurrencyObject.Code + " withdrawal rejected"); } else { user.MoneyCashout -= CryptocurrencyObject.ConvertToMoney(AmountWithFee.ToDecimal()); user.AddToCryptocurrencyBalance(Cryptocurrency, AmountWithFee.ToDecimal(), CryptocurrencyObject.Code = " withdrawal rejected"); } user.Save(); }
public static void TryToCreditReferrerAfterPurchase(Member user, Money price, string defaultNote = "PTC purchase") { if (user.HasReferer) { var note = string.Format("{0} /ref/{1}", defaultNote, user.Name); var referer = new Member(user.ReferrerId); var commission = Money.MultiplyPercent(price, referer.Membership.PTCPurchaseCommissionPercent); if (commission == Money.Zero) { return; } if (AppSettings.Payments.CommissionBalanceEnabled) { referer.AddToCommissionBalance(commission, note); } else { referer.AddToMainBalance(commission, note); } referer.IncreaseEarnings(commission); referer.IncreaseEarningsFromDirectReferral(commission); referer.StatsCommissionsCurrentWeekIncome += commission; referer.StatsCommissionsCurrentMonthIncome += commission; referer.SaveStatisticsAndBalances(); try { if (AppSettings.Emails.NewReferralCommisionEnabled) { Mailer.SendNewReferralCommisionMessage(referer.Name, user.Name, commission, referer.Email, note); } } catch (Exception ex) { ErrorLogger.Log(ex); } } }
public static void GivePrize(int rankId, Member user) { var rank = RankList.Find(e => e.Id == rankId); switch (rank.PrizeKind) { case PrizeKind.MainBalance: user.AddToMainBalance(new Money(int.Parse(rank.PrizeValue)), "LeadershipSystem Rank " + rank.RankName); user.SaveBalances(); break; case PrizeKind.Points: user.AddToPointsBalance(int.Parse(rank.PrizeValue), "LeadershipSystem Rank " + rank.RankName, BalanceLogType.Other, true, false); user.SaveBalances(); break; case PrizeKind.CustomPrize: //NOTHING break; } }
/// <summary> /// FROM AP /// </summary> /// <param name="request"></param> public static void RejectRequest(PayoutRequest request) { Member User = new Member(request.Username); try { PaymentProcessor processor = PaymentAccountDetails.GetFromStringType(request.PaymentProcessor); PaymentProportionsManager.UndoMemberPaidOut(request.Amount, processor, User); } catch { //processor = custom processor } request.IsPaid = true; request.PaymentProcessor = "REJECTED"; request.Save(); User.MoneyCashout -= request.Amount; User.AddToMainBalance(request.Amount, "Payout rejected"); User.Save(); History.AddCashoutRejection(User.Name, request.Amount.ToString()); }
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); } }
private void CreditAncestor(Member ancestor, Money servicePrice, decimal percentage, MatrixLeg leg) { try { if (percentage <= 0) { return; } Money bonus = Money.MultiplyPercent(servicePrice, percentage); //We are adding to left or right leg if (leg == MatrixLeg.Left) { ancestor.MatrixBonusMoneyFromLeftLeg += bonus; } else { ancestor.MatrixBonusMoneyFromRightLeg += bonus; } if (ancestor.MatrixBonusMoneyFromLeftLeg > AppSettings.Matrix.MatrixCyclesBonusMoneyFromLeg && ancestor.MatrixBonusMoneyFromRightLeg > AppSettings.Matrix.MatrixCyclesBonusMoneyFromLeg) { int cyclesPerDay = -1; if (AppSettings.Matrix.MatrixCyclesFromRank) { LeadershipRank rank = ancestor.GetRank(); cyclesPerDay = rank != null ? rank.MatrixCyclesPerDay : cyclesPerDay; } else { cyclesPerDay = AppSettings.Matrix.MatrixCyclesPerDay; } //We cycle or flush out if (ancestor.MatrixBonusMoneyCyclesToday < cyclesPerDay) { ancestor.MatrixBonusMoneyCyclesToday++; ancestor.MatrixBonusMoneyFromLeftLeg -= AppSettings.Matrix.MatrixCyclesBonusMoneyFromLeg; ancestor.MatrixBonusMoneyFromRightLeg -= AppSettings.Matrix.MatrixCyclesBonusMoneyFromLeg; if (TitanFeatures.IsTrafficThunder) { ancestor.AddToCommissionBalance(AppSettings.Matrix.MatrixCyclesPrizeMoney, "Matrix Cycle bonus"); } else { ancestor.AddToMainBalance(AppSettings.Matrix.MatrixCyclesPrizeMoney, "Matrix Cycle bonus"); } ancestor.IncreaseMetrixBonusEarnings(AppSettings.Matrix.MatrixCyclesPrizeMoney); ancestor.Save(); } else { //We flush ancestor.MatrixBonusMoneyFromLeftLeg = Money.Zero; ancestor.MatrixBonusMoneyFromRightLeg = Money.Zero; ancestor.SaveMatrixId(); } } else { ancestor.SaveMatrixId(); } } catch (Exception ex) { ErrorLogger.Log(ex); } }
private void TryCreditDirectReferer(PtcAdvert ad) { if (!User.HasReferer || TitanFeatures.IsGambinos && User.MembershipId == 1) { return; } Member referer = new Member(User.ReferrerId); if (referer.IsRented) { return; } if (referer.HasClickedEnoughToProfitFromReferrals()) { Money amountToCredit = PtcAdvert.CalculateEarningsFromDirectReferral(referer.Membership, ad); if (AppSettings.Payments.CommissionBalanceEnabled) { referer.AddToCommissionBalance(amountToCredit, "PTC /ref/" + User.Name, BalanceLogType.Other); } else { referer.AddToMainBalance(amountToCredit, "PTC /ref/" + User.Name, BalanceLogType.Other); } referer.IncreaseEarnings(amountToCredit); referer.IncreaseEarningsFromDirectReferral(amountToCredit); referer.IncreaseDRClicks(); referer.IncreaseStatClicks(1); referer.IncreaseDRCashLinksEarnings(amountToCredit); referer.StatsCommissionsCurrentWeekIncome += amountToCredit; referer.StatsCommissionsCurrentMonthIncome += amountToCredit; var pointsEarnings = referer.Membership.DirectReferralAdvertClickEarningsPoints; referer.AddToPointsBalance(pointsEarnings, "PTC /ref/" + User.Name); referer.IncreaseDirectRefPointsEarnings(pointsEarnings); referer.IncreasePointsEarnings(pointsEarnings); User.TotalPTCClicksToDReferer += 1; User.TotalEarnedToDReferer += amountToCredit; User.LastDRActivity = AppSettings.ServerTime; User.TotalPointsEarnedToDReferer += pointsEarnings; User.SaveStatisticsAndBalances(); bool isFullSaveRequired1 = false; bool isFullSaveRequired2 = false; //Achievements trial isFullSaveRequired1 = referer.TryToAddAchievements( Prem.PTC.Achievements.Achievement.GetProperAchievements( Prem.PTC.Achievements.AchievementType.AfterClicks, referer.TotalClicks + 1)); string inter = (referer.TotalEarned + amountToCredit).ToClearString(); Decimal tempMoney = Decimal.Parse(inter, new System.Globalization.CultureInfo("en-US")); isFullSaveRequired2 = referer.TryToAddAchievements( Prem.PTC.Achievements.Achievement.GetProperAchievements( Prem.PTC.Achievements.AchievementType.AfterEarning, Convert.ToInt32(tempMoney))); if (isFullSaveRequired1 || isFullSaveRequired2) { referer.Save(); } else { referer.SaveStatisticsAndBalances(); } } }
public static void TryToBet(Money maxProfit, Money minBet, decimal formChance, Money formBetAmount, int houseEdge, Money formProfit, bool low) { if (formBetAmount < minBet) { throw new MsgException(U4200.BETTOOLOW + " " + minBet); } else if (formChance <= 0) { throw new MsgException(U4200.CHANCEBELOWZERO); } else if (formChance > AppSettings.DiceGame.MaxChance) { throw new MsgException(U4200.CHANCETOOHIGH); } Money houseProfit = formBetAmount * houseEdge / formChance; if (formProfit > maxProfit) { throw new MsgException(U4200.PROFITTOOHIGH + " " + maxProfit); } else if (formProfit <= Money.Zero) { throw new MsgException(U4200.PROFITBELOWZERO); } else if (houseProfit < new Money(0.00000001)) { throw new MsgException(U4200.HOUSEPROFITTOOLOW); } Member User = Member.Current; DiceGameHash CurrentDiceGameHash = DiceGameHash.Get(User); UserBet Bet = new UserBet(); Bet.UserId = User.Id; if (User.PurchaseBalance < formBetAmount) { throw new MsgException(L1.NOTENOUGHFUNDS); } string serverSeed = CurrentDiceGameHash.ServerSeedCurrent; string clientSeed = CurrentDiceGameHash.ClientSeedCurrent; string salt = DiceGameHashLogic.GenerateSalt(clientSeed, Bet.UserId); string hashToCompute = DiceGameHashLogic.ComputeHash(salt, serverSeed); decimal diceRoll = RollTheDice(hashToCompute); bool hasWon = HasWon(formChance, low, diceRoll); string query; Bet.BetSize = formBetAmount; Bet.BetDate = DateTime.Now; Bet.Chance = formChance; Bet.Low = low; if (hasWon) { Bet.Profit = formProfit; User.AddToMainBalance(Bet.Profit, "Dice bet win", BalanceLogType.Other); query = SiteInvestmentManager.GetUpdateAmountQuery(formProfit.Negatify()); //To do: should investors lose money based on betsize or profit? //AppSettings.DiceGame.HouseProfit += (houseProfit); } else { Bet.Profit = Bet.BetSize.Negatify(); User.SubtractFromPurchaseBalance(Bet.BetSize, "Dice bet lose", BalanceLogType.Other); query = SiteInvestmentManager.GetUpdateAmountQuery(formBetAmount); //AppSettings.DiceGame.HouseProfit += ((0.01m * formBetAmount)); } Bet.Roll = diceRoll; Bet.Save(); string clearTableQuery = " DELETE FROM SiteInvestments WHERE Amount = 0;"; TableHelper.ExecuteRawCommandNonQuery(query + clearTableQuery); AppSettings.DiceGame.Save(); User.SaveBalances(); }
protected static void CreditMainBalanceHelper(ref Member User, Money Input, string note, BalanceLogType balanceLogType) { User.AddToMainBalance(Input, note, balanceLogType); User.IncreaseEarnings(Input); }
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)); } }
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"); } }
private void HandleOwnerUser(Member OwnerUser, PtcAdvert Ad, bool FiredByDirectReferral = false, Member WhoFired = null) { bool CreditMoney = OwnerUser.HasClickedEnoughToProfitFromReferrals(); //Check if earning only from Standard and Extended is enabled //TO REMOVE if (CreditMoney && AppSettings.Misc.ExposureRefEarningsEnabled) { if (Ad.ExposureType == AdExposure.Standard || Ad.ExposureType == AdExposure.Extended) { CreditMoney = true; } else { CreditMoney = false; } } if (CreditMoney) { var Earnings = FiredByDirectReferral ? PtcAdvert.CalculateEarningsFromDirectReferral(OwnerUser, Ad) : PtcAdvert.CalculateEarningsFromRentedReferral(OwnerUser, Ad); if (FiredByDirectReferral) { OwnerUser.AddToMainBalance(Earnings, "PTC /ref/" + Username, BalanceLogType.Other); } else { OwnerUser.AddToMainBalance(Earnings, "PTC /ref/", BalanceLogType.Other); } bool isFullSaveRequired1 = false; bool isFullSaveRequired2 = false; //Achievements trial isFullSaveRequired1 = OwnerUser.TryToAddAchievements( Prem.PTC.Achievements.Achievement.GetProperAchievements( Prem.PTC.Achievements.AchievementType.AfterClicks, OwnerUser.TotalClicks + 1)); string inter = (OwnerUser.TotalEarned + Earnings).ToClearString(); Decimal tempMoney = Decimal.Parse(inter, new System.Globalization.CultureInfo("en-US")); isFullSaveRequired2 = OwnerUser.TryToAddAchievements( Prem.PTC.Achievements.Achievement.GetProperAchievements( Prem.PTC.Achievements.AchievementType.AfterEarning, Convert.ToInt32(tempMoney))); OwnerUser.IncreaseEarnings(Earnings); OwnerUser.IncreaseStatClicks(1); if (FiredByDirectReferral) { var pointsEarnings = OwnerUser.Membership.DirectReferralAdvertClickEarningsPoints; OwnerUser.AddToPointsBalance(pointsEarnings, "PTC /ref/" + Username); OwnerUser.IncreaseDRClicks(); OwnerUser.IncreaseEarningsFromDirectReferral(Earnings); if (WhoFired != null) { WhoFired.TotalPTCClicksToDReferer += 1; WhoFired.TotalEarnedToDReferer += Earnings; WhoFired.SaveStatisticsAndBalances(); } } else { OwnerUser.IncreaseRRClicks(); } if (isFullSaveRequired1 || isFullSaveRequired2) { OwnerUser.Save(); } else { OwnerUser.SaveStatisticsAndBalances(); } } else { OwnerUser.IncreaseStatClicks(1); if (FiredByDirectReferral) { var Earnings = PtcAdvert.CalculateEarningsFromDirectReferral(OwnerUser, Ad); OwnerUser.AddToMainBalance(Earnings, "PTC /ref/" + Username, BalanceLogType.Other); OwnerUser.IncreaseEarnings(Earnings); var pointsEarnings = OwnerUser.Membership.DirectReferralAdvertClickEarningsPoints; OwnerUser.AddToPointsBalance(pointsEarnings, "PTC /ref/" + Username); OwnerUser.IncreaseDRClicks(); OwnerUser.TotalEarned += Earnings; if (WhoFired != null) { WhoFired.TotalPTCClicksToDReferer += 1; WhoFired.TotalEarnedToDReferer += Earnings; WhoFired.LastDRActivity = AppSettings.ServerTime; WhoFired.SaveStatisticsAndBalances(); } } else { OwnerUser.IncreaseRRClicks(); } OwnerUser.SaveStatisticsAndBalances(); } }