Skip to content

Commit

Permalink
add ProspectivePayment.RetrieveMany() and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hwjeremy committed Jan 21, 2021
1 parent 626e7a8 commit 0261213
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ProcuretAPI/ProcuretAPI.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
</description>
<summary>A .NET Standard libary for the Procuret API. Procuret facilitates business to business transations. Suppliers get paid upfront, while customer businesses pay over time. Use Procuret .NET to add Procuret as a payment option in your .NET application.
</summary>
<releaseNotes>Added `ProspectivePayment`, `InstalmentLink` properties</releaseNotes>
<copyright>Copyright 2020 Procuret Operating Pty Ltd</copyright>
<releaseNotes>Added `ProspectivePayment.RetrieveMany()`, `InstalmentLink.RetrieveMany()`</releaseNotes>
<copyright>Copyright 2021 Procuret Operating Pty Ltd</copyright>
<tags>api finance</tags>
<language>en-au</language>
<repository
Expand Down
52 changes: 51 additions & 1 deletion ProcuretAPI/src/ProspectivePayment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
using System.Threading.Tasks;
using System.Runtime.Serialization;
using System.Net.Http;
using System.Collections.Generic;


namespace ProcuretAPI
{
public struct ProspectivePayment
{
internal const String Path = "/credit/prospective-payment";
internal const String ListPath = ProspectivePayment.Path + "/list";

public readonly Decimal RecurringPayment;
public readonly String SupplierId;
Expand Down Expand Up @@ -70,9 +72,57 @@ public static async Task<ProspectivePayment> Retrieve(

}

public static async Task<ProspectivePayment[]> RetrieveMany(
Session session,
String supplierId,
Decimal principle,
HttpClient httpClient = null
)
{

QueryParameter[] parameters = {
new QueryParameter(supplierId, "supplier_id"),
new QueryParameter(principle.ToString(), "principle"),
new QueryParameter((Int16)Cycle.ADVANCE, "cycle")
};

QueryString query = new QueryString(parameters);

String resultBody = await ApiRequest.Make(
ProspectivePayment.ListPath,
query,
session,
HttpMethod.Get,
httpClient
);

var responsePayload = ApiRequest.DecodeResponse<ArrayResponse>(
resultBody
);

var resultList = new List<ProspectivePayment>();

foreach (ResponsePayload payload in responsePayload)
{
resultList.Add(new ProspectivePayment(
Convert.ToDecimal(payload.payment),
payload.supplierId,
payload.periods,
(Cycle)payload.cycle

));
continue;
}

return resultList.ToArray();

}

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

[DataContract(Name="procuret_data", Namespace="")]
internal struct ResponsePayload
internal class ResponsePayload
{
[DataMember]
internal readonly String payment;
Expand Down
16 changes: 16 additions & 0 deletions ProcuretAPI_Tests/ProspectivePayment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,24 @@ public async Task TestRetreiveProspectivePayment()
12
);

Assert.True(payment.PaymentCount == 12);

return;

}

[Fact]
public async Task TestListProspectivePayment()
{
var payments = await ProspectivePayment.RetrieveMany(
session: this.Session,
supplierId: "4000",
principle: Convert.ToDecimal("1000")
);

Assert.True(payments.Length > 0);

return;
}
}
}

0 comments on commit 0261213

Please sign in to comment.