예제 #1
0
        public Boolean ProcessNotification(String code, String port)
        {
            PagSeguroPagamento oPagSeguroPagamento = new PagSeguroPagamento();

            string      idInstituicao = System.Configuration.ConfigurationManager.AppSettings["pagSeguro_" + port];
            Instituicao oInstituicao  = new Instituicao().Get(Convert.ToInt32(idInstituicao));

            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)
                {
                    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);

                    oPagSeguroPagamento.statusDate = DateTime.Now;

                    XmlNodeList nodeList = xml.GetElementsByTagName("status");
                    oPagSeguroPagamento.status = nodeList[0].InnerText;

                    nodeList = xml.GetElementsByTagName("code");
                    oPagSeguroPagamento.code = nodeList[0].InnerText;

                    nodeList = xml.GetElementsByTagName("paymentMethod")[0].SelectNodes("type");
                    oPagSeguroPagamento.formaPagamento = nodeList[0].InnerText;

                    List <tf_pagseguro_pagamento> lst = db.tf_pagseguro_pagamento.Where(x => (x.codeResponse == oPagSeguroPagamento.code)).ToList <tf_pagseguro_pagamento>();

                    if (lst.Count == 0)
                    {
                        return(false);
                    }

                    lst[0].statusDate     = DateTime.Now;
                    lst[0].status         = GetStatus(oPagSeguroPagamento.status);
                    lst[0].formaPagamento = GetPaymentMethod(oPagSeguroPagamento.formaPagamento);

                    db.SaveChanges();
                    return(true);
                }
            }
            return(true);
        }
예제 #2
0
 public Boolean Post([FromBody] PagSeguroPagamento code)
 {
     try
     {
         return(new PagSeguro().CheckoutSuccess(code.code, code.codeResponse));
     }
     catch (Exception e)
     {
         ErroHandler.Log("PagSeguro_CheckoutSuccessController", e, "POST", "");
         throw e;
     }
 }
예제 #3
0
        public PagSeguroPagamento Checkout(dao.Mensalidade oMensalidade, dao.Aluno oAluno, dao.Instituicao oInstituicao)
        {
            string urlPagSeguro = System.Configuration.ConfigurationManager.AppSettings["pagSeguroURL_CHECKOUT"];

            urlPagSeguro = urlPagSeguro.Replace("#descricao#", "Mensalidade (" + oMensalidade.mes.ToString() + "/" + oMensalidade.ano.ToString() + ")");
            urlPagSeguro = urlPagSeguro.Replace("#valor#", Convert.ToInt32(oMensalidade.valor).ToString("N2"));
            urlPagSeguro = urlPagSeguro.Replace("#nome#", oAluno.nome);
            urlPagSeguro = urlPagSeguro.Replace("#email#", oAluno.email);
            urlPagSeguro = urlPagSeguro.Replace("#emailInstituicao#", oInstituicao.email);
            urlPagSeguro = urlPagSeguro.Replace("#token#", oInstituicao.token);
            urlPagSeguro = urlPagSeguro.Replace("#reference#", oMensalidade.id.ToString());


            using (var client = new HttpClient())
            {
                var values   = new Dictionary <string, string>();
                var content  = new FormUrlEncodedContent(values);
                var response = client.PostAsync(urlPagSeguro, content).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);

                    PagSeguroPagamento oPagSeguroPagamento = new PagSeguroPagamento();

                    XmlNodeList nodeList = xml.GetElementsByTagName("code");
                    oPagSeguroPagamento.code = nodeList[0].InnerText;

                    nodeList = xml.GetElementsByTagName("date");
                    oPagSeguroPagamento.date = nodeList[0].InnerText;

                    return(oPagSeguroPagamento);
                }
            }
            return(null);
        }