public void IPNMap() { NameValueCollection nvc = HttpUtility.ParseQueryString(ipnMsg); IPNMessage ipn = new IPNMessage(nvc); NameValueCollection ipnMap = ipn.IpnMap; Assert.IsNotNull(ipnMap); }
/// <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 }); } }
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; } }
public void IPNRequest() { NameValueCollection nvc = HttpUtility.ParseQueryString(ipnMsg); IPNMessage ipn = new IPNMessage(nvc); Assert.IsTrue(ipn.Validate()); }
public void IPNRequestInvalid() { NameValueCollection nvc = HttpUtility.ParseQueryString("test=tests"); IPNMessage ipn = new IPNMessage(nvc); Assert.IsFalse(ipn.Validate()); }
public void IPNTransaction() { NameValueCollection nvc = HttpUtility.ParseQueryString(ipnMsg); IPNMessage ipn = new IPNMessage(nvc); string transactionType = ipn.TransactionType; Assert.AreEqual("Adaptive Payment PAY", transactionType); }
public void IPNMissingParameter() { NameValueCollection nvc = HttpUtility.ParseQueryString(ipnMsg); IPNMessage ipn = new IPNMessage(nvc); string parameter = ipn.IpnValue("not_found"); Assert.IsTrue(string.IsNullOrEmpty(parameter)); }
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()); }
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(); } )); }
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()); }
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); } }
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); } } }