Пример #1
0
 public void IPNMap()
 {
     NameValueCollection nvc = HttpUtility.ParseQueryString(ipnMsg);
     IPNMessage ipn = new IPNMessage(nvc);
     NameValueCollection ipnMap = ipn.IpnMap;
     Assert.IsNotNull(ipnMap);
 }
Пример #2
0
        /// <summary>
        /// IPN messages received.
        /// This is only for handling special cases like sending email or
        /// automating a workflow. It is not for simple transactions
        /// </summary>
        public void HandleIPNMessage(byte[] parameters)
        {
            if (parameters != null && parameters.Length > 0)
            {
                // Configuration map containing signature credentials and other required configuration.
                // For a full list of configuration parameters refer at
                // (https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters)
                Dictionary <string, string> configurationMap = FWUtils.ConfigUtils.GetAppSettings().Paypal.GetConfig();

                IPNMessage          ipn             = new IPNMessage(configurationMap, parameters);
                bool                isIpnValidated  = ipn.Validate();
                string              transactionType = ipn.TransactionType;
                NameValueCollection map             = ipn.IpnMap;

                string logMsg = "Map:" + map + "\r\n"
                                + "TranType:" + transactionType + "\r\n"
                                + "IsValidated:" + isIpnValidated;

                long?userId = null;
                if (FWUtils.SecurityUtils.IsUserAuthenticated())
                {
                    userId = FWUtils.SecurityUtils.GetCurrentUserIDLong();
                }
                FWUtils.ExpLogUtils.Logger.WriteLog(new AppLog()
                {
                    AppLogTypeID = (short)EntityEnums.AppLogType.PayPal_IPNURL, UserID = userId, ExtraString1 = logMsg
                });
            }
        }
Пример #3
0
 public void IPNParameter()
 {
     NameValueCollection nvc = HttpUtility.ParseQueryString(ipnMsg);
     IPNMessage ipn = new IPNMessage(nvc);
     string parameter = ipn.IpnValue("fees_payer");
     Assert.AreEqual("EACHRECEIVER", parameter);
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                byte[] parameters = Request.BinaryRead(HttpContext.Current.Request.ContentLength);

                if (parameters.Length > 0)
                {
                    // Configuration map containing signature credentials and other required configuration.
                    // For a full list of configuration parameters refer in wiki page
                    // (https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters)
                    Dictionary <string, string> configurationMap = Configuration.GetConfig();
                    IPNMessage ipn = new IPNMessage(configurationMap, parameters);

                    bool   isIpnValidated   = ipn.Validate();
                    string transactionType  = ipn.TransactionType;
                    NameValueCollection map = ipn.IpnMap;

                    logger.Info("----------Type-------------------" + this.GetType().Name + "\n"
                                + "*********IPN Name Value Pair****" + map + "\n"
                                + "#########IPN Transaction Type###" + transactionType + "\n"
                                + "=========IPN Validation=========" + isIpnValidated);
                }
            }
            catch (System.Exception ex)
            {
                logger.Debug("Exception in class " + this.GetType().Name + ": " + ex.Message);
                return;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                byte[] parameters = Request.BinaryRead(HttpContext.Current.Request.ContentLength);

                if (parameters.Length > 0)
                {
                    IPNMessage          ipn             = new IPNMessage(parameters);
                    bool                isIpnValidated  = ipn.Validate();
                    string              transactionType = ipn.TransactionType;
                    NameValueCollection map             = ipn.IpnMap;

                    logger.Info("----------Type-------------------" + this.GetType().Name + "\n"
                                + "*********IPN Name Value Pair****" + map + "\n"
                                + "#########IPN Transaction Type###" + transactionType + "\n"
                                + "=========IPN Validation=========" + isIpnValidated);
                }
            }
            catch (System.Exception ex)
            {
                logger.Debug("Exception in class " + this.GetType().Name + ": " + ex.Message);
                return;
            }
        }
Пример #6
0
        public void IPNRequest()
        {
            NameValueCollection nvc = HttpUtility.ParseQueryString(ipnMsg);
            IPNMessage          ipn = new IPNMessage(nvc);

            Assert.IsTrue(ipn.Validate());
        }
Пример #7
0
        public void IPNRequestInvalid()
        {
            NameValueCollection nvc = HttpUtility.ParseQueryString("test=tests");
            IPNMessage          ipn = new IPNMessage(nvc);

            Assert.IsFalse(ipn.Validate());
        }
Пример #8
0
 public void IPNTransaction()
 {
     NameValueCollection nvc = HttpUtility.ParseQueryString(ipnMsg);
     IPNMessage ipn = new IPNMessage(nvc);
     string transactionType = ipn.TransactionType;
     Assert.AreEqual("Adaptive Payment PAY", transactionType);
 }
Пример #9
0
        public void IPNParameter()
        {
            NameValueCollection nvc = HttpUtility.ParseQueryString(ipnMsg);
            IPNMessage          ipn = new IPNMessage(nvc);
            string parameter        = ipn.IpnValue("fees_payer");

            Assert.AreEqual("EACHRECEIVER", parameter);
        }
Пример #10
0
        public void IPNTransaction()
        {
            NameValueCollection nvc = HttpUtility.ParseQueryString(ipnMsg);
            IPNMessage          ipn = new IPNMessage(nvc);
            string transactionType  = ipn.TransactionType;

            Assert.AreEqual("Adaptive Payment PAY", transactionType);
        }
Пример #11
0
        public void IPNMissingParameter()
        {
            NameValueCollection nvc = HttpUtility.ParseQueryString(ipnMsg);
            IPNMessage          ipn = new IPNMessage(nvc);
            string parameter        = ipn.IpnValue("not_found");

            Assert.IsTrue(string.IsNullOrEmpty(parameter));
        }
Пример #12
0
        public void IPNMap()
        {
            NameValueCollection nvc    = HttpUtility.ParseQueryString(ipnMsg);
            IPNMessage          ipn    = new IPNMessage(nvc);
            NameValueCollection ipnMap = ipn.IpnMap;

            Assert.IsNotNull(ipnMap);
        }
 public void IPNConfigMissingIpnEndpoint()
 {
     Encoding ipnEncoding = Encoding.GetEncoding("windows-1252");
     byte[] message = ipnEncoding.GetBytes(ipnMsg);
     Dictionary<string, string> config = ConfigManager.Instance.GetProperties();
     config.Remove(BaseConstants.IPNEndpointConfig);
     IPNMessage ipn = new IPNMessage(config, message);
     Assert.IsTrue(ipn.Validate());
 }
Пример #14
0
 public void IPNConfigMissingModeAndIpnEndpoint()
 {
     Encoding ipnEncoding = Encoding.GetEncoding("windows-1252");
     byte[] message = ipnEncoding.GetBytes(ipnMsg);
     Dictionary<string, string> config = ConfigManager.Instance.GetProperties();
     config.Remove(BaseConstants.ApplicationModeConfig);
     config.Remove(BaseConstants.IPNEndpointConfig);
     IPNMessage ipn = new IPNMessage(config, message);
     Assert.Throws(typeof(ConfigException), new NUnit.Framework.TestDelegate(delegate { ipn.Validate(); } ));
 }
Пример #15
0
        public void IPNConfigMissingIpnEndpoint()
        {
            Encoding ipnEncoding = Encoding.GetEncoding("windows-1252");

            byte[] message = ipnEncoding.GetBytes(ipnMsg);
            Dictionary <string, string> config = ConfigManager.Instance.GetProperties();

            config.Remove(BaseConstants.IPNEndpointConfig);
            IPNMessage ipn = new IPNMessage(config, message);

            Assert.IsTrue(ipn.Validate());
        }
Пример #16
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                byte[]                       parameters         = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
                PaymentTransaction           paymentTransaction = new PaymentTransaction();
                PaymentTransactionRepository paymentRepo        = new PaymentTransactionRepository();

                if (parameters.Length > 0)
                {
                    IPNMessage          ipn             = new IPNMessage(parameters);
                    bool                isIpnValidated  = ipn.Validate();
                    string              transactionType = ipn.TransactionType;
                    NameValueCollection map             = ipn.IpnMap;

                    paymentTransaction.AmountPaid          = map["payment_gross"];
                    paymentTransaction.PayPalTransactionId = map["txn_id"];
                    paymentTransaction.UserId     = Guid.Parse(map["custom"].ToString());
                    paymentTransaction.Id         = Guid.NewGuid();
                    paymentTransaction.IPNTrackId = map["ipn_track_id"];

                    paymentTransaction.PayerEmail    = map["payer_email"];
                    paymentTransaction.PayerId       = map["payer_id"];
                    paymentTransaction.PaymentStatus = map["payment_status"];



                    logger.Info("Payment Status : " + paymentTransaction.PaymentStatus);
                    logger.Info("User Id : " + paymentTransaction.UserId);


                    paymentTransaction.PaymentDate       = DateTime.Now;
                    paymentTransaction.PaypalPaymentDate = map["payment_date"];
                    paymentTransaction.ReceiverId        = map["receiver_id"];
                    paymentRepo.SavePayPalTransaction(paymentTransaction);
                    UserRepository userrepo = new UserRepository();
                    if (paymentTransaction.PaymentStatus == "Completed")
                    {
                        userrepo.changePaymentStatus(paymentTransaction.UserId, "paid");
                    }
                }
            }

            catch (System.Exception ex)
            {
                logger.Error(ex.StackTrace);
            }
        }
 public void IPNRequestInvalid()
 {
     NameValueCollection nvc = HttpUtility.ParseQueryString("test=tests");
     IPNMessage ipn = new IPNMessage(nvc);
     Assert.IsFalse(ipn.Validate());
 }
Пример #18
0
 public void IPNRequest()
 {
     NameValueCollection nvc = HttpUtility.ParseQueryString(ipnMsg);
     IPNMessage ipn = new IPNMessage(nvc);
     Assert.IsTrue(ipn.Validate());
 }
 public void IPNMissingParameter()
 {
     NameValueCollection nvc = HttpUtility.ParseQueryString(ipnMsg);
     IPNMessage ipn = new IPNMessage(nvc);
     string parameter = ipn.IpnValue("not_found");
     Assert.IsTrue(string.IsNullOrEmpty(parameter));
 }
Пример #20
0
        private static void IPNConnection(IAsyncResult result)
        {
            const string LiveURL = @"https://ipnpb.paypal.com/cgi-bin/webscr";

            const string verified = "VERIFIED";

            try
            {
                if (IPNListener == null || !IPNListener.IsListening)
                {
                    return;
                }

                HttpListenerContext context = IPNListener.EndGetContext(result);

                string rawMessage;
                using (StreamReader readStream = new StreamReader(context.Request.InputStream, Encoding.UTF8))
                    rawMessage = readStream.ReadToEnd();


                Task.Run(() =>
                {
                    string data = "cmd=_notify-validate&" + rawMessage;

                    HttpWebRequest wRequest = (HttpWebRequest)WebRequest.Create(LiveURL);

                    wRequest.Method        = "POST";
                    wRequest.ContentType   = "application/x-www-form-urlencoded";
                    wRequest.ContentLength = data.Length;

                    using (StreamWriter writer = new StreamWriter(wRequest.GetRequestStream(), Encoding.ASCII))
                        writer.Write(data);

                    using (StreamReader reader = new StreamReader(wRequest.GetResponse().GetResponseStream()))
                    {
                        IPNMessage message = new IPNMessage {
                            Message = rawMessage, Verified = reader.ReadToEnd() == verified
                        };


                        if (!Directory.Exists(VerifiedPath))
                        {
                            Directory.CreateDirectory(VerifiedPath);
                        }

                        if (!Directory.Exists(InvalidPath))
                        {
                            Directory.CreateDirectory(InvalidPath);
                        }

                        string path = (message.Verified ? VerifiedPath : InvalidPath) + Path.GetRandomFileName();

                        File.WriteAllText(path, message.Message);

                        message.FileName = path;


                        Messages.Enqueue(message);
                    }
                });

                context.Response.StatusCode = (int)HttpStatusCode.OK;
                context.Response.Close();
            }
            catch (Exception ex)
            {
                SEnvir.Log(ex.ToString());
            }
            finally
            {
                if (IPNListener != null && IPNListener.IsListening) //IsBound ?
                {
                    IPNListener.BeginGetContext(IPNConnection, null);
                }
            }
        }