Skip to content

Commit

Permalink
deprecated IsValidWebhook, introduces isValidPlatformWebhook
Browse files Browse the repository at this point in the history
  • Loading branch information
DjoykeAbyah committed Sep 9, 2024
1 parent 92bc77e commit f1da77d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
15 changes: 14 additions & 1 deletion Adyen.Test/UtilTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,28 @@ public void TestHmac()
Assert.IsTrue(string.Equals(encrypted, "34oR8T1whkQWTv9P+SzKyp8zhusf9n0dpqrm9nsqSJs="));
}

//[Deprecated]
[TestMethod]
public void TestBalancePlatformHmac()
{
var notification =
"{\"data\":{\"balancePlatform\":\"Integration_tools_test\",\"accountId\":\"BA32272223222H5HVKTBK4MLB\",\"sweep\":{\"id\":\"SWPC42272223222H5HVKV6H8C64DP5\",\"schedule\":{\"type\":\"balance\"},\"status\":\"active\",\"targetAmount\":{\"currency\":\"EUR\",\"value\":0},\"triggerAmount\":{\"currency\":\"EUR\",\"value\":0},\"type\":\"pull\",\"counterparty\":{\"balanceAccountId\":\"BA3227C223222H5HVKT3H9WLC\"},\"currency\":\"EUR\"}},\"environment\":\"test\",\"type\":\"balancePlatform.balanceAccountSweep.updated\"}";
var signKey = "D7DD5BA6146493707BF0BE7496F6404EC7A63616B7158EC927B9F54BB436765F";
var hmacKey = "9Qz9S/0xpar1klkniKdshxpAhRKbiSAewPpWoxKefQA=";
var hmacValidator = new HmacValidator();
bool response = hmacValidator.IsValidWebhook(signKey, hmacKey, notification);
Assert.IsTrue(response);
}

[TestMethod]
public void IsValidPlatformWebhookTest()
{
var notification =
"{\"data\":{\"balancePlatform\":\"Integration_tools_test\",\"accountId\":\"BA32272223222H5HVKTBK4MLB\",\"sweep\":{\"id\":\"SWPC42272223222H5HVKV6H8C64DP5\",\"schedule\":{\"type\":\"balance\"},\"status\":\"active\",\"targetAmount\":{\"currency\":\"EUR\",\"value\":0},\"triggerAmount\":{\"currency\":\"EUR\",\"value\":0},\"type\":\"pull\",\"counterparty\":{\"balanceAccountId\":\"BA3227C223222H5HVKT3H9WLC\"},\"currency\":\"EUR\"}},\"environment\":\"test\",\"type\":\"balancePlatform.balanceAccountSweep.updated\"}";
var hmacKey = "D7DD5BA6146493707BF0BE7496F6404EC7A63616B7158EC927B9F54BB436765F";
var signature = "9Qz9S/0xpar1klkniKdshxpAhRKbiSAewPpWoxKefQA=";
var hmacValidator = new HmacValidator();
bool response = hmacValidator.IsValidWebhook(signature, hmacKey, notification);
bool response = hmacValidator.IsValidPlatformWebhook(signature, hmacKey, notification);
Assert.IsTrue(response);
}

Expand Down
15 changes: 12 additions & 3 deletions Adyen/Util/HMACValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,22 @@ public bool IsValidHmac(NotificationRequestItem notificationRequestItem, string
}

/// <summary>
/// Validates a balance platform and management webhook payload with the given <paramref name="hmacKey"/> and <paramref name="hmacSignature"/>.
/// [Deprecated]
/// Please use IsValidPlatformebhook()
/// </summary>
public bool IsValidWebhook(string hmacKey, string hmacSignature, string payload)
{
return IsValidPlatformWebhook(hmacSignature, hmacKey, payload);
}

/// <summary>
/// Validates a balance platform and management webhook payload with the given <paramref name="hmacSignature"/> and <paramref name="hmacKey"/>.
/// </summary>
/// <param name="hmacKey">The HMAC key, retrieved from the Adyen Customer Area.</param>
/// <param name="hmacSignature">The HMAC signature, retrieved from the request header.</param>
/// <param name="hmacKey">The HMAC key, retrieved from the Adyen Customer Area.</param>
/// <param name="payload">The webhook payload.</param>
/// <returns>A return value indicates the HMAC validation succeeded.</returns>
public bool IsValidWebhook(string hmacSignature, string hmacKey, string payload)
public bool IsValidPlatformWebhook(string hmacSignature, string hmacKey, string payload)
{
var calculatedSign = CalculateHmac(payload, hmacKey);
return TimeSafeEquals(Encoding.UTF8.GetBytes(hmacSignature), Encoding.UTF8.GetBytes(calculatedSign));
Expand Down

0 comments on commit f1da77d

Please sign in to comment.