Skip to content

Commit 1592e88

Browse files
authored
Merge pull request #90 from mercadopago/mercadopago/add-request-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
2 parents e29cc13 + aa25f2d commit 1592e88

22 files changed

+1050
-377
lines changed

MercadoPagoSDK.Test/Core/MPIPNTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
using System.Collections.Generic;
99
using System.Linq;
1010
using System.Text;
11-
using System.Collections;
12-
11+
using System.Collections;
12+
1313
namespace MercadoPagoSDK.Test.Core
1414
{
1515
[TestFixture()]
@@ -151,7 +151,7 @@ public string GenerateSingleUseCardToken()
151151
{
152152
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\" } } }");
153153
MPRESTClient client = new MPRESTClient();
154-
MPAPIResponse responseCardToken = client.ExecuteRequestCore(
154+
MPAPIResponse responseCardToken = client.ExecuteRequest(
155155
HttpMethod.POST,
156156
"https://api.mercadopago.com/v1/card_tokens?public_key=" + Environment.GetEnvironmentVariable("PUBLIC_KEY"),
157157
PayloadType.JSON,

MercadoPagoSDK.Test/Helpers/CardHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static string SingleUseCardToken(string PublicKey, string Status)
1414

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

1919
JObject jsonResponse = JObject.Parse(responseCardToken.StringResponse.ToString());
2020
List<JToken> tokens = MPCoreUtils.FindTokens(jsonResponse, "id");

px-dotnet/Core/MPAPIResponse.cs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private void ParseRequest(HttpMethod httpMethod, HttpWebRequest request, JObject
5858
{
5959
this.Payload = payload.ToString();
6060
}
61-
}
61+
}
6262

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

72-
var stream = response.GetResponseStream();
73-
74-
if (stream != null)
72+
using (var stream = response.GetResponseStream())
7573
{
76-
try
77-
{
78-
Stream dataStream = response.GetResponseStream();
79-
StreamReader reader = new StreamReader(dataStream, Encoding.UTF8);
80-
this.StringResponse = reader.ReadToEnd();
81-
82-
reader.Close();
83-
dataStream.Close();
84-
}
85-
catch (Exception ex)
86-
{
87-
throw new MPException(ex.Message);
88-
}
89-
90-
// Try to parse the response to a json, and a extract the entity of the response.
91-
// When the response is not a json parseable string then the string response must be used.
92-
try
93-
{
94-
this.JsonObjectResponse = JObject.Parse(this.StringResponse);
95-
}
96-
catch (Exception)
74+
if (stream != null)
9775
{
98-
Console.WriteLine("Error parsing jsonObect");
99-
// If not an object
76+
try
77+
{
78+
using (var reader = new StreamReader(stream, Encoding.UTF8))
79+
{
80+
this.StringResponse = reader.ReadToEnd();
81+
}
82+
}
83+
catch (Exception ex)
84+
{
85+
throw new MPException(ex.Message);
86+
}
87+
88+
// Try to parse the response to a json, and a extract the entity of the response.
89+
// When the response is not a json parseable string then the string response must be used.
90+
try
91+
{
92+
this.JsonObjectResponse = JObject.Parse(this.StringResponse);
93+
}
94+
catch (Exception)
95+
{
96+
Console.WriteLine("Error parsing jsonObect");
97+
// If not an object
98+
}
10099
}
101100
}
102101
}

0 commit comments

Comments
 (0)