Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions StarkBank/StarkBank/Boleto/Boleto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace StarkBank
/// <item>WorkspaceID [string]: ID of the Workspace where this Boleto was generated. ex: "4545454545454545"</item>
/// <item>OurNumber [string]: Reference number registered at the settlement bank. ex:"10131474"</item>
/// <item>Created [DateTime]: creation datetime for the Boleto. ex: DateTime(2020, 3, 10, 10, 30, 0, 0)</item>
/// <item>Splits [list of StarkBank.Split]: Array of Split objects to indicate payment receivers</item>
/// </list>
/// </summary>
public partial class Boleto : Resource
Expand Down Expand Up @@ -73,6 +74,7 @@ public partial class Boleto : Resource
public string WorkspaceID { get; }
public string OurNumber { get; }
public DateTime? Created { get; }
public List<Split> Splits { get; }

/// <summary>
/// Boleto object
Expand Down Expand Up @@ -105,6 +107,7 @@ public partial class Boleto : Resource
/// <item>descriptions [list of dictionaries, default null]: list of dictionaries with "text":string and (optional) "amount":int pairs. ex: new List<Dictionary<string,string>>(){new Dictionary<string, string>{{"amount", 1000},{"text", "Taxes"}}</item>
/// <item>discounts [list of dictionaries, default null]: list of dictionaries with "percentage":float and "date":DateTime pairs. ex: new List<Dictionary<string,string>>(){new Dictionary<string, string>{{"percentage", 1.5},{"date", new DateTime(2020, 3, 8)}}</item>
/// <item>tags [list of strings]: list of strings for tagging</item>
/// <item>splits [list of Split]: array of Split objects to indicate payment receivers</item>
/// </list>
/// <br/>
/// Attributes (return-only):
Expand All @@ -123,10 +126,10 @@ public partial class Boleto : Resource
public Boleto(long amount, string name, string taxID, string streetLine1, string streetLine2, string district,
string city, string stateCode, string zipCode, DateTime? due = null, double? fine = null, double? interest = null,
int? overdueLimit = null, string receiverName = null, string receiverTaxID = null, List<string> tags = null,
List<Dictionary<string, object>> descriptions = null, List<Dictionary<string, object>> discounts = null,
string id = null, int? fee = null, string line = null, string barCode = null, string status = null,
List<string> transactionIds = null, string workspaceID = null, DateTime? created = null,
string ourNumber = null) : base(id)
List<Dictionary<string, object>> descriptions = null, List<Dictionary<string, object>> discounts = null,
string id = null, int? fee = null, string line = null, string barCode = null, string status = null,
List<string> transactionIds = null, string workspaceID = null, DateTime? created = null,
string ourNumber = null, List<Split> splits = null) : base(id)
{
Amount = amount;
Name = name;
Expand Down Expand Up @@ -154,6 +157,7 @@ public Boleto(long amount, string name, string taxID, string streetLine1, string
WorkspaceID = workspaceID;
OurNumber = ourNumber;
Created = created;
Splits = splits;
}

internal new Dictionary<string, object> ToJson()
Expand Down Expand Up @@ -455,15 +459,29 @@ internal static Resource ResourceMaker(dynamic json)
DateTime? created = StarkCore.Utils.Checks.CheckDateTime(createdString);
string workspaceID = json.workspaceId;
string ourNumber = json.ourNumber;
List<Split> splits = ParseSplits(json.splits);

return new Boleto(
amount: amount, name: name, taxID: taxID, streetLine1: streetLine1, streetLine2: streetLine2,
district: district, city: city, stateCode: stateCode, zipCode: zipCode, due: due, fine: fine,
interest: interest, overdueLimit: overdueLimit, receiverName: receiverName, receiverTaxID: receiverTaxID,
tags: tags, descriptions: descriptions, discounts: discounts, id: id, fee: fee, line: line,
barCode: barCode, status: status, transactionIds: transactionIds, workspaceID: workspaceID,
created: created, ourNumber: ourNumber
created: created, ourNumber: ourNumber, splits: splits
);
}

private static List<Split> ParseSplits(dynamic json)
{
if (json is null) return null;

List<Split> splits = new List<Split>();

foreach (dynamic split in json)
{
splits.Add(Split.ResourceMaker(split));
}
return splits;
}
}
}
21 changes: 19 additions & 2 deletions StarkBank/StarkBank/Invoice/Invoice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace StarkBank
/// <item>TransactionIds [list of strings]: ledger transaction ids linked to this Invoice (if there are more than one, all but the first are reversals or failed reversal chargebacks). ex: ["19827356981273"]</item>
/// <item>Created [DateTime]: creation datetime for the Invoice. ex: DateTime(2020, 3, 10, 10, 30, 0, 0)</item>
/// <item>Updated [DateTime]: latest update datetime for the Invoice. ex: DateTime(2020, 3, 10, 10, 30, 0, 0)</item>
/// <item>Splits [list of StarkBank.Split]: Array of Split objects to indicate payment receivers</item>
/// </list>
/// </summary>
public partial class Invoice : Resource
Expand Down Expand Up @@ -67,6 +68,7 @@ public partial class Invoice : Resource
public List<string> TransactionIds { get; }
public DateTime? Created { get; }
public DateTime? Updated { get; }
public List<Split> Splits { get; }

/// <summary>
/// Invoice object
Expand Down Expand Up @@ -94,6 +96,7 @@ public partial class Invoice : Resource
/// <item>rules [list of StarkBank.Invoice.Rule objects, default null]: list of Invoice.Rule objects for modifying invoice behavior. ex: [Invoice.Rule(key="allowedTaxIds", value=["012.345.678-90", "45.059.493/0001-73"])]</item>
/// <item>tags [list of strings, default null]: list of strings for tagging</item>
/// <item>descriptions [list of dictionaries, default null]: list of dictionaries with "key":string and (optional) "value":string pairs. ex: new List<Dictionary<string,string>>(){new Dictionary<string, string>{{"key", "Taxes"},{"value", "100"}}</item>
/// <item>splits [list of Split]: array of Split objects to indicate payment receivers</item>
/// </list>
/// <br/>
/// Attributes (return-only):
Expand All @@ -116,7 +119,7 @@ public partial class Invoice : Resource
public Invoice(long amount, string name, string taxID, DateTime? due = null, long? expiration = null, double? fine = null, double? interest = null,
List<string> tags = null, List<Dictionary<string, object>> descriptions = null, List<Dictionary<string, object>> discounts = null, List<Rule> rules = null,
long? nominalAmount = null, long? fineAmount = null, long? interestAmount = null, long? discountAmount = null,
string id = null, string brcode = null, string pdfUrl = null, string link = null, int? fee = null, string status = null, List<string> transactionIds = null, DateTime? created = null, DateTime? updated = null) : base(id)
string id = null, string brcode = null, string pdfUrl = null, string link = null, int? fee = null, string status = null, List<string> transactionIds = null, DateTime? created = null, DateTime? updated = null, List<Split> splits = null) : base(id)
{
Amount = amount;
Name = name;
Expand All @@ -141,6 +144,7 @@ public Invoice(long amount, string name, string taxID, DateTime? due = null, lon
TransactionIds = transactionIds;
Created = created;
Updated = updated;
Splits = splits;
}

internal new Dictionary<string, object> ToJson()
Expand Down Expand Up @@ -514,16 +518,29 @@ internal static Resource ResourceMaker(dynamic json)
List<string> transactionIds = json.transactionIds.ToObject<List<string>>();
DateTime? created = StarkCore.Utils.Checks.CheckDateTime(createdString);
DateTime? updated = StarkCore.Utils.Checks.CheckDateTime(updatedString);
List<Split> splits = ParseSplits(json.splits);

return new Invoice(
amount: amount, name: name, taxID: taxID, due: due, expiration: expiration, fine: fine, interest: interest,
tags: tags, descriptions: descriptions, discounts: discounts, nominalAmount: nominalAmount, fineAmount: fineAmount,
interestAmount: interestAmount, discountAmount: discountAmount, id: id, brcode: brcode, pdfUrl: pdf, link: link,
rules: rules, fee: fee, status: status, transactionIds: transactionIds, created: created, updated: updated
rules: rules, fee: fee, status: status, transactionIds: transactionIds, created: created, updated: updated, splits: splits
);

}

private static List<Split> ParseSplits(dynamic json)
{
if (json is null) return null;

List<Split> splits = new List<Split>();

foreach (dynamic split in json)
{
splits.Add(Split.ResourceMaker(split));
}
return splits;
}
private static List<Rule> ParseRule(dynamic json)
{
if(json is null) return null;
Expand Down
167 changes: 167 additions & 0 deletions StarkBank/StarkBank/Split/Log.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
using StarkBank.Utils;
using System;
using System.Collections.Generic;
using System.Linq;

namespace StarkBank
{
/// <summary>
/// Split object
/// <br/>
/// Represents a financial split transaction, detailing the distribution of an amount to a specified receiver.
/// </summary>
/// <remarks>The Split resource is used to split an Invoice or Boleto between different receivers.</remarks>
public partial class Split
{
public class Log : Resource
{

public DateTime Created { get; }
public string Type { get; }
public List<string> Errors { get; }
public Split Split { get; }

public Log(string id, DateTime created, string type, List<string> errors, Split split) : base(id)
{
Created = created;
Type = type;
Errors = errors;
Split = split;
}


/// <summary>
/// Retrieve a specific Split.Log
/// <br/>
/// Retrieve a single Split.Log object previously created in the Stark Bank API by passing its id
/// <br/>
/// Parameters(required):
/// <list>
/// <item>id[string]: object unique id. ex: "5659211052613632"</item>
/// </list>
/// <br/>
/// Parameters(optional):
/// <list>
/// <item>user[Project object]: Project object. Not necessary if StarkBank.User.Default was set before function call</item>
/// </list>
/// <br/>
/// Return:
/// <list>
/// <item>Split.Log object with updated attributes</item>
/// </list>
/// </summary>
public static Log Get(string id, User user = null)
{
(string resourceName, StarkCore.Utils.Api.ResourceMaker resourceMaker) = Resource();
return Rest.GetId(
resourceName: resourceName,
resourceMaker: resourceMaker,
id: id,
user: user
) as Log;
}

/// <summary>
/// Retrieve Split Logs
/// <br/>
/// Receive an IEnumerable of Split.Log objects previously created in the Stark Bank API
/// <br/>
/// Parameters (optional):
/// <list>
/// <item>limit [integer, default null]: maximum number of objects to be retrieved. Unlimited if null. ex: 35</item>
/// <item>after [DateTime, default null]: date filter for objects created only after specified date. ex: DateTime(2020, 3, 10)</item>
/// <item>before [DateTime, default null]: date filter for objects created only before specified date. ex: DateTime(2020, 3, 10)</item>
/// <item>types [list of strings, default null]: filter for log event types. ex: "paid" or "registered"</item>
/// <item>splitIds [list of strings, default null]: list of Split ids to filter logs. ex: ["5656565656565656", "5745664021495808"]</item>
/// <item>user [Project object, default null]: Project object. Not necessary if StarkBank.User.Default was set before function call</item>
/// </list>
/// <br/>
/// Return:
/// <list>
/// <item>list of Split.Log objects with updated attributes</item>
/// </list>
/// </summary>
public static IEnumerable<Log> Query(int? limit = null, DateTime? after = null, DateTime? before = null,
List<string> types = null, List<string> splitIds = null, User user = null)
{
(string resourceName, StarkCore.Utils.Api.ResourceMaker resourceMaker) = Resource();
return Rest.GetList(
resourceName: resourceName,
resourceMaker: resourceMaker,
query: new Dictionary<string, object> {
{ "limit", limit },
{ "after", new StarkCore.Utils.StarkDate(after) },
{ "before", new StarkCore.Utils.StarkDate(before) },
{ "types", types },
{ "splitIds ", splitIds }
},
user: user
).Cast<Log>();
}

/// <summary>
/// Retrieve paged Split.Logs
/// <br/>
/// Receive a list of up to 100 Split.Log objects previously created in the Stark Bank API and the cursor to the next page.
/// Use this function instead of query if you want to manually page your requests.
/// <br/>
/// Parameters (optional):
/// <list>
/// <item>cursor [string, default null]: cursor returned on the previous page function call</item>
/// <item>limit [integer, default null]: maximum number of objects to be retrieved. Unlimited if null. ex: 35</item>
/// <item>after [DateTime, default null]: date filter for objects created only after specified date. ex: DateTime(2020, 3, 10)</item>
/// <item>before [DateTime, default null]: date filter for objects created only before specified date. ex: DateTime(2020, 3, 10)</item>
/// <item>types [list of strings, default null]: filter for log event types. ex: "paid" or "registered"</item>
/// <item>splitIds [list of strings, default null]: list of Split ids to filter logs. ex: ["5656565656565656", "5745664021495808"]</item>
/// <item>user [Project object, default null]: Project object. Not necessary if StarkBank.User.Default was set before function call</item>
/// </list>
/// <br/>
/// Return:
/// <list>
/// <item>list of Split.Log objects with updated attributes and cursor to retrieve the next page of Split.Log objects</item>
/// </list>
/// </summary>
public static (List<Log> page, string pageCursor) Page(string cursor = null, int? limit = null, DateTime? after = null,
DateTime? before = null, List<string> types = null, List<string> splitIds = null, User user = null)
{
(string resourceName, StarkCore.Utils.Api.ResourceMaker resourceMaker) = Resource();
(List<StarkCore.Utils.SubResource> page, string pageCursor) = Rest.GetPage(
resourceName: resourceName,
resourceMaker: resourceMaker,
query: new Dictionary<string, object> {
{ "cursor", cursor },
{ "limit", limit },
{ "after", new StarkCore.Utils.StarkDate(after) },
{ "before", new StarkCore.Utils.StarkDate(before) },
{ "types", types },
{ "splitIds", splitIds }
},
user: user
);
List<Log> logs = new List<Log>();
foreach (StarkCore.Utils.SubResource subResource in page)
{
logs.Add(subResource as Log);
}
return (logs, pageCursor);
}

internal static (string resourceName, StarkCore.Utils.Api.ResourceMaker resourceMaker) Resource()
{
return (resourceName: "SplitLog", resourceMaker: ResourceMaker);
}

internal static Resource ResourceMaker(dynamic json)
{
List<string> errors = json.errors.ToObject<List<string>>();
string id = json.id;
string createdString = json.created;
DateTime created = StarkCore.Utils.Checks.CheckDateTime(createdString);
string type = json.type;
Split split = Split.ResourceMaker(json.split);

return new Log(id: id, created: created, type: type, errors: errors, split: split);
}
}
}
}
Loading