コード例 #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 DenyEntryManually(OfferRegisterEntry entry, Member user)
 {
     CPAManager.DenyEntry(entry, user, entry.Offer.Title);
     entry.Offer.PerformStatusControlCheck();
 }
コード例 #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); }
        }