Skip to content

Commit

Permalink
Merge pull request #132 from mercadopago/release/1.9.1
Browse files Browse the repository at this point in the history
Release 1.9.1
  • Loading branch information
delias-silva authored Feb 17, 2021
2 parents 9e4a8ff + d70495f commit 59c9c4c
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 32 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 MercadoPago Developers
Copyright (c) 2021 MercadoPago Developers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 6 additions & 6 deletions MercadoPagoSDK.Test/Helpers/CardHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ namespace MercadoPagoSDK.Test.Helpers
{
public static class CardHelper
{
public static string SingleUseCardToken(string PublicKey, string Status)
public static string SingleUseCardToken(string Status)
{
JObject payload = JObject.Parse(CardDummyWithSpecificStatus(Status));

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

JObject jsonResponse = JObject.Parse(responseCardToken.StringResponse.ToString());
Expand All @@ -36,17 +36,17 @@ public static string CardDummyWithSpecificStatus(string status)
};

string StringPayload = "{ " +
"\"card_number\": \"4508336715544174\", " +
"\"security_code\": \"122\", " +
"\"card_number\": \"5031433215406351\", " +
"\"security_code\": \"123\", " +
"\"expiration_month\": \"7\", " +
"\"expiration_year\": \"2030\", " +
"\"cardholder\": " +
"{ " +
"\"name\": \"" + CardsNameForStatus[status] + "\", " +
"\"identification\": " +
"{ " +
"\"type\": \"DNI\", " +
"\"number\": \"12345678\" " +
"\"type\": \"CPF\", " +
"\"number\": \"37462770865\" " +
"} " +
"} " +
"}";
Expand Down
12 changes: 4 additions & 8 deletions MercadoPagoSDK.Test/Resources/AdvancedPaymentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
using System.Linq;
using System.Threading;
using MercadoPago.Resources;
using MercadoPagoSDK.Test.Helpers;
using NUnit.Framework;
using AdvPayDS = MercadoPago.DataStructures.AdvancedPayment;

namespace MercadoPagoSDK.Test.Resources
{
[TestFixture(Ignore = "Skipping")]
public class AdvancedPaymentTest : BaseResourceTest
{
[Test]
Expand Down Expand Up @@ -115,13 +117,7 @@ public void AdvancedPaymentSearchTest()

private static AdvancedPayment NewAdvancedPayment(bool capture)
{
var cardToken = new CardToken
{
CardId = "8940397939",
CustomerId = "649457098-FybpOkG6zH8QRm",
SecurityCode = "123",
};
cardToken.Save();
string token = CardHelper.SingleUseCardToken("approved");

return new AdvancedPayment
{
Expand All @@ -132,7 +128,7 @@ private static AdvancedPayment NewAdvancedPayment(bool capture)
{
PaymentMethodId = "master",
PaymentTypeId = "credit_card",
Token = cardToken.Id,
Token = token,
DateOfExpiration = DateTime.UtcNow.Add(TimeSpan.FromDays(120)),
TransactionAmount = 1000,
Installments = 1,
Expand Down
11 changes: 3 additions & 8 deletions MercadoPagoSDK.Test/Resources/PaymentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using MercadoPago.Common;
using MercadoPago.DataStructures.Payment;
using MercadoPago.Resources;
using MercadoPagoSDK.Test.Helpers;
using Newtonsoft.Json.Linq;
using NUnit.Framework;

Expand Down Expand Up @@ -227,13 +228,7 @@ public void PaymentCreateErrorTest()

private static Payment NewPayment(bool capture)
{
var cardToken = new CardToken
{
CardId = "8940397939",
CustomerId = "649457098-FybpOkG6zH8QRm",
SecurityCode = "123",
};
cardToken.Save();
string token = CardHelper.SingleUseCardToken("approved");

return new Payment
{
Expand Down Expand Up @@ -262,7 +257,7 @@ private static Payment NewPayment(bool capture)
},
TransactionAmount = 10,
//PaymentMethodId = "master",
Token = cardToken.Id,
Token = token,
Installments = 1,
StatementDescriptor = "STAT-DESC",
NotificationUrl = "https://seu-site.com.br/webhooks",
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ First time using Mercado Pago? Create your [Mercado Pago account](https://www.me

**Using Package Manager**

`PM> Install-Package mercadopago-sdk -Version 1.8.1`
`PM> Install-Package mercadopago-sdk -Version 1.9.1`

**Using .Net CLI**

`> dotnet add package mercadopago-sdk --version 1.8.1`
`> dotnet add package mercadopago-sdk --version 1.9.1`

**Using Packet CLI**

`> paket add mercadopago-sdk --version 1.8.1`
`> paket add mercadopago-sdk --version 1.9.1`

Copy the access_token in the [credentials](https://www.mercadopago.com/mlb/account/credentials) section of the page and replace YOUR_ACCESS_TOKEN with it.

Expand Down Expand Up @@ -78,6 +78,6 @@ If you require technical support, please contact our support team at [developers
## 🏻 License

```
MIT license. Copyright (c) 2018 - Mercado Pago / Mercado Libre
MIT license. Copyright (c) 2021 - Mercado Pago / Mercado Libre
For more information, see the LICENSE file.
```
2 changes: 1 addition & 1 deletion px-dotnet/Common/ShipmentMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace MercadoPago.Common
{
[JsonConverter(typeof(StringEnumConverter))]
[JsonConverter(typeof(ShippingModeConverter))]
public enum ShipmentMode
{
/// <summary>Custom shipping</summary>
Expand Down
80 changes: 80 additions & 0 deletions px-dotnet/Common/ShippingModeConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Text;
using Newtonsoft.Json;

namespace MercadoPago.Common
{
public class ShippingModeConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return objectType == typeof(string);
}

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
string value = (string)reader.Value;
if (string.IsNullOrEmpty(value))
{
return null;
}
return Enum.Parse(typeof(ShipmentMode), SnakeCaseToLowerCase(value), true);
}

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
ShipmentMode? shipmentMode = (ShipmentMode?)value;
if (shipmentMode.HasValue)
{
writer.WriteValue(PascalCaseToSnakeCase(shipmentMode.ToString()));
}
}

private static string PascalCaseToSnakeCase(string value)
{
if (value == null || value.Trim().Length == 0)
{
return value;
}

value = value.Trim();
StringBuilder sb = new StringBuilder();
sb.Append(char.ToLowerInvariant(value[0]));
for (int i = 1; i < value.Length; i++)
{
char c = value[i];
if (char.IsUpper(c))
{
sb.Append('_');
sb.Append(char.ToLowerInvariant(c));
}
else
{
sb.Append(c);
}
}

return sb.ToString();
}

private static string SnakeCaseToLowerCase(string value)
{
if (value == null || value.Trim().Length == 0)
{
return value;
}

StringBuilder sb = new StringBuilder();
string[] tokens = value.Trim().Split('_');
for (int i = 0; i < tokens.Length; i++)
{
if (!string.IsNullOrEmpty(tokens[i]) && tokens[i].Length > 0)
{
sb.Append(tokens[i]);
}
}

return sb.ToString();
}
}
}
5 changes: 3 additions & 2 deletions 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.9.0</PackageVersion>
<PackageVersion>1.9.1</PackageVersion>
<Authors>MercadoPago</Authors>
<Description>MercadoPago SDK para .Net</Description>
<Owners>MercadoPago</Owners>
Expand All @@ -25,7 +25,7 @@
<Title>Mercado Pago SDK</Title>
<NeutralLanguage>es</NeutralLanguage>
<PackageTags>mercadopago</PackageTags>
<ReleaseVersion>1.8.1</ReleaseVersion>
<ReleaseVersion>1.9.1</ReleaseVersion>
<SynchReleaseVersion>false</SynchReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down Expand Up @@ -233,6 +233,7 @@
<Compile Include="DataStructures\Payment\Passenger.cs" />
<Compile Include="DataStructures\Payment\CategoryDescriptor.cs" />
<Compile Include="DataStructures\Preference\CategoryDescriptor.cs" />
<Compile Include="Common\ShippingModeConverter.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
4 changes: 2 additions & 2 deletions px-dotnet/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("1.8.1")]
[assembly: AssemblyFileVersion("1.8.1")]
[assembly: AssemblyVersion("1.9.1")]
[assembly: AssemblyFileVersion("1.9.1")]

0 comments on commit 59c9c4c

Please sign in to comment.