Skip to content

Commit

Permalink
Fix DevelopersRede#1 - Corrige hierarquia de chamada de métodos e aju…
Browse files Browse the repository at this point in the history
…sta tipo de retorno
  • Loading branch information
netojoaobatista committed Mar 26, 2019
1 parent d0bea80 commit c113594
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 37 deletions.
9 changes: 9 additions & 0 deletions eRede/eRede/Link.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace eRede
{
public class Link
{
public string method { get; set; }
public string rel { get; set; }
public string href { get; set; }
}
}
15 changes: 4 additions & 11 deletions eRede/eRede/Service/AbstractTransactionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,21 @@ internal AbstractTransactionService(Store store, Transaction transaction)

public string tid { get; set; }

protected string getUri()
protected virtual string getUri()
{
return store.environment.Endpoint("transactions");
}

public Transaction Execute(Method method = Method.POST)
public TransactionResponse Execute(Method method = Method.POST)
{
var json = JsonConvert.SerializeObject(transaction, Formatting.None,
new JsonSerializerSettings
{
DefaultValueHandling = DefaultValueHandling.Ignore,
NullValueHandling = NullValueHandling.Ignore
});

var request = new RestRequest {Method = method, RequestFormat = DataFormat.Json};

request.AddJsonBody(transaction);

return sendRequest(request);
}

protected Transaction sendRequest(RestRequest request)
protected TransactionResponse sendRequest(RestRequest request)
{
var client = new RestClient(getUri())
{
Expand All @@ -51,7 +44,7 @@ protected Transaction sendRequest(RestRequest request)

if (status < 200 || status >= 400) throw response.ErrorException;

return JsonConvert.DeserializeObject<Transaction>(response.Content);
return JsonConvert.DeserializeObject<TransactionResponse>(response.Content);
}
}
}
4 changes: 2 additions & 2 deletions eRede/eRede/Service/CancelTransactionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ public CancelTransactionService(Store store, Transaction transaction) : base(sto
{
}

protected string getUri()
protected override string getUri()
{
return getUri() + "/" + tid + "/refunds";
return base.getUri() + "/" + tid + "/refunds";
}
}
}
4 changes: 2 additions & 2 deletions eRede/eRede/Service/CaptureTransactionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public CaptureTransactionService(Store store, Transaction transaction) : base(st
{
}

public Transaction Execute()
public TransactionResponse Execute()
{
return Execute(Method.PUT);
return base.Execute(Method.PUT);
}
}
}
8 changes: 4 additions & 4 deletions eRede/eRede/Service/GetTransactionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ public GetTransactionService(Store store, Transaction transaction = null) : base
public string reference { get; set; }
public bool refund { get; set; }

protected string getUri()
protected override string getUri()
{
var uri = getUri();
var uri = base.getUri();

if (reference != null) return uri + "?reference=" + reference;

if (refund) return uri + "/" + tid + "/refunds";

return uri;
return uri + "/" + tid;
}

public Transaction Execute()
public TransactionResponse Execute()
{
var request = new RestRequest {Method = Method.GET};

Expand Down
5 changes: 2 additions & 3 deletions eRede/eRede/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Transaction
public Authorization authorization { get; set; }
public string authorizationCode { get; set; }
public string cancelId { get; set; }

public bool capture { get; set; }
public string cardBin { get; set; }
public string cardHolderName { get; set; }
Expand Down Expand Up @@ -107,7 +108,7 @@ public Transaction DebitCard(string cardNumber, string securityCode, string expi
}


private Transaction SetCard(string cardNumber, string securityCode, string expirationMonth,
private void SetCard(string cardNumber, string securityCode, string expirationMonth,
string expirationYear,
string cardHolderName, string kind)
{
Expand All @@ -117,8 +118,6 @@ private Transaction SetCard(string cardNumber, string securityCode, string expir
this.expirationYear = expirationYear;
this.cardHolderName = cardHolderName;
this.kind = kind;

return this;
}
}
}
53 changes: 53 additions & 0 deletions eRede/eRede/TransactionResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System.Collections.Generic;

namespace eRede
{
public class TransactionResponse
{
public int amount { get; set; }
public Antifraud antifraud { get; set; }
public bool antifraudRequired { get; set; }

public string authorizationCode { get; set; }
public string cancelId { get; set; }


public string cardBin { get; set; }
public string cardHolderName { get; set; }
public string cardNumber { get; set; }
public Cart cart { get; set; }
public string dateTime { get; set; }
public int distributorAffiliation { get; set; }
public string expirationMonth { get; set; }
public string expirationYear { get; set; }
public Iata iata { get; set; }
public int installments { get; set; }
public string kind { get; set; }
public string last4 { get; set; }
public string nsu { get; set; }
public string origin { get; set; }
public string reference { get; set; }
public string refundDateTime { get; set; }
public string refundId { get; set; }
public List<Refund> refunds { get; set; }


public string securityCode { get; set; }
public string softDescriptor { get; set; }
public string storageCard { get; set; }


public bool subscription { get; set; }
public ThreeDSecure threeDSecure { get; set; }

public List<Url> urls { get; set; }

public List<Link> links { get; set; }
public Capture capture { get; set; }
public Authorization authorization { get; set; }
public string requestDateTime { get; set; }
public string tid { get; set; }
public string returnCode { get; set; }
public string returnMessage { get; set; }
}
}
24 changes: 9 additions & 15 deletions eRede/eRede/eRede.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,33 @@ public eRede(Store store)
this.store = store;
}

public Transaction authorize(Transaction transaction)
public TransactionResponse authorize(Transaction transaction)
{
return create(transaction);
}

public Transaction create(Transaction transaction)
public TransactionResponse create(Transaction transaction)
{
var createTransactionService = new CreateTransactionService(store, transaction);

return createTransactionService.Execute();
}

public Transaction cancel(Transaction transaction)
public TransactionResponse cancel(Transaction transaction)
{
var cancelTransactionService = new CancelTransactionService(store, transaction);

return cancelTransactionService.Execute();
}

public Transaction capture(Transaction transaction)
public TransactionResponse capture(Transaction transaction)
{
var captureTransactionService = new CaptureTransactionService(store, transaction);

return captureTransactionService.Execute();
}

public Transaction get(string tid)
public TransactionResponse get(string tid)
{
var getTransactionService = new GetTransactionService(store)
{
Expand All @@ -50,7 +50,7 @@ public Transaction get(string tid)
return getTransactionService.Execute();
}

public Transaction getByReference(string reference)
public TransactionResponse getByReference(string reference)
{
var getTransactionService = new GetTransactionService(store)
{
Expand All @@ -60,7 +60,7 @@ public Transaction getByReference(string reference)
return getTransactionService.Execute();
}

public Transaction getRefunds(string tid)
public TransactionResponse getRefunds(string tid)
{
var getTransactionService = new GetTransactionService(store)
{
Expand All @@ -71,18 +71,12 @@ public Transaction getRefunds(string tid)
return getTransactionService.Execute();
}

public Transaction zero(Transaction transaction)
public TransactionResponse zero(Transaction transaction)
{
var amount = transaction.amount;
var capture = transaction.capture;

transaction.amount = 0;
transaction.capture = true;
transaction = create(transaction);
transaction.amount = amount;
transaction.capture = capture;

return transaction;
return create(transaction);
}
}
}
2 changes: 2 additions & 0 deletions eRede/eRede/eRede.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<Compile Include="Flight.cs" />
<Compile Include="Iata.cs" />
<Compile Include="Item.cs" />
<Compile Include="Link.cs" />
<Compile Include="Passenger.cs" />
<Compile Include="Phone.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand All @@ -75,6 +76,7 @@
<Compile Include="Store.cs" />
<Compile Include="ThreeDSecure.cs" />
<Compile Include="Transaction.cs" />
<Compile Include="TransactionResponse.cs" />
<Compile Include="Url.cs" />
</ItemGroup>
<ItemGroup>
Expand Down

0 comments on commit c113594

Please sign in to comment.