private Money CreditGeneral(Money Input, CreditAs As, string OfferwallName, bool RequiresConversion = false, bool IsReversal = false) { Money Calculated = Money.MultiplyPercent(Input, base.User.Membership.OfferwallsProfitPercent); //Conversion? if (RequiresConversion) { if (As == CreditAs.Points) { Calculated = new Money(PointsConverter.ToPoints(Calculated)); } if (As == CreditAs.MainBalance) { Calculated = PointsConverter.ToMoney(Calculated.ToDecimal()); } } if (As == CreditAs.Points) { base.CreditPoints(Calculated.GetRealTotals(), "CrowdFlower", BalanceLogType.Other); base.CreditReferersPoints(Calculated.GetRealTotals(), "CrowdFlower /ref/ " + User.Name, BalanceLogType.Other); } if (As == CreditAs.MainBalance) { base.CreditMainBalance(Calculated, "CrowdFlower", BalanceLogType.Other); base.CreditReferersMainBalance(Calculated, "CrowdFlower /ref/ " + User.Name, BalanceLogType.Other); } History.AddOfferwalCompleted(User.Name, OfferwallName, Calculated, As); return(Calculated); }
public Money CalculateManual(OfferRegisterEntry entry) { Money Calculated = Money.MultiplyPercent(entry.Offer.BaseValue, User.Membership.CPAProfitPercent); //Recalculate if needed if (entry.Offer.GetFinalCreditAs() == CreditAs.Points) { Calculated = new Money(PointsConverter.ToPoints(Calculated)); } return(Calculated); }
private int CalculateRefPointsEarnings(Member user, Money amount, int tier) { List <Commission> commissions = (List <Commission>) new CommissionsCache().Get(); var commission = commissions.FirstOrDefault(c => c.MembershipId == user.Membership.Id && c.RefLevel == tier); if (commission == null) { return(0); } var moneyAmount = Money.MultiplyPercent(amount, commission.PointsForAdPackPurchasePercent); var points = PointsConverter.ToPoints(moneyAmount); return(points); }
protected virtual void CreditReferersPoints(int input, String note, BalanceLogType balanceLogType, int level = 1, Member forcedUser = null) { if (AppSettings.Referrals.AreIndirectReferralsEnabled && level > AppSettings.Referrals.ReferralEarningsUpToTier) { return; } if (level == 1) { MoneySpent = Money.Zero; OriginalUser = User; } if (forcedUser != null) { User = forcedUser; } if (User.HasReferer) { Member referer = new Member(User.ReferrerId); if (referer.HasClickedEnoughToProfitFromReferrals()) { int calculated = PointsConverter.ToPoints(CalculateRefEarnings(referer, PointsConverter.ToMoney(input), level)); //Credit CreditPointsHelper(ref referer, calculated, note, balanceLogType); referer.IncreaseDirectRefPointsEarnings(calculated); referer.SaveStatisticsAndBalances(); User.TotalPointsEarnedToDReferer += calculated; User.SaveStatisticsAndBalances(); if (AppSettings.Referrals.AreIndirectReferralsEnabled) { CreditReferersPoints(input, note, balanceLogType, level + 1, referer); //change to Original user when leaving recurrence if (level == 1 && User.Id != OriginalUser.Id) { User = OriginalUser; } } } } }
public static Money CalculatedAndConversion(Money Input, Member member, Offerwall Wall) { Money Calculated = new Money(Input.ToDecimal()); //Money to Money in diffrent Currency if (Wall.WhatIsSent == WhatIsSent.Money && Wall.CreditAs == CreditAs.MainBalance && AppSettings.Site.CurrencyCode != Wall.CurrencyCode) { Calculated = Calculated.ExchangeFrom(Wall.CurrencyCode); } //Poinst to Money else if (Wall.WhatIsSent == WhatIsSent.Points && Wall.CreditAs == CreditAs.MainBalance) { if (AppSettings.Points.PointsEnabled && Wall.UseVirtualCurrencySetting) { Calculated = PointsConverter.ToMoney(Calculated.ToDecimal()); Calculated = Calculated.ExchangeFrom(Wall.CurrencyCode); } else { Calculated = PointsConverter.ToMoney(Calculated.ToDecimal(), Wall.MoneyToPointsRate.ToDecimal()); Calculated = Calculated.ExchangeFrom(Wall.CurrencyCode); } } //Money to Points else if (Wall.WhatIsSent == WhatIsSent.Money && Wall.CreditAs == CreditAs.Points) { Calculated = Calculated.ExchangeFrom(Wall.CurrencyCode); Calculated = new Money(PointsConverter.ToPoints(Calculated)); } //Points to Points in diffrent Currency else if (Wall.WhatIsSent == WhatIsSent.Points && Wall.CreditAs == CreditAs.Points && AppSettings.Site.CurrencyCode != Wall.CurrencyCode) { Calculated = PointsConverter.ToMoney(Calculated.ToDecimal(), Wall.MoneyToPointsRate.ToDecimal()); Calculated = Calculated.ExchangeFrom(Wall.CurrencyCode); Calculated = new Money(PointsConverter.ToPoints(Calculated)); } //No conversion //Modify by credit percentage Calculated = Money.MultiplyPercent(Calculated, Wall.CreditPercentage); ///Membership fee Calculated = Money.MultiplyPercent(Calculated, member.Membership.OfferwallsProfitPercent); return(Calculated); }
public static Money CalculatePostback(Money Input, bool RequiresConversion, Member member, CreditAs As) { Money Calculated = Money.MultiplyPercent(Input, member.Membership.CPAProfitPercent); if (RequiresConversion) { if (As == CreditAs.Points) { Calculated = new Money(PointsConverter.ToPoints(Calculated)); } if (As == CreditAs.MainBalance) { Calculated = PointsConverter.ToMoney(Calculated.GetRealTotals()); } } return(Calculated); }
protected Money CreditReferersMainAndPointBalance(Money input, String note, BalanceLogType balanceLogType, int level = 1, Member forcedUser = null, bool forceSave = true) { if (level == 1) { MoneySpent = Money.Zero; } if (AppSettings.Referrals.AreIndirectReferralsEnabled && level > AppSettings.Referrals.ReferralEarningsUpToTier) { return(MoneySpent); } if (forcedUser != null) { User = forcedUser; } if (User.HasReferer) { Member referer = new Member(User.ReferrerId); if (!MatrixBase.CanCreditReferer(User, referer)) { return(MoneySpent); } Money calculated = CalculateRefEarnings(referer, input, level); var points = CalculateRefPointsEarnings(referer, input, level); Money calculatedPoints = PointsConverter.ToMoney(points); //Representatives bonus calculated += Representative.IncreaseAmountForRepresentative(input, User, referer.Id, level); bool refererCredited = false; bool adminCommissionPoolCredited = false; if (AppSettings.RevShare.IsRevShareEnabled && referer.Id == AppSettings.RevShare.AdminUserId) { adminCommissionPoolCredited = PoolDistributionManager.AddProfit(ProfitSource.RevenueAdminCommissions, calculated + calculatedPoints); } if (!adminCommissionPoolCredited) { if (AppSettings.Misc.SpilloverEnabled && referer.Membership.Id == Membership.Standard.Id) { //Add commission to Revenue Pool instead of crediting member SpilloverManager.AddMoneyToRevenuePool(calculated); } //Credit else if (!AppSettings.Payments.CommissionBalanceEnabled) { CreditMainBalanceHelper(ref referer, calculated, note, balanceLogType); refererCredited = true; } else { CreditCommissionBalanceHelper(ref referer, calculated, note, balanceLogType); refererCredited = true; } if (calculatedPoints > Money.Zero) { CreditPointsHelper(ref referer, PointsConverter.ToPoints(calculatedPoints), note, BalanceLogType.AdPackPurchase); } } if (refererCredited) { referer.IncreaseAdPackEarningsFromDR(calculated + calculatedPoints); referer.IncreaseDirectRefPointsEarnings(points); referer.IncreaseEarningsFromDirectReferral(calculated); User.TotalAdPacksToDReferer += calculated + calculatedPoints; referer.SaveStatisticsAndBalances(); User.TotalPointsEarnedToDReferer += points; User.TotalEarnedToDReferer += calculated; } User.LastDRActivity = DateTime.Now; if (forceSave) { User.SaveStatisticsAndBalances(); } try { if (AppSettings.Emails.NewReferralCommisionEnabled && calculated + calculatedPoints != Money.Zero) { Mailer.SendNewReferralCommisionMessage(referer.Name, User.Name, calculated, referer.Email, note, points); } } catch (Exception ex) { ErrorLogger.Log(ex); } //Mailer //increase Money spent MoneySpent += calculated + calculatedPoints; //Indirect referrals don't get paid for CashLinks if (AppSettings.Referrals.AreIndirectReferralsEnabled) { return(CreditReferersMainAndPointBalance(input, note, balanceLogType, level + 1, referer)); } } return(MoneySpent); }