Skip to content

Commit

Permalink
2.42.0
Browse files Browse the repository at this point in the history
  • Loading branch information
braintreeps committed Jun 2, 2015
1 parent 900b948 commit a92abae
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 17 deletions.
10 changes: 6 additions & 4 deletions Braintree.Tests/SettlementBatchSummaryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ public void Generate_ReturnsTransactionsSettledOnAGivenDay()
};

Transaction transaction = gateway.Transaction.Sale(request).Target;
TestHelper.Settle(service, transaction.Id);
NodeWrapper settlementResult = TestHelper.Settle(service, transaction.Id);
var settlementDate = settlementResult.GetString("/transaction/settlement-batch-id").Split('_')[0];
transaction = gateway.Transaction.Find(transaction.Id);

var result = gateway.SettlementBatchSummary.Generate(TestHelper.NowInEastern());
var result = gateway.SettlementBatchSummary.Generate(System.DateTime.Parse(settlementDate));
var visas = new List<IDictionary<String,String>>();
foreach (var row in result.Target.Records)
{
Expand Down Expand Up @@ -109,10 +110,11 @@ public void Generate_CanBeGroupedByACustomField()
};

Transaction transaction = gateway.Transaction.Sale(request).Target;
TestHelper.Settle(service, transaction.Id);
NodeWrapper settlementResult = TestHelper.Settle(service, transaction.Id);
var settlementDate = settlementResult.GetString("/transaction/settlement-batch-id").Split('_')[0];
transaction = gateway.Transaction.Find(transaction.Id);

var result = gateway.SettlementBatchSummary.Generate(TestHelper.NowInEastern(), "store_me");
var result = gateway.SettlementBatchSummary.Generate(System.DateTime.Parse(settlementDate), "store_me");
var customValues = new List<IDictionary<String, String>>();
foreach (var row in result.Target.Records)
{
Expand Down
8 changes: 2 additions & 6 deletions Braintree.Tests/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ public static Boolean IncludesSubscription(ResourceCollection<Subscription> coll
return false;
}

public static void Settle(BraintreeService service, String transactionId)
public static NodeWrapper Settle(BraintreeService service, String transactionId)
{
NodeWrapper response = new NodeWrapper(service.Put("/transactions/" + transactionId + "/settle"));
Assert.IsTrue(response.IsSuccess());
return response;
}

public static void SettlementDecline(BraintreeService service, String transactionId)
Expand All @@ -103,11 +104,6 @@ public static void Escrow(BraintreeService service, String transactionId)
Assert.IsTrue(response.IsSuccess());
}

public static DateTime NowInEastern()
{
return DateTime.UtcNow - new TimeSpan(05, 00, 00);
}

public static string GetResponseContent(HttpWebResponse response)
{
using (var reader = new StreamReader(response.GetResponseStream()))
Expand Down
11 changes: 9 additions & 2 deletions Braintree.Tests/WebhookNotificationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ public void Setup()
[Test]
public void Verify_CreatesVerificationString()
{
string verification = gateway.WebhookNotification.Verify("verification_token");
Assert.AreEqual("integration_public_key|c9f15b74b0d98635cd182c51e2703cffa83388c3", verification);
string verification = gateway.WebhookNotification.Verify("20f9f8ed05f77439fe955c977e4c8a53");
Assert.AreEqual("integration_public_key|d9b899556c966b3f06945ec21311865d35df3ce4", verification);
}

[Test]
[ExpectedException(typeof(InvalidChallengeException), ExpectedMessage="challenge contains non-hex characters")]
public void Verify_ThrowsErrorOnInvalidChallenge()
{
gateway.WebhookNotification.Verify("bad challenge");
}

[Test]
Expand Down
7 changes: 4 additions & 3 deletions Braintree/Braintree.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Braintree</RootNamespace>
<AssemblyName>Braintree-2.41.0</AssemblyName>
<AssemblyName>Braintree-2.42.0</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkSubset>
Expand All @@ -23,7 +23,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\Braintree-2.41.0.xml</DocumentationFile>
<DocumentationFile>bin\Debug\Braintree-2.42.0.xml</DocumentationFile>
<NoWarn>1591</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
Expand All @@ -33,7 +33,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\Braintree-2.41.0.xml</DocumentationFile>
<DocumentationFile>bin\Debug\Braintree-2.42.0.xml</DocumentationFile>
<NoWarn>1591</NoWarn>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
Expand Down Expand Up @@ -196,6 +196,7 @@
<Compile Include="WebhookTestingGateway.cs" />
<Compile Include="UnknownPaymentMethod.cs" />
<Compile Include="WebhookNotification.cs" />
<Compile Include="Exceptions\InvalidChallengeException.cs" />
<Compile Include="Exceptions\InvalidSignatureException.cs" />
<Compile Include="WebhookNotificationGateway.cs" />
</ItemGroup>
Expand Down
12 changes: 12 additions & 0 deletions Braintree/Exceptions/InvalidChallengeException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma warning disable 1591

using System;

namespace Braintree.Exceptions
{
public class InvalidChallengeException : BraintreeException
{
public InvalidChallengeException(String message) : base(message) {}
public InvalidChallengeException() : base() {}
}
}
4 changes: 2 additions & 2 deletions Braintree/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("2.41.0.0")]
[assembly: AssemblyFileVersion("2.41.0.0")]
[assembly: AssemblyVersion("2.42.0.0")]
[assembly: AssemblyFileVersion("2.42.0.0")]
5 changes: 5 additions & 0 deletions Braintree/WebhookNotificationGateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public virtual WebhookNotification Parse(string signature, string payload)

public virtual string Verify(string challenge)
{
Match match = Regex.Match (challenge, @"^[a-f0-9]{20,32}$");
if (!match.Success)
{
throw new InvalidChallengeException ("challenge contains non-hex characters");
}
string digest = new Sha1Hasher().HmacHash(Service.PrivateKey, challenge);
return String.Format("{0}|{1}", Service.PublicKey, digest.ToLower());
}
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2.42.0
* Validate webhook challenge payload

## 2.41.0
* Add 3DS info the server side

Expand Down

0 comments on commit a92abae

Please sign in to comment.