Skip to content
This repository was archived by the owner on Apr 12, 2021. It is now read-only.

Commit c02f62e

Browse files
authored
Merge branch 'master' into patch-1
2 parents 5a1bf6c + 1d3a029 commit c02f62e

17 files changed

Lines changed: 175 additions & 13 deletions

File tree

CoreTests/CoreTests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686
<Compile Include="Integration\BankTransfers\BankTransfersTest.cs" />
8787
<Compile Include="Integration\BankTransfers\Create.cs" />
8888
<Compile Include="Integration\BankTransfers\Find.cs" />
89+
<Compile Include="Integration\BatchPayment\Create.cs" />
90+
<Compile Include="Integration\BatchPayment\BatchPaymentsTest.cs" />
8991
<Compile Include="Integration\ContactGroups\Add_Contact.cs" />
9092
<Compile Include="Integration\ContactGroups\ContactGroupsTest.cs" />
9193
<Compile Include="Integration\ContactGroups\Create.cs" />
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Xero.Api.Core.Model;
4+
using Xero.Api.Core.Model.Status;
5+
using Xero.Api.Core.Model.Types;
6+
7+
namespace CoreTests.Integration.BatchPayments
8+
{
9+
public abstract class BatchPaymentsTest : ApiWrapperTest
10+
{
11+
protected BatchPayment Given_a_batch_payment(decimal invoiceAmount, DateTime date, decimal amount, bool isReconciled = false)
12+
{
13+
var batchPayment = CreateBatchPayment(invoiceAmount, date, amount, isReconciled);
14+
15+
return Api.BatchPayments.Create(batchPayment);
16+
}
17+
18+
protected BatchPayment CreateBatchPayment(decimal invoiceAmount, DateTime date, decimal amount, bool isReconciled = false)
19+
{
20+
var invoice = Given_an_invoice(invoiceAmount, Account.Code);
21+
var bankCode = BankAccount.Id;
22+
23+
var payment = new BatchPayment
24+
{
25+
Account = new Account { Id = bankCode },
26+
Date = date,
27+
Payments = new List<BatchPaymentPayment> { new BatchPaymentPayment {
28+
Amount = amount,
29+
Invoice = new Invoice { Id = invoice.Id},
30+
BankAccountNumber = BankAccount.BankAccountNumber,
31+
}}
32+
};
33+
34+
if (isReconciled)
35+
{
36+
payment.IsReconciled = true;
37+
}
38+
39+
return payment;
40+
}
41+
42+
private Invoice Given_an_invoice(decimal amount = 100m, string accountCode = "100")
43+
{
44+
return Api.Create(new Invoice
45+
{
46+
Contact = new Contact { Name = "Richard" },
47+
Number = Random.GetRandomString(10),
48+
Type = InvoiceType.AccountsPayable,
49+
Date = DateTime.UtcNow,
50+
DueDate = DateTime.UtcNow.AddDays(90),
51+
LineAmountTypes = LineAmountType.Inclusive,
52+
Status = InvoiceStatus.Authorised,
53+
LineItems = new List<LineItem>
54+
{
55+
new LineItem
56+
{
57+
AccountCode = accountCode,
58+
Description = "Good value item",
59+
LineAmount = amount
60+
}
61+
}
62+
});
63+
}
64+
65+
}
66+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using NUnit.Framework;
5+
using Xero.Api.Core.Model;
6+
7+
namespace CoreTests.Integration.BatchPayments
8+
{
9+
[TestFixture]
10+
public class Create : BatchPaymentsTest
11+
{
12+
[TestFixtureSetUp]
13+
public void CreateBatchPaymentsSetUp()
14+
{
15+
SetUp();
16+
}
17+
18+
[Test]
19+
public void create_simple_batch_payment()
20+
{
21+
var date = DateTime.UtcNow;
22+
const decimal expectedTotal = 32.6m;
23+
const decimal invoiceAmount = 100;
24+
25+
var batchPayment = Given_a_batch_payment(invoiceAmount, date, expectedTotal);
26+
27+
Assert.IsNotNull(batchPayment);
28+
29+
Assert.AreEqual(expectedTotal, batchPayment.Total);
30+
Assert.AreEqual(date.Date, batchPayment.Date);
31+
32+
33+
}
34+
35+
}
36+
}

CoreTests/Integration/Contacts/Find.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ public void find_by_id()
2828
Assert.AreEqual(expected, id);
2929
}
3030

31+
[Test]
32+
public void find_by_id_list()
33+
{
34+
var created = Given_a_contact();
35+
var contacts = Api.Contacts.Ids(new[] { created.Id }).Find().ToList();
36+
37+
Assert.AreEqual(1, contacts.Count());
38+
Assert.AreEqual(created.Id, contacts.First().Id);
39+
}
40+
3141
[Test]
3242
public void find_by_value()
3343
{

Xero.Api/Common/XeroReadEndpoint.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ private IEnumerable<TResult> Get(string endpoint, string child)
172172
Client.ModifiedSince = _modifiedSince;
173173
Client.Parameters = Parameters;
174174

175-
return Client.Get<TResult, TResponse>(endpoint + (child ?? string.Empty));
175+
var result = Client.Get<TResult, TResponse>(endpoint + (child ?? string.Empty));
176+
return result;
176177
}
177178
finally
178179
{

Xero.Api/Core/Endpoints/ContactsEndpoint.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using Xero.Api.Common;
45
using Xero.Api.Core.Endpoints.Base;
@@ -15,6 +16,7 @@ public interface IContactsEndpoint
1516
{
1617
IContactsEndpoint IncludeArchived(bool include);
1718
ContactCisSetting GetCisSettings(Guid id);
19+
IContactsEndpoint Ids(IEnumerable<Guid> ids);
1820
}
1921

2022
public class ContactsEndpoint
@@ -52,6 +54,13 @@ public override void ClearQueryString()
5254
{
5355
base.ClearQueryString();
5456
Page(1);
57+
}
58+
59+
public IContactsEndpoint Ids(IEnumerable<Guid> ids)
60+
{
61+
AddParameter("ids", string.Join(",", ids));
62+
63+
return this;
5564
}
5665
}
5766
}

Xero.Api/Core/Model/BatchPayment.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Xero.Api.Common;
55
using Xero.Api.Core.Model.Status;
66
using Xero.Api.Core.Model.Types;
7+
using Xero.Api.Infrastructure.ThirdParty.ServiceStack.Text.Common;
78

89
namespace Xero.Api.Core.Model
910
{
@@ -37,10 +38,21 @@ public class BatchPayment : HasUpdatedDate, IHasId
3738
[DataMember(Name = "Narrative", EmitDefaultValue = false)]
3839
public string Narrative { get; set; }
3940

40-
[DataMember(Name = "Date", EmitDefaultValue = false)]
41-
public DateTime? Date { get; set; }
41+
public DateTime? Date { get; set; }
4242

43-
[DataMember(Name = "Payments")]
43+
[DataMember(Name = "Date", EmitDefaultValue = false)]
44+
public string DateString {
45+
get
46+
{
47+
return Date.Value.ToString("yyyy-MM-dd");
48+
}
49+
set
50+
{
51+
Date = DateTimeSerializer.ParseDateTimeOffset(value).UtcDateTime;
52+
}
53+
}
54+
55+
[DataMember(Name = "Payments")]
4456
public List<BatchPaymentPayment> Payments { get; set; }
4557

4658
[DataMember(Name = "TotalAmount", EmitDefaultValue = false)]

Xero.Api/Core/Model/Organisation.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public class Organisation
5454
[DataMember(EmitDefaultValue = false)]
5555
public int? FinancialYearEndMonth { get; set; }
5656

57+
[DataMember(EmitDefaultValue = false)]
58+
public string EmployerIdentificationNumber { get; set; }
59+
5760
[DataMember(EmitDefaultValue = false)]
5861
public DateTime? PeriodLockDate { get; set; }
5962

@@ -75,12 +78,18 @@ public class Organisation
7578
[DataMember(EmitDefaultValue = false)]
7679
public PaymentTerms PaymentTerms { get; set; }
7780

78-
[DataMember(EmitDefaultValue = false)]
81+
[DataMember(Name = "SalesTaxBasis", EmitDefaultValue = false)]
7982
public SalesTaxBasisType SalesTaxBasisType { get; set; }
8083

8184
[DataMember(EmitDefaultValue = false)]
8285
public SalesTaxPeriodType SalesTaxPeriod { get; set; }
8386

87+
[DataMember(EmitDefaultValue = false)]
88+
public string DefaultSalesTax { get; set; }
89+
90+
[DataMember(EmitDefaultValue = false)]
91+
public string DefaultPurchasesTax { get; set; }
92+
8493
[DataMember(EmitDefaultValue = false)]
8594
public List<Address> Addresses { get; set; }
8695

Xero.Api/Core/Model/Overpayment.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public class Overpayment : HasUpdatedDate, IHasId, IHasAttachment
4646
[DataMember(EmitDefaultValue = false)]
4747
public OverpaymentType Type { get; set; }
4848

49+
[DataMember(EmitDefaultValue = false)]
50+
public decimal AppliedAmount { get; set; }
51+
4952
[DataMember]
5053
public Decimal RemainingCredit { get; set; }
5154

Xero.Api/Core/Model/Prepayment.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public class Prepayment : HasUpdatedDate, IHasId, IHasAttachment
4646
[DataMember]
4747
public PrepaymentType Type { get; set; }
4848

49+
[DataMember(EmitDefaultValue = false)]
50+
public decimal AppliedAmount { get; set; }
51+
4952
[DataMember]
5053
public Decimal RemainingCredit { get; set; }
5154

0 commit comments

Comments
 (0)