Skip to content

Commit

Permalink
Merge pull request mercadopago#90 from mercadopago/mercadopago/add-re…
Browse files Browse the repository at this point in the history
…quest-options

Addition of MPRequestOptions to allow configure each request (configure access token, add headers, configure timeouts)
Addition of DiscountCampaign class to allow find a valid discount
Added the functionality of saving customer card using the card token
Change the type of StreetNumber property from string to int in Customer/Address
Adjust Refund method in Payment
  • Loading branch information
delias-silva authored Sep 18, 2019
2 parents e29cc13 + aa25f2d commit 1592e88
Show file tree
Hide file tree
Showing 22 changed files with 1,050 additions and 377 deletions.
6 changes: 3 additions & 3 deletions MercadoPagoSDK.Test/Core/MPIPNTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using System.Collections;

namespace MercadoPagoSDK.Test.Core
{
[TestFixture()]
Expand Down Expand Up @@ -151,7 +151,7 @@ public string GenerateSingleUseCardToken()
{
JObject payload = JObject.Parse("{ \"card_number\": \"4544610257481730\", \"security_code\": \"122\", \"expiration_month\": \"7\", \"expiration_year\": \"2030\", \"cardholder\": { \"name\": \"Test test\", \"identification\": { \"type\": \"DNI\", \"number\": \"12345678\" } } }");
MPRESTClient client = new MPRESTClient();
MPAPIResponse responseCardToken = client.ExecuteRequestCore(
MPAPIResponse responseCardToken = client.ExecuteRequest(
HttpMethod.POST,
"https://api.mercadopago.com/v1/card_tokens?public_key=" + Environment.GetEnvironmentVariable("PUBLIC_KEY"),
PayloadType.JSON,
Expand Down
2 changes: 1 addition & 1 deletion MercadoPagoSDK.Test/Helpers/CardHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static string SingleUseCardToken(string PublicKey, string Status)

MPRESTClient client = new MPRESTClient();
String path = "https://api.mercadopago.com/v1/card_tokens?public_key=" + PublicKey;
MPAPIResponse responseCardToken = client.ExecuteRequestCore(HttpMethod.POST, path, PayloadType.JSON, payload, null, 0, 1);
MPAPIResponse responseCardToken = client.ExecuteRequest(HttpMethod.POST, path, PayloadType.JSON, payload, null, 0, 1);

JObject jsonResponse = JObject.Parse(responseCardToken.StringResponse.ToString());
List<JToken> tokens = MPCoreUtils.FindTokens(jsonResponse, "id");
Expand Down
53 changes: 26 additions & 27 deletions px-dotnet/Core/MPAPIResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private void ParseRequest(HttpMethod httpMethod, HttpWebRequest request, JObject
{
this.Payload = payload.ToString();
}
}
}

/// <summary>
/// Parses the http response in a custom MPApiResponse object.
Expand All @@ -69,34 +69,33 @@ private void ParseResponse(HttpWebResponse response)
this.StatusCode = (int)response.StatusCode;
this.StatusDescription = response.StatusDescription;

var stream = response.GetResponseStream();

if (stream != null)
using (var stream = response.GetResponseStream())
{
try
{
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream, Encoding.UTF8);
this.StringResponse = reader.ReadToEnd();

reader.Close();
dataStream.Close();
}
catch (Exception ex)
{
throw new MPException(ex.Message);
}

// Try to parse the response to a json, and a extract the entity of the response.
// When the response is not a json parseable string then the string response must be used.
try
{
this.JsonObjectResponse = JObject.Parse(this.StringResponse);
}
catch (Exception)
if (stream != null)
{
Console.WriteLine("Error parsing jsonObect");
// If not an object
try
{
using (var reader = new StreamReader(stream, Encoding.UTF8))
{
this.StringResponse = reader.ReadToEnd();
}
}
catch (Exception ex)
{
throw new MPException(ex.Message);
}

// Try to parse the response to a json, and a extract the entity of the response.
// When the response is not a json parseable string then the string response must be used.
try
{
this.JsonObjectResponse = JObject.Parse(this.StringResponse);
}
catch (Exception)
{
Console.WriteLine("Error parsing jsonObect");
// If not an object
}
}
}
}
Expand Down
Loading

0 comments on commit 1592e88

Please sign in to comment.