public async Task <string> GetNossoNumeroAsync(BoletoRequest request)
        {
            if (request == null)
            {
                throw new System.ArgumentNullException(nameof(request));
            }

            return(await Task.Run(() =>
            {
                var nossoNumero = request.SequencialNossoNumero.ToString();
                var cedente = request.Cedente;

                //somente monta o digito verificador no nosso numero se o convenio tiver 6 posições
                if (cedente.Convenio.Length == 6)
                {
                    nossoNumero = string.Format("{0}/{1}-{2}", CodigoCarteira, nossoNumero, Mod11BancoBrasil(nossoNumero));
                }
                else
                {
                    nossoNumero = string.Format("{0}/{1}", CodigoCarteira, nossoNumero);
                }

                return nossoNumero;
            }));
        }
Beispiel #2
0
        public IActionResult Boleto([FromBody] BoletoRequest boletoRequest)
        {
            try
            {
                paymentService.BoletoCheckout(boletoRequest);

                Response response = new Response
                {
                    Status  = Constants.SUCCESS,
                    Message = "Pagamento realizado com sucesso",
                    Error   = false,
                    Data    = null
                };

                return(new ObjectResult(response));
            }
            catch (Exception e)
            {
                Response response = new Response
                {
                    Status  = "error",
                    Message = e.Message,
                    Error   = true,
                    Data    = null
                };

                return(BadRequest(response));
            }
        }
Beispiel #3
0
        public async Task Carteira18_Convenio_7()
        {
            var request = new BoletoRequest(_cedente)
            {
                SequencialNossoNumero = 999
            };
            var boleto = await _boletoGenerator.GenerateAsync(
                _carteira,
                request);

            Assert.IsNotNull(boleto);
            Assert.AreEqual(boleto.NossoNumero, "18/999");
        }
        public IActionResult Gerar(string convenio, [FromBody][Required] BoletoRequest boleto)
        {
            var token = _tokenService.Gerar(_configuration);

            if (token != null)
            {
                var boletoReg = _boletoService.Gerar(_configuration, token.access_token, boleto, convenio);
                if (boletoReg.Result.Erros != null)
                {
                    return(BadRequest(boletoReg.Result.Erros));
                }
                return(Ok(boletoReg.Result));
            }
            return(BadRequest());
        }
Beispiel #5
0
        public async Task <TransactionResponse> CreateBoletoAsync(BoletoRequest request, Guid companyId)
        {
            var company = await _context.Company.Find(x => x.Id == companyId).FirstOrDefaultAsync();

            var gateway = GetGatewayBoleto(company);

            var service = _boletoGatewayFactory.CreateBoletoGateway(gateway);

            var boleto = await service.CreateBoletoAsync(request);

            var transaction = new Transaction();

            await _mediator.Send(new CreateTransactionCommand(transaction));

            return(_mapper.Map <Transaction, TransactionResponse>(transaction));
        }
Beispiel #6
0
        public async Task <Boleto> CreateBoletoAsync(BoletoRequest request)
        {
            var boletoRequest = new PagSeguroBoletoRequest();

            try
            {
                var boleto = await _boletoService.CreateBoletoAsync(boletoRequest);

                // TODO map to boleto
                return(new Boleto());
            }
            catch (PagSeguroException e)
            {
                _log.LogError($"Error creating boleto on {nameof(PagSeguroGateway)} | {e.Errors}");
                // TODO map to domain exception
                throw;
            }
        }
Beispiel #7
0
 private NameValueCollection ResolverInformacao(BoletoRequest boletoRequest)
 {
     throw new NotImplementedException();
 }
Beispiel #8
0
 public string BoletoCheckout(BoletoRequest boletoRequest)
 {
     return(Checkout(ResolverInformacao(boletoRequest)));
 }
 private static void CalcularNossoNumero(BoletoRequest boleto)
 {
     boleto.NossoNumero = Utils.CalcularNossoNumero(boleto.NossoNumero);
 }
        async Task <BoletoResponse> IBoletoService.Gerar(IConfiguration configuration, string token, BoletoRequest boleto, string convenio)
        {
            try
            {
                CalcularNossoNumero(boleto);
                using (HttpClient client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Add("Authorization", string.Format("Bearer {0}", token));
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    var jsonContent   = JsonConvert.SerializeObject(boleto);
                    var contentString = new StringContent(jsonContent, Encoding.UTF8, "application/json");
                    contentString.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                    string urlGerarBoleto = string.Format("{0}/{1}", configuration["UrlBase"], string.Format(configuration["MethodGerarBoleto"], convenio));

                    HttpResponseMessage response = await client.PostAsync(urlGerarBoleto, contentString);

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        var dados     = response.Content.ReadAsStringAsync().Result;
                        var boletoReg = JsonConvert.DeserializeObject <BoletoResponse>(dados);
                        return(boletoReg);
                    }
                    else
                    {
                        var erros       = response.Content.ReadAsStringAsync().Result;
                        var errosBoleto = JsonConvert.DeserializeObject <ErrosBoleto>(erros);

                        return(new BoletoResponse
                        {
                            Erros = errosBoleto,
                            NumeroCodigoBarras = "",
                            NumeroLinhaDigitavel = ""
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }