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); }
public Money CreditMember(TrafficExchangeAdvert Ad) { try { var referer = new Member(User.ReferrerId); Money DRCaltulated = TrafficExchangeAdvert.CalculateEarningsFromDirectReferralTE(referer, Ad); referer.AddToTrafficBalance(DRCaltulated, "Referrals Traffic Exchange", BalanceLogType.Other); referer.SaveBalances(); } catch (Exception e) { } Money Calculated = TrafficExchangeAdvert.CalculateNormalMemberEarningsTE(User, Ad); User.AddToTrafficBalance(Calculated, "Traffic Exchange", BalanceLogType.Other); User.SaveBalances(); return(Calculated); }
/// <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(); }
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); } }); }
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)); } }
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); } }
protected void CreateAdButton_Click(object sender, EventArgs e) { ErrorMessagePanel.Visible = false; SuccMessagePanel.Visible = false; if (Page.IsValid) { try { AppSettings.DemoCheck(); Member User = null; int oldPackId = 0; if (Member.IsLogged) { User = Member.Logged(Context); } if (URL.Enabled) { throw new MsgException(U4200.CHECKURL); } PtcAdvert Ad; if (PageRequest == RequestType.Edit) { int adId = Convert.ToInt32(ViewState["editid"]); Ad = new PtcAdvert(adId); oldPackId = Ad.Pack.Id; } else { Ad = new PtcAdvert(); } Money AdCost = Money.Zero; PtcAdvertPack Pack = new PtcAdvertPack(); GetAdWithPrice(ref Ad, ref AdCost, ref Pack); //Add the ad to the db (for approval) Ad.Price = AdCost; if (Pack != null) { Ad.Pack = Pack; } if (Member.IsLogged) { //Take money and save the user int adViews = 0; if (AppSettings.PtcAdverts.PTCCreditsEnabled && UseExtraViewsCheckBox.Checked) { adViews = Convert.ToInt32(PTCCreditsTextBox.Text); if (adViews < 0) { throw new MsgException("Input cannot be negative."); } decimal adCreditsSpent = 0; var creditsPerDayOrClick = 0m; if (Pack == null) { if (TitanFeatures.isSatvetErturkmen) { PtcAdvertPack advertPack = TableHelper.GetListFromRawQuery <PtcAdvertPack>("SELECT TOP 1 * FROM PtcAdvertPacks")[0]; Ad.Pack = advertPack; Ad.Ends = End.FromClicks(adViews); creditsPerDayOrClick = advertPack.PTCCreditsPerDayOrClick; } } else { Ad.Ends = Ad.Ends.AddValue(adViews); creditsPerDayOrClick = Pack.PTCCreditsPerDayOrClick; } if (PageRequest == RequestType.Edit && Ad.ExtraViews != -1) { adCreditsSpent = (adViews - Ad.ExtraViews) * creditsPerDayOrClick; if (adCreditsSpent < 0) { adCreditsSpent = 0; } } else { adCreditsSpent = adViews * creditsPerDayOrClick; } Ad.ExtraViews = adViews; if (adCreditsSpent > Member.Current.PTCCredits) { throw new MsgException(U5006.NOTENOUGHADCREDITS); } else { User.SubstractFromPTCCredits(adCreditsSpent, "PTC advert"); } } else { Ad.ExtraViews = -1; } if (PageRequest == RequestType.Edit) { Ad.IsEdited = true; } Ad.TargetBalance = TargetBalanceRadioButtonList.TargetBalance; PurchaseOption.ChargeBalance(User, AdCost, TargetBalanceRadioButtonList.Feature, Ad.TargetBalance, PageRequest == RequestType.Edit ? "PTC update" : "PTC advert"); Ad.Advertiser = Advertiser.AsMember(User.Name); Ad.AdvertiserUserId = User.Id; Ad.Status = AdvertStatusExtensions.GetStartingStatus(); if (AppSettings.PtcAdverts.AdvertPTCPackCashbackEnabled && Pack.PTCPackCashBackPercent != 0) { Money CashBack = new Money(Double.Parse(AdCost.ToClearString()) * ((Double)Pack.PTCPackCashBackPercent / 100.0)); User.AddToTrafficBalance(CashBack, U6010.PTCCASHBACK); User.Save(); } } else { Ad.Advertiser = Advertiser.AsStranger(OutEmail.Text); Ad.TargetBalance = PurchaseBalances.PaymentProcessor; Ad.Status = AdvertStatus.Null; } if (oldPackId != 0 && oldPackId != Ad.Pack.Id) { Ad.ResetClicks(); } Ad.Save(); if (Member.IsLogged) { //Achievements trial int UserCurrentCampaigns = TableHelper.CountOf <PtcAdvert>(TableHelper.MakeDictionary("CreatorUsername", User.Name)); bool ShouldBeSaved = User.TryToAddAchievements( Prem.PTC.Achievements.Achievement.GetProperAchievements( Prem.PTC.Achievements.AchievementType.AfterAdvertisingPtcCampaigns, UserCurrentCampaigns)); if (ShouldBeSaved) { User.Save(); } if (PageRequest == RequestType.Edit) { History.AddEdit(User.Name, AdCost, "Advert campaign"); } else { History.AddPurchase(User.Name, AdCost, "Advert campaign"); MatrixBase.TryAddMemberAndCredit(User, AdCost, AdvertType.PTC); } if (Ad.Status != AdvertStatus.WaitingForAcceptance) { PtcCrediter.TryToCreditReferrerAfterPurchase(User, AdCost, PageRequest == RequestType.Edit ? "PTC update" : "PTC advert"); } Title.Text = ""; URL.Text = ""; chbDescription.Checked = false; chbGeolocation.Checked = false; chbBold.Checked = false; BackgroundColorCheckBox.Checked = false; StarredAdCheckBox.Checked = false; SuccMessagePanel.Visible = true; if (PageRequest == RequestType.Edit) { SuccMessage.Text = Ad.Status == AdvertStatus.WaitingForAcceptance ? U6012.EDITEDADAWAITSAPPROVAL : U6012.ADUPDATED; } else { SuccMessage.Text = Ad.Status == AdvertStatus.WaitingForAcceptance ? U4200.ADAWAITSAPPROVAL : U3501.ADCREATED; } } else { //Show buttons PaymentButtons.Visible = true; CreateAdButton.Visible = false; PaymentButtons.Text = GenerateHTMLButtons.GetPaymentButtons(new BuyAdvertButtonGenerator <IPtcAdvertPack>(Ad)); } ViewState["editid"] = null; } catch (MsgException ex) { ErrorMessagePanel.Visible = true; ErrorMessage.Text = ex.Message; } catch (Exception ex) { ErrorLogger.Log(ex); } } }