public Boolean ProcessNotification(String code, String port) { string idInstituicao = System.Configuration.ConfigurationManager.AppSettings["pagSeguro_" + port]; GC_Academia oInstituicao = (from item in db.GC_Academia where item.Id.ToString() == idInstituicao select item).FirstOrDefault(); string urlPagSeguro = System.Configuration.ConfigurationManager.AppSettings["pagSeguroURL_NOTIFICATION"]; urlPagSeguro = urlPagSeguro.Replace("#email#", oInstituicao.Email); urlPagSeguro = urlPagSeguro.Replace("#token#", oInstituicao.Token); urlPagSeguro = urlPagSeguro.Replace("#code#", code); using (var client = new HttpClient()) { var values = new Dictionary <string, string>(); var content = new FormUrlEncodedContent(values); var response = client.GetAsync(urlPagSeguro).Result; if (response.IsSuccessStatusCode) { try { var responseContent = response.Content; // by calling .Result you are synchronously reading the result string responseString = responseContent.ReadAsStringAsync().Result; XmlDocument xml = new XmlDocument(); xml.LoadXml(responseString); XmlNodeList nodeList = xml.GetElementsByTagName("status"); String status = nodeList[0].InnerText; nodeList = xml.GetElementsByTagName("code"); String pagseguroCode = nodeList[0].InnerText; GC_PagSeguroPagamento oGC_PagSeguroPagamento = (from item in db.GC_PagSeguroPagamento where item.Code == pagseguroCode select item).FirstOrDefault(); GC_Mensalidade oGC_Mensalidade = (from item in db.GC_Mensalidade where item.Id == oGC_PagSeguroPagamento.GC_MensalidadeId select item).FirstOrDefault(); oGC_Mensalidade.GC_MensalidadeStatusId = Convert.ToInt32(status); db.SaveChanges(); new MensalidadeLogger().Log(oGC_Mensalidade, null, "Pagseguro"); return(true); } catch (Exception) { return(false); } } } return(false); }
public async Task <IHttpActionResult> PutGC_PagSeguroPagamento(int id, GC_PagSeguroPagamento gC_PagSeguroPagamento) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != gC_PagSeguroPagamento.Id) { return(BadRequest()); } db.Entry(gC_PagSeguroPagamento).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GC_PagSeguroPagamentoExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public bool Post([FromBody] GC_Mensalidade value) { value = (from item in db.GC_Mensalidade where item.Id == value.Id select item).FirstOrDefault(); GC_Usuario oGC_Usuario = (from item in db.GC_Usuario where item.Id == value.GC_UsuarioId select item).FirstOrDefault(); GC_Academia OGC_Academia = (from item in db.GC_Academia where item.Id == value.GC_AcademiaId select item).FirstOrDefault(); GC_PagSeguroPagamento oGC_PagSeguroPagamento = (from item in db.GC_PagSeguroPagamento where item.GC_MensalidadeId == value.Id select item).FirstOrDefault(); if (oGC_Usuario.Telefone == null) { return(false); } String message = "Olá {0}! Seu boleto com vencimento para {1} referente a academia {3} pode ser impresso em {2}"; message = message.Replace("{0}", oGC_Usuario.Nome); message = message.Replace("{1}", value.Vencimento.ToString("dd/MM/yyyy")); message = message.Replace("{2}", "http://basicflux.com/#/eu"); message = message.Replace("{3}", OGC_Academia.Nome); new PapoSms().EnviarMensalidade(oGC_Usuario.Telefone, message); return(true); }
public async Task <IHttpActionResult> GetGC_PagSeguroPagamento(int id) { GC_PagSeguroPagamento gC_PagSeguroPagamento = await db.GC_PagSeguroPagamento.FindAsync(id); if (gC_PagSeguroPagamento == null) { return(NotFound()); } return(Ok(gC_PagSeguroPagamento)); }
public async Task <IHttpActionResult> PostGC_PagSeguroPagamento(GC_PagSeguroPagamento gC_PagSeguroPagamento) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.GC_PagSeguroPagamento.Add(gC_PagSeguroPagamento); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = gC_PagSeguroPagamento.Id }, gC_PagSeguroPagamento)); }
public async Task <IHttpActionResult> DeleteGC_PagSeguroPagamento(int id) { GC_PagSeguroPagamento gC_PagSeguroPagamento = await db.GC_PagSeguroPagamento.FindAsync(id); if (gC_PagSeguroPagamento == null) { return(NotFound()); } db.GC_PagSeguroPagamento.Remove(gC_PagSeguroPagamento); await db.SaveChangesAsync(); return(Ok(gC_PagSeguroPagamento)); }
public bool Post([FromBody] GC_Mensalidade value) { value = (from item in db.GC_Mensalidade where item.Id == value.Id select item).FirstOrDefault(); GC_Usuario oGC_Usuario = (from item in db.GC_Usuario where item.Id == value.GC_UsuarioId select item).FirstOrDefault(); GC_Academia OGC_Academia = (from item in db.GC_Academia where item.Id == value.GC_AcademiaId select item).FirstOrDefault(); GC_PagSeguroPagamento oGC_PagSeguroPagamento = (from item in db.GC_PagSeguroPagamento where item.GC_MensalidadeId == value.Id select item).FirstOrDefault(); return(new Mailer().Boleto(oGC_Usuario.Email, oGC_Usuario.Nome, value.Vencimento.ToString("dd/MM/yyyy"), oGC_PagSeguroPagamento.BarCode, oGC_PagSeguroPagamento.Link, OGC_Academia.Nome, OGC_Academia)); }
public List <GC_PagSeguroPagamento> GerarBoletos(List <GC_Mensalidade> oGC_Mensalidade) { String url = System.Configuration.ConfigurationManager.AppSettings["pagSeguro_Boleto"]; Int32 idMensalidade = oGC_Mensalidade[0].Id; GC_Mensalidade targetGC_Mensalidade = (from item in db.GC_Mensalidade where item.Id == idMensalidade select item).FirstOrDefault(); GC_Usuario oGC_Usuario = (from item in db.GC_Usuario where item.Id == targetGC_Mensalidade.GC_UsuarioId select item).FirstOrDefault(); GC_Academia oGC_Academia = (from item in db.GC_Academia where item.Id == targetGC_Mensalidade.GC_AcademiaId select item).FirstOrDefault(); String cpf = oGC_Usuario.CPF.Split('.').Aggregate((current, next) => current + "" + next).Split('-').Aggregate((current, next) => current + "" + next); String oBody = sBody.Replace("#Mensalidade_ID#", oGC_Mensalidade[0].Id.ToString()); oBody = oBody.Replace("#FirstDueDate#", targetGC_Mensalidade.Vencimento.ToString("yyyy-MM-dd")); oBody = oBody.Replace("#amount#", (targetGC_Mensalidade.Valor - 1).ToString()); oBody = oBody.Replace("#numberOfPayments#", oGC_Mensalidade.Count.ToString()); oBody = oBody.Replace("#CPF#", cpf); oBody = oBody.Replace("#Name#", oGC_Usuario.Nome); oBody = oBody.Replace("#Email#", "fake_" + oGC_Usuario.Email); oBody = oBody.Replace("#AcademiaNome#", oGC_Academia.Nome); oBody = oBody.Split('\'').Aggregate((current, next) => current + "\"" + next); url = url.Replace("#token#", oGC_Academia.Token); url = url.Replace("#email#", oGC_Academia.Email); using (var client = new HttpClient()) { var httpContent = new StringContent(oBody, Encoding.UTF8, "application/json"); var response = client.PostAsync(url, httpContent).Result; if (response.IsSuccessStatusCode) { var responseContent = response.Content; string responseString = responseContent.ReadAsStringAsync().Result; dynamic myClass = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(responseString); List <dynamic> boletos = myClass.boletos.ToObject <List <dynamic> >(); List <GC_PagSeguroPagamento> lstGC_PagSeguroPagamento = new List <GC_PagSeguroPagamento>(); boletos.ForEach((x) => { GC_PagSeguroPagamento oGC_PagSeguroPagamento = new GC_PagSeguroPagamento(); oGC_PagSeguroPagamento.BarCode = x.barcode; oGC_PagSeguroPagamento.Code = x.code; oGC_PagSeguroPagamento.Link = x.paymentLink; oGC_PagSeguroPagamento.DueDate = x.dueDate; lstGC_PagSeguroPagamento.Add(oGC_PagSeguroPagamento); }); lstGC_PagSeguroPagamento = lstGC_PagSeguroPagamento.OrderBy(x => x.DueDate).ToList(); return(lstGC_PagSeguroPagamento); } else { var responseContent = response.Content; string responseString = responseContent.ReadAsStringAsync().Result; throw new Exception(responseString); } } return(null); //var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://ws.pagseguro.uol.com.br/recurring-payment/[email protected]&token=32728DC4EF0A4615BD716904E82DA4AE"); //httpWebRequest.ContentType = "application/json"; //httpWebRequest.Method = "POST"; //using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) //{ // streamWriter.Write(oBody); // streamWriter.Flush(); // streamWriter.Close(); //} //var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); //using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) //{ // var result = streamReader.ReadToEnd(); // dynamic myClass = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(result); // List<dynamic> boletos = myClass.boletos.ToObject<List<dynamic>>(); // List<GC_PagSeguroPagamento> lstGC_PagSeguroPagamento = new List<GC_PagSeguroPagamento>(); // boletos.ForEach((x) => // { // GC_PagSeguroPagamento oGC_PagSeguroPagamento = new GC_PagSeguroPagamento(); // oGC_PagSeguroPagamento.BarCode = x.barcode; // oGC_PagSeguroPagamento.Code = x.code; // oGC_PagSeguroPagamento.Link = x.paymentLink; // oGC_PagSeguroPagamento.DueDate = x.dueDate; // lstGC_PagSeguroPagamento.Add(oGC_PagSeguroPagamento); // }); // lstGC_PagSeguroPagamento = lstGC_PagSeguroPagamento.OrderBy(x => x.DueDate).ToList(); // return lstGC_PagSeguroPagamento; //} }
public GC_PagSeguroPagamento Checkout(GC_Mensalidade oMensalidade, GC_Usuario oAluno, GC_Academia oInstituicao, String token, String senderHash) { string urlPagSeguro = System.Configuration.ConfigurationManager.AppSettings["pagSeguroURL_CHECKOUT"]; string urlNotification = System.Configuration.ConfigurationManager.AppSettings["notificationURL_" + oInstituicao.Id]; String sXML = @"<?xml version='1.0' encoding='ISO-8859-1' standalone='yes'?> <payment> <mode>default</mode> <method>creditCard</method> <sender> <name>#nome#</name> <email>#email#</email> <phone> <areaCode>11</areaCode> <number>30380000</number> </phone> <documents> <document> <type>CPF</type> <value>#cpf#</value> </document> </documents> <hash>#senderHash#</hash> </sender> <notificationURL>#notificationURL#</notificationURL> <currency>BRL</currency> <items> <item> <id>1</id> <description>#descricao#</description> <quantity>1</quantity> <amount>#valor#</amount> </item> </items> <extraAmount>0.00</extraAmount> <reference>R123456</reference> <shipping> <address> <street>Av. capistrano de Abreu</street> <number>486</number> <complement>1 andar</complement> <district>Jaguaribe</district> <city>Osasco</city> <state>SP</state> <country>BRA</country> <postalCode>06065120</postalCode> </address> <type>3</type> <cost>0.00</cost> </shipping> <creditCard> <token>#creditCardToken#</token> <installment> <quantity>1</quantity> <value>#valor#</value> </installment> <holder> <name>Nome No Cartao</name> <documents> <document> <type>CPF</type> <value>#cpf#</value> </document> </documents> <birthDate>20/10/1980</birthDate> <phone> <areaCode>11</areaCode> <number>999991111</number> </phone> </holder> <billingAddress> <street>Av. capistrano de Abreu</street> <number>486</number> <complement>1 andar</complement> <district>Jaguaribe</district> <city>Osasco</city> <state>SP</state> <country>BRA</country> <postalCode>06065120</postalCode> </billingAddress> </creditCard> </payment>"; sXML = sXML.Replace("#descricao#", "Mensalidade (" + oMensalidade.Vencimento.ToString("DD") + "/" + oMensalidade.Vencimento.ToString("YYYY") + ")"); sXML = sXML.Replace("#valor#", Convert.ToInt32(oMensalidade.Valor).ToString("N2")); sXML = sXML.Replace("#valor#", Convert.ToInt32(oMensalidade.Valor).ToString("N2")); sXML = sXML.Replace("#nome#", oAluno.Nome); sXML = sXML.Replace("#email#", oAluno.Email); sXML = sXML.Replace("#cpf#", oAluno.CPF); sXML = sXML.Replace("#cpf#", oAluno.CPF); sXML = sXML.Replace("#reference#", oMensalidade.Id.ToString()); sXML = sXML.Replace("#creditCardToken#", token); sXML = sXML.Replace("#senderHash#", senderHash); sXML = sXML.Replace("#notificationURL#", urlNotification); urlPagSeguro = urlPagSeguro.Replace("#emailInstituicao#", oInstituicao.Email); urlPagSeguro = urlPagSeguro.Replace("#token#", oInstituicao.Token); using (var client = new HttpClient()) { var httpContent = new StringContent(sXML, Encoding.UTF8, "application/xml"); var response = client.PostAsync(urlPagSeguro, httpContent).Result; if (response.IsSuccessStatusCode) { var responseContent = response.Content; // by calling .Result you are synchronously reading the result string responseString = responseContent.ReadAsStringAsync().Result; XmlDocument xml = new XmlDocument(); xml.LoadXml(responseString); GC_PagSeguroPagamento oPagSeguroPagamento = new GC_PagSeguroPagamento(); XmlNodeList nodeList = xml.GetElementsByTagName("code"); oPagSeguroPagamento.Code = nodeList[0].InnerText; nodeList = xml.GetElementsByTagName("date"); oPagSeguroPagamento.DueDate = nodeList[0].InnerText; return(oPagSeguroPagamento); } } return(null); }