public static SyncedNetwork Acquire(AffiliateNetwork Network, bool ThrowExceptions = false) { switch (Network.AffiliateNetworkSoftwareType) { case AffiliateNetworkSoftwareType.CPALead: return(new CPALeadSyncedNetwork(Network, ThrowExceptions)); case AffiliateNetworkSoftwareType.Performa: return(new PerformaManager(Network, ThrowExceptions)); case AffiliateNetworkSoftwareType.AdGateMedia: return(new AdGateSyncedNetwork(Network, ThrowExceptions)); case AffiliateNetworkSoftwareType.ProLeadsMedia: return(new ProLeadsMediaSyncedNetwork(Network, ThrowExceptions)); case AffiliateNetworkSoftwareType.PointClickTrack: return(new PointClickTrackSyncedNetwork(Network, ThrowExceptions)); case AffiliateNetworkSoftwareType.HasOffers: return(new HasOffersSyncedNetwork(Network, ThrowExceptions)); case AffiliateNetworkSoftwareType.RedFireNetwork: return(new RedFireNetworkSyncedNetwork(Network, ThrowExceptions)); } return(new PerformaManager(Network, ThrowExceptions)); }
private static CreditAs GetCreditAs(CPAOffer Offer, AffiliateNetwork Network) { if (Offer.CreditOfferAs == CreditOfferAs.NetworkDefault) { return(Network.CreditAs); } if (Offer.CreditOfferAs == CreditOfferAs.NonCash) { return(CreditAs.Points); } return(CreditAs.MainBalance); }
private static PostbackActionType GetActionType(AffiliateNetwork Network, Money Balance, string _CreditVal) { if ((_CreditVal != null && _CreditVal == Network.VariableValueOfTypeReversed) || (_CreditVal == null && Balance < new Money(0))) { return(PostbackActionType.Reverse); } if ((_CreditVal != null && _CreditVal == Network.VariableValueOfTypeCredited) || (_CreditVal == null && Balance >= new Money(0))) { return(PostbackActionType.Credit); } return(PostbackActionType.None); }
public static void ProcessRequest(HttpContext context) { try { string RequestIP = IP.Current; //Log string LogMessage = context.Request.Params.ToRawString(); ErrorLogger.Log(LogMessage, LogType.CPAGPTNetworks); AppSettings.Points.Reload(); //Get proper Network string Hash = CPAFileManager.GetHashFromClientHandlerHit(context); AffiliateNetwork Network = TableHelper.SelectRows <AffiliateNetwork>(TableHelper.MakeDictionary("Hash", Hash))[0]; //All OK string Username = GetFromRequest(context, Network.VariableNameOfUsername); //string _Balance = GetFromRequest(context, Network.VariableNameOfBalance); string OfferID = GetFromRequest(context, Network.VariableNameOfOfferId); string _WebsiteId = GetFromRequest(context, Network.VariableNameOfWebsiteId); //Can be null string OfferTitle = GetFromRequest(context, Network.VariableNameOfOfferName); //Can be null string _CreditVal = GetFromRequest(context, Network.VariableNameOfType); //Can be null string Signature = GetFromRequest(context, Network.VariableNameOfSignature); //Can be null string UserIP = GetFromRequest(context, Network.VariableNameOfMemberIP); //Can be null string ShortOfferTitle = OfferTitle != null ? ": " + ShortenString(OfferTitle, 8) + "..." : ""; string TrackingInfo = OfferID; bool isLocked = false; //Points Locking feature Money Balance = new Money(0); //try //{ // Balance = Money.Parse(_Balance); //} //catch (Exception ex) { } //Check Status and IP restrictions bool ActiveRestriction = Network.Status == NetworkStatus.Active; bool IPRestriction = !Network.HasRestrictedIPs || (Network.HasRestrictedIPs && Network.RestrictedIPs.Contains(RequestIP)); if (ActiveRestriction && IPRestriction) { //Check condition if (Signature == null || Signature.Trim() == CPAParser.ParseSignatureCondition(Network.SIgnatureCondition, context).Trim()) { //All OK, Verified CPAPostBackLogStatus Status = CPAPostBackLogStatus.Null; Money Calculated = new Money(0); //Let's get our offer CPAOffer OurOffer = null; try { var where = TableHelper.MakeDictionary("NetworkOfferIdInt", OfferID); where.Add("AdvertiserUsername", Network.Name); where.Add("Status", (int)AdvertStatus.Active); OurOffer = TableHelper.SelectRows <CPAOffer>(where)[0]; Balance = OurOffer.BaseValue; } catch (Exception ex) { ErrorLogger.Log(ex); } if (OurOffer != null) { //Lets find submission try { Member User = new Member(Username); CreditAs As = GetCreditAs(OurOffer, Network); PostbackActionType ActionType = CPAHandler.GetActionType(Network, Balance, _CreditVal); var conditions = TableHelper.MakeDictionary("Username", Username); conditions.Add("OfferId", OurOffer.Id); conditions.Add("OfferStatus", (int)OfferStatus.Pending); int IsSubmissionPresent = TableHelper.CountOf <OfferRegisterEntry>(conditions); //Add submission automatically if credit and not found if (IsSubmissionPresent == 0 && ActionType == PostbackActionType.Credit) { OfferRegisterEntry.CheckDuplicateAndStatus(User.Name, OurOffer, true); OfferRegisterEntry.AddNew(OurOffer, User.Name, OfferStatus.Pending, String.Empty, String.Empty); IsSubmissionPresent = TableHelper.CountOf <OfferRegisterEntry>(conditions); } if (IsSubmissionPresent > 0) { OfferRegisterEntry ThisEntry = TableHelper.SelectRows <OfferRegisterEntry>(conditions)[0]; if (ActionType == PostbackActionType.Reverse) { CPAPostbackLog oldLog = PointsLockingHelper.FindSimilarCpaLog(User.Name, Network.Name, TrackingInfo); if (oldLog == null) { Calculated = CPAManager.DenyEntryFromPostback(ThisEntry, Balance, As, OurOffer.Id, Network.Name, OfferTitle, Network.RequiresConversion); Status = CPAPostBackLogStatus.ReversedByNetwork; } else { Status = CPAPostBackLogStatus.ReversedByNetwork; oldLog.Status = Status; CPAManager.DenyEntry(ThisEntry, User, OfferTitle); } } if (ActionType == PostbackActionType.Credit) { if (PointsLockingManager.CPAGPTShouldBeLocked(Balance, As, User, Network.RequiresConversion)) { ThisEntry.HasBeenLocked = true; ThisEntry.Save(); Calculated = CPAGPTCrediter.CalculatePostback(Balance, Network.RequiresConversion, User, As); Status = CPAPostBackLogStatus.CreditedAndPointsLocked; History.AddOfferLocked(User.Name, Network.Name, OfferTitle, Calculated, As); } else { var where = TableHelper.MakeDictionary("Id", ThisEntry._OfferId); var CpaOffer_entryId = TableHelper.SelectRows <CPAOffer>(where); Calculated = CPAManager.AcceptEntryFromPostback(ThisEntry, Balance, As, OurOffer.Id, Network.Name, CpaOffer_entryId[0].Title, Network.RequiresConversion, out isLocked); Status = CPAPostBackLogStatus.CreditedByNetwork; } } //Add CPAPostbackLog CPAPostbackLog.Create(Network, Username, Balance, Calculated, TrackingInfo, Status); //If All was handled OK, than succResponse context.Response.Write(Network.ValueOfSuccessfulResponse); } else { CPAPostbackLog.Create(Network, Username, Balance, Calculated, TrackingInfo, CPAPostBackLogStatus.SubmissionNotFound); } } catch (MsgException ex) { //Offer has been already submited and it's not daily //Offer is daily, but was submited today //Offer is daly and can be submited X times a day, but was submited >= X today CPAPostbackLog.Create(Network, Username, Balance, Calculated, TrackingInfo, CPAPostBackLogStatus.ExceededSubmissionLimitForThisOffer); context.Response.Write(Network.ValueOfSuccessfulResponse); } catch (Exception ex) { ErrorLogger.Log(ex); CPAPostbackLog.Create(Network, Username, Balance, Calculated, TrackingInfo, CPAPostBackLogStatus.Null); } } else { CPAPostbackLog.Create(Network, Username, Balance, null, TrackingInfo, CPAPostBackLogStatus.OfferNotFoundByOfferId); } } else { CPAPostbackLog.Create(Network, Username, Balance, null, TrackingInfo, CPAPostBackLogStatus.WrongSignature); } } else if (IPRestriction) { CPAPostbackLog.Create(Network, Username, Balance, null, TrackingInfo, CPAPostBackLogStatus.NetworkInactive); } else if (ActiveRestriction) { CPAPostbackLog.Create(Network, Username, Balance, null, TrackingInfo, CPAPostBackLogStatus.SentFromUnallowedIP); } } catch (Exception ex) { Prem.PTC.ErrorLogger.Log(ex); } }
public static void HandleAddition(string name, string description, string rate, string banner, string url, string incent, string countriesCC, AffiliateNetwork Network, string id, List <CPAOfferOnHold> OnHoldList, ref bool AreSomeRecordsInQuery, ref StringBuilder Query, string geolocatedCities = null, int ageMin = 0, int ageMax = 0, Gender gender = Gender.Null) { CPAOfferOnHold ThisOffer = SyncedNetwork.HasThisOffer(OnHoldList, id, name); if (ThisOffer != null) { //We have it, just change the status ThisOffer.Status = AdvertStatus.WaitingForAcceptance; } else { AreSomeRecordsInQuery = true; //Preparte the variables to fit database Money UserRate = Money.Zero; try { if (rate.Contains(".")) { UserRate = Money.Parse(rate); } else { UserRate = Money.Parse(rate + ".0"); } UserRate = Money.MultiplyPercent(UserRate, Network.DefaultPercentForMembers); } catch (Exception ex) { } if (name.Length > 50) { name = name.Substring(0, 49); } if (!string.IsNullOrEmpty(banner) && banner.Length > 150) { banner = banner.Substring(0, 149); } //We need to add it CPAOfferOnHold NewOffer = new CPAOfferOnHold(); NewOffer.IsFromAutomaticNetwork = true; NewOffer.NetworkOfferId = id; NewOffer.Title = InputChecker.HtmlEncode(name); NewOffer.ImageURL = banner; NewOffer.TargetURL = url; NewOffer.DateAdded = DateTime.Now; NewOffer.Status = AdvertStatus.Active; NewOffer.AdvertiserUsername = Network.Name; NewOffer.LoginBoxRequired = false; NewOffer.EmailBoxRequired = false; NewOffer.LastCredited = OffersManager.DateTimeZero; NewOffer.Description = InputChecker.HtmlEncode(description); NewOffer.Category = new CPACategory(CPACategory.DEFAULT_CATEGORY_ID); NewOffer.BaseValue = UserRate; NewOffer.CreditsBought = 1000000; //Infinity NewOffer.NetworkName = Network.Name; NewOffer.NetworkRate = rate; NewOffer.IsSyncWithNetwork = false; // by default NewOffer.IsDaily = false; NewOffer.MaxDailyCredits = 1; NewOffer.AddGeolocation(new GeolocationUnit(countriesCC, geolocatedCities, ageMin, ageMax, gender)); if (incent.Trim().ToUpper() == "NO") { NewOffer.CreditOfferAs = CreditOfferAs.NonCash; } else { NewOffer.CreditOfferAs = CreditOfferAs.NetworkDefault; } SyncedNetwork.ConstructInsertQuery(Query, NewOffer); } }
public SyncedNetwork(AffiliateNetwork Network, bool ThrowExceptions = false) { this.Network = Network; this.ThrowExceptions = ThrowExceptions; }