Skip to content

Commit

Permalink
Merge pull request mercadopago#98 from mercadopago/release/1.4.0
Browse files Browse the repository at this point in the history
Release/1.4.0
  • Loading branch information
Pedro Gonçalves authored Jan 2, 2020
2 parents 2f6bdeb + 8e03804 commit 4a41cd0
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 3 deletions.
33 changes: 33 additions & 0 deletions px-dotnet/DataStructures/Preference/Track.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json.Linq;

namespace MercadoPago.DataStructures.Preference
{
public struct Track
{
#region Properties
[StringLength(256)]
private string _type;
private JObject _values;
#endregion

#region Accessors
/// <summary>
/// Track type
/// </summary>
public string Type
{
get { return _type; }
set { _type = value; }
}
/// <summary>
/// Track values
/// </summary>
public JObject Values
{
get { return _values; }
set { _values = value; }
}
#endregion
}
}
3 changes: 2 additions & 1 deletion px-dotnet/MercadoPagoSDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<PackageId>mercadopago-sdk</PackageId>
<PackageVersion>1.3.0</PackageVersion>
<PackageVersion>1.4.0</PackageVersion>
<Authors>Williner Rafael, Zachary Gerardo, Joel Ibaceta</Authors>
<Description>MercadoPago SDK para .Net</Description>
<Owners>MercadoPago</Owners>
Expand Down Expand Up @@ -193,6 +193,7 @@
<Compile Include="Resources\Refund.cs" />
<Compile Include="Common\ProcessingMode.cs" />
<Compile Include="Common\TaxType.cs" />
<Compile Include="DataStructures\Preference\Track.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
13 changes: 12 additions & 1 deletion px-dotnet/Net/MPRESTClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using MercadoPago;
using MercadoPago;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
Expand Down Expand Up @@ -268,6 +268,17 @@ public MPRequest CreateRequest(HttpMethod httpMethod,
}
}

if (requestOptions.TrackHeaders != null)
{
foreach (var trackHeader in requestOptions.TrackHeaders)
{
if (mpRequest.Request.Headers[trackHeader.Key] == null && trackHeader.Value != null)
{
mpRequest.Request.Headers[trackHeader.Key] = trackHeader.Value;
}
}
}

if (payload != null) // POST & PUT
{
byte[] data = null;
Expand Down
7 changes: 7 additions & 0 deletions px-dotnet/Net/MPRequestOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ public class MPRequestOptions

public IDictionary<String, String> CustomHeaders { get; set; }

public IDictionary<String, String> TrackHeaders { get; private set; }

public MPRequestOptions()
{
Timeout = SDK.RequestsTimeout;
Retries = SDK.RequestsRetries;
Proxy = SDK.Proxy;
CustomHeaders = new Dictionary<String, String>();
TrackHeaders = new Dictionary<String, String> {
{ "x-platform-id", SDK.GetPlatformId() },
{ "x-corporation-id", SDK.GetCorporationId() },
{ "x-integrator-id", SDK.GetIntegratorId() }
};
}
}
}
23 changes: 22 additions & 1 deletion px-dotnet/Resources/Payment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ public Payment Refund(decimal? amount, MPRequestOptions requestOptions)
private DateTime? _date_of_expiration;
private long? _sponsor_id;
private List<Taxes> _taxes;
private string _integrator_id;
private string _platform_id;
private string _corporation_id;
#endregion

#region Accessors
Expand Down Expand Up @@ -581,8 +584,26 @@ public List<Taxes> Taxes
{
get { return this._taxes; }
set { this._taxes = value; }
}

public string IntegratorId
{
get { return _integrator_id; }
private set { _integrator_id = value; }
}
#endregion

public string PlatformId
{
get { return _platform_id; }
private set { _platform_id = value; }
}

public string CorporationId
{
get { return _corporation_id; }
private set { _corporation_id = value; }
}
#endregion

}
}
18 changes: 18 additions & 0 deletions px-dotnet/Resources/Preference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public Boolean Update(MPRequestOptions requestOptions)
private bool? _binary_mode;
private List<Tax> _taxes;
private JObject _metadata;
private List<Track> _tracks;
#endregion

#region Accesors
Expand Down Expand Up @@ -510,6 +511,23 @@ public JObject Metadata
get { return this._metadata; }
set { this._metadata = value; }
}

/// <summary>
/// Preference ad tracks
/// </summary>
public List<Track> Tracks
{
get
{
if (_tracks == null)
{
_tracks = new List<Track>();
}
return _tracks;
}

set { _tracks = value; }
}
#endregion
}
}
80 changes: 80 additions & 0 deletions px-dotnet/SDK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class SDK
private static string _userToken;
private static string _refreshToken;
private static readonly string _version;
private static string _corporationId;
private static string _integratorId;
private static string _platformId;

static SDK()
{
Expand Down Expand Up @@ -311,5 +314,82 @@ public static JToken Put(string uri, JObject payload)
return client.ExecuteGenericRequest(HttpMethod.PUT, uri, PayloadType.JSON, payload);
}

/// <summary>
/// Property that represent the corporation id.
/// </summary>
public static string CorporationId
{
get { return _corporationId; }
set
{
if (!string.IsNullOrEmpty(_corporationId))
{
throw new MPConfException("corporationId setting can not be changed");
}
_corporationId = value;
}
}

/// <summary>
/// Property that represent the integrator id.
/// </summary>
public static string IntegratorId
{
get { return _integratorId; }
set
{
if(!string.IsNullOrEmpty(_integratorId))
{
throw new MPConfException("integratorId setting can not be changed");
}
_integratorId = value;
}
}

/// <summary>
/// Property that represent the plataform id.
/// </summary>
public static string PlatformId
{
get { return _platformId; }
set
{
if (!string.IsNullOrEmpty(_platformId))
{
throw new MPConfException("platformId setting can not be changed");
}
_platformId = value;
}
}

public static void SetCorporationId(string corporationId)
{
CorporationId = corporationId;
}

public static string GetCorporationId()
{
return CorporationId;
}

public static void SetIntegratorId(string integratorId)
{
IntegratorId = integratorId;
}

public static string GetIntegratorId()
{
return IntegratorId;
}

public static void SetPlatformId(string platformId)
{
PlatformId = platformId;
}

public static string GetPlatformId()
{
return PlatformId;
}
}
}

0 comments on commit 4a41cd0

Please sign in to comment.