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

Commit e93e117

Browse files
authored
Merge pull request #244 from MJMortimer/f/PayrollUpdates
Payroll updates
2 parents 6d19236 + fa24b1c commit e93e117

File tree

18 files changed

+115
-21
lines changed

18 files changed

+115
-21
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Linq;
2+
using NUnit.Framework;
3+
using Xero.Api.Infrastructure.Exceptions;
4+
using Xero.Api.Payroll.Australia.Model;
5+
6+
namespace PayrollTests.AU.Integration.ValidationErrors
7+
{
8+
public class AUPayrollValidationErrors : ApiWrapperTest
9+
{
10+
[Test]
11+
public void Validation_errors_are_returned_from_the_AU_payroll_api()
12+
{
13+
var employee = new Employee() {FirstName = "Jimmy"};
14+
15+
try
16+
{
17+
Api.Employees.Create(employee);
18+
}
19+
catch (ValidationException e)
20+
{
21+
Assert.True(e.ValidationErrors.Any(p => p.Message == "The Last Name is required."));
22+
Assert.True(e.ValidationErrors.Any(p => p.Message == "The Home Address is required."));
23+
return;
24+
}
25+
26+
throw new AssertionException("Expected validation errors");
27+
}
28+
}
29+
}

PayrollTests.AU/PayrollTests.AU.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<Compile Include="Integration\TimeSheets\Create.cs" />
7070
<Compile Include="Integration\TimeSheets\Find.cs" />
7171
<Compile Include="Integration\TimeSheets\TimesheetTest.cs" />
72+
<Compile Include="Integration\ValidationErrors\AUPayrollValidationErrors.cs" />
7273
<Compile Include="Properties\AssemblyInfo.cs" />
7374
</ItemGroup>
7475
<ItemGroup>

Xero.Api.Example.MVC/Web.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
6060
<bindingRedirect oldVersion="4.0.0.0-4.0.0.1" newVersion="4.0.0.1" />
6161
</dependentAssembly>
62+
<dependentAssembly>
63+
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
64+
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
65+
</dependentAssembly>
6266
</assemblyBinding>
6367
</runtime>
6468
<entityFramework>

Xero.Api.Example.MVC/Xero.Api.Example.MVC.csproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
<IISExpressAnonymousAuthentication />
2121
<IISExpressWindowsAuthentication />
2222
<IISExpressUseClassicPipelineMode />
23-
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">.\</SolutionDir> <TargetFrameworkProfile />
23+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">.\</SolutionDir>
24+
<TargetFrameworkProfile />
25+
<UseGlobalApplicationHostFile />
2426
</PropertyGroup>
2527
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2628
<DebugSymbols>true</DebugSymbols>
@@ -45,8 +47,8 @@
4547
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
4648
<Private>True</Private>
4749
</Reference>
48-
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
49-
<HintPath>..\packages\Newtonsoft.Json.4.5.6\lib\net40\Newtonsoft.Json.dll</HintPath>
50+
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
51+
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json.dll</HintPath>
5052
<Private>True</Private>
5153
</Reference>
5254
<Reference Include="System" />

Xero.Api.Example.MVC/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
<package id="Microsoft.AspNet.WebPages" version="2.0.20710.0" targetFramework="net40" />
99
<package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net40" />
1010
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
11-
<package id="Newtonsoft.Json" version="4.5.6" targetFramework="net40" />
11+
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net40" />
1212
</packages>

Xero.Api/Infrastructure/Http/XeroHttpClient.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
using System.Collections.Specialized;
44
using System.Linq;
55
using System.Net;
6+
using Newtonsoft.Json.Linq;
67
using Xero.Api.Common;
78
using Xero.Api.Infrastructure.Exceptions;
89
using Xero.Api.Infrastructure.Interfaces;
10+
using Xero.Api.Infrastructure.Model;
911
using Xero.Api.Infrastructure.RateLimiter;
1012

1113
namespace Xero.Api.Infrastructure.Http
@@ -109,6 +111,16 @@ internal void HandleErrors(Response response)
109111
throw new ValidationException(data);
110112
}
111113

114+
//CHeck for inline errors
115+
var jsonObject = JObject.Parse(response.Body);
116+
var inlineValidationErrors = jsonObject.SelectTokens("$..ValidationErrors..Message").Select(p => new ValidationError { Message = p.ToString() }).ToList();
117+
118+
if (inlineValidationErrors.Any())
119+
{
120+
data.Elements = new List<DataContractBase> { new DataContractBase {ValidationErrors = inlineValidationErrors } };
121+
throw new ValidationException(data);
122+
}
123+
112124
throw new BadRequestException(data);
113125
}
114126

Xero.Api/Payroll/Australia/Model/DeductionLine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class DeductionLine
1414
public decimal? Amount { get; set; }
1515

1616
[DataMember(EmitDefaultValue = false)]
17-
public DeductionCalculationType CalculationType { get; set; }
17+
public DeductionCalculationType? CalculationType { get; set; }
1818

1919
[DataMember(EmitDefaultValue = false)]
2020
public decimal NumberOfUnits { get; set; }

Xero.Api/Payroll/Australia/Model/EarningsLine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ public class EarningsLine
2929
public decimal? NumberOfUnits { get; set; }
3030

3131
[DataMember(EmitDefaultValue = false)]
32-
public EarningsRateCalculationType EarningsRateCalculation { get; set; }
32+
public EarningsRateCalculationType? CalculationType { get; set; }
3333
}
3434
}

Xero.Api/Payroll/Australia/Model/LeaveLine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class LeaveLine
1111
public Guid LeaveTypeId { get; set; }
1212

1313
[DataMember(EmitDefaultValue = false)]
14-
public decimal NumberOfUnits { get; set; }
14+
public decimal? NumberOfUnits { get; set; }
1515

1616
[DataMember(EmitDefaultValue = false)]
1717
public decimal AnnualNumberOfUnits { get; set; }

Xero.Api/Payroll/Australia/Model/Payslip.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class Payslip : PayNotice
2424
public decimal Wages { get; set; }
2525

2626
[DataMember]
27-
public List<EarningsLine> EarningsLines { get; set; }
27+
public List<PayslipEarningsLine> EarningsLines { get; set; }
2828

2929
[DataMember]
3030
public List<DeductionLine> DeductionLines { get; set; }
@@ -46,5 +46,9 @@ public class Payslip : PayNotice
4646

4747
[DataMember]
4848
public List<TaxLine> TaxLines { get; set; }
49+
50+
[DataMember(EmitDefaultValue = false, Name = "PayRunID")]
51+
public Guid PayRunId { get; set; }
52+
4953
}
5054
}

0 commit comments

Comments
 (0)