Cielo’s integration with C# and Asp.Net MVC?

Asked

Viewed 213 times

1

I’m trying to integrate Cielo to make payments on my site "Asp.Net MVC" but I’m not getting it. I read the Cielo integration manual, followed all the steps, performed tests in Postman and works well, but in my application I am not able to make it work, always returns the error: Method Not Allowed and looking at Cielo’s website, I couldn’t find a way to solve this problem.

For integration, I tested using Httpclient and Restsharp and both return the same error.

How to solve this problem ?

//pagamento com cartão
public static bool Pay(CieloObject obj){

        try{
            string URL_FINAL = "https://apisandbox.cieloecommerce.cielo.com.br";
            string mid = "<meu-id>";
            string key = "<minha-chave>";

            var request = new RestRequest();
            request.Method = Method.POST;
            request.AddHeader("content-type", "application/json");
            request.AddHeader("Accept", "application/json");
            request.AddHeader("MerchantId", mid);
            request.AddHeader("MerchantKey", key);
            request.Parameters.Clear();
            request.AddParameter("application/json", JsonConvert.SerializeObject(obj), ParameterType.RequestBody);             

            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
            var client = new RestClient(URL_FINAL);
            var response = client.Execute(request);

            Debug.WriteLine(response.StatusDescription);


            return true;
        }catch(Exception e){

            return false;
        }       

       
    }
  • 1

    I may be talking nonsense, but don’t you need to pass something after "https://apisandbox.cieloecommerce.cielo.com.br/METODO"? He doesn’t have a bar after that?

  • @Leonardobuta does not. See: https://developercielo.github.io/manual/cielo-ecommerce

  • 1

    According to the website of Mozilla this answer means that the method used (POST) is not allowed, check if the url is correct and if the method is POST even... Some servers are case sensitive for headers, try using the "Content-Type" header (with uppercase initials).

  • @Edney is POST yes. Even in Postman works with POST

  • 1

    I am not very familiar with this API, Cielo does not have a technical support that meets?

  • @Edney emailed me and there’s no reply

  • 1

    I took a look at your link and it seems that the requests are made at: https://apisandbox.cieloecommerce.cielo.com.br/1/sales/

  • 1

    don’t forget the "https://"

  • @Edney worked. The problem was Webdav. I found the solution here: https://stackoverflow.com/questions/9854602/asp-net-web-api-405-http-verb-used-to-accessthis-page-is-not-allowed-how

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.