Skip to content

Commit

Permalink
add InstalmentLink.RetrieveMany()
Browse files Browse the repository at this point in the history
  • Loading branch information
hwjeremy committed Jan 20, 2021
1 parent 6f7873c commit a462a57
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ProcuretAPI/ProcuretAPI.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>ProcuretAPI</id>
<version>0.0.4</version>
<version>0.0.5</version>
<title>Procuret API</title>
<authors>[email protected]</authors>
<owners>Procuret Operating Pty Ltd</owners>
Expand Down
86 changes: 82 additions & 4 deletions ProcuretAPI/src/InstalmentLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading.Tasks;
using System.Runtime.Serialization;
using System.Net.Http;
using System.Collections.Generic;


namespace ProcuretAPI
Expand All @@ -16,20 +17,23 @@ public struct InstalmentLink
public readonly Decimal InvoiceAmount;
public readonly String InvoiceIdentifier;
public readonly String InviteeEmail;
public readonly LinkOpen[] Opens;

internal InstalmentLink(
String publicId,
EntityHeadline supplier,
String inviteeEmail,
Decimal invoiceAmount,
String invoiceIdentifier
String invoiceIdentifier,
LinkOpen[] linkOpens
)
{
this.PublicId = publicId;
this.Supplier = supplier;
this.InviteeEmail = inviteeEmail;
this.InvoiceAmount = invoiceAmount;
this.InvoiceIdentifier = invoiceIdentifier;
this.Opens = linkOpens;
return;
}

Expand Down Expand Up @@ -78,12 +82,81 @@ Session session
decodePayload.supplier,
decodePayload.invitee_email,
Convert.ToDecimal(decodePayload.invoice_amount),
decodePayload.invoice_identifier
decodePayload.invoice_identifier,
decodePayload.opens
);

return link;
}

public enum OrderBy
{
CREATED = 1
}

public static async Task<InstalmentLink[]> RetrieveMany(
Session session,
Int64? supplierId = null,
Int32 offset = 0,
Int32 limit = 20,
Order order = Order.ASCENDING,
InstalmentLink.OrderBy orderBy = InstalmentLink.OrderBy.CREATED,
String publicId = null
)
{

List<QueryParameter> parameters = new List<QueryParameter>();

parameters.Add(new QueryParameter(offset, "offset"));
parameters.Add(new QueryParameter(limit, "limit"));
parameters.Add(new QueryParameter(order));
parameters.Add(new QueryParameter(orderBy));

if (supplierId != null)
{
parameters.Add(
new QueryParameter(supplierId ?? 0, "supplier_id")
);
}

if (publicId != null)
{
parameters.Add(
new QueryParameter(publicId, "public_id")
);
}


String resultBody = await ApiRequest.Make(
path: InstalmentLink.path + "/list",
query: new QueryString(parameters),
session: session,
method: HttpMethod.Get
);

var decodePayload = ApiRequest.DecodeResponse<DecodeArrayPayload>(
resultBody
);

var resultList = new List<InstalmentLink>();

foreach (InstalmentLink.DecodePayload link in decodePayload)
{
resultList.Add(new InstalmentLink(
link.public_id,
link.supplier,
link.invitee_email,
Convert.ToDecimal(link.invoice_amount),
link.invoice_identifier,
link.opens
));
continue;
}

return resultList.ToArray();

}

[DataContract(Name="procuret_data", Namespace="")]
internal struct CreatePayload
{
Expand Down Expand Up @@ -115,8 +188,12 @@ String communicate
}
}


[CollectionDataContract(Name = "procuret_data", Namespace = "")]
internal class DecodeArrayPayload : List<DecodePayload> { }

[DataContract(Name="procuret_data", Namespace="")]
internal struct DecodePayload
internal class DecodePayload
{
[DataMember]
internal readonly String public_id;
Expand All @@ -133,8 +210,9 @@ internal struct DecodePayload
[DataMember]
internal readonly String invoice_identifier;

[DataMember]
internal readonly LinkOpen[] opens;

}

}
}
12 changes: 12 additions & 0 deletions ProcuretAPI/src/LinkOpen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Runtime.Serialization;

namespace ProcuretAPI
{
[DataContract(Name="procuret_data", Namespace="")]
public struct LinkOpen
{
public readonly Int32 Sequence;
public readonly String Created;
}
}
9 changes: 9 additions & 0 deletions ProcuretAPI/src/Order.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;
namespace ProcuretAPI
{
public enum Order
{
ASCENDING = 1,
DESCENDING = 2
}
}
32 changes: 32 additions & 0 deletions ProcuretAPI/src/QueryParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,38 @@ internal QueryParameter(Int16 value, String key)
{
this.key = key;
this.value = value.ToString();
return;
}

internal QueryParameter(Int64 value, String key)
{
this.key = key;
this.value = value.ToString();
return;
}

internal QueryParameter(Order value)
{
this.key = "order";
if (value == Order.ASCENDING)
{
this.value = "ascending";
} else
{
this.value = "descending";
}
return;
}

internal QueryParameter(InstalmentLink.OrderBy value)
{
this.key = "order_by";
if (value == InstalmentLink.OrderBy.CREATED)
{
this.value = "created";
return;
}
throw new ApiRequestException();
}

}
Expand Down
10 changes: 9 additions & 1 deletion ProcuretAPI/src/QueryString.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System;

namespace ProcuretAPI
{
internal struct QueryString
Expand Down Expand Up @@ -39,6 +41,12 @@ internal QueryString(QueryParameter[] parameters)
return;
}

internal QueryString(List<QueryParameter> parameters)
{
this.parameters = parameters.ToArray();
return;
}



}
Expand Down
27 changes: 26 additions & 1 deletion ProcuretAPI_Tests/InstalmentLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace ProcuretAPI_Tests
{
public class CreateInstalmentLink: WithSession
public class ExerciseInstalmentLink : WithSession
{
[Fact]
public async Task TestCreateInstalmentLink()
Expand All @@ -25,5 +25,30 @@ public async Task TestCreateInstalmentLink()
return;

}

[Fact]
public async Task TestListInstalmentLink()
{

InstalmentLink link = await InstalmentLink.Create(
supplierId: 4000,
customerEmail: "[email protected]",
invoiceIdentifier: "Test ID",
invoiceValue: Convert.ToDecimal("422.22"),
communication: CommunicationOption.NotifyCustomer,
session: this.Session
);

InstalmentLink[] links = await InstalmentLink.RetrieveMany(
supplierId: 4000,
limit: 2,
session: this.Session
);

Assert.True(links.Length > 0, "Actual length: " + links.Length.ToString());

return;

}
}
}
File renamed without changes.

0 comments on commit a462a57

Please sign in to comment.