CieloRest 1.0.19

dotnet add package CieloRest --version 1.0.19                
NuGet\Install-Package CieloRest -Version 1.0.19                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CieloRest" Version="1.0.19" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CieloRest --version 1.0.19                
#r "nuget: CieloRest, 1.0.19"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install CieloRest as a Cake Addin
#addin nuget:?package=CieloRest&version=1.0.19

// Install CieloRest as a Cake Tool
#tool nuget:?package=CieloRest&version=1.0.19                

Características

  • Funções Assincronas.
  • HttpClient.
  • Sem dependência a bibliotecas JSON (NewtonSoft, Jil, MessagePack...)
  • Testes Unitários
  • .Net Standard 2

Principais recursos

  • Pagamentos por cartão de crédito.
  • Pagamentos por cartão de débito.
  • Pagamentos recorrentes (de acordo com a Cielo funciona somente para crédito)
    • Com autorização na primeira recorrência ou a partir de uma data.
  • Boleto
  • Transferência Eletrônica
  • Cancelamento de autorização.
  • Consulta de pagamentos.
  • Tokenização do Cartão
    • GetRecurrentPayment - Busca informações sobre a recorrência
    • CreateToken - Tokeniza o cartão válido (ou inválido).
    • CreateTokenValid - Gera um pagamento de 1 real (cancela logo em seguida) para garantir que o cartão é válido e retorna a Token.

Como utilizar

Como não tem uma documentação formal utilize o projeto de Teste (CieloTestsCore) para ver os exemplos criados (e verificar se ainda estão funcionando).

Implemente seu provider JSON

Você pode utilizar qualquer provider JSON. Para isso implemente a interface ISerializerJSON. Exemplo utilizando Newtonsoft:

public class SerializerJSON : ISerializerJSON
{
    public string Serialize<T>(T value)
    {
        // return System.Text.Json.JsonSerializer.Serialize<T>(value);

        return Newtonsoft.Json.JsonConvert.SerializeObject(value);
    }

    public T Deserialize<T>(string jsonText)
    {
        //var json = MessagePackSerializer.Serialize(p);
        //return MessagePackSerializer.Deserialize<Transaction>(jsonText);

        // return Jil.JSON.Deserialize<T>(jsonText);

        return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(jsonText);
    }

    public async Task<T> DeserializeAsync<T>(HttpContent content)
    {
        // return await System.Text.Json.JsonSerializer.DeserializeAsync<T>(await content.ReadAsStreamAsync(), _jsonOptions).ConfigureAwait(false);

        var serializer = new JsonSerializer();
        using (var textReader = new StreamReader(await content.ReadAsStreamAsync().ConfigureAwait(false)))
        using (var jsonReader = new JsonTextReader(textReader))
        {
            return serializer.Deserialize<T>(jsonReader);
        }
    }
}

Métodos Async e Sync

Método com o Sufixo Async será executado de forma assincrona.

   await api.CreateTransactionAsync(Guid.NewGuid(), transaction);

Quando não tiver o sufixo Async será executado de forma sincrona.

   api.CreateTransaction(Guid.NewGuid(), transaction));

Chave do Sandbox

Caso queira executar o teste unitário pode deixar a minha chave do Sandbox, se deseja utilizar a sua altere a classe:

  public class Merchant
  {
          public static readonly Merchant SANDBOX = 
                 new Merchant(Guid.Parse("00000000-0000-0000-0000-000000000000"), "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");

  }
 

Nuget

Install-Package CieloRest -Version 1.0.19

Documentação da Cielo

Exemplo de utilização (utilize os casos de Teste para ver mais exemplos)

        var customer = new Customer(name: _nome);

        var creditCard = new Card(
            cardNumber: SandboxCreditCard.NotAuthorizedCardExpired,
            holder: _nomeCartao,
            expirationDate: _invalidDate,
            securityCode: "123",
            brand: CardBrand.Visa);

        var payment = new Payment(
            amount: 150.04M,
            currency: Currency.BRL,
            installments: 1,
            capture: true,
            softDescriptor: _descricao,
            card: creditCard);

        var transaction = new Transaction(
            merchantOrderId: Random().Next().ToString(),
            customer: customer,
            payment: payment);

        try
        {
            var returnTransaction = _api.CreateTransaction(Guid.NewGuid(), transaction);

            Assert.IsTrue(returnTransaction.Payment.GetStatus() == Status.Denied, "Transação não foi negada");
        }
        catch (CieloException ex)
        {
            Assert.IsTrue(ex.GetCieloErrors().Any(i => i.Code == 126));
        }

MIT License

Copyright (c) 2019 Hugo de Brito V. R. Alves

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.19 3,398 6/23/2022
1.0.18 398 6/23/2022
1.0.17 399 6/23/2022
1.0.16 407 6/23/2022
1.0.15 4,144 7/2/2020
1.0.14 596 7/2/2020
1.0.13 439 7/2/2020
1.0.12 454 7/2/2020
1.0.11 16,459 3/20/2019
1.0.10 981 7/31/2018
1.0.9 1,071 6/18/2018
1.0.8 1,033 6/4/2018
1.0.7 1,054 5/9/2018
1.0.6 1,006 11/29/2017
1.0.5 1,058 10/24/2017
1.0.4 1,082 10/24/2017
1.0.3 1,244 10/23/2017
1.0.2 1,046 10/19/2017
1.0.1 1,086 10/19/2017
1.0.0 1,143 10/18/2017

Update em Package
Colocando o Deserialize de forma Async