Skip to content

Commit

Permalink
Fix Token History deserialization
Browse files Browse the repository at this point in the history
When the History is empty, this field is returned as an array
and when it is full, it is returned as an object. We need to
handle this field separately in order to compensate for this
difference
  • Loading branch information
paracycle committed Feb 18, 2015
1 parent be39f5c commit 742e647
Show file tree
Hide file tree
Showing 19 changed files with 47 additions and 23 deletions.
2 changes: 1 addition & 1 deletion PayUSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Global
$0.DotNetNamingPolicy = $4
$4.DirectoryNamespaceAssociation = PrefixedHierarchical
$4.ResourceNamePolicy = FileFormatDefault
version = 2.0.1.0
version = 2.0.1.1
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<OutputType>Library</OutputType>
<RootNamespace>PayU.AutomaticLiveUpdate</RootNamespace>
<AssemblyName>PayUSharp.AutomaticLiveUpdate</AssemblyName>
<ReleaseVersion>2.0.1.0</ReleaseVersion>
<ReleaseVersion>2.0.1.1</ReleaseVersion>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly:AssemblyVersion("2.0.1.0")]
[assembly:AssemblyVersion("2.0.1.1")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
Expand Down
2 changes: 1 addition & 1 deletion src/PayUSharp.Core/PayUSharp.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<RootNamespace>PayU.Core</RootNamespace>
<AssemblyName>PayUSharp.Core</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<ReleaseVersion>2.0.1.0</ReleaseVersion>
<ReleaseVersion>2.0.1.1</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
2 changes: 1 addition & 1 deletion src/PayUSharp.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly:AssemblyVersion("2.0.1.0")]
[assembly:AssemblyVersion("2.0.1.1")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
Expand Down
2 changes: 1 addition & 1 deletion src/PayUSharp.IPN/PayUSharp.IPN.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<RootNamespace>PayU.IPN</RootNamespace>
<AssemblyName>PayUSharp.IPN</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<ReleaseVersion>2.0.1.0</ReleaseVersion>
<ReleaseVersion>2.0.1.1</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
2 changes: 1 addition & 1 deletion src/PayUSharp.IPN/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly:AssemblyVersion("2.0.1.0")]
[assembly:AssemblyVersion("2.0.1.1")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
Expand Down
2 changes: 1 addition & 1 deletion src/PayUSharp.LiveUpdate/PayUSharp.LiveUpdate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<OutputType>Library</OutputType>
<RootNamespace>PayU.LiveUpdate</RootNamespace>
<AssemblyName>PayUSharp.LiveUpdate</AssemblyName>
<ReleaseVersion>2.0.1.0</ReleaseVersion>
<ReleaseVersion>2.0.1.1</ReleaseVersion>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down
2 changes: 1 addition & 1 deletion src/PayUSharp.LiveUpdate/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly:AssemblyVersion("2.0.1.0")]
[assembly:AssemblyVersion("2.0.1.1")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
Expand Down
2 changes: 1 addition & 1 deletion src/PayUSharp.Token/PayUSharp.Token.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<RootNamespace>PayU.Token</RootNamespace>
<AssemblyName>PayUSharp.Token</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<ReleaseVersion>2.0.1.0</ReleaseVersion>
<ReleaseVersion>2.0.1.1</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
2 changes: 1 addition & 1 deletion src/PayUSharp.Token/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly:AssemblyVersion("2.0.1.0")]
[assembly:AssemblyVersion("2.0.1.1")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
Expand Down
32 changes: 28 additions & 4 deletions src/PayUSharp.Token/TokenRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Globalization;
using System.Collections.Specialized;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PayU.Core;

namespace PayU.Token
Expand Down Expand Up @@ -91,10 +92,8 @@ public TokenResponse SendRequest(string Endpoint, string SignatureKey) {
if (Service.IgnoreSSLCertificate) {
ServicePointManager.ServerCertificateValidationCallback = Validator;
}
// Console.WriteLine("Posting data: {0}", string.Join(", ", data.AllKeys.Select(key => key + ": " + data[key]).ToArray()));
var response = Encoding.UTF8.GetString(webClient.UploadValues(Endpoint, data));
// Console.WriteLine("Response is: {0}", response);
return JsonConvert.DeserializeObject<TokenResponse>(response);
return ParseResponse(response);
}
catch (WebException ex)
{
Expand All @@ -106,10 +105,35 @@ public TokenResponse SendRequest(string Endpoint, string SignatureKey) {
}
catch (Exception ex)
{
throw new PayuException("An exception occured during ALU request", ex);
throw new PayuException("An exception occured during Token request", ex);
}
}

static TokenResponse ParseResponse(string stringResponse)
{
var result = JsonConvert.DeserializeObject<TokenResponse>(stringResponse);
result.History = ParseHistory(stringResponse);
return result;
}

static IDictionary<int, TokenHistory> ParseHistory(string stringResponse)
{
var jsonResponse = JObject.Parse(stringResponse);
var history = jsonResponse["HISTORY"];
switch (history.Type)
{
case JTokenType.Array:
return history.Select((value, index) => new {
value = JsonConvert.DeserializeObject<TokenHistory>(value.ToString()),
index = index
}).ToDictionary(v => v.index, v => v.value);
case JTokenType.Object:
return JsonConvert.DeserializeObject<Dictionary<int, TokenHistory>>(history.ToString());
}

return null;
}

public static bool Validator (object sender, X509Certificate certificate, X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
Expand Down
2 changes: 1 addition & 1 deletion src/PayUSharp.Token/TokenResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class TokenResponse
[JsonProperty("EXPIRATION_DATE")]
public string ExpirationDate { get; set; }

[JsonProperty("HISTORY")]
[JsonIgnore]
public IDictionary<int, TokenHistory> History { get; set; }
}

Expand Down
4 changes: 2 additions & 2 deletions test/TestApp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly:AssemblyVersion("2.0.1.0")]
[assembly:AssemblyFileVersion("2.0.1.0")]
[assembly:AssemblyVersion("2.0.1.1")]
[assembly:AssemblyFileVersion("2.0.1.1")]
2 changes: 1 addition & 1 deletion test/TestApp/TestApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<AssemblyName>TestApp</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ReleaseVersion>2.0.1.0</ReleaseVersion>
<ReleaseVersion>2.0.1.1</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down
2 changes: 1 addition & 1 deletion test/TestWeb/TestWeb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>Library</OutputType>
<RootNamespace>TestWeb</RootNamespace>
<AssemblyName>TestWeb</AssemblyName>
<ReleaseVersion>2.0.1.0</ReleaseVersion>
<ReleaseVersion>2.0.1.1</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>True</DebugSymbols>
Expand Down
2 changes: 1 addition & 1 deletion util/DocGen/Doc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<OutputType>Exe</OutputType>
<RootNamespace>Doc</RootNamespace>
<AssemblyName>Doc</AssemblyName>
<ReleaseVersion>2.0.1.0</ReleaseVersion>
<ReleaseVersion>2.0.1.1</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
2 changes: 1 addition & 1 deletion util/DocGen/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly:AssemblyVersion("2.0.1.0")]
[assembly:AssemblyVersion("2.0.1.1")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
Expand Down
2 changes: 1 addition & 1 deletion util/Packages.mdproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
</Package>
</Packages>
</Packages>
<ReleaseVersion>2.0.1.0</ReleaseVersion>
<ReleaseVersion>2.0.1.1</ReleaseVersion>
</PropertyGroup>
</Project>

0 comments on commit 742e647

Please sign in to comment.