Skip to content

Commit

Permalink
Merge pull request #133 from Adyen/develop
Browse files Browse the repository at this point in the history
Release 4.2.0
  • Loading branch information
Aleffio authored Nov 5, 2019
2 parents d461d91 + 7e27a56 commit 3cba36d
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 16 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @msilvagarcia @cyattilakiss @Aleffio @AlexandrosMor @rikterbeek
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ composer.lock

# ignore PhpStorm .idea folder
.idea

# ignore Vagrant metadata files
# these files are unique to each user
.vagrant
4 changes: 4 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/bionic64"
config.vm.box_version = "1.0.282"
end
31 changes: 24 additions & 7 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
<!--
~ ######
~ ######
~ ############ ####( ###### #####. ###### ############ ############
~ ############# #####( ###### #####. ###### ############# #############
~ ###### #####( ###### #####. ###### ##### ###### ##### ######
~ ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
~ ###### ###### #####( ###### #####. ###### ##### ##### ######
~ ############# ############# ############# ############# ##### ######
~ ############ ############ ############# ############ ##### ######
~ ######
~ #############
~ ############
~
~ Adyen API Library for PHP
~
~ Copyright (c) 2019 Adyen B.V.
~ This file is open source and available under the MIT license.
~ See the LICENSE file for more info.
~
-->

<phpunit bootstrap="tests/bootstrap.php" colors="true">
<testsuites>
<testsuite name="Adyen PHP Test Suite">
<directory suffix="Test.php">tests</directory>
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
</phpunit>
12 changes: 7 additions & 5 deletions src/Adyen/AdyenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class AdyenException extends Exception
* @param string $message
* @param int $code
* @param Exception|null $previous
* @param null $status
* @param null $errorType
* @param null $pspReference
* @param string|null $status
* @param string|null $errorType
* @param string|null $pspReference
*/
public function __construct(
$message = "",
Expand All @@ -48,7 +48,7 @@ public function __construct(
/**
* Get status
*
* @return null
* @return string|null
*/
public function getStatus()
{
Expand All @@ -57,14 +57,16 @@ public function getStatus()

/**
* Get Adyen Error type
*
* @return string|null
*/
public function getErrorType()
{
return $this->errorType;
}

/**
* @return string
* @return string|null
*/
public function getPspReference()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Adyen/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class Client
{
const LIB_VERSION = "4.1.0";
const LIB_VERSION = "4.2.0";
const LIB_NAME = "adyen-php-api-library";
const USER_AGENT_SUFFIX = "adyen-php-api-library/";
const ENDPOINT_TEST = "https://pal-test.adyen.com";
Expand All @@ -24,7 +24,7 @@ class Client
const API_CHECKOUT_UTILITY_VERSION = "v1";
const API_NOTIFICATION_VERSION = "v1";
const API_ACCOUNT_VERSION = "v5";
const API_FUND_VERSION = "v3";
const API_FUND_VERSION = "v5";
const ENDPOINT_TERMINAL_CLOUD_TEST = "https://terminal-api-test.adyen.com";
const ENDPOINT_TERMINAL_CLOUD_LIVE = "https://terminal-api-live.adyen.com";
const ENDPOINT_CHECKOUT_TEST = "https://checkout-test.adyen.com/checkout";
Expand Down
4 changes: 3 additions & 1 deletion src/Adyen/HttpClient/CurlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ public function requestPost(\Adyen\Service $service, $requestUrl, $params)

curl_close($ch);

if ($httpStatus != 200 && $result) {
$resultOKHttpStatusCodes = array(200, 201, 202, 204);

if (!in_array($httpStatus, $resultOKHttpStatusCodes) && $result) {
$this->handleResultError($result, $logger);
} elseif (!$result) {
$this->handleCurlError($requestUrl, $errno, $message, $logger);
Expand Down
3 changes: 2 additions & 1 deletion src/Adyen/Util/HmacSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ private function getNotificationDataToSign($params)
$originalReference = (!empty($params['originalReference'])) ? $params['originalReference'] : "";
$merchantAccountCode = (!empty($params['merchantAccountCode'])) ? $params['merchantAccountCode'] : "";
$merchantReference = (!empty($params['merchantReference'])) ? $params['merchantReference'] : "";
$value = (!empty($params['amount']['value'])) ? $params['amount']['value'] : "";
// `empty` treats too many value types as empty. `isset` should prevent some of these cases.
$value = (isset($params['amount']['value'])) ? $params['amount']['value'] : "";
$currency = (!empty($params['amount']['currency'])) ? $params['amount']['currency'] : "";
$eventCode = (!empty($params['eventCode'])) ? $params['eventCode'] : "";
$success = (!empty($params['success'])) ? $params['success'] : "";
Expand Down
28 changes: 28 additions & 0 deletions tests/Adyen/Util/HmacSignatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,32 @@ public function testNotificationRequestItemHmac()
$this->fail('Unexpected exception');
}
}
public function testHmacSignatureForRefundWithZeroValue()
{
$params = json_decode('{
"pspReference": "7914073381342284",
"merchantAccountCode": "TestMerchant",
"merchantReference": "TestPayment-1407325143704",
"amount": {
"value": 0,
"currency": "EUR"
},
"eventCode": "REFUND",
"success": "true"
}', true);
$key = "44782DEF547AAA06C910C43932B1EB0C71FC68D9D0C057550C48EC2ACF6BA056";
$hmac = new HmacSignature();
try {
$hmacCalculation = $hmac->calculateNotificationHMAC($key, $params);
$this->assertNotEmpty($hmacCalculation);
$this->assertEquals("J7HhsgZo5KwqdB7LFZJV6rfQgp+RqC2kuYyw/3x3w+8=", $hmacCalculation);
$params['additionalData'] = array(
'hmacSignature' => $hmacCalculation
);
$hmacValidate = $hmac->isValidNotificationHMAC($key, $params);
$this->assertTrue($hmacValidate);
} catch (AdyenException $e) {
$this->fail('Unexpected exception');
}
}
}

0 comments on commit 3cba36d

Please sign in to comment.