Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rikterbeek committed Oct 26, 2016
2 parents 4e1f7ba + e11502f commit c84a99f
Show file tree
Hide file tree
Showing 21 changed files with 95 additions and 61 deletions.
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
/tests/config/*
# ignore config file
/tests/config/*

# Ignore the /vendor/ directory
/vendor/

# composer.lock file should be ignored
composer.lock

# ignore Mac OS X file
.DS_Store
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ The Adyen API Library for PHP enables you to work with Adyen APIs.
Make sure you have an Adyen account. If you don't have this you can request it <a href="https://www.adyen.com/home/discover/test-account-signup#form" target="_blank">here</a>
To make the automatice testing cases working for your account change the credentials in the config/test.ini file.

## Beta ##
This library is in Beta. We're comfortable enough with the stability and features of the library that we want you to build real production applications on it. We are using this Libary in our Magento plugins. We will make an effort to support the public and protected surface of the library and maintain backwards compatibility in the future. While we are still in Beta, we reserve the right to make incompatible changes. If we do remove some functionality (typically because better functionality exists or if the feature proved infeasible), we will release a new version of the application.
## DISCLAIMER ##
The ownership of the content of the Adyen API Library remains with Adyen. The content of the Adyen API Library may only be used in connection with the services of Adyen and subject to the applicable license (Apache License, Version 2.0, the “License”), a copy of which is included in the library.
Unless required by applicable law or agreed to in writing, the library is offered and/or distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Adyen does not warrant that the library or any content will be available uninterrupted or error free, that defects will be corrected, or that the library or its supporting systems are free of viruses or bugs. Please refer to the License for the specific language governing permissions and limitations under the License.

## Documentation ##
http://adyen.github.io/adyen-php-api-library/
Expand Down
16 changes: 9 additions & 7 deletions src/Adyen/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

class Client
{
const LIB_VERSION = "0.1.0";
const LIB_VERSION = "1.1.0";
const USER_AGENT_SUFFIX = "adyen-php-api-library/";
const ENDPOINT_TEST = "https://pal-test.adyen.com";
const ENDPOINT_LIVE = "https://pal-live.adyen.com";
const ENPOINT_TEST_DIRECTORY_LOOKUP = "https://test.adyen.com/hpp/directory.shtml";
const ENPOINT_LIVE_DIRECTORY_LOOKUP = "https://live.adyen.com/hpp/directory.shtml";
const API_VERSION = "v12";
const API_VERSION = "v18";

/**
* @var Adyen_Config $config
Expand All @@ -27,17 +27,20 @@ class Client
*/
private $logger;


/**
* @param $config
* Client constructor.
* @param null $config
* @throws AdyenException
*/
public function __construct($config = null)
{
if(!$config) {
if (!$config) {
// create config
$this->_config = new \Adyen\Config();
}else {
}elseif ($config instanceof \Adyen\ConfigInterface) {
$this->_config = $config;
} else {
throw new \Adyen\AdyenException("This config object is not supported, you need to implement the ConfigInterface");
}
}

Expand All @@ -46,7 +49,6 @@ public function getConfig()
return $this->_config;
}


/**
* Set Username of Web Service User
*
Expand Down
2 changes: 1 addition & 1 deletion src/Adyen/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Adyen;

class Config
class Config implements ConfigInterface
{

/** @var array */
Expand Down
14 changes: 14 additions & 0 deletions src/Adyen/ConfigInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Adyen;

Interface ConfigInterface {

public function getUsername();
public function getPassword();
public function get($param);
public function getInputType();
public function getOutputType();
public function getMerchantAccount();

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Adyen\Service;

class Resource
class AbstractResource
{

protected $_service;
Expand Down Expand Up @@ -103,7 +103,7 @@ protected function _validate($params)
$missingFields[] = $requiredField;
} else {
// check if value is set
if($params[$requiredField] == "") {
if($params[$requiredField] === "") {
$missingValues[] = $requiredField;
}
}
Expand All @@ -112,11 +112,13 @@ protected function _validate($params)

if(!empty($missingFields)) {
$msg = 'Missing the following fields: ' . implode($missingFields, ',');
$this->_service->getClient()->getLogger()->error($msg);
throw new \Adyen\AdyenException($msg);
}

if(!empty($missingValues)) {
$msg = 'Missing the following values: ' . implode($missingValues, ',');
$this->_service->getClient()->getLogger()->error($msg);
throw new \Adyen\AdyenException($msg);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Adyen/Service/DirectoryLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function __construct(\Adyen\Client $client)
{
parent::__construct($client);

$this->_directoryLookup = new \Adyen\Service\Resource\DirectoryLookup\Directory($this);
$this->_directoryLookup = new \Adyen\Service\ResourceModel\DirectoryLookup\Directory($this);
}

public function directoryLookup($params)
Expand Down
8 changes: 4 additions & 4 deletions src/Adyen/Service/Modification.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public function __construct(\Adyen\Client $client)
{
parent::__construct($client);

$this->_cancel = new \Adyen\Service\Resource\Modification\Cancel($this);
$this->_cancelOrRefund = new \Adyen\Service\Resource\Modification\CancelOrRefund($this);
$this->_capture = new \Adyen\Service\Resource\Modification\Capture($this);
$this->_refund = new \Adyen\Service\Resource\Modification\Refund($this);
$this->_cancel = new \Adyen\Service\ResourceModel\Modification\Cancel($this);
$this->_cancelOrRefund = new \Adyen\Service\ResourceModel\Modification\CancelOrRefund($this);
$this->_capture = new \Adyen\Service\ResourceModel\Modification\Capture($this);
$this->_refund = new \Adyen\Service\ResourceModel\Modification\Refund($this);
}

public function cancel($params)
Expand Down
4 changes: 2 additions & 2 deletions src/Adyen/Service/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public function __construct(\Adyen\Client $client)
{
parent::__construct($client);

$this->_authorise = new \Adyen\Service\Resource\Payment\Authorise($this);
$this->_authorise3D = new \Adyen\Service\Resource\Payment\Authorise3D($this);
$this->_authorise = new \Adyen\Service\ResourceModel\Payment\Authorise($this);
$this->_authorise3D = new \Adyen\Service\ResourceModel\Payment\Authorise3D($this);

}

Expand Down
4 changes: 2 additions & 2 deletions src/Adyen/Service/Recurring.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public function __construct(\Adyen\Client $client)
{
parent::__construct($client);

$this->_listRecurringDetails = new \Adyen\Service\Resource\Recurring\ListRecurringDetails(
$this->_listRecurringDetails = new \Adyen\Service\ResourceModel\Recurring\ListRecurringDetails(
$this);

$this->_disable = new \Adyen\Service\Resource\Recurring\Disable(
$this->_disable = new \Adyen\Service\ResourceModel\Recurring\Disable(
$this,
$this->getClient()->getConfig()->get('endpoint') . '/disable',
array('merchantAccount', 'shopperReference'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
//https://test.adyen.com/hpp/directory.shtml


namespace Adyen\Service\Resource\DirectoryLookup;
namespace Adyen\Service\ResourceModel\DirectoryLookup;

class Directory extends \Adyen\Service\Resource
class Directory extends \Adyen\Service\AbstractResource
{
protected $_requiredFields = array(
'paymentAmount',
Expand All @@ -14,7 +14,6 @@ class Directory extends \Adyen\Service\Resource
'skinCode',
'merchantAccount',
'sessionValidity',
'countryCode',
'shopperLocale',
'merchantSig'
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Adyen\Service\Resource\Modification;
namespace Adyen\Service\ResourceModel\Modification;

class Cancel extends \Adyen\Service\Resource
class Cancel extends \Adyen\Service\AbstractResource
{
protected $_requiredFields = array(
'merchantAccount',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Adyen\Service\Resource\Modification;
namespace Adyen\Service\ResourceModel\Modification;

class CancelOrRefund extends \Adyen\Service\Resource
class CancelOrRefund extends \Adyen\Service\AbstractResource
{
protected $_requiredFields = array(
'merchantAccount',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Adyen\Service\Resource\Modification;
namespace Adyen\Service\ResourceModel\Modification;

class Capture extends \Adyen\Service\Resource
class Capture extends \Adyen\Service\AbstractResource
{
protected $_requiredFields = array(
'merchantAccount',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Adyen\Service\Resource\Modification;
namespace Adyen\Service\ResourceModel\Modification;

class Refund extends \Adyen\Service\Resource
class Refund extends \Adyen\Service\AbstractResource
{
protected $_requiredFields = array(
'merchantAccount',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Adyen\Service\Resource\Payment;
namespace Adyen\Service\ResourceModel\Payment;

class Authorise extends \Adyen\Service\Resource
class Authorise extends \Adyen\Service\AbstractResource
{
protected $_requiredFields = array(
'merchantAccount',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Adyen\Service\Resource\Payment;
namespace Adyen\Service\ResourceModel\Payment;

class Authorise3D extends \Adyen\Service\Resource
class Authorise3D extends \Adyen\Service\AbstractResource
{
protected $_requiredFields = array(
'merchantAccount',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Adyen\Service\Resource\Recurring;
namespace Adyen\Service\ResourceModel\Recurring;

class Disable extends \Adyen\Service\Resource
class Disable extends \Adyen\Service\AbstractResource
{
protected $_requiredFields = array(
'merchantAccount',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Adyen\Service\Resource\Recurring;
namespace Adyen\Service\ResourceModel\Recurring;

class ListRecurringDetails extends \Adyen\Service\Resource
class ListRecurringDetails extends \Adyen\Service\AbstractResource
{

protected $_requiredFields = array(
Expand Down
22 changes: 14 additions & 8 deletions src/Adyen/Util/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,33 @@

namespace Adyen\Util;


class Util
{

public static function calculateSha256Signature($hmacKey, $params)
{
// validate if hmacKey is provided
if ($hmacKey == "") {
throw new \Adyen\AdyenException("You did not provide a HMAC key");
}

if (empty($params)) {
throw new \Adyen\AdyenException("You did not provide any parameters");
}

// The character escape function
$escapeval = function($val) {
return str_replace(':','\\:',str_replace('\\','\\\\',$val));
$escapeval = function ($val) {
return str_replace(':', '\\:', str_replace('\\', '\\\\', $val));
};

// Sort the array by key using SORT_STRING order
ksort($params, SORT_STRING);

// Generate the signing data string
$signData = implode(":",array_map($escapeval,array_merge(array_keys($params), array_values($params))));
$signData = implode(":", array_map($escapeval, array_merge(array_keys($params), array_values($params))));

// base64-encode the binary result of the HMAC computation
$merchantSig = base64_encode(hash_hmac('sha256',$signData,pack("H*" , $hmacKey),true));
$merchantSig = base64_encode(hash_hmac('sha256', $signData, pack("H*", $hmacKey), true));
return $merchantSig;
}


}
}
24 changes: 12 additions & 12 deletions tests/CreatePaymentRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public function testCreatePaymentMissingReference()
$json = '{
"card": {
"number": "4111111111111111",
"expiryMonth": "6",
"expiryYear": "2016",
"expiryMonth": "08",
"expiryYear": "2018",
"cvc": "737",
"holderName": "John Smith"
},
Expand Down Expand Up @@ -59,8 +59,8 @@ public function testCreatePaymentSuccess()
$json = '{
"card": {
"number": "4111111111111111",
"expiryMonth": "6",
"expiryYear": "2016",
"expiryMonth": "08",
"expiryYear": "2018",
"cvc": "737",
"holderName": "John Smith"
},
Expand Down Expand Up @@ -106,8 +106,8 @@ public function testCreatePaymentWithRecurringSuccess()
},
"card": {
"cvc": "737",
"expiryMonth": "6",
"expiryYear": "2016",
"expiryMonth": "08",
"expiryYear": "2018",
"holderName": "John Smith",
"number": "4111111111111111"
},
Expand Down Expand Up @@ -152,8 +152,8 @@ public function testCreatePaymentSuccessWithMerchantAccountInClient()
$json = '{
"card": {
"number": "4111111111111111",
"expiryMonth": "6",
"expiryYear": "2016",
"expiryMonth": "08",
"expiryYear": "2018",
"cvc": "737",
"holderName": "John Smith"
},
Expand Down Expand Up @@ -200,8 +200,8 @@ public function testCreatePaymentSuccessJson()
$json = '{
"card": {
"number": "4111111111111111",
"expiryMonth": "6",
"expiryYear": "2016",
"expiryMonth": "08",
"expiryYear": "2018",
"cvc": "737",
"holderName": "John Smith"
},
Expand Down Expand Up @@ -249,8 +249,8 @@ public function testCreatePaymentWrongCvc()
$json = '{
"card": {
"number": "4111111111111111",
"expiryMonth": "6",
"expiryYear": "2016",
"expiryMonth": "08",
"expiryYear": "2018",
"cvc": "111",
"holderName": "John Smith"
},
Expand Down

0 comments on commit c84a99f

Please sign in to comment.