├── eRede
├── global.json
├── eRede
│ ├── Document.cs
│ ├── Additional.cs
│ ├── Link.cs
│ ├── Capture.cs
│ ├── Service
│ │ ├── Error
│ │ │ ├── RedeError.cs
│ │ │ └── RedeException.cs
│ │ ├── CreateTransactionService.cs
│ │ ├── CancelTransactionService.cs
│ │ ├── CaptureTransactionService.cs
│ │ ├── GetTransactionService.cs
│ │ └── AbstractTransactionService.cs
│ ├── SubMerchant.cs
│ ├── Brand.cs
│ ├── Passenger.cs
│ ├── Refund.cs
│ ├── packages.config
│ ├── Url.cs
│ ├── Device.cs
│ ├── Iata.cs
│ ├── Phone.cs
│ ├── Store.cs
│ ├── Address.cs
│ ├── Item.cs
│ ├── eRede.csproj
│ ├── Flight.cs
│ ├── Authorization.cs
│ ├── Environment.cs
│ ├── Customer.cs
│ ├── Cart.cs
│ ├── ThreeDSecure.cs
│ ├── TransactionResponse.cs
│ ├── eRede.cs
│ └── Transaction.cs
├── eRedeTests
│ ├── eRedeTests.csproj
│ └── eRedeTest.cs
└── eRede.sln
├── LICENSE
├── README.md
└── .gitignore
/eRede/global.json:
--------------------------------------------------------------------------------
1 | {
2 | "sdk": {
3 | "version": "6.0.0",
4 | "rollForward": "latestMajor",
5 | "allowPrerelease": true
6 | }
7 | }
--------------------------------------------------------------------------------
/eRede/eRede/Document.cs:
--------------------------------------------------------------------------------
1 | namespace eRede;
2 |
3 | public class Document
4 | {
5 | public string Type { get; set; }
6 | public string Number { get; set; }
7 | }
--------------------------------------------------------------------------------
/eRede/eRede/Additional.cs:
--------------------------------------------------------------------------------
1 | namespace eRede;
2 |
3 | public class Additional
4 | {
5 | public string Gateway { get; set; }
6 | public string Module { get; set; }
7 | }
--------------------------------------------------------------------------------
/eRede/eRede/Link.cs:
--------------------------------------------------------------------------------
1 | namespace eRede;
2 |
3 | public class Link
4 | {
5 | public string Method { get; set; }
6 | public string Rel { get; set; }
7 | public string Href { get; set; }
8 | }
--------------------------------------------------------------------------------
/eRede/eRede/Capture.cs:
--------------------------------------------------------------------------------
1 | namespace eRede;
2 |
3 | public class Capture
4 | {
5 | public int Amount { get; set; }
6 | public string DateTime { get; set; }
7 | public string Nsu { get; set; }
8 | }
--------------------------------------------------------------------------------
/eRede/eRede/Service/Error/RedeError.cs:
--------------------------------------------------------------------------------
1 | namespace eRede.Service.Error;
2 |
3 | public class RedeError
4 | {
5 | public string ReturnCode { get; set; }
6 | public string ReturnMessage { get; set; }
7 | }
--------------------------------------------------------------------------------
/eRede/eRede/SubMerchant.cs:
--------------------------------------------------------------------------------
1 | namespace eRede;
2 |
3 | public class SubMerchant
4 | {
5 | public string mcc { get; set; }
6 | public string city { get; set; }
7 | public string country { get; set; }
8 | }
--------------------------------------------------------------------------------
/eRede/eRede/Brand.cs:
--------------------------------------------------------------------------------
1 | namespace eRede;
2 |
3 | public class Brand
4 | {
5 | public string Name { get; set; }
6 | public string ReturnCode { get; set; }
7 | public string ReturnMessage { get; set; }
8 | }
--------------------------------------------------------------------------------
/eRede/eRede/Passenger.cs:
--------------------------------------------------------------------------------
1 | namespace eRede;
2 |
3 | public class Passenger
4 | {
5 | public string Email { get; set; }
6 | public string Name { get; set; }
7 | public Phone Phone { get; set; }
8 | public string Ticket { get; set; }
9 | }
--------------------------------------------------------------------------------
/eRede/eRede/Refund.cs:
--------------------------------------------------------------------------------
1 | namespace eRede;
2 |
3 | public class Refund
4 | {
5 | public int Amount { get; set; }
6 | public string RefundDateTime { get; set; }
7 | public string RefundId { get; set; }
8 | public string Status { get; set; }
9 | }
--------------------------------------------------------------------------------
/eRede/eRede/Service/CreateTransactionService.cs:
--------------------------------------------------------------------------------
1 | namespace eRede.Service;
2 |
3 | internal class CreateTransactionService : AbstractTransactionService
4 | {
5 | public CreateTransactionService(Store store, Transaction transaction) : base(store, transaction)
6 | {
7 | }
8 | }
--------------------------------------------------------------------------------
/eRede/eRede/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/eRede/eRede/Service/Error/RedeException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace eRede.Service.Error;
4 |
5 | public class RedeException : Exception
6 | {
7 | public RedeException()
8 | {
9 | }
10 |
11 | public RedeException(string message) : base(message)
12 | {
13 | }
14 |
15 | public RedeError Error { get; init; }
16 | }
--------------------------------------------------------------------------------
/eRede/eRede/Url.cs:
--------------------------------------------------------------------------------
1 | namespace eRede;
2 |
3 | public class Url
4 | {
5 | public const string Callback = "callback";
6 | public const string ThreeDSecureFailure = "threeDSecureFailure";
7 | public const string ThreeDSecureSuccess = "threeDSecureSuccess";
8 |
9 | public string Kind { get; set; }
10 | public string Type { get; set; }
11 | public string url { get; set; }
12 | }
--------------------------------------------------------------------------------
/eRede/eRede/Device.cs:
--------------------------------------------------------------------------------
1 | namespace eRede;
2 |
3 | public class Device
4 | {
5 | public int ColorDepth { get; set; }
6 | public string DeviceType3ds { get; set; }
7 | public bool JavaEnabled { get; set; }
8 | public string Language { get; set; } = "BR";
9 | public int ScreenHeight { get; set; }
10 | public int ScreenWidth { get; set; }
11 | public int TimeZoneOffset { get; set; } = 3;
12 | }
--------------------------------------------------------------------------------
/eRede/eRede/Service/CancelTransactionService.cs:
--------------------------------------------------------------------------------
1 | namespace eRede.Service;
2 |
3 | internal class CancelTransactionService : AbstractTransactionService
4 | {
5 | public CancelTransactionService(Store store, Transaction transaction) : base(store, transaction)
6 | {
7 | Tid = transaction.Tid;
8 | }
9 |
10 | protected override string GetUri()
11 | {
12 | return base.GetUri() + "/" + Tid + "/refunds";
13 | }
14 | }
--------------------------------------------------------------------------------
/eRede/eRede/Iata.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace eRede;
4 |
5 | public class Iata
6 | {
7 | public string Code { get; set; }
8 | public string DepartureTax { get; set; }
9 | public List Flight { get; set; }
10 |
11 | private void PrepareFlight()
12 | {
13 | Flight ??= new List();
14 | }
15 |
16 | public Iata AddFlight(Flight flight)
17 | {
18 | PrepareFlight();
19 |
20 | Flight.Add(flight);
21 |
22 | return this;
23 | }
24 | }
--------------------------------------------------------------------------------
/eRede/eRede/Phone.cs:
--------------------------------------------------------------------------------
1 | namespace eRede;
2 |
3 | public class Phone
4 | {
5 | public const string Cellphone = "1";
6 | public const string Home = "2";
7 | public const string Work = "3";
8 | public const string Other = "4";
9 |
10 | public Phone(string ddd, string number, string type = Cellphone)
11 | {
12 | Ddd = ddd;
13 | Number = number;
14 | Type = type;
15 | }
16 |
17 | public string Ddd { get; }
18 | public string Number { get; }
19 | public string Type { get; }
20 | }
--------------------------------------------------------------------------------
/eRede/eRede/Store.cs:
--------------------------------------------------------------------------------
1 | namespace eRede;
2 |
3 | public class Store
4 | {
5 | public Store(string filliation, string token) : this(filliation, token, Environment.Production())
6 | {
7 | }
8 |
9 | public Store(string filliation, string token, Environment environment)
10 | {
11 | Environment = environment;
12 | Filliation = filliation;
13 | Token = token;
14 | }
15 |
16 | public Environment Environment { get; }
17 | public string Filliation { get; }
18 | public string Token { get; }
19 | }
--------------------------------------------------------------------------------
/eRede/eRede/Service/CaptureTransactionService.cs:
--------------------------------------------------------------------------------
1 | using RestSharp;
2 |
3 | namespace eRede.Service;
4 |
5 | internal class CaptureTransactionService : AbstractTransactionService
6 | {
7 | public CaptureTransactionService(Store store, Transaction transaction) : base(store, transaction)
8 | {
9 | Tid = transaction.Tid;
10 | }
11 |
12 | protected override string GetUri()
13 | {
14 | return base.GetUri() + "/" + Tid;
15 | }
16 |
17 | public TransactionResponse Execute()
18 | {
19 | return base.Execute(Method.Put);
20 | }
21 | }
--------------------------------------------------------------------------------
/eRede/eRede/Address.cs:
--------------------------------------------------------------------------------
1 | namespace eRede;
2 |
3 | public class Address
4 | {
5 | public const int Billing = 1;
6 | public const int Shipping = 2;
7 | public const int Both = 3;
8 |
9 | public const int Apartment = 1;
10 | public const int Houst = 2;
11 | public const int Commercial = 3;
12 | public const int Other = 4;
13 |
14 | private string address { get; set; }
15 | private string AddresseeName { get; set; }
16 | private string City { get; set; }
17 | private string Number { get; set; }
18 | private string State { get; set; }
19 | private int Type { get; set; }
20 | private string ZipCode { get; set; }
21 | }
--------------------------------------------------------------------------------
/eRede/eRede/Item.cs:
--------------------------------------------------------------------------------
1 | namespace eRede;
2 |
3 | public class Item
4 | {
5 | public const int Physical = 1;
6 | public const int Digital = 2;
7 | public const int Service = 3;
8 | public const int Airline = 4;
9 |
10 | public Item(string id, int quantity, int type = Physical)
11 | {
12 | Id = id;
13 | Quantity = quantity;
14 | Type = type;
15 | }
16 |
17 | public int Amount { get; set; }
18 | public string Description { get; set; }
19 | public int Freight { get; set; }
20 | public string Id { get; }
21 | public int Quantity { get; }
22 | public string ShippingType { get; set; }
23 | public int Type { get; }
24 | }
--------------------------------------------------------------------------------
/eRede/eRede/eRede.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | latestmajor
5 | net6.0
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/eRede/eRedeTests/eRedeTests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 | enable
6 |
7 | false
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/eRede/eRede/Flight.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace eRede;
4 |
5 | public class Flight
6 | {
7 | public string Date { get; set; }
8 | public string Ip { get; set; }
9 | public string Number { get; set; }
10 | public List Passenger { get; set; }
11 |
12 | public string To { get; set; }
13 |
14 | private void PreparePassenger()
15 | {
16 | Passenger ??= new List();
17 | }
18 |
19 |
20 | public Flight AddPassenger(Passenger passenger)
21 | {
22 | PreparePassenger();
23 |
24 | Passenger.Add(passenger);
25 |
26 | return this;
27 | }
28 |
29 | public List.Enumerator GetPassengerEnumerator()
30 | {
31 | PreparePassenger();
32 |
33 | return Passenger.GetEnumerator();
34 | }
35 | }
--------------------------------------------------------------------------------
/eRede/eRede/Authorization.cs:
--------------------------------------------------------------------------------
1 | namespace eRede;
2 |
3 | public class Authorization
4 | {
5 | public string Affiliation { get; set; }
6 | public int Amount { get; set; }
7 | public string AuthorizationCode { get; set; }
8 | public string CardBin { get; set; }
9 | public string CardHolderName { get; set; }
10 | public string DateTime { get; set; }
11 | public int Installments { get; set; }
12 | public string Kind { get; set; }
13 | public string Last4 { get; set; }
14 | public string Nsu { get; set; }
15 | public string Origin { get; set; }
16 | public string Reference { get; set; }
17 | public string ReturnCode { get; set; }
18 | public string ReturnMessage { get; set; }
19 | public string Status { get; set; }
20 | public string Subscription { get; set; }
21 | public string Tid { get; set; }
22 | }
--------------------------------------------------------------------------------
/eRede/eRede/Service/GetTransactionService.cs:
--------------------------------------------------------------------------------
1 | using RestSharp;
2 |
3 | namespace eRede.Service;
4 |
5 | internal class GetTransactionService : AbstractTransactionService
6 | {
7 | public GetTransactionService(Store store, Transaction transaction = null) : base(store, transaction)
8 | {
9 | }
10 |
11 | public string Reference { get; init; }
12 | public bool Refund { get; init; }
13 |
14 | protected override string GetUri()
15 | {
16 | var uri = base.GetUri();
17 |
18 | if (Reference != null) return uri + "?reference=" + Reference;
19 |
20 | if (Refund) return uri + "/" + Tid + "/Refunds";
21 |
22 | return uri + "/" + Tid;
23 | }
24 |
25 | public TransactionResponse Execute()
26 | {
27 | var request = new RestRequest { Method = Method.Get };
28 |
29 | return SendRequest(request);
30 | }
31 | }
--------------------------------------------------------------------------------
/eRede/eRede/Environment.cs:
--------------------------------------------------------------------------------
1 | namespace eRede;
2 |
3 | public class Environment
4 | {
5 | private const string ProductionEndpoint = "https://api.userede.com.br/erede";
6 | private const string SandboxEndpoint = "https://api.userede.com.br/desenvolvedores";
7 | private const string Version = "v1";
8 |
9 | private Environment(string baseUrl, string version)
10 | {
11 | _endpoint = $"{baseUrl}/{version}/";
12 | }
13 |
14 | public string Ip { get; set; }
15 | public string SessionId { get; set; }
16 |
17 | private string _endpoint { get; }
18 |
19 | public static Environment Production()
20 | {
21 | return new Environment(ProductionEndpoint, Version);
22 | }
23 |
24 | public static Environment Sandbox()
25 | {
26 | return new Environment(SandboxEndpoint, Version);
27 | }
28 |
29 | public string Endpoint(string service)
30 | {
31 | return _endpoint + service;
32 | }
33 | }
--------------------------------------------------------------------------------
/eRede/eRede/Customer.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace eRede;
4 |
5 | public class Customer
6 | {
7 | public const string Male = "S";
8 | public const string Female = "M";
9 |
10 | public string Cpf { get; set; }
11 | public List Documents { get; set; }
12 | public string Email { get; set; }
13 |
14 | public string Name { get; set; }
15 | public string Gender { get; set; }
16 | public Phone Phone { get; set; }
17 |
18 | private void PrepareDocuments()
19 | {
20 | Documents ??= new List();
21 | }
22 |
23 |
24 | public Customer AddDocument(string type, string number)
25 | {
26 | PrepareDocuments();
27 |
28 | Documents.Add(new Document { Type = type, Number = number });
29 |
30 | return this;
31 | }
32 |
33 | public List.Enumerator GetEnumerator()
34 | {
35 | PrepareDocuments();
36 |
37 | return Documents.GetEnumerator();
38 | }
39 | }
--------------------------------------------------------------------------------
/eRede/eRede/Cart.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace eRede;
4 |
5 | public class Cart
6 | {
7 | public Address Billing { get; set; }
8 | public Customer Customer { get; set; }
9 | public Environment Environment { get; set; }
10 | public Iata Iata { get; set; }
11 | public List- Items { get; set; }
12 | public List Addresses { get; set; }
13 |
14 | private void PrepareItems()
15 | {
16 | Items ??= new List
- ();
17 | }
18 |
19 | public Address Address(int type = global::eRede.Address.Both)
20 | {
21 | var address = new Address();
22 |
23 | if ((type & global::eRede.Address.Billing) == global::eRede.Address.Billing) Billing = address;
24 |
25 | if ((type & global::eRede.Address.Shipping) == global::eRede.Address.Shipping)
26 | Addresses = new List { address };
27 |
28 | return address;
29 | }
30 |
31 | public List
- .Enumerator GetItemEnumerator()
32 | {
33 | PrepareItems();
34 |
35 | return Items.GetEnumerator();
36 | }
37 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Rede
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/eRede/eRede/ThreeDSecure.cs:
--------------------------------------------------------------------------------
1 | namespace eRede;
2 |
3 | public class ThreeDSecure
4 | {
5 | public const string DataOnly = "DATA_ONLY";
6 | public const string MpiRede = "MPI Rede";
7 | public const string MpiCliente = "MPI Cliente";
8 |
9 | public const string ContinueOnFailure = "continue";
10 | public const string DeclineOnFailure = "decline";
11 |
12 | public ThreeDSecure()
13 | {
14 | Embedded = true;
15 | }
16 |
17 | public ThreeDSecure(string mpi)
18 | {
19 | Embedded = mpi == MpiRede;
20 | }
21 |
22 | public string Cavv { get; set; }
23 | public string Eci { get; set; }
24 | public bool Embedded { get; set; }
25 | public string OnFailure { get; set; } = DeclineOnFailure;
26 | public string Url { get; set; }
27 | public string UserAgent { get; set; }
28 | public string Xid { get; set; }
29 | public Device Device { get; set; }
30 | public string ReturnCode { get; set; }
31 | public string ReturnMessage { get; set; }
32 | public string ThreeDIndicator { get; set; }
33 | public string DirectoryServerTransactionId { get; set; }
34 | public string challengePreference { get; set; }
35 | }
--------------------------------------------------------------------------------
/eRede/eRede.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "eRede", "eRede\eRede.csproj", "{A0BD7AFA-3EDA-4B4E-B88B-1D88C8FBF2C3}"
4 | EndProject
5 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "eRedeTests", "eRedeTests\eRedeTests.csproj", "{CC7BE3B9-15AE-4418-8D8B-97D6CE576312}"
6 | EndProject
7 | Global
8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
9 | Debug|Any CPU = Debug|Any CPU
10 | Release|Any CPU = Release|Any CPU
11 | EndGlobalSection
12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
13 | {A0BD7AFA-3EDA-4B4E-B88B-1D88C8FBF2C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14 | {A0BD7AFA-3EDA-4B4E-B88B-1D88C8FBF2C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
15 | {A0BD7AFA-3EDA-4B4E-B88B-1D88C8FBF2C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
16 | {A0BD7AFA-3EDA-4B4E-B88B-1D88C8FBF2C3}.Release|Any CPU.Build.0 = Release|Any CPU
17 | {CC7BE3B9-15AE-4418-8D8B-97D6CE576312}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18 | {CC7BE3B9-15AE-4418-8D8B-97D6CE576312}.Debug|Any CPU.Build.0 = Debug|Any CPU
19 | {CC7BE3B9-15AE-4418-8D8B-97D6CE576312}.Release|Any CPU.ActiveCfg = Release|Any CPU
20 | {CC7BE3B9-15AE-4418-8D8B-97D6CE576312}.Release|Any CPU.Build.0 = Release|Any CPU
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/eRede/eRede/TransactionResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace eRede;
4 |
5 | public class TransactionResponse
6 | {
7 | public int Amount { get; set; }
8 |
9 | public string AuthorizationCode { get; set; }
10 | public string CancelId { get; set; }
11 | public Brand Brand { get; set; }
12 | public string BrandTid { get; set; }
13 |
14 | public string CardBin { get; set; }
15 | public string CardHolderName { get; set; }
16 | public string CardNumber { get; set; }
17 | public Cart Cart { get; set; }
18 | public string DateTime { get; set; }
19 | public int DistributorAffiliation { get; set; }
20 | public string ExpirationMonth { get; set; }
21 | public string ExpirationYear { get; set; }
22 | public Iata Iata { get; set; }
23 | public int Installments { get; set; }
24 | public string Kind { get; set; }
25 | public string Last4 { get; set; }
26 | public string Nsu { get; set; }
27 | public string Origin { get; set; }
28 | public string Reference { get; set; }
29 | public string RefundDateTime { get; set; }
30 | public string RefundId { get; set; }
31 | public List Refunds { get; set; }
32 |
33 |
34 | public string SecurityCode { get; set; }
35 | public string SoftDescriptor { get; set; }
36 | public string StorageCard { get; set; }
37 |
38 |
39 | public bool Subscription { get; set; }
40 | public ThreeDSecure ThreeDSecure { get; set; }
41 |
42 | public List Urls { get; set; }
43 |
44 | public List Links { get; set; }
45 | public Capture Capture { get; set; }
46 | public Authorization Authorization { get; set; }
47 | public string RequestDateTime { get; set; }
48 | public string Tid { get; set; }
49 | public string ReturnCode { get; set; }
50 | public string ReturnMessage { get; set; }
51 | }
--------------------------------------------------------------------------------
/eRede/eRede/Service/AbstractTransactionService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using eRede.Service.Error;
3 | using Newtonsoft.Json;
4 | using RestSharp;
5 | using RestSharp.Authenticators;
6 |
7 | namespace eRede.Service;
8 |
9 | internal abstract class AbstractTransactionService
10 | {
11 | private readonly Store _store;
12 | private readonly Transaction _transaction;
13 |
14 | internal AbstractTransactionService(Store store, Transaction transaction)
15 | {
16 | _store = store;
17 | _transaction = transaction;
18 | }
19 |
20 | public string Tid { get; init; }
21 |
22 | protected virtual string GetUri()
23 | {
24 | return _store.Environment.Endpoint("transactions");
25 | }
26 |
27 | public TransactionResponse Execute(Method method = Method.Post)
28 | {
29 | var request = new RestRequest { Method = method, RequestFormat = DataFormat.Json };
30 |
31 | request.AddJsonBody(_transaction);
32 |
33 | return SendRequest(request);
34 | }
35 |
36 | protected TransactionResponse SendRequest(RestRequest request)
37 | {
38 | var client = new RestClient(GetUri())
39 | {
40 | Authenticator = new HttpBasicAuthenticator(_store.Filliation, _store.Token)
41 | };
42 |
43 | request.AddHeader("Transaction-Response", "brand-return-opened");
44 | request.AddHeader("User-Agent", eRede.UserAgent);
45 |
46 | var response = client.Execute(request);
47 |
48 | if (response is null) throw new NullReferenceException("Response is null");
49 | if (response.Content is null) throw new NullReferenceException("Response content is null");
50 |
51 | var status = (int)response.StatusCode;
52 |
53 | switch (status)
54 | {
55 | case >= 200 and < 300:
56 | return JsonConvert.DeserializeObject(response.Content);
57 | case >= 300 and < 400:
58 | throw new RedeException("A requisição foi redirecionada");
59 | }
60 |
61 | var error = JsonConvert.DeserializeObject(response.Content);
62 | var exception = new RedeException
63 | {
64 | Error = error
65 | };
66 |
67 | throw exception;
68 | }
69 | }
--------------------------------------------------------------------------------
/eRede/eRede/eRede.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using eRede.Service;
3 |
4 | namespace eRede;
5 |
6 | public class eRede
7 | {
8 | public const string Version = "2.0.0";
9 | public const string UserAgent = "eRede/" + Version + "(SDK; C#)";
10 |
11 | private readonly Store _store;
12 |
13 | public eRede(Store store)
14 | {
15 | _store = store;
16 | }
17 |
18 | public TransactionResponse Authorize(Transaction transaction)
19 | {
20 | return Create(transaction);
21 | }
22 |
23 | public TransactionResponse Create(Transaction transaction)
24 | {
25 | var createTransactionService = new CreateTransactionService(_store, transaction);
26 |
27 | return createTransactionService.Execute();
28 | }
29 |
30 | public TransactionResponse Cancel(Transaction transaction)
31 | {
32 | if (transaction.Tid is null) throw new ArgumentException("O tid não foi informado");
33 |
34 | var cancelTransactionService = new CancelTransactionService(_store, transaction);
35 |
36 | return cancelTransactionService.Execute();
37 | }
38 |
39 | public TransactionResponse Cancel(Transaction transaction, string tid)
40 | {
41 | transaction.Tid = tid;
42 |
43 | return Cancel(transaction);
44 | }
45 |
46 | public TransactionResponse Capture(Transaction transaction)
47 | {
48 | if (transaction.Tid is null) throw new ArgumentException("O tid não foi informado");
49 |
50 | var captureTransactionService = new CaptureTransactionService(_store, transaction);
51 |
52 | return captureTransactionService.Execute();
53 | }
54 |
55 | public TransactionResponse Capture(Transaction transaction, string tid)
56 | {
57 | transaction.Tid = tid;
58 |
59 | return Capture(transaction);
60 | }
61 |
62 | public TransactionResponse Get(string tid)
63 | {
64 | var getTransactionService = new GetTransactionService(_store)
65 | {
66 | Tid = tid
67 | };
68 |
69 | return getTransactionService.Execute();
70 | }
71 |
72 | public TransactionResponse GetByReference(string reference)
73 | {
74 | var getTransactionService = new GetTransactionService(_store)
75 | {
76 | Reference = reference
77 | };
78 |
79 | return getTransactionService.Execute();
80 | }
81 |
82 | public TransactionResponse GetRefunds(string tid)
83 | {
84 | var getTransactionService = new GetTransactionService(_store)
85 | {
86 | Tid = tid,
87 | Refund = true
88 | };
89 |
90 | return getTransactionService.Execute();
91 | }
92 |
93 | public TransactionResponse Zero(Transaction transaction)
94 | {
95 | transaction.Amount = 0;
96 | transaction.Capture = true;
97 |
98 | return Create(transaction);
99 | }
100 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SDK C#
2 |
3 | SDK de integração eRede
4 |
5 | # Utilizando
6 |
7 | ## Autorizando uma transação
8 |
9 | ```csharp
10 | // Configuração da loja
11 | var store = new Store(pv, token, environment);
12 |
13 | // Transação que será autorizada
14 | var transaction = new Transaction
15 | {
16 | amount = 20,
17 | reference = "pedido123"
18 | }.CreditCard(
19 | "5448280000000007",
20 | "235",
21 | "12",
22 | "2020",
23 | "Fulano de tal"
24 | );
25 |
26 | // Autoriza a transação
27 | var response = new eRede.eRede(store).create(transaction);
28 |
29 | if (response.returnCode == "00")
30 | {
31 | Console.WriteLine("Transação autorizada com sucesso: " + response.tid);
32 | }
33 | ```
34 |
35 | Por padrão, a transação é capturada automaticamente; caso seja necessário apenas autorizar a transação, o
36 | método `Transaction::capture()` deverá ser chamado com o parâmetro `false`:
37 |
38 | ```csharp
39 | // Configuração da loja
40 | var store = new Store(pv, token, environment);
41 |
42 | // Transação que será autorizada
43 | var transaction = new Transaction
44 | {
45 | amount = 20,
46 | reference = "pedido123"
47 | }.CreditCard(
48 | "5448280000000007",
49 | "235",
50 | "12",
51 | "2020",
52 | "Fulano de tal"
53 | ).Capture(false);
54 |
55 | // Autoriza a transação
56 | var response = new eRede.eRede(store).create(transaction);
57 |
58 | if (response.returnCode == "00")
59 | {
60 | Console.WriteLine("Transação autorizada com sucesso: " + response.tid);
61 | }
62 | ```
63 |
64 | ## Autorizando uma transação IATA
65 |
66 | ```csharp
67 | // Configuração da loja
68 | var store = new Store(pv, token, environment);
69 |
70 | // Transação que será autorizada
71 | var transaction = new Transaction
72 | {
73 | amount = 20,
74 | reference = "pedido123"
75 | }.CreditCard(
76 | "5448280000000007",
77 | "235",
78 | "12",
79 | "2020",
80 | "Fulano de tal"
81 | ).Iata("code123", "250");
82 |
83 | // Autoriza a transação
84 | var response = new eRede.eRede(store).create(transaction);
85 |
86 | if (response.returnCode == "00")
87 | {
88 | Console.WriteLine("Transação autorizada com sucesso: " + response.tid);
89 | }
90 | ```
91 |
92 | ## Autorizando uma transação com autenticação
93 |
94 | O 3DS é um serviço de autenticação que é obrigatório em transações de débito e opcional em transações de crédito. Saiba
95 | mais através [da documentação](https://www.userede.com.br/desenvolvedores/pt/produto/e-Rede#documentacao-3ds)
96 |
97 | ```csharp
98 | var store = new Store(pv, token, environment);
99 | var transaction = new Transaction
100 | {
101 | Amount = 20,
102 | Reference = "pedido" + new Random().Next(200, 10000),
103 | ThreeDSecure = new ThreeDSecure
104 | {
105 | Embedded = true,
106 | UserAgent =
107 | "Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405",
108 | OnFailure = ThreeDSecure.ContinueOnFailure,
109 | Device = new Device
110 | {
111 | ColorDepth = 1,
112 | DeviceType3ds = "BROWSER",
113 | JavaEnabled = false,
114 | ScreenHeight = 1080,
115 | ScreenWidth = 1920,
116 | TimeZoneOffset = 3
117 | }
118 | },
119 | Urls = new List
120 | {
121 | new()
122 | {
123 | Kind = Url.ThreeDSecureSuccess, url = "https://scommerce.userede.com.br/LojaTeste/Venda/sucesso"
124 | },
125 | new()
126 | {
127 | Kind = Url.ThreeDSecureFailure, url = "https://scommerce.userede.com.br/LojaTeste/Venda/opz"
128 | }
129 | }
130 | }.CreditCard(
131 | "5448280000000007",
132 | "235",
133 | "12",
134 | "2020",
135 | "Fulano de tal"
136 | );
137 |
138 | var response = new eRede.eRede(store).Create(transaction);
139 | ```
140 |
141 | Assim que a transação for criada, o cliente precisará ir até a página do banco para autenticar. O código de status `220`
142 | indica que o cliente precisará ser redirecionado:
143 |
144 | ```csharp
145 | switch (response.ReturnCode)
146 | {
147 | case "201":
148 | Console.WriteLine("A autenticação não é necessária");
149 | break;
150 | case "220":
151 | Console.WriteLine($"URL de redirecionamento enviada: {response.ThreeDSecure.Url}");
152 | break;
153 | default:
154 | Console.WriteLine(
155 | $"Foi retornado o código {response.ReturnCode} com a seguinte mensagem: '{response.ReturnMessage}");
156 | break;
157 | }
158 | ```
159 |
160 | Os códigos de [Retorno 3DS](https://www.userede.com.br/desenvolvedores/pt/produto/e-Rede#documentacao-ret3ds) também
161 | estão disponíveis na documentação.
162 |
163 |
164 |
--------------------------------------------------------------------------------
/eRede/eRede/Transaction.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.IO;
3 |
4 | namespace eRede;
5 |
6 | public class Transaction
7 | {
8 | public const string Credit = "credit";
9 | public const string Debit = "debit";
10 |
11 | public const int OrigineRede = 1;
12 | public const int OriginVisaCheckout = 4;
13 | public const int OriginMasterpass = 6;
14 |
15 | private bool _capture;
16 |
17 | public int Amount { get; set; }
18 | public Authorization Authorization { get; set; }
19 | public string AuthorizationCode { get; set; }
20 | public string CancelId { get; set; }
21 |
22 | public bool Capture
23 | {
24 | get => _capture;
25 | set
26 | {
27 | if (!value && Kind.Equals(Debit))
28 | throw new InvalidDataException("Debit transactions will always be captured");
29 |
30 | _capture = value;
31 | }
32 | }
33 |
34 | public string CardBin { get; set; }
35 | public string CardHolderName { get; set; }
36 | public string CardNumber { get; set; }
37 | public Cart Cart { get; set; }
38 | public string DateTime { get; set; }
39 | public int DistributorAffiliation { get; set; }
40 | public string ExpirationMonth { get; set; }
41 | public string ExpirationYear { get; set; }
42 | public Iata Iata { get; set; }
43 | public int Installments { get; set; }
44 | public string Kind { get; set; }
45 | public string Last4 { get; set; }
46 | public string Nsu { get; set; }
47 | public string Origin { get; set; }
48 | public string Reference { get; set; }
49 | public string RefundDateTime { get; set; }
50 | public string RefundId { get; set; }
51 | public List Refunds { get; set; }
52 | public string RequestDateTime { get; set; }
53 | public string ReturnCode { get; set; }
54 | public string ReturnMessage { get; set; }
55 | public string SecurityCode { get; set; }
56 | public string SoftDescriptor { get; set; }
57 | public string StorageCard { get; set; }
58 |
59 | public bool Subscription { get; set; }
60 | public ThreeDSecure ThreeDSecure { get; set; }
61 | public string Tid { get; set; }
62 | public List Urls { get; set; }
63 | public Additional Additional { get; set; }
64 |
65 | public SubMerchant SubMerchant { get; set; }
66 | public string PaymentFacilitatorID { get; set; }
67 |
68 | private void PrepareRefunds()
69 | {
70 | Refunds ??= new List();
71 | }
72 |
73 | private void PrepareUrls()
74 | {
75 | Urls ??= new List();
76 | }
77 |
78 | public Transaction AddUrl(string url, string kind = Url.Callback)
79 | {
80 | PrepareUrls();
81 | Urls.Add(new Url { Kind = kind, url = url });
82 |
83 | return this;
84 | }
85 |
86 | public Transaction IataTransaction(string code, string departureTax)
87 | {
88 | Iata = new Iata { Code = code, DepartureTax = departureTax };
89 |
90 | return this;
91 | }
92 |
93 | public Transaction CreditCard(
94 | string cardNumber,
95 | string securityCode,
96 | string expirationMonth,
97 | string expirationYear,
98 | string cardHolderName,
99 | bool capture = true
100 | )
101 | {
102 | Card(cardNumber, securityCode, expirationMonth, expirationYear, cardHolderName, Credit);
103 |
104 | Capture = capture;
105 |
106 | return this;
107 | }
108 |
109 | public Transaction DebitCard(
110 | string cardNumber,
111 | string securityCode,
112 | string expirationMonth,
113 | string expirationYear,
114 | string cardHolderName
115 | )
116 | {
117 | Card(cardNumber, securityCode, expirationMonth, expirationYear, cardHolderName, Debit);
118 |
119 | Capture = true;
120 | ThreeDSecure = new ThreeDSecure
121 | {
122 | Embedded = true,
123 | OnFailure = ThreeDSecure.DeclineOnFailure
124 | };
125 |
126 | return this;
127 | }
128 |
129 |
130 | private void Card(string cardNumber, string securityCode, string expirationMonth,
131 | string expirationYear,
132 | string cardHolderName, string kind)
133 | {
134 | CardNumber = cardNumber;
135 | SecurityCode = securityCode;
136 | ExpirationMonth = expirationMonth;
137 | ExpirationYear = expirationYear;
138 | CardHolderName = cardHolderName;
139 | Kind = kind;
140 | }
141 |
142 | public void Mcc(string softDescriptor, string paymentFacilitatorID, SubMerchant subMerchant)
143 | {
144 | SoftDescriptor = softDescriptor;
145 | PaymentFacilitatorID = paymentFacilitatorID;
146 | SubMerchant = subMerchant;
147 | }
148 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # Visual Studio code coverage results
114 | *.coverage
115 | *.coveragexml
116 |
117 | # NCrunch
118 | _NCrunch_*
119 | .*crunch*.local.xml
120 | nCrunchTemp_*
121 |
122 | # MightyMoose
123 | *.mm.*
124 | AutoTest.Net/
125 |
126 | # Web workbench (sass)
127 | .sass-cache/
128 |
129 | # Installshield output folder
130 | [Ee]xpress/
131 |
132 | # DocProject is a documentation generator add-in
133 | DocProject/buildhelp/
134 | DocProject/Help/*.HxT
135 | DocProject/Help/*.HxC
136 | DocProject/Help/*.hhc
137 | DocProject/Help/*.hhk
138 | DocProject/Help/*.hhp
139 | DocProject/Help/Html2
140 | DocProject/Help/html
141 |
142 | # Click-Once directory
143 | publish/
144 |
145 | # Publish Web Output
146 | *.[Pp]ublish.xml
147 | *.azurePubxml
148 | # TODO: Comment the next line if you want to checkin your web deploy settings
149 | # but database connection strings (with potential passwords) will be unencrypted
150 | *.pubxml
151 | *.publishproj
152 |
153 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
154 | # checkin your Azure Web App publish settings, but sensitive information contained
155 | # in these scripts will be unencrypted
156 | PublishScripts/
157 |
158 | # NuGet Packages
159 | *.nupkg
160 | # The packages folder can be ignored because of Package Restore
161 | **/packages/*
162 | # except build/, which is used as an MSBuild target.
163 | !**/packages/build/
164 | # Uncomment if necessary however generally it will be regenerated when needed
165 | #!**/packages/repositories.config
166 | # NuGet v3's project.json files produces more ignoreable files
167 | *.nuget.props
168 | *.nuget.targets
169 |
170 | # Microsoft Azure Build Output
171 | csx/
172 | *.build.csdef
173 |
174 | # Microsoft Azure Emulator
175 | ecf/
176 | rcf/
177 |
178 | # Windows Store app package directories and files
179 | AppPackages/
180 | BundleArtifacts/
181 | Package.StoreAssociation.xml
182 | _pkginfo.txt
183 |
184 | # Visual Studio cache files
185 | # files ending in .cache can be ignored
186 | *.[Cc]ache
187 | # but keep track of directories ending in .cache
188 | !*.[Cc]ache/
189 |
190 | # Others
191 | ClientBin/
192 | ~$*
193 | *~
194 | *.dbmdl
195 | *.dbproj.schemaview
196 | *.jfm
197 | *.pfx
198 | *.publishsettings
199 | node_modules/
200 | orleans.codegen.cs
201 |
202 | # Since there are multiple workflows, uncomment next line to ignore bower_components
203 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
204 | #bower_components/
205 |
206 | # RIA/Silverlight projects
207 | Generated_Code/
208 |
209 | # Backup & report files from converting an old project file
210 | # to a newer Visual Studio version. Backup files are not needed,
211 | # because we have git ;-)
212 | _UpgradeReport_Files/
213 | Backup*/
214 | UpgradeLog*.XML
215 | UpgradeLog*.htm
216 |
217 | # SQL Server files
218 | *.mdf
219 | *.ldf
220 |
221 | # Business Intelligence projects
222 | *.rdl.data
223 | *.bim.layout
224 | *.bim_*.settings
225 |
226 | # Microsoft Fakes
227 | FakesAssemblies/
228 |
229 | # GhostDoc plugin setting file
230 | *.GhostDoc.xml
231 |
232 | # Node.js Tools for Visual Studio
233 | .ntvs_analysis.dat
234 |
235 | # Visual Studio 6 build log
236 | *.plg
237 |
238 | # Visual Studio 6 workspace options file
239 | *.opt
240 |
241 | # Visual Studio LightSwitch build output
242 | **/*.HTMLClient/GeneratedArtifacts
243 | **/*.DesktopClient/GeneratedArtifacts
244 | **/*.DesktopClient/ModelManifest.xml
245 | **/*.Server/GeneratedArtifacts
246 | **/*.Server/ModelManifest.xml
247 | _Pvt_Extensions
248 |
249 | # Paket dependency manager
250 | .paket/paket.exe
251 | paket-files/
252 |
253 | # FAKE - F# Make
254 | .fake/
255 |
256 | # JetBrains Rider
257 | .idea/
258 | *.sln.iml
259 |
260 | # CodeRush
261 | .cr/
262 |
263 | # Python Tools for Visual Studio (PTVS)
264 | __pycache__/
265 | *.pyc
266 |
267 | # Cake - Uncomment if you are using it
268 | # tools/
269 |
--------------------------------------------------------------------------------
/eRede/eRedeTests/eRedeTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using eRede;
4 | using eRede.Service.Error;
5 | using NUnit.Framework;
6 | using Environment = eRede.Environment;
7 |
8 | namespace eRedeTests;
9 |
10 | public class eRedeTest
11 | {
12 | private string? _cardCvv;
13 | private string? _cardHolder;
14 | private string? _cardNumber;
15 | private string? _ec;
16 | private Environment? _environment;
17 | private DateTime _expiration;
18 | private string? _token;
19 |
20 | [SetUp]
21 | public void Setup()
22 | {
23 | _ec = System.Environment.GetEnvironmentVariable("EC");
24 | _token = System.Environment.GetEnvironmentVariable("TOKEN");
25 |
26 | if (_ec is null || _token is null) throw new NullReferenceException("EC e Token devem ser informados");
27 |
28 | _environment = Environment.Sandbox();
29 | _expiration = DateTime.Today.AddMonths(3);
30 |
31 | _cardNumber = "5448280000000007";
32 | _cardCvv = "123";
33 | _cardHolder = "Fulano de tal";
34 | }
35 |
36 | [Test]
37 | public void Test3DS2()
38 | {
39 | var store = new Store("", "", _environment);
40 | var transaction = new Transaction
41 | {
42 | Amount = 20,
43 | Reference = "pedido" + new Random().Next(200, 10000),
44 | ThreeDSecure = new ThreeDSecure
45 | {
46 | Embedded = true,
47 | UserAgent =
48 | "Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405",
49 | OnFailure = ThreeDSecure.ContinueOnFailure,
50 | Device = new Device
51 | {
52 | ColorDepth = 1,
53 | DeviceType3ds = "BROWSER",
54 | JavaEnabled = false,
55 | Language = "BR",
56 | ScreenHeight = 1080,
57 | ScreenWidth = 1920,
58 | TimeZoneOffset = 3
59 | }
60 | },
61 | Urls = new List
62 | {
63 | new()
64 | {
65 | Kind = Url.ThreeDSecureSuccess, url = "https://scommerce.userede.com.br/LojaTeste/Venda/sucesso"
66 | },
67 | new()
68 | {
69 | Kind = Url.ThreeDSecureFailure, url = "https://scommerce.userede.com.br/LojaTeste/Venda/opz"
70 | }
71 | }
72 | }.CreditCard(
73 | _cardNumber,
74 | _cardCvv,
75 | _expiration.Month.ToString(),
76 | _expiration.Year.ToString(),
77 | _cardHolder
78 | );
79 |
80 | var response = new eRede.eRede(store).Create(transaction);
81 |
82 | switch (response.ReturnCode)
83 | {
84 | case "201":
85 | Console.WriteLine("A autenticação não é necessária");
86 | break;
87 | case "220":
88 | Console.WriteLine($"URL de redirecionamento enviada: {response.ThreeDSecure.Url}");
89 | break;
90 | default:
91 | Console.WriteLine(
92 | $"Foi retornado o código {response.ReturnCode} com a seguinte mensagem: '{response.ReturnMessage}");
93 | break;
94 | }
95 | }
96 |
97 | [Test]
98 | public void TestEcTokenAreRequired()
99 | {
100 | var store = new Store("", "", _environment);
101 | var transaction = new Transaction
102 | {
103 | Amount = 20,
104 | Reference = "pedido" + new Random().Next(200, 10000)
105 | }.CreditCard(
106 | _cardNumber,
107 | _cardCvv,
108 | _expiration.Month.ToString(),
109 | _expiration.Year.ToString(),
110 | _cardHolder
111 | );
112 |
113 | Assert.Throws(() => new eRede.eRede(store).Create(transaction));
114 | }
115 |
116 | [Test]
117 | public void TestCreditCardAuthorization()
118 | {
119 | var store = new Store(_ec, _token, _environment);
120 | var transaction = new Transaction
121 | {
122 | Amount = 20,
123 | Reference = "pedido" + new Random().Next(200, 10000)
124 | }.CreditCard(
125 | _cardNumber,
126 | _cardCvv,
127 | _expiration.Month.ToString(),
128 | _expiration.Year.ToString(),
129 | _cardHolder,
130 | false
131 | );
132 |
133 | var response = new eRede.eRede(store).Create(transaction);
134 |
135 | Assert.AreEqual("00", response.ReturnCode);
136 | Assert.That(response.AuthorizationCode, Is.Not.Empty);
137 | Assert.That(response.Tid, Is.Not.Empty);
138 | Assert.That(response.Brand, Is.Not.Null);
139 | Assert.That(response.Brand.Name, Is.Not.Null);
140 | Assert.That(response.Brand.ReturnCode, Is.Not.Null);
141 | Assert.That(response.Brand.ReturnMessage, Is.Not.Null);
142 | }
143 |
144 | [Test]
145 | public void TestCreditCardAuthorizationWithCapture()
146 | {
147 | var store = new Store(_ec, _token, _environment);
148 | var transaction = new Transaction
149 | {
150 | Amount = 20,
151 | Reference = "pedido" + new Random().Next(200, 10000)
152 | }.CreditCard(
153 | _cardNumber,
154 | _cardCvv,
155 | _expiration.Month.ToString(),
156 | _expiration.Year.ToString(),
157 | _cardHolder
158 | );
159 |
160 | var response = new eRede.eRede(store).Create(transaction);
161 |
162 | Assert.AreEqual("00", response.ReturnCode);
163 | Assert.That(response.AuthorizationCode, Is.Not.Empty);
164 | Assert.That(response.Tid, Is.Not.Empty);
165 | Assert.That(response.Brand, Is.Not.Null);
166 | Assert.That(response.Brand.Name, Is.Not.Null);
167 | Assert.That(response.Brand.ReturnCode, Is.Not.Null);
168 | Assert.That(response.Brand.ReturnMessage, Is.Not.Null);
169 | }
170 |
171 | [Test]
172 | public void TestCancellation()
173 | {
174 | var store = new Store(_ec, _token, _environment);
175 | var transaction = new Transaction
176 | {
177 | Amount = 20,
178 | Reference = "pedido" + new Random().Next(200, 10000)
179 | }.CreditCard(
180 | _cardNumber,
181 | _cardCvv,
182 | _expiration.Month.ToString(),
183 | _expiration.Year.ToString(),
184 | _cardHolder
185 | );
186 |
187 | var eRede = new eRede.eRede(store);
188 | var response = eRede.Create(transaction);
189 |
190 | var cancellation = eRede.Cancel(transaction, response.Tid);
191 |
192 | Assert.That(cancellation.RefundId, Is.Not.Empty);
193 | }
194 |
195 | [Test]
196 | public void TestCapture()
197 | {
198 | var store = new Store(_ec, _token, _environment);
199 | var transaction = new Transaction
200 | {
201 | Amount = 20,
202 | Reference = "pedido" + new Random().Next(200, 10000)
203 | }.CreditCard(
204 | _cardNumber,
205 | _cardCvv,
206 | _expiration.Month.ToString(),
207 | _expiration.Year.ToString(),
208 | _cardHolder,
209 | false
210 | );
211 |
212 | var eRede = new eRede.eRede(store);
213 | var response = eRede.Create(transaction);
214 |
215 | try
216 | {
217 | var capture = eRede.Capture(transaction, response.Tid);
218 |
219 | Assert.That(capture.Nsu, Is.Not.Empty);
220 | }
221 | catch (RedeException e)
222 | {
223 | Console.WriteLine(e.Message);
224 | Console.WriteLine(e.Error);
225 | }
226 | }
227 |
228 | [Test]
229 | public void TestZeroDolarAuthorization()
230 | {
231 | var store = new Store(_ec, _token, _environment);
232 | var transaction = new Transaction
233 | {
234 | Amount = 20,
235 | Reference = "pedido" + new Random().Next(200, 10000)
236 | }.CreditCard(
237 | _cardNumber,
238 | _cardCvv,
239 | _expiration.Month.ToString(),
240 | _expiration.Year.ToString(),
241 | _cardHolder,
242 | false
243 | );
244 |
245 | var response = new eRede.eRede(store).Zero(transaction);
246 |
247 | Assert.AreEqual("174", response.ReturnCode);
248 | Assert.That(response.AuthorizationCode, Is.Not.Empty);
249 | Assert.That(response.Tid, Is.Not.Empty);
250 | Assert.That(response.Brand, Is.Not.Null);
251 | Assert.That(response.Brand.Name, Is.Not.Null);
252 | Assert.That(response.Brand.ReturnCode, Is.Not.Null);
253 | Assert.That(response.Brand.ReturnMessage, Is.Not.Null);
254 | }
255 | }
--------------------------------------------------------------------------------