Exemplo n.º 1
0
        protected void writeBAPointsToDb(string transactionId, string profileIdString, BAPointsType paymentType, ISession session, string pointsName)
        {
            Guid profileId = new Guid(profileIdString);

            using (var tx = session.BeginSaveTransaction())
            {
                //first check if this order has been already processed

                var count = session.QueryOver <BAPoints>().Where(x => x.Identifier == transactionId).RowCount();
                if (count > 0)
                {
                    Log.Write("TransactionId {0} is already processed.", TraceEventType.Warning, "PayPal", transactionId);
                    throw new UniqueException("This transaction is already processed");
                }
                Log.Write("TransactionId is not duplicated We can continue.", TraceEventType.Information, "PayPal", transactionId);


                var pointsToAdd = getPointsFromItemNumber(pointsName);
                Log.Write("Request is OK. Adding {0} BA points for ProfileId {1}", TraceEventType.Error, "PayPal", pointsToAdd, profileId);
                var      profile = session.Get <Profile>(profileId);
                BAPoints points  = new BAPoints();
                points.ImportedDate = DateTime.UtcNow;
                points.Profile      = profile;
                points.Points       = pointsToAdd;
                points.Type         = paymentType;
                points.Identifier   = transactionId;
                session.Save(points);
                profile.Licence.BAPoints += points.Points;
                session.Update(profile);
                tx.Commit();
                Log.Write("Everything OK. END", TraceEventType.Error, "PayPal", pointsToAdd);
            }
        }
Exemplo n.º 2
0
        public void DuplicatedOrder_BuyNow()
        {
            BAPoints point = new BAPoints();

            point.Identifier   = "174IG322ASL4JBRAQQHNDPM3H2FTMFLNQ8I";
            point.Profile      = profile;
            point.ImportedDate = DateTime.UtcNow;
            insertToDatabase(point);

            NameValueCollection requestData = new NameValueCollection();

            requestData.Add("buyerEmail", "*****@*****.**");
            requestData.Add("transactionId", "174IG322ASL4JBRAQQHNDPM3H2FTMFLNQ8I");
            requestData.Add("status", "PS");
            requestData.Add("transactionAmount", "USD 5.000000");
            requestData.Add("paymentReason", "BAPoints_30");
            requestData.Add("operation", "pay");
            requestData.Add("referenceId", profile.GlobalId.ToString());
            requestData.Add("signatureVersion", "2");
            requestData.Add("certificateUrl", "https://fps.sandbox.amazonaws.com/certs/090911/PKICert.pem%3frequestId%3d15n8qoapsoddqfe380kvbpmb4h0cy47zhl9n1f1tv07aofo");
            requestData.Add("paymentMethod", "CC");
            requestData.Add("signatureMethod", "RSA-SHA1");
            requestData.Add("recipientEmail", "*****@*****.**");
            requestData.Add("transactionDate", "1344945621");
            requestData.Add("buyerName", "Darth Vader");
            requestData.Add("signature", "pHaRbT6UjbHEykNhatobDr8TVVTRdrAM2Xr3mRzTgEbeWk8flESxznXO4EfDDiM5b0u0YLeJoJTj%0ar6hihivc1bZqMZ6XuBTS/qWK/aO6KHzGUVtAEwWt1mCtLaJBdxlJrrO86F/GkYmg9mBwQw9847gl%0abyDetj1ntIa%2bHS8RN4M%3d");

            var handler = new TestableAmazonHandler(manager, "*****@*****.**");

            handler.AmazonResponse = true;
            var serviceSession = sessionFactory.OpenSession();

            using (serviceSession)
            {
                try
                {
                    handler.ProcessOrderRequest(serviceSession, requestData, null);
                    Assert.Fail();
                }
                catch (UniqueException)
                {
                }
            }
            Session.Clear();
            var baPoints = Session.QueryOver <BAPoints>().RowCount();

            Assert.AreEqual(1, baPoints);
        }
        public void DuplicatedOrder()
        {
            BAPoints point = new BAPoints();

            point.Identifier   = "TR-USR-11APEX";
            point.Profile      = profile;
            point.ImportedDate = DateTime.UtcNow;
            insertToDatabase(point);

            var handler = new TestableTranferujHandler(manager);

            NameValueCollection requestData = new NameValueCollection();

            requestData.Add("id", handler.TransferujId);
            requestData.Add("tr_id", "TR-USR-11APEX");
            requestData.Add("tr_date", "2012-08-21+19%3a37%3a50");
            requestData.Add("tr_crc", profile.GlobalId.ToString() + "|BAPoints_30");
            requestData.Add("tr_amount", "5.00");
            requestData.Add("tr_paid", "5.00");
            requestData.Add("tr_desc", "BAPoints_30");
            requestData.Add("tr_status", "TRUE");
            requestData.Add("tr_error", "none");
            requestData.Add("tr_email", "*****@*****.**");
            var md5 = FormsAuthentication.HashPasswordForStoringInConfigFile(handler.TransferujId + requestData["tr_id"] + requestData["tr_amount"] + requestData["tr_crc"] + handler.TransferujKodPotwierdzajcy, "MD5");

            requestData.Add("md5sum", md5);
            var serviceSession = sessionFactory.OpenSession();

            using (serviceSession)
            {
                try
                {
                    handler.ProcessOrderRequest(serviceSession, requestData, null);
                    Assert.Fail();
                }
                catch (UniqueException)
                {
                }
            }
            Session.Clear();
            var baPoints = Session.QueryOver <BAPoints>().RowCount();

            Assert.AreEqual(1, baPoints);
        }
Exemplo n.º 4
0
        public void DuplicatedOrder_BuyNow()
        {
            BAPoints point = new BAPoints();

            point.Identifier   = "6AY89642EM656753M";
            point.Profile      = profile;
            point.ImportedDate = DateTime.UtcNow;
            insertToDatabase(point);

            NameValueCollection requestData = new NameValueCollection();

            requestData.Add("receiver_email", "*****@*****.**");
            requestData.Add("txn_id", "6AY89642EM656753M");
            requestData.Add("payment_status", "Completed");
            requestData.Add("txn_type", "web_accept");
            requestData.Add("quantity", "1");
            requestData.Add("item_number", "BAPoints_30");
            requestData.Add("custom", profile.GlobalId.ToString());

            TestablePayPalHandler handler = new TestablePayPalHandler(manager, "*****@*****.**");

            handler.PayPalResponse = "VERIFIED";
            var serviceSession = sessionFactory.OpenSession();

            using (serviceSession)
            {
                try
                {
                    handler.ProcessOrderRequest(serviceSession, requestData, null);
                    Assert.Fail();
                }
                catch (UniqueException)
                {
                }
            }
            Session.Clear();
            var baPoints = Session.QueryOver <BAPoints>().RowCount();

            Assert.AreEqual(1, baPoints);
        }
Exemplo n.º 5
0
        public void DuplicatedOrder()
        {
            BAPoints point = new BAPoints();

            point.Identifier   = "191015";
            point.Profile      = profile;
            point.ImportedDate = DateTime.UtcNow;
            insertToDatabase(point);

            var handler = new TestablePrzelewy24Handler(manager);

            NameValueCollection requestData = new NameValueCollection();

            requestData.Add("p24_id_sprzedawcy", handler.MyId);
            requestData.Add("p24_order_id", "191015");
            requestData.Add("p24_order_id_full", "18191015");
            requestData.Add("p24_kwota", "500");
            requestData.Add("p24_session_id", Guid.NewGuid() + "|" + profile.GlobalId.ToString() + "|BAPoints_120");
            requestData.Add("p24_crc", "fghgfhfrtyryr");
            requestData.Add("p24_karta", "0");
            var serviceSession = sessionFactory.OpenSession();

            using (serviceSession)
            {
                try
                {
                    handler.ProcessOrderRequest(serviceSession, requestData, null);
                    Assert.Fail();
                }
                catch (UniqueException)
                {
                }
            }
            Session.Clear();
            var baPoints = Session.QueryOver <BAPoints>().RowCount();

            Assert.AreEqual(1, baPoints);
        }
Exemplo n.º 6
0
        public void ImportLicence(string licenceKey)
        {
            Log.WriteWarning("ImportLicence:Username={0}, key={1}", SecurityInfo.SessionData.Profile.UserName, licenceKey);

            using (var tx = Session.BeginSaveTransaction())
            {
                var dbProfile = Session.Load <Profile>(SecurityInfo.SessionData.Profile.GlobalId);
                LicenceGenerator generator = new LicenceGenerator();
                var licenceInfo            = generator.GetLicence(licenceKey);
                if (licenceInfo != null)
                {
                    //now check if this licence key has been used in the past. If yes, then error. One licence key can be used only once!
                    var count = Session.QueryOver <BAPoints>().Where(x => x.Identifier == licenceInfo.Id.ToString()).RowCount();
                    if (count > 0)
                    {
                        throw new AlreadyOccupiedException("This licence key has been already used.");
                    }
                    BAPoints dbLicence = new BAPoints();
                    dbLicence.Points       = licenceInfo.BAPoints;
                    dbLicence.Identifier   = licenceInfo.Id.ToString();
                    dbLicence.Type         = BAPointsType.Serialkey;
                    dbLicence.ImportedDate = Configuration.TimerService.UtcNow;
                    dbLicence.Profile      = dbProfile;
                    dbLicence.LoginData    = SecurityInfo.LoginData;
                    Session.Save(dbLicence);

                    dbProfile.Licence.BAPoints += dbLicence.Points;
                    Session.Update(dbProfile);
                    tx.Commit();
                    //update currently logged user in SecurityManager
                    var currentAccountType = SecurityInfo.Licence.CurrentAccountType;
                    SecurityInfo.Licence = dbProfile.Licence.Map <LicenceInfoDTO>();
                    SecurityInfo.Licence.CurrentAccountType = currentAccountType;
                }
            }
        }