From 3030f734e9c493fab21aa084b291566c9bd1ab79 Mon Sep 17 00:00:00 2001 From: MJMortimer Date: Fri, 25 Jan 2019 13:52:01 +1300 Subject: [PATCH] Add BatchPayments functionality --- .../Core/Endpoints/BatchPaymentsEndpoint.cs | 23 ++++++++ Xero.Api/Core/IXeroCoreApi.cs | 1 + Xero.Api/Core/Model/BatchPayment.cs | 52 +++++++++++++++++++ ...ents.cs => BatchPaymentContactDefaults.cs} | 4 +- Xero.Api/Core/Model/BatchPaymentPayment.cs | 37 +++++++++++++ Xero.Api/Core/Model/Contact.cs | 2 +- .../Core/Model/Status/BatchPaymentStatus.cs | 13 +++++ Xero.Api/Core/Model/Types/BatchPaymentType.cs | 13 +++++ Xero.Api/Core/Request/BatchPaymentsRequest.cs | 11 ++++ .../Core/Response/BatchPaymentsResponse.cs | 16 ++++++ Xero.Api/Core/XeroCoreApi.cs | 2 + Xero.Api/Serialization/DefaultMapper.cs | 2 + Xero.Api/Xero.Api.csproj | 9 +++- 13 files changed, 181 insertions(+), 4 deletions(-) create mode 100644 Xero.Api/Core/Endpoints/BatchPaymentsEndpoint.cs create mode 100644 Xero.Api/Core/Model/BatchPayment.cs rename Xero.Api/Core/Model/{BatchPayments.cs => BatchPaymentContactDefaults.cs} (84%) create mode 100644 Xero.Api/Core/Model/BatchPaymentPayment.cs create mode 100644 Xero.Api/Core/Model/Status/BatchPaymentStatus.cs create mode 100644 Xero.Api/Core/Model/Types/BatchPaymentType.cs create mode 100644 Xero.Api/Core/Request/BatchPaymentsRequest.cs create mode 100644 Xero.Api/Core/Response/BatchPaymentsResponse.cs diff --git a/Xero.Api/Core/Endpoints/BatchPaymentsEndpoint.cs b/Xero.Api/Core/Endpoints/BatchPaymentsEndpoint.cs new file mode 100644 index 00000000..b9c737b4 --- /dev/null +++ b/Xero.Api/Core/Endpoints/BatchPaymentsEndpoint.cs @@ -0,0 +1,23 @@ +using Xero.Api.Core.Endpoints.Base; +using Xero.Api.Core.Model; +using Xero.Api.Core.Request; +using Xero.Api.Core.Response; +using Xero.Api.Infrastructure.Http; + +namespace Xero.Api.Core.Endpoints +{ + public interface IBatchPaymentsEndpoint + : IXeroCreateEndpoint + { + + } + + public class BatchPaymentsEndpoint + : XeroCreateEndpoint, IBatchPaymentsEndpoint + { + public BatchPaymentsEndpoint(XeroHttpClient client) : + base(client, "/api.xro/2.0/BatchPayments") + { + } + } +} \ No newline at end of file diff --git a/Xero.Api/Core/IXeroCoreApi.cs b/Xero.Api/Core/IXeroCoreApi.cs index 6523f3ea..f717a28c 100644 --- a/Xero.Api/Core/IXeroCoreApi.cs +++ b/Xero.Api/Core/IXeroCoreApi.cs @@ -13,6 +13,7 @@ public interface IXeroCoreApi AttachmentsEndpoint Attachments { get; } IBankTransactionsEndpoint BankTransactions { get; } IBankTransfersEndpoint BankTransfers { get; } + IBatchPaymentsEndpoint BatchPayments { get; } IBrandingThemesEndpoint BrandingThemes { get; } IContactsEndpoint Contacts { get; } IContactGroupsEndpoint ContactGroups { get; } diff --git a/Xero.Api/Core/Model/BatchPayment.cs b/Xero.Api/Core/Model/BatchPayment.cs new file mode 100644 index 00000000..167ed40d --- /dev/null +++ b/Xero.Api/Core/Model/BatchPayment.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using Xero.Api.Common; +using Xero.Api.Core.Model.Status; +using Xero.Api.Core.Model.Types; + +namespace Xero.Api.Core.Model +{ + [DataContract(Namespace = "")] + public class BatchPayment : HasUpdatedDate, IHasId + { + [DataMember(Name = "BatchPaymentID", EmitDefaultValue = false)] + public Guid Id { get; set; } + + [DataMember(Name = "Type", EmitDefaultValue = false)] + public BatchPaymentType? Type { get; set; } + + [DataMember(Name = "Status", EmitDefaultValue = false)] + public BatchPaymentStatus? Status { get; set; } + + [DataMember(Name = "Account")] + public Account Account { get; set; } + + [DataMember(Name = "Particulars", EmitDefaultValue = false)] + public string Particulars { get; set; } + + [DataMember(Name = "Code", EmitDefaultValue = false)] + public string Code { get; set; } + + [DataMember(Name = "Reference", EmitDefaultValue = false)] + public string Reference { get; set; } + + [DataMember(Name = "Details", EmitDefaultValue = false)] + public string Details { get; set; } + + [DataMember(Name = "Narrative", EmitDefaultValue = false)] + public string Narrative { get; set; } + + [DataMember(Name = "Date", EmitDefaultValue = false)] + public DateTime? Date { get; set; } + + [DataMember(Name = "Payments")] + public List Payments { get; set; } + + [DataMember(Name = "TotalAmount", EmitDefaultValue = false)] + public decimal? Total { get; set; } + + [DataMember(Name = "IsReconciled", EmitDefaultValue = false)] + public bool? IsReconciled { get; set; } + } +} \ No newline at end of file diff --git a/Xero.Api/Core/Model/BatchPayments.cs b/Xero.Api/Core/Model/BatchPaymentContactDefaults.cs similarity index 84% rename from Xero.Api/Core/Model/BatchPayments.cs rename to Xero.Api/Core/Model/BatchPaymentContactDefaults.cs index bc1d6fa2..6d5e3655 100644 --- a/Xero.Api/Core/Model/BatchPayments.cs +++ b/Xero.Api/Core/Model/BatchPaymentContactDefaults.cs @@ -3,8 +3,8 @@ namespace Xero.Api.Core.Model { - [DataContract(Namespace = "")] - public class BatchPayments : CoreData + [DataContract(Namespace = "", Name = "BatchPayments")] + public class BatchPaymentContactDefaults : CoreData { [DataMember(EmitDefaultValue = false)] public string BankAccountNumber { get; set; } diff --git a/Xero.Api/Core/Model/BatchPaymentPayment.cs b/Xero.Api/Core/Model/BatchPaymentPayment.cs new file mode 100644 index 00000000..9e01a861 --- /dev/null +++ b/Xero.Api/Core/Model/BatchPaymentPayment.cs @@ -0,0 +1,37 @@ +using System; +using System.Runtime.Serialization; +using Xero.Api.Common; + +namespace Xero.Api.Core.Model +{ + [DataContract(Namespace = "", Name = "Payment")] + public class BatchPaymentPayment : CoreData + { + [DataMember(Name = "Invoice")] + public Invoice Invoice { get; set; } + + [DataMember(Name = "PaymentID", EmitDefaultValue = false)] + public Guid? PaymentId { get; set; } + + [DataMember(Name = "BankAccountNumber", EmitDefaultValue = false)] + public string BankAccountNumber { get; set; } + + [DataMember(Name = "Particulars", EmitDefaultValue = false)] + public string Particulars { get; set; } + + [DataMember(Name = "Code", EmitDefaultValue = false)] + public string Code { get; set; } + + [DataMember(Name = "Reference", EmitDefaultValue = false)] + public string Reference { get; set; } + + [DataMember(Name = "Details", EmitDefaultValue = false)] + public string Details { get; set; } + + [DataMember(Name = "Narrative", EmitDefaultValue = false)] + public string Narrative { get; set; } + + [DataMember(Name = "Amount", EmitDefaultValue = false)] + public decimal? Amount { get; set; } + } +} \ No newline at end of file diff --git a/Xero.Api/Core/Model/Contact.cs b/Xero.Api/Core/Model/Contact.cs index 3f75f6a2..e9201430 100644 --- a/Xero.Api/Core/Model/Contact.cs +++ b/Xero.Api/Core/Model/Contact.cs @@ -82,7 +82,7 @@ public class Contact : HasUpdatedDate, IHasId, IHasAttachment public BrandingTheme BrandingTheme { get; set; } [DataMember(EmitDefaultValue = false)] - public BatchPayments BatchPayments { get; set; } + public BatchPaymentContactDefaults BatchPayments { get; set; } [DataMember(EmitDefaultValue = false)] public Balances Balances { get; set; } diff --git a/Xero.Api/Core/Model/Status/BatchPaymentStatus.cs b/Xero.Api/Core/Model/Status/BatchPaymentStatus.cs new file mode 100644 index 00000000..670827af --- /dev/null +++ b/Xero.Api/Core/Model/Status/BatchPaymentStatus.cs @@ -0,0 +1,13 @@ +using System.Runtime.Serialization; + +namespace Xero.Api.Core.Model.Status +{ + [DataContract(Namespace = "")] + public enum BatchPaymentStatus + { + [EnumMember(Value = "AUTHORISED")] + Authorised, + [EnumMember(Value = "DELETED")] + Deleted + } +} \ No newline at end of file diff --git a/Xero.Api/Core/Model/Types/BatchPaymentType.cs b/Xero.Api/Core/Model/Types/BatchPaymentType.cs new file mode 100644 index 00000000..11a60d74 --- /dev/null +++ b/Xero.Api/Core/Model/Types/BatchPaymentType.cs @@ -0,0 +1,13 @@ +using System.Runtime.Serialization; + +namespace Xero.Api.Core.Model.Types +{ + [DataContract(Namespace = "")] + public enum BatchPaymentType + { + [EnumMember(Value = "PAYBATCH")] + PayBatch, + [EnumMember(Value = "RECBATCH")] + RecBatch + } +} \ No newline at end of file diff --git a/Xero.Api/Core/Request/BatchPaymentsRequest.cs b/Xero.Api/Core/Request/BatchPaymentsRequest.cs new file mode 100644 index 00000000..dc435705 --- /dev/null +++ b/Xero.Api/Core/Request/BatchPaymentsRequest.cs @@ -0,0 +1,11 @@ +using System.Runtime.Serialization; +using Xero.Api.Common; +using Xero.Api.Core.Model; + +namespace Xero.Api.Core.Request +{ + [CollectionDataContract(Namespace = "", Name = "BatchPayments")] + public class BatchPaymentsRequest : XeroRequest + { + } +} \ No newline at end of file diff --git a/Xero.Api/Core/Response/BatchPaymentsResponse.cs b/Xero.Api/Core/Response/BatchPaymentsResponse.cs new file mode 100644 index 00000000..fd478500 --- /dev/null +++ b/Xero.Api/Core/Response/BatchPaymentsResponse.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; +using Xero.Api.Common; +using Xero.Api.Core.Model; + +namespace Xero.Api.Core.Response +{ + public class BatchPaymentsResponse : XeroResponse + { + public List BatchPayments { get; set; } + + public override IList Values + { + get { return BatchPayments; } + } + } +} \ No newline at end of file diff --git a/Xero.Api/Core/XeroCoreApi.cs b/Xero.Api/Core/XeroCoreApi.cs index bcb4a6c9..012ab40e 100644 --- a/Xero.Api/Core/XeroCoreApi.cs +++ b/Xero.Api/Core/XeroCoreApi.cs @@ -40,6 +40,7 @@ public XeroCoreApi(string baseUri, IAuthenticator auth, IConsumer consumer, IUse public AttachmentsEndpoint Attachments { get; private set; } public IBankTransactionsEndpoint BankTransactions { get; private set; } public IBankTransfersEndpoint BankTransfers { get; private set; } + public IBatchPaymentsEndpoint BatchPayments { get; private set; } public IBrandingThemesEndpoint BrandingThemes { get; private set; } public IContactsEndpoint Contacts { get; private set; } public IContactGroupsEndpoint ContactGroups { get; private set;} @@ -81,6 +82,7 @@ private void Connect() Attachments = new AttachmentsEndpoint(Client); BankTransactions = new BankTransactionsEndpoint(Client); BankTransfers = new BankTransfersEndpoint(Client); + BatchPayments = new BatchPaymentsEndpoint(Client); BrandingThemes = new BrandingThemesEndpoint(Client); Contacts = new ContactsEndpoint(Client); ContactGroups = new ContactGroupsEndpoint(Client); diff --git a/Xero.Api/Serialization/DefaultMapper.cs b/Xero.Api/Serialization/DefaultMapper.cs index 680fc232..78f8f791 100644 --- a/Xero.Api/Serialization/DefaultMapper.cs +++ b/Xero.Api/Serialization/DefaultMapper.cs @@ -66,6 +66,7 @@ private void BuildCore() { JsConfig.DeSerializeFn = EnumDeserializer; JsConfig.DeSerializeFn = EnumDeserializer; + JsConfig.DeSerializeFn = EnumDeserializerNullable; JsConfig.DeSerializeFn = EnumDeserializer; JsConfig.DeSerializeFn = EnumDeserializer; JsConfig.DeSerializeFn = EnumDeserializer; @@ -83,6 +84,7 @@ private void BuildCore() JsConfig.DeSerializeFn = EnumDeserializer; JsConfig.DeSerializeFn = EnumDeserializer; JsConfig.DeSerializeFn = EnumDeserializer; + JsConfig.DeSerializeFn = EnumDeserializerNullable; JsConfig.DeSerializeFn = EnumDeserializer; JsConfig.DeSerializeFn = EnumDeserializer; JsConfig.DeSerializeFn = EnumDeserializer; diff --git a/Xero.Api/Xero.Api.csproj b/Xero.Api/Xero.Api.csproj index 82fef447..7cb3d26f 100644 --- a/Xero.Api/Xero.Api.csproj +++ b/Xero.Api/Xero.Api.csproj @@ -55,11 +55,14 @@ + + + @@ -71,10 +74,12 @@ + + @@ -83,6 +88,7 @@ + @@ -103,6 +109,7 @@ + @@ -296,7 +303,7 @@ - +