コード例 #1
0
        //From U-A
        //From AP
        //If you made any changes here, also change TryToCreditAllOffers() metod
        public static void AcceptEntryManually(OfferRegisterEntry entry, Member user)
        {
            CPAManager.AcceptEntry(entry, user);

            CPAGPTCrediter Crediter = (CPAGPTCrediter)CrediterFactory.Acquire(user, CreditType.CPAGPTOffer);

            Crediter.CreditManual(entry);

            entry.Offer.PerformStatusControlCheck();
        }
コード例 #2
0
        //From AP
        public static void ReverseEntry(OfferRegisterEntry Entry, Member User)
        {
            CPAManager.DenyEntry(Entry, User, Entry.Offer.Title);

            User.TotalCPACompleted -= 1;

            //Now return the money back
            CPAGPTCrediter Crediter = (CPAGPTCrediter)CrediterFactory.Acquire(User, CreditType.CPAGPTOffer);

            Crediter.ReverseManual(Entry);
        }
コード例 #3
0
        //From Postback
        public static Money DenyEntryFromPostback(OfferRegisterEntry entry, Money balance, CreditAs creditAs, int offerId,
                                                  string networkName, string offerTitle, bool requiresConversion)
        {
            Money  Calculated = new Money(0);
            Member User       = new Member(entry.Username);

            CPAManager.DenyEntry(entry, User, offerTitle);

            User.TotalCPACompleted -= 1;

            CPAGPTCrediter Crediter = (CPAGPTCrediter)CrediterFactory.Acquire(User.Name, CreditType.CPAGPTOffer);

            Calculated = Crediter.ReverseCreditFromPostback(balance, creditAs, networkName, offerId, offerTitle, requiresConversion);

            return(Calculated);
        }
コード例 #4
0
        //From Postback
        public static Money AcceptEntryFromPostback(OfferRegisterEntry entry, Money balance, CreditAs creditAs, int offerId,
                                                    string networkName, string offerTitle, bool requiresConversion, out bool isLocked)
        {
            Money  Calculated = new Money(0);
            Member User       = new Member(entry.Username);

            CPAManager.AcceptEntry(entry, User);
            CPAGPTCrediter Crediter = (CPAGPTCrediter)CrediterFactory.Acquire(User.Name, CreditType.CPAGPTOffer);

            Calculated = Crediter.CreditFromPostback(balance, creditAs, networkName, offerId, offerTitle, entry._OfferId, requiresConversion);

            //isLocked = Crediter.isLocked;
            isLocked = false; //TODO

            return(Calculated);
        }
コード例 #5
0
        public static void TryToCreditAllOffers()
        {
            //Get all nonLocked Entries
            var entriesQuery = string.Format(@"SELECT * FROM OfferRegisterEntries WHERE OfferStatus = {0} OR OfferStatus = {1} AND HasBeenLocked = 0",
                                             (int)OfferStatus.Pending, (int)OfferStatus.UnderReview);
            var entriesList = TableHelper.GetListFromRawQuery <OfferRegisterEntry>(entriesQuery).OrderBy(x => x.Username);

            Member user = null;

            //Creadit all Entries
            foreach (var entry in entriesList)
            {
                if (user == null || (user == null && user.Name != entry.Username))
                {
                    user = new Member(entry.Username);
                }

                CPAGPTCrediter Crediter = (CPAGPTCrediter)CrediterFactory.Acquire(user, CreditType.CPAGPTOffer);
                Crediter.CreditManual(entry);
            }

            //Change status of credited offers
            var changeCPAOffersStatusQuery = string.Format(@"
                        WITH CTE AS 
                            (SELECT OfferId, COUNT(*) As CounfOfDone FROM OfferRegisterEntries WHERE OfferStatus IN ({0}, {1}, {2}) GROUP BY OfferId),
                        CTE2 AS
                            (SELECT OfferId, COUNT(*) As CounfOfCompleted FROM OfferRegisterEntries WHERE OfferStatus = {0} GROUP BY OfferId)
                        UPDATE CPAOffers 
                            SET [Status] = (SELECT CASE 
                                WHEN(Id IN (SELECT OfferId FROM CTE) AND CreditsBought > (SELECT CounfOfDone FROM CTE WHERE OfferId = Id) and [Status] = {4})
                                    THEN {3}
                                WHEN(Id IN (SELECT OfferId FROM CTE) AND CreditsBought <= (SELECT CounfOfDone FROM CTE WHERE OfferId = Id) and [Status] = {3})
                                    THEN {4}
                                WHEN(Id IN (SELECT OfferId FROM CTE) AND CreditsBought <= (SELECT CounfOfCompleted FROM CTE2 WHERE OfferId = Id) and [Status] != {5})
                                    THEN {5}
                                ELSE [Status]
                                END) ",
                                                           (int)OfferStatus.Completed, (int)OfferStatus.Pending, (int)OfferStatus.UnderReview,
                                                           (int)AdvertStatus.Active, (int)AdvertStatus.Stopped, (int)AdvertStatus.Finished);

            //Increase Users TotalCPACompleted
            var increaseUsersTotalCPACompletedQuery = string.Format(@"
                        WITH CTE AS 
                            (SELECT Username, COUNT(*) AS CountOf FROM OfferRegisterEntries WHERE OfferStatus = {0} OR OfferStatus = {1} GROUP BY username)
                        UPDATE Users 
                            SET TotalCPACompleted += (SELECT CountOf FROM CTE WHERE Username = Users.Username)
                            WHERE Username IN 
                                (SELECT Username from CTE)",
                                                                    (int)OfferStatus.Pending, (int)OfferStatus.UnderReview);

            //Update status of completed entries
            var updateEntriesQuery = string.Format(@"
                        UPDATE OfferRegisterEntries 
                            SET OfferStatus = {0}, CompletedDate = GETDATE() WHERE OfferStatus = {1} OR OfferStatus = {2} AND HasBeenLocked = 0",
                                                   (int)OfferStatus.Completed, (int)OfferStatus.Pending, (int)OfferStatus.UnderReview);

            //Executing Queries in the correct order
            TableHelper.ExecuteRawCommandNonQuery(changeCPAOffersStatusQuery);
            TableHelper.ExecuteRawCommandNonQuery(increaseUsersTotalCPACompletedQuery);
            TableHelper.ExecuteRawCommandNonQuery(updateEntriesQuery);
        }
コード例 #6
0
ファイル: CPAHandler.cs プロジェクト: dovanduy/titan
        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); }
        }