public async Task <MyJsonResult> PagSeguroPayment() { var user = _UserRepo.GetByEmail(User.Identity.Name); var config = _ServerConfigRepo.GetAllConfig(); var tokenPagament = Guid.NewGuid().ToString(); var PagamentoLicenca = new PagamentoLicenca() { Usuario_Id = user.Id, DataCriacaoInvoice = DateTime.UtcNow, MetodoPagamentoId = 1, PagamentoLicencaStatusId = 1, ValoraReceber = config.PrecoLicenca, TokenPagamento = tokenPagament }; _PagamentoRepo.Add(PagamentoLicenca); var apiPagSeguro = new ApiPagSeguro(config.PagseguroToken, config.AppServer, PagseguroisSandbox); var response = apiPagSeguro.GeneratePayment(PagamentoLicenca.Id, config.PrecoLicenca); if (response.IsSuccessStatusCode) { var result = await response.Content.ReadAsStringAsync(); var xmlSerializer = new XmlSerializer(typeof(checkout)); using (var textReader = new StringReader(result)) { var objret = (checkout)xmlSerializer.Deserialize(textReader); return(new MyJsonResult(apiPagSeguro.pagseguroUrl + objret.code, JsonRequestBehavior.AllowGet)); } } Response.TrySkipIisCustomErrors = true; Response.StatusCode = 400; return(new MyJsonResult("Erro no metodo de Pagamento", JsonRequestBehavior.AllowGet)); }
public HttpResponse pagseguroSuccesso(string notificationCode) { var config = _ServerConfigRepo.GetAllConfig(); var apiPagSeguro = new ApiPagSeguro(config.PagseguroToken, config.AppServer, PagseguroisSandbox); Response.AppendHeader("Access-Control-Allow-Origin", "https://sandbox.pagseguro.uol.com.br"); var res = apiPagSeguro.CheckPayment(notificationCode); if (res.IsSuccessStatusCode) { var obj = res.Content.ReadAsStringAsync().Result; var xmlSerializer = new XmlSerializer(typeof(transaction)); using (var textReader = new StringReader(obj)) { var objret = (transaction)xmlSerializer.Deserialize(textReader); var pagamentoLicenca = _PagamentoRepo.GetById(objret.reference); if (objret.status == 3)//Pago { pagamentoLicenca.DataPagamento = DateTime.UtcNow; pagamentoLicenca.CodigoPagSeguro = objret.code; pagamentoLicenca.PagamentoLicencaStatusId = 3; pagamentoLicenca.ValorPago = objret.netAmount; _PagamentoRepo.Update(pagamentoLicenca); var user = _UserRepo.GetById(pagamentoLicenca.Usuario_Id); if (user.DataVencimentoLicenca < DateTime.UtcNow) { user.DataVencimentoLicenca = DateTime.UtcNow.AddMonths(1); } else { user.DataVencimentoLicenca = user.DataVencimentoLicenca.AddMonths(1); } _UserRepo.Update(user); } } } var response = new HttpResponse(TextWriter.Null); response.ContentType = "application/json"; response.StatusCode = 201; return(response); }