Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PW-445: Removed required fields, validate function and related tests #69

Merged
merged 2 commits into from
Jul 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 1 addition & 73 deletions src/Adyen/Service/AbstractResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ class AbstractResource

protected $_service;
protected $_endpoint;
protected $_requiredFields;

public function __construct(\Adyen\Service $service, $endpoint, $requiredFields)
public function __construct(\Adyen\Service $service, $endpoint)
{
$this->_service = $service;
$this->_endpoint = $endpoint;
$this->_requiredFields = $requiredFields;
}

/**
Expand All @@ -35,9 +33,6 @@ public function request($params)
$params['merchantAccount'] = $this->_service->getClient()->getConfig()->getMerchantAccount();
}

// validate the request parameters
$this->_validate($params);

$curlClient = $this->_service->getClient()->getHttpClient();
return $curlClient->requestJson($this->_service, $this->_endpoint, $params);
}
Expand All @@ -51,75 +46,8 @@ public function requestPost($params)
throw new \Adyen\AdyenException($msg);
}

// validate the request parameters
$this->_validate($params);

$curlClient = $this->_service->getClient()->getHttpClient();
return $curlClient->requestPost($this->_service, $this->_endpoint, $params);
}

/**
* Validate if all required fields are in the params
*
* @param $params
*/
protected function _validate($params)
{
$missingFields = array();
$missingValues = array();

if(is_array($this->_requiredFields)) {
foreach($this->_requiredFields as $requiredField) {

// if validation is two levels validate if parent and child is in the request
if(strpos($requiredField, ".") !== FALSE) {
$results = explode('.', $requiredField);

// for validation only a depth for 2 levels is needed
$parent = $results[0];
$child = $results[1];

if(!isset($params[$parent])) {
// missing the parent param in request
$missingFields[] = $requiredField;
continue;
}
if(!isset($params[$parent][$child])) {
// missing the child param in request
$missingFields[] = $requiredField;
continue;
} else {
// check if value is set
if($params[$parent][$child] === "") {
$missingValues[] = $requiredField;
}
}

// the param is in the request so continue
continue;
}

if(!array_key_exists($requiredField, $params)) {
$missingFields[] = $requiredField;
} else {
// check if value is set
if($params[$requiredField] === "") {
$missingValues[] = $requiredField;
}
}
}
}

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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@

class PaymentMethods extends \Adyen\Service\AbstractResource
{

protected $_requiredFields = array(
'merchantAccount'
);

protected $_endpoint;

public function __construct($service)
{
$this->_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutVersion() . '/paymentMethods';
parent::__construct($service, $this->_endpoint, $this->_requiredFields);
parent::__construct($service, $this->_endpoint);
}

}
12 changes: 1 addition & 11 deletions src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,12 @@

class PaymentSession extends \Adyen\Service\AbstractResource
{

protected $_requiredFields = array(
'amount.value',
'amount.currency',
'countryCode',
'merchantAccount',
'returnUrl',
'reference'
);

protected $_endpoint;

public function __construct($service)
{
$this->_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutVersion() . '/paymentSession';
parent::__construct($service, $this->_endpoint, $this->_requiredFields);
parent::__construct($service, $this->_endpoint);
}

}
11 changes: 1 addition & 10 deletions src/Adyen/Service/ResourceModel/Checkout/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,12 @@
class Payments extends \Adyen\Service\AbstractResource
{

protected $_requiredFields = array(
'amount.value',
'amount.currency',
'merchantAccount',
'paymentMethod',
'reference',
'returnUrl'
);

protected $_endpoint;

public function __construct($service)
{
$this->_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments';
parent::__construct($service, $this->_endpoint, $this->_requiredFields);
parent::__construct($service, $this->_endpoint);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@

class PaymentsDetails extends \Adyen\Service\AbstractResource
{

protected $_requiredFields = array(
'paymentData',
'details'
);

protected $_endpoint;

public function __construct($service)
{
$this->_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments/details';
parent::__construct($service, $this->_endpoint, $this->_requiredFields);
parent::__construct($service, $this->_endpoint);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@

class PaymentsResult extends \Adyen\Service\AbstractResource
{

protected $_requiredFields = array(
'payload'
);

protected $_endpoint;

public function __construct($service)
{
$this->_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments/result';
parent::__construct($service, $this->_endpoint, $this->_requiredFields);
parent::__construct($service, $this->_endpoint);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@

class OriginKeys extends \Adyen\Service\AbstractResource
{

protected $_requiredFields = array(
'originDomains'
);

protected $_endpoint;

public function __construct($service)
{
$this->_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutUtilityVersion() . '/originKeys';
parent::__construct($service, $this->_endpoint, $this->_requiredFields);
parent::__construct($service, $this->_endpoint);
}

}
13 changes: 1 addition & 12 deletions src/Adyen/Service/ResourceModel/DirectoryLookup/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,12 @@

class Directory extends \Adyen\Service\AbstractResource
{
protected $_requiredFields = array(
'paymentAmount',
'currencyCode',
'merchantReference',
'skinCode',
'merchantAccount',
'sessionValidity',
'shopperLocale',
'merchantSig'
);

protected $_endpoint;

public function __construct($service)
{
$this->_endpoint = $service->getClient()->getConfig()->get('endpointDirectorylookup');
parent::__construct($service, $this->_endpoint, $this->_requiredFields);
parent::__construct($service, $this->_endpoint);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@

class AdjustAuthorisation extends \Adyen\Service\AbstractResource
{
protected $_requiredFields = array(
'merchantAccount',
'originalReference',
'modificationAmount.value',
'modificationAmount.currency',
);

protected $_endpoint;

public function __construct($service)
{
$this->_endpoint = $service->getClient()->getConfig()->get('endpoint').'/pal/servlet/Payment/'.$service->getClient()->getApiVersion().'/adjustAuthorisation';
parent::__construct($service, $this->_endpoint, $this->_requiredFields);
parent::__construct($service, $this->_endpoint);
}

}
7 changes: 1 addition & 6 deletions src/Adyen/Service/ResourceModel/Modification/Cancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@

class Cancel extends \Adyen\Service\AbstractResource
{
protected $_requiredFields = array(
'merchantAccount',
'originalReference'
);

protected $_endpoint;

public function __construct($service)
{
$this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/' . $service->getClient()->getApiVersion() . '/cancel';
parent::__construct($service, $this->_endpoint, $this->_requiredFields);
parent::__construct($service, $this->_endpoint);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@

class CancelOrRefund extends \Adyen\Service\AbstractResource
{
protected $_requiredFields = array(
'merchantAccount',
'originalReference',
);

protected $_endpoint;

public function __construct($service)
{
$this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/'. $service->getClient()->getApiVersion() . '/cancelOrRefund';
parent::__construct($service, $this->_endpoint, $this->_requiredFields);
parent::__construct($service, $this->_endpoint);
}

}
10 changes: 1 addition & 9 deletions src/Adyen/Service/ResourceModel/Modification/Capture.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,12 @@

class Capture extends \Adyen\Service\AbstractResource
{
protected $_requiredFields = array(
'merchantAccount',
'modificationAmount',
'modificationAmount.value',
'modificationAmount.currency',
'originalReference'
);

protected $_endpoint;

public function __construct($service)
{
$this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/' . $service->getClient()->getApiVersion() . '/capture';
parent::__construct($service, $this->_endpoint, $this->_requiredFields);
parent::__construct($service, $this->_endpoint);
}

}
10 changes: 1 addition & 9 deletions src/Adyen/Service/ResourceModel/Modification/Refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,12 @@

class Refund extends \Adyen\Service\AbstractResource
{
protected $_requiredFields = array(
'merchantAccount',
'modificationAmount',
'modificationAmount.value',
'modificationAmount.currency',
'originalReference'
);

protected $_endpoint;

public function __construct($service)
{
$this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/' . $service->getClient()->getApiVersion() . '/refund';
parent::__construct($service, $this->_endpoint, $this->_requiredFields);
parent::__construct($service, $this->_endpoint);
}

}
9 changes: 1 addition & 8 deletions src/Adyen/Service/ResourceModel/Payment/Authorise.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@

class Authorise extends \Adyen\Service\AbstractResource
{
protected $_requiredFields = array(
'merchantAccount',
'amount.value',
'amount.currency',
'reference'
);

protected $_endpoint;

public function __construct($service)
{
$this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/' . $service->getClient()->getApiVersion() . '/authorise';
parent::__construct($service, $this->_endpoint, $this->_requiredFields);
parent::__construct($service, $this->_endpoint);
}

}
Loading