From 553f919edcf49959f21a6e00aa6c2703d3073186 Mon Sep 17 00:00:00 2001 From: aprasker Date: Wed, 3 Jan 2018 10:00:56 +0100 Subject: [PATCH 01/31] Add x-api key for Terminal API (Cloud) --- tests/config/test.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/config/test.ini b/tests/config/test.ini index 928280fec..f1946c6d9 100644 --- a/tests/config/test.ini +++ b/tests/config/test.ini @@ -4,6 +4,7 @@ password = "YOUR PASSWORD" merchantAccount = YOUR MERCHANT ACCOUNT skinCode = YOUR SKIN CODE hmacSignature = YOUR HMAC SIGNATURE +x-api-key = YOUR X-API KEY storePayoutUsername = YOUR STORE PAYOUT USERNAME storePayoutPassword = "YOUR STORE PAYOUT PASSWORD" From 6833c363b230b923d33472d1152f3806fc773c6c Mon Sep 17 00:00:00 2001 From: aprasker Date: Fri, 19 Jan 2018 13:24:29 +0100 Subject: [PATCH 02/31] Added POIID entr for Unique Terminal ID --- tests/config/test.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/config/test.ini b/tests/config/test.ini index f1946c6d9..a6dead4fa 100644 --- a/tests/config/test.ini +++ b/tests/config/test.ini @@ -5,6 +5,7 @@ merchantAccount = YOUR MERCHANT ACCOUNT skinCode = YOUR SKIN CODE hmacSignature = YOUR HMAC SIGNATURE x-api-key = YOUR X-API KEY +POIID = UNIQUETERMINALID ([MODEL]-[SERIAL_NUMBER]) storePayoutUsername = YOUR STORE PAYOUT USERNAME storePayoutPassword = "YOUR STORE PAYOUT PASSWORD" From 296a165b53a0ac08f10c243e664c766ec7c33e6c Mon Sep 17 00:00:00 2001 From: aprasker Date: Fri, 19 Jan 2018 14:04:59 +0100 Subject: [PATCH 03/31] First iteration for Terminal API (Cloud) --- src/Adyen/Client.php | 14 ++ src/Adyen/Config.php | 10 ++ src/Adyen/ConfigInterface.php | 2 + src/Adyen/HttpClient/CurlClient.php | 33 +++-- src/Adyen/Service.php | 6 + src/Adyen/Service/PosPayment.php | 111 +++++++++++++++ .../Payment/TerminalCloudAPI.php | 30 +++++ src/Adyen/TransactionType.php | 12 ++ tests/PosPaymentTest.php | 126 ++++++++++++++++++ tests/TestCase.php | 31 +++++ 10 files changed, 365 insertions(+), 10 deletions(-) create mode 100644 src/Adyen/Service/PosPayment.php create mode 100644 src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php create mode 100644 src/Adyen/TransactionType.php create mode 100644 tests/PosPaymentTest.php diff --git a/src/Adyen/Client.php b/src/Adyen/Client.php index 9fa2cf108..4126b1607 100644 --- a/src/Adyen/Client.php +++ b/src/Adyen/Client.php @@ -16,6 +16,8 @@ class Client const ENPOINT_LIVE_DIRECTORY_LOOKUP = "https://live.adyen.com/hpp/directory/v2.shtml"; const API_VERSION = "v30"; const API_RECURRING_VERSION = "v25"; + const TERMINAL_CLOUD_TEST = "https://terminal-api-test.adyen.com"; + const TERMINAL_CLOUD_LIVE = "https://terminal-api-live.adyen.com"; /** * @var Adyen_Config $config @@ -71,6 +73,16 @@ public function setPassword($password) $this->_config->set('password', $password); } + /** + * Set x-api-key for Web Service Client + * + * @param $xapikey + */ + public function setXApiKey($xapikey) + { + $this->_config->set('x-api-key', $xapikey); + } + /** * Set environment to connect to test or live platform of Adyen * @@ -83,10 +95,12 @@ public function setEnvironment($environment) $this->_config->set('environment', \Adyen\Environment::TEST); $this->_config->set('endpoint', self::ENDPOINT_TEST); $this->_config->set('endpointDirectorylookup', self::ENPOINT_TEST_DIRECTORY_LOOKUP); + $this->_config->set('endpointTerminalCloud', self::TERMINAL_CLOUD_TEST); } elseif($environment == \Adyen\Environment::LIVE) { $this->_config->set('environment', \Adyen\Environment::LIVE); $this->_config->set('endpoint', self::ENDPOINT_LIVE); $this->_config->set('endpointDirectorylookup', self::ENPOINT_LIVE_DIRECTORY_LOOKUP); + $this->_config->set('endpointTerminalCloud', self::TERMINAL_CLOUD_LIVE); } else { // environment does not exists $msg = "This environment does not exists use " . \Adyen\Environment::TEST . ' or ' . \Adyen\Environment::LIVE; diff --git a/src/Adyen/Config.php b/src/Adyen/Config.php index 6f1e3709c..c96603d14 100644 --- a/src/Adyen/Config.php +++ b/src/Adyen/Config.php @@ -59,6 +59,16 @@ public function getPassword() return isset($this->data['password']) ? $this->data['password'] : null; } + public function getXApiKey() + { + return isset($this->data['x-api-key']) ? $this->data['x-api-key'] : null; + } + + public function getPOIID() + { + return isset($this->data['POIID']) ? $this->data['POIID'] : null; + } + public function getInputType() { if(isset($this->data['inputType']) && in_array($this->data['inputType'], $this->allowedInput)) { diff --git a/src/Adyen/ConfigInterface.php b/src/Adyen/ConfigInterface.php index 94bfd4463..fb8c22fb9 100644 --- a/src/Adyen/ConfigInterface.php +++ b/src/Adyen/ConfigInterface.php @@ -6,9 +6,11 @@ public function getUsername(); public function getPassword(); + public function getXApiKey(); public function get($param); public function getInputType(); public function getOutputType(); public function getMerchantAccount(); + public function getPOIID(); } \ No newline at end of file diff --git a/src/Adyen/HttpClient/CurlClient.php b/src/Adyen/HttpClient/CurlClient.php index c6deab363..e992bcfef 100644 --- a/src/Adyen/HttpClient/CurlClient.php +++ b/src/Adyen/HttpClient/CurlClient.php @@ -21,6 +21,8 @@ public function requestJson(\Adyen\Service $service, $requestUrl, $params) $logger = $client->getLogger(); $username = $config->getUsername(); $password = $config->getPassword(); + $xapikey = $config->getXApiKey(); + $jsonRequest = json_encode($params); // log the request @@ -32,22 +34,33 @@ public function requestJson(\Adyen\Service $service, $requestUrl, $params) //Tell cURL that we want to send a POST request. curl_setopt($ch, CURLOPT_POST, 1); - // set authorisation - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); - curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); - //Attach our encoded JSON string to the POST fields. curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonRequest); - // set a custom User-Agent + //create a custom User-Agent $userAgent = $config->get('applicationName') . " " . \Adyen\Client::USER_AGENT_SUFFIX . $client->getLibraryVersion(); - //Set the content type to application/json and use the defined userAgent - $headers = array( - 'Content-Type: application/json', - 'User-Agent: ' . $userAgent - ); + // set authorisation credentials according to support & availability + if ($service->supportsXAPIKey() && $xapikey != "") { + //Set the content type to application/json and use the defined userAgent along with the x-api-key + $headers = array( + 'Content-Type: application/json', + 'User-Agent: ' . $userAgent, + 'x-api-key: ' . $xapikey + ); + } else { + //Set the basic auth credentials + curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); + curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); + + //Set the content type to application/json and use the defined userAgent + $headers = array( + 'Content-Type: application/json', + 'User-Agent: ' . $userAgent + ); + } + //Set the headers curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // return the result diff --git a/src/Adyen/Service.php b/src/Adyen/Service.php index 880c1dfcb..06b4d50fe 100644 --- a/src/Adyen/Service.php +++ b/src/Adyen/Service.php @@ -5,6 +5,7 @@ class Service { private $client; + protected $_supportsXAPIKey = false; public function __construct(\Adyen\Client $client) { @@ -25,4 +26,9 @@ public function getClient() return $this->client; } + public function supportsXAPIKey() + { + return $this->_supportsXAPIKey; + } + } \ No newline at end of file diff --git a/src/Adyen/Service/PosPayment.php b/src/Adyen/Service/PosPayment.php new file mode 100644 index 000000000..d0a40ac67 --- /dev/null +++ b/src/Adyen/Service/PosPayment.php @@ -0,0 +1,111 @@ +_runTenderSync = new \Adyen\Service\ResourceModel\Payment\TerminalCloudAPI($this, false); + $this->_runTenderAsync = new \Adyen\Service\ResourceModel\Payment\TerminalCloudAPI($this, true); + + } + + public function runTenderSync($params) + { + $result = $this->_runTenderSync->request($params); + return $result; + } + + public function runTenderAsync($params) + { + $result = $this->_runTenderAsync->request($params); + return $result; + } + + private function _getFormattedAmountValue($amountValue) + { //Terminal API amountValue requires 42.42 format + if (strlen($amountValue) > 2) { + return substr($amountValue, 0, strlen($amountValue) - 2) . '.' . substr($amountValue, strlen($amountValue) - 2); + } elseif (strlen($amountValue) > 1) { + return '0.' . $amountValue; + } else { + return '0.0' . $amountValue; + } + } + + public function getServiceId($request) + { + if (isset($request['SaleToPOIRequest']['MessageHeader']['ServiceID'])) { + return $request['SaleToPOIRequest']['MessageHeader']['ServiceID']; + } + return null; + } + + public function getPaymentRequest($POIID, $amountValue, $amountCurrency, $merchantReference, $transactionType) + { + //Set specific dynamic parameters + $serviceID = date("dHis"); + $timeStamper = date("Y-m-d") . "T" . date("H:i:s+00:00"); + + //check for existing '.' + $_amountValue = $this->_getFormattedAmountValue($amountValue); + + //Convert requested type + switch ($transactionType) { + case "GOODS_SERVICES": + $this->_txType = 'Normal'; + break; + case "REFUND": + $this->_txType = 'Refund'; + break; + + default: + $this->_txType = $transactionType; + } + + //Provide json as result + $result = '{ + "SaleToPOIRequest": { + "MessageHeader": { + "MessageType": "Request", + "MessageClass": "Service", + "MessageCategory": "Payment", + "SaleID": "MagentoCloudEMV", + "POIID": "' . $POIID . '", + "ProtocolVersion": "3.0", + "ServiceID": "' . $serviceID . '" + }, + "PaymentRequest": { + "SaleData": { + "SaleTransactionID": { + "TransactionID": "' . $merchantReference . '", + "TimeStamp": "' . $timeStamper . '" + }, + "TokenRequestedType": "Customer", + "SaleReferenceID": "SalesRefABC" + }, + "PaymentTransaction": { + "AmountsReq": { + "Currency": "' . $amountCurrency . '", + "RequestedAmount": ' . $_amountValue . ' + } + }, + "PaymentData": { + "PaymentType": "' . $this->_txType . '" + } + } + } + } + '; + return $result; + } +} diff --git a/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php b/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php new file mode 100644 index 000000000..a22d05448 --- /dev/null +++ b/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php @@ -0,0 +1,30 @@ +_endpoint = $service->getClient()->getConfig()->get('endpointTerminalCloud') . '/async'; + }else { + $this->_endpoint = $service->getClient()->getConfig()->get('endpointTerminalCloud') . '/sync'; + } + parent::__construct($service, $this->_endpoint, $this->_requiredFields); + } + +} \ No newline at end of file diff --git a/src/Adyen/TransactionType.php b/src/Adyen/TransactionType.php new file mode 100644 index 000000000..19a2239cd --- /dev/null +++ b/src/Adyen/TransactionType.php @@ -0,0 +1,12 @@ +createTerminalCloudAPIClient(); + $logger = $client->getLogger(); + + // initialize service + $service = new Service\PosPayment($client); + + //Construct request + $transactionType = \Adyen\TransactionType::GOODS_SERVICES; + $json = $service->getPaymentRequest($this->getPOIID(), 1491, "EUR", "let's rock!", $transactionType); + $params = json_decode($json, true); //Create associative array for passing along + $serviceID = $service->getServiceId($params); + + try { + $result = $service->runTenderSync($params); + } catch (\Exception $e) { + $this->validateApiPermission($e); + } + + // must exists + $this->assertTrue(isset($result['SaleToPOIResponse'])); + + if (!(isset($result['SaleToPOIResponse']))) { + $logger->error("Received:", $result); + } + if (!(isset($result['SaleToPOIResponse']['PaymentResponse']['Response']['Result']))) { + $logger->error("Response: ", $result); + } else { + // Assert success for this test + //$this->assertEquals('Success', $result['SaleToPOIResponse']['PaymentResponse']['Response']['Result']); + //AdditionalResponse":"errors= + if (('Success' != $result['SaleToPOIResponse']['PaymentResponse']['Response']['Result'])) { + $tmp[0] = $result['SaleToPOIResponse']['PaymentResponse']['Response']['AdditionalResponse']; + $logger->error("Errors: ", $tmp); + $logger->error("What did we send to deserve this: ", $params); + } + } + + // return the result so this can be used in other test cases + return $result; + + } + + public function testCreatePosPaymentDeclined() + { + // initialize client + $client = $this->createTerminalCloudAPIClient(); + $logger = $client->getLogger(); + + // initialize service + $service = new Service\PosPayment($client); + + //Construct request + $transactionType = \Adyen\TransactionType::GOODS_SERVICES; + $json = $service->getPaymentRequest($this->getPOIID(), 149, "EUR", "let's decline dis!", $transactionType); + $params = json_decode($json, true); //Create associative array for passing along + $serviceID = $service->getServiceId($params); + + try { + $result = $service->runTenderSync($params); + } catch (\Exception $e) { + $this->validateApiPermission($e); + } + + // must exists & be Failure + $this->assertTrue(isset($result['SaleToPOIResponse']['PaymentResponse']['Response']['Result'])); + $this->assertEquals('Failure', $result['SaleToPOIResponse']['PaymentResponse']['Response']['Result']); + + // return the result so this can be used in other test cases + return $result; + + } + + public function testCreatePosEMVRefundSuccess() + { + // initialize client + $client = $this->createTerminalCloudAPIClient(); + $logger = $client->getLogger(); + + // initialize service + $service = new Service\PosPayment($client); + + //Construct request + $transactionType = \Adyen\TransactionType::REFUND; + $json = $service->getPaymentRequest($this->getPOIID(), 1491, "EUR", "let's refund dis!", $transactionType); + $params = json_decode($json, true); //Create associative array for passing along + $logger->error("What we sending: ",$params); + $serviceID = $service->getServiceId($params); + + try { + $result = $service->runTenderSync($params); + } catch (\Exception $e) { + $this->validateApiPermission($e); + } + + // must exists + $this->assertTrue(isset($result['SaleToPOIResponse'])); + + if (!(isset($result['SaleToPOIResponse']))) { + $logger->error("Received:", $result); + } + if (!(isset($result['SaleToPOIResponse']['PaymentResponse']['Response']['Result']))) { + $logger->error("Response: ", $result); + } else { + if (('Success' != $result['SaleToPOIResponse']['PaymentResponse']['Response']['Result'])) { + $tmp[0] = $result['SaleToPOIResponse']['PaymentResponse']['Response']['AdditionalResponse']; + $logger->error("Errors: ", $tmp); + $logger->error("What did we send to deserve this: ", $params); + } + } + + // return the result so this can be used in other test cases + return $result; + + } + +} \ No newline at end of file diff --git a/tests/TestCase.php b/tests/TestCase.php index ab6c93e53..120715a3f 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -11,9 +11,13 @@ class TestCase extends \PHPUnit_Framework_TestCase public function __construct() { + + date_default_timezone_set('Europe/Amsterdam'); + $this->_merchantAccount = $this->getMerchantAccount(); $this->_skinCode = $this->getSkinCode(); $this->_hmacSignature = $this->getHmacSignature(); + } @@ -128,6 +132,22 @@ protected function createReviewPayoutClient() } } + protected function createTerminalCloudAPIClient() + { + // load settings from .ini file + $settings = $this->_loadConfigIni(); + + if(isset($settings['x-api-key']) && isset($settings['POIID'])){ + $client = new \Adyen\Client(); + $client->setApplicationName("My Test Terminal API App"); + $client->setEnvironment(\Adyen\Environment::TEST); + $client->setXApiKey($settings['x-api-key']); + return $client; + + }else{ + $this->_skipTest("Skipped the test. Configure your x-api-key and POIID in the config"); + } + } protected function createClientWithMerchantAccount() { @@ -178,6 +198,17 @@ protected function getHmacSignature() return $settings['hmacSignature']; } + protected function getPOIID() + { + $settings = $this->_loadConfigIni(); + + if(!isset($settings['POIID']) || $settings['POIID'] == 'MODEL-SERIALNUMBER') { + return null; + } + + return $settings['POIID']; + } + protected function _loadConfigIni() { return parse_ini_file(__DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'test.ini', true); From bfd0646478c52ec75a4ac23a8d16238840a08faf Mon Sep 17 00:00:00 2001 From: Aleffio Date: Fri, 26 Jan 2018 13:05:30 +0100 Subject: [PATCH 04/31] PW-351: Moved buildPosPaymentRequest to Util. Refactoring. --- src/Adyen/Service/PosPayment.php | 69 ----------- .../Payment/TerminalCloudAPI.php | 5 +- src/Adyen/Util/Util.php | 117 ++++++++++++++++++ tests/PosPaymentTest.php | 56 ++------- tests/config/test.ini | 2 +- 5 files changed, 128 insertions(+), 121 deletions(-) diff --git a/src/Adyen/Service/PosPayment.php b/src/Adyen/Service/PosPayment.php index d0a40ac67..8fb07515d 100644 --- a/src/Adyen/Service/PosPayment.php +++ b/src/Adyen/Service/PosPayment.php @@ -31,17 +31,6 @@ public function runTenderAsync($params) return $result; } - private function _getFormattedAmountValue($amountValue) - { //Terminal API amountValue requires 42.42 format - if (strlen($amountValue) > 2) { - return substr($amountValue, 0, strlen($amountValue) - 2) . '.' . substr($amountValue, strlen($amountValue) - 2); - } elseif (strlen($amountValue) > 1) { - return '0.' . $amountValue; - } else { - return '0.0' . $amountValue; - } - } - public function getServiceId($request) { if (isset($request['SaleToPOIRequest']['MessageHeader']['ServiceID'])) { @@ -50,62 +39,4 @@ public function getServiceId($request) return null; } - public function getPaymentRequest($POIID, $amountValue, $amountCurrency, $merchantReference, $transactionType) - { - //Set specific dynamic parameters - $serviceID = date("dHis"); - $timeStamper = date("Y-m-d") . "T" . date("H:i:s+00:00"); - - //check for existing '.' - $_amountValue = $this->_getFormattedAmountValue($amountValue); - - //Convert requested type - switch ($transactionType) { - case "GOODS_SERVICES": - $this->_txType = 'Normal'; - break; - case "REFUND": - $this->_txType = 'Refund'; - break; - - default: - $this->_txType = $transactionType; - } - - //Provide json as result - $result = '{ - "SaleToPOIRequest": { - "MessageHeader": { - "MessageType": "Request", - "MessageClass": "Service", - "MessageCategory": "Payment", - "SaleID": "MagentoCloudEMV", - "POIID": "' . $POIID . '", - "ProtocolVersion": "3.0", - "ServiceID": "' . $serviceID . '" - }, - "PaymentRequest": { - "SaleData": { - "SaleTransactionID": { - "TransactionID": "' . $merchantReference . '", - "TimeStamp": "' . $timeStamper . '" - }, - "TokenRequestedType": "Customer", - "SaleReferenceID": "SalesRefABC" - }, - "PaymentTransaction": { - "AmountsReq": { - "Currency": "' . $amountCurrency . '", - "RequestedAmount": ' . $_amountValue . ' - } - }, - "PaymentData": { - "PaymentType": "' . $this->_txType . '" - } - } - } - } - '; - return $result; - } } diff --git a/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php b/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php index a22d05448..063572360 100644 --- a/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php +++ b/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php @@ -18,10 +18,9 @@ class TerminalCloudAPI extends \Adyen\Service\AbstractResource public function __construct($service, $asynchronous) { - if ($asynchronous) - { + if ($asynchronous) { $this->_endpoint = $service->getClient()->getConfig()->get('endpointTerminalCloud') . '/async'; - }else { + } else { $this->_endpoint = $service->getClient()->getConfig()->get('endpointTerminalCloud') . '/sync'; } parent::__construct($service, $this->_endpoint, $this->_requiredFields); diff --git a/src/Adyen/Util/Util.php b/src/Adyen/Util/Util.php index 73508ff79..1f65115ff 100644 --- a/src/Adyen/Util/Util.php +++ b/src/Adyen/Util/Util.php @@ -31,4 +31,121 @@ public static function calculateSha256Signature($hmacKey, $params) $merchantSig = base64_encode(hash_hmac('sha256', $signData, pack("H*", $hmacKey), true)); return $merchantSig; } + + public static function buildPosPaymentRequest( + $POIID, + $amountValue, + $amountCurrency, + $merchantReference, + $transactionType + ) { + //Set specific dynamic parameters + $serviceID = date("dHis"); + $timeStamper = date("Y-m-d") . "T" . date("H:i:s+00:00"); + + //check for existing '.' + $_amountValue = self::fromMinorUnits($amountValue, $amountCurrency); + + //Convert requested type + switch ($transactionType) { + case "GOODS_SERVICES": + $txType = 'Normal'; + break; + case "REFUND": + $txType = 'Refund'; + break; + default: + $txType = $transactionType; + } + + //Provide json as result + $result = '{ + "SaleToPOIRequest": { + "MessageHeader": { + "MessageType": "Request", + "MessageClass": "Service", + "MessageCategory": "Payment", + "SaleID": "MagentoCloudEMV", + "POIID": "' . $POIID . '", + "ProtocolVersion": "3.0", + "ServiceID": "' . $serviceID . '" + }, + "PaymentRequest": { + "SaleData": { + "SaleTransactionID": { + "TransactionID": "' . $merchantReference . '", + "TimeStamp": "' . $timeStamper . '" + }, + "TokenRequestedType": "Customer", + "SaleReferenceID": "SalesRefABC" + }, + "PaymentTransaction": { + "AmountsReq": { + "Currency": "' . $amountCurrency . '", + "RequestedAmount": ' . $_amountValue . ' + } + }, + "PaymentData": { + "PaymentType": "' . $txType . '" + } + } + } + } + '; + return $result; + } + + public static function getDecimalDigits($currency) + { + switch ($currency) { + case "JPY": + case "IDR": + case "KRW": + case "BYR": + case "VND": + case "CVE": + case "DJF": + case "GNF": + case "PYG": + case "RWF": + case "UGX": + case "VUV": + case "XAF": + case "XOF": + case "XPF": + case "GHC": + case "KMF": + $format = 0; + break; + case "MRO": + $format = 1; + break; + case "BHD": + case "JOD": + case "KWD": + case "OMR": + case "LYD": + case "TND": + $format = 3; + break; + default: + $format = 2; + break; + } + return $format; + } + + public static function toMinorUnits($amount, $currency) + { + $format = self::getDecimalDigits($currency); + + return (int)number_format($amount, $format, '', ''); + } + + public static function fromMinorUnits($amount, $currency) + { + $format = self::getDecimalDigits($currency); + + return number_format($amount / pow(10, $format), $format, '.', ''); + } } \ No newline at end of file diff --git a/tests/PosPaymentTest.php b/tests/PosPaymentTest.php index 3f81aa9f1..0354a13de 100644 --- a/tests/PosPaymentTest.php +++ b/tests/PosPaymentTest.php @@ -2,6 +2,8 @@ namespace Adyen; +use Adyen\Util\Util; + class PosPaymentTest extends TestCase { @@ -9,14 +11,13 @@ public function testCreatePosPaymentSuccess() { // initialize client $client = $this->createTerminalCloudAPIClient(); - $logger = $client->getLogger(); // initialize service $service = new Service\PosPayment($client); //Construct request $transactionType = \Adyen\TransactionType::GOODS_SERVICES; - $json = $service->getPaymentRequest($this->getPOIID(), 1491, "EUR", "let's rock!", $transactionType); + $json = Util::buildPosPaymentRequest($this->getPOIID(), 1491, "BHD", "let's rock!", $transactionType); $params = json_decode($json, true); //Create associative array for passing along $serviceID = $service->getServiceId($params); @@ -26,27 +27,8 @@ public function testCreatePosPaymentSuccess() $this->validateApiPermission($e); } - // must exists $this->assertTrue(isset($result['SaleToPOIResponse'])); - - if (!(isset($result['SaleToPOIResponse']))) { - $logger->error("Received:", $result); - } - if (!(isset($result['SaleToPOIResponse']['PaymentResponse']['Response']['Result']))) { - $logger->error("Response: ", $result); - } else { - // Assert success for this test - //$this->assertEquals('Success', $result['SaleToPOIResponse']['PaymentResponse']['Response']['Result']); - //AdditionalResponse":"errors= - if (('Success' != $result['SaleToPOIResponse']['PaymentResponse']['Response']['Result'])) { - $tmp[0] = $result['SaleToPOIResponse']['PaymentResponse']['Response']['AdditionalResponse']; - $logger->error("Errors: ", $tmp); - $logger->error("What did we send to deserve this: ", $params); - } - } - - // return the result so this can be used in other test cases - return $result; + $this->assertEquals('Success', $result['SaleToPOIResponse']['PaymentResponse']['Response']['Result']); } @@ -54,14 +36,13 @@ public function testCreatePosPaymentDeclined() { // initialize client $client = $this->createTerminalCloudAPIClient(); - $logger = $client->getLogger(); // initialize service $service = new Service\PosPayment($client); //Construct request $transactionType = \Adyen\TransactionType::GOODS_SERVICES; - $json = $service->getPaymentRequest($this->getPOIID(), 149, "EUR", "let's decline dis!", $transactionType); + $json = Util::buildPosPaymentRequest($this->getPOIID(), 149, "EUR", "let's decline dis!", $transactionType); $params = json_decode($json, true); //Create associative array for passing along $serviceID = $service->getServiceId($params); @@ -71,29 +52,24 @@ public function testCreatePosPaymentDeclined() $this->validateApiPermission($e); } - // must exists & be Failure $this->assertTrue(isset($result['SaleToPOIResponse']['PaymentResponse']['Response']['Result'])); $this->assertEquals('Failure', $result['SaleToPOIResponse']['PaymentResponse']['Response']['Result']); - // return the result so this can be used in other test cases - return $result; - } public function testCreatePosEMVRefundSuccess() { // initialize client $client = $this->createTerminalCloudAPIClient(); - $logger = $client->getLogger(); // initialize service $service = new Service\PosPayment($client); //Construct request $transactionType = \Adyen\TransactionType::REFUND; - $json = $service->getPaymentRequest($this->getPOIID(), 1491, "EUR", "let's refund dis!", $transactionType); + $json = Util::buildPosPaymentRequest($this->getPOIID(), 1491, "EUR", "let's refund dis!", $transactionType); $params = json_decode($json, true); //Create associative array for passing along - $logger->error("What we sending: ",$params); + $serviceID = $service->getServiceId($params); try { @@ -102,24 +78,8 @@ public function testCreatePosEMVRefundSuccess() $this->validateApiPermission($e); } - // must exists $this->assertTrue(isset($result['SaleToPOIResponse'])); - - if (!(isset($result['SaleToPOIResponse']))) { - $logger->error("Received:", $result); - } - if (!(isset($result['SaleToPOIResponse']['PaymentResponse']['Response']['Result']))) { - $logger->error("Response: ", $result); - } else { - if (('Success' != $result['SaleToPOIResponse']['PaymentResponse']['Response']['Result'])) { - $tmp[0] = $result['SaleToPOIResponse']['PaymentResponse']['Response']['AdditionalResponse']; - $logger->error("Errors: ", $tmp); - $logger->error("What did we send to deserve this: ", $params); - } - } - - // return the result so this can be used in other test cases - return $result; + $this->assertEquals('Success', $result['SaleToPOIResponse']['PaymentResponse']['Response']['Result']); } diff --git a/tests/config/test.ini b/tests/config/test.ini index a6dead4fa..2c550e032 100644 --- a/tests/config/test.ini +++ b/tests/config/test.ini @@ -5,7 +5,7 @@ merchantAccount = YOUR MERCHANT ACCOUNT skinCode = YOUR SKIN CODE hmacSignature = YOUR HMAC SIGNATURE x-api-key = YOUR X-API KEY -POIID = UNIQUETERMINALID ([MODEL]-[SERIAL_NUMBER]) +POIID = UNIQUETERMINALID storePayoutUsername = YOUR STORE PAYOUT USERNAME storePayoutPassword = "YOUR STORE PAYOUT PASSWORD" From 320707247e5c6622bc8f7d5e98e11fde42e6aa82 Mon Sep 17 00:00:00 2001 From: Aleffio Date: Fri, 26 Jan 2018 13:16:46 +0100 Subject: [PATCH 05/31] PW-351: Exclude POS tests. --- phpunit.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/phpunit.xml b/phpunit.xml index a27aa3298..7d3cb3f58 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,6 +2,7 @@ tests + tests/PosPaymentTest.php From 79bb2a9835240067544c297aa5d2df1f5c43ddbc Mon Sep 17 00:00:00 2001 From: Aleffio Date: Fri, 26 Jan 2018 13:47:37 +0100 Subject: [PATCH 06/31] PW-351: Tests change to EUR --- tests/PosPaymentTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/PosPaymentTest.php b/tests/PosPaymentTest.php index 0354a13de..c53ea6891 100644 --- a/tests/PosPaymentTest.php +++ b/tests/PosPaymentTest.php @@ -17,7 +17,7 @@ public function testCreatePosPaymentSuccess() //Construct request $transactionType = \Adyen\TransactionType::GOODS_SERVICES; - $json = Util::buildPosPaymentRequest($this->getPOIID(), 1491, "BHD", "let's rock!", $transactionType); + $json = Util::buildPosPaymentRequest($this->getPOIID(), 1491, "EUR", "POSauth", $transactionType); $params = json_decode($json, true); //Create associative array for passing along $serviceID = $service->getServiceId($params); @@ -42,7 +42,7 @@ public function testCreatePosPaymentDeclined() //Construct request $transactionType = \Adyen\TransactionType::GOODS_SERVICES; - $json = Util::buildPosPaymentRequest($this->getPOIID(), 149, "EUR", "let's decline dis!", $transactionType); + $json = Util::buildPosPaymentRequest($this->getPOIID(), 149, "EUR", "POSdeclined", $transactionType); $params = json_decode($json, true); //Create associative array for passing along $serviceID = $service->getServiceId($params); @@ -67,7 +67,7 @@ public function testCreatePosEMVRefundSuccess() //Construct request $transactionType = \Adyen\TransactionType::REFUND; - $json = Util::buildPosPaymentRequest($this->getPOIID(), 1491, "EUR", "let's refund dis!", $transactionType); + $json = Util::buildPosPaymentRequest($this->getPOIID(), 1491, "EUR", "POSrefund", $transactionType); $params = json_decode($json, true); //Create associative array for passing along $serviceID = $service->getServiceId($params); From b1db46a9ebb890f1c32993a9d7a3f7c43d1ff244 Mon Sep 17 00:00:00 2001 From: Aleffio Date: Fri, 26 Jan 2018 15:16:47 +0100 Subject: [PATCH 07/31] PW-351: Provide original amount --- src/Adyen/Util/Util.php | 58 +--------------------------------------- tests/PosPaymentTest.php | 6 ++--- 2 files changed, 4 insertions(+), 60 deletions(-) diff --git a/src/Adyen/Util/Util.php b/src/Adyen/Util/Util.php index 1f65115ff..9f6195377 100644 --- a/src/Adyen/Util/Util.php +++ b/src/Adyen/Util/Util.php @@ -43,8 +43,6 @@ public static function buildPosPaymentRequest( $serviceID = date("dHis"); $timeStamper = date("Y-m-d") . "T" . date("H:i:s+00:00"); - //check for existing '.' - $_amountValue = self::fromMinorUnits($amountValue, $amountCurrency); //Convert requested type switch ($transactionType) { @@ -82,7 +80,7 @@ public static function buildPosPaymentRequest( "PaymentTransaction": { "AmountsReq": { "Currency": "' . $amountCurrency . '", - "RequestedAmount": ' . $_amountValue . ' + "RequestedAmount": ' . $amountValue . ' } }, "PaymentData": { @@ -94,58 +92,4 @@ public static function buildPosPaymentRequest( '; return $result; } - - public static function getDecimalDigits($currency) - { - switch ($currency) { - case "JPY": - case "IDR": - case "KRW": - case "BYR": - case "VND": - case "CVE": - case "DJF": - case "GNF": - case "PYG": - case "RWF": - case "UGX": - case "VUV": - case "XAF": - case "XOF": - case "XPF": - case "GHC": - case "KMF": - $format = 0; - break; - case "MRO": - $format = 1; - break; - case "BHD": - case "JOD": - case "KWD": - case "OMR": - case "LYD": - case "TND": - $format = 3; - break; - default: - $format = 2; - break; - } - return $format; - } - - public static function toMinorUnits($amount, $currency) - { - $format = self::getDecimalDigits($currency); - - return (int)number_format($amount, $format, '', ''); - } - - public static function fromMinorUnits($amount, $currency) - { - $format = self::getDecimalDigits($currency); - - return number_format($amount / pow(10, $format), $format, '.', ''); - } } \ No newline at end of file diff --git a/tests/PosPaymentTest.php b/tests/PosPaymentTest.php index c53ea6891..a218d6ffb 100644 --- a/tests/PosPaymentTest.php +++ b/tests/PosPaymentTest.php @@ -17,7 +17,7 @@ public function testCreatePosPaymentSuccess() //Construct request $transactionType = \Adyen\TransactionType::GOODS_SERVICES; - $json = Util::buildPosPaymentRequest($this->getPOIID(), 1491, "EUR", "POSauth", $transactionType); + $json = Util::buildPosPaymentRequest($this->getPOIID(), 14.91, "EUR", "POSauth", $transactionType); $params = json_decode($json, true); //Create associative array for passing along $serviceID = $service->getServiceId($params); @@ -42,7 +42,7 @@ public function testCreatePosPaymentDeclined() //Construct request $transactionType = \Adyen\TransactionType::GOODS_SERVICES; - $json = Util::buildPosPaymentRequest($this->getPOIID(), 149, "EUR", "POSdeclined", $transactionType); + $json = Util::buildPosPaymentRequest($this->getPOIID(), 1.49, "EUR", "POSdeclined", $transactionType); $params = json_decode($json, true); //Create associative array for passing along $serviceID = $service->getServiceId($params); @@ -67,7 +67,7 @@ public function testCreatePosEMVRefundSuccess() //Construct request $transactionType = \Adyen\TransactionType::REFUND; - $json = Util::buildPosPaymentRequest($this->getPOIID(), 1491, "EUR", "POSrefund", $transactionType); + $json = Util::buildPosPaymentRequest($this->getPOIID(), 14.91, "EUR", "POSrefund", $transactionType); $params = json_decode($json, true); //Create associative array for passing along $serviceID = $service->getServiceId($params); From b6c2b24a1906c740389d4a9e3b78fad73bb8660b Mon Sep 17 00:00:00 2001 From: Aleffio Date: Fri, 26 Jan 2018 16:31:51 +0100 Subject: [PATCH 08/31] PW-351: Changed isset to !empty. --- src/Adyen/Config.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Adyen/Config.php b/src/Adyen/Config.php index c96603d14..bf53fce46 100644 --- a/src/Adyen/Config.php +++ b/src/Adyen/Config.php @@ -61,12 +61,12 @@ public function getPassword() public function getXApiKey() { - return isset($this->data['x-api-key']) ? $this->data['x-api-key'] : null; + return !empty($this->data['x-api-key']) ? $this->data['x-api-key'] : null; } public function getPOIID() { - return isset($this->data['POIID']) ? $this->data['POIID'] : null; + return !empty($this->data['POIID']) ? $this->data['POIID'] : null; } public function getInputType() From 6d4caf5b58b61c13e9b2eab1f09a0581be2e02a5 Mon Sep 17 00:00:00 2001 From: Aleffio Date: Fri, 26 Jan 2018 17:20:36 +0100 Subject: [PATCH 09/31] PW-351: Refactoring. --- src/Adyen/Client.php | 4 ++-- src/Adyen/HttpClient/CurlClient.php | 22 +++++++++------------- src/Adyen/Util/Util.php | 8 ++++++++ tests/PosPaymentTest.php | 5 +++++ 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/Adyen/Client.php b/src/Adyen/Client.php index 4126b1607..e8a13321f 100644 --- a/src/Adyen/Client.php +++ b/src/Adyen/Client.php @@ -78,9 +78,9 @@ public function setPassword($password) * * @param $xapikey */ - public function setXApiKey($xapikey) + public function setXApiKey($xApiKey) { - $this->_config->set('x-api-key', $xapikey); + $this->_config->set('x-api-key', $xApiKey); } /** diff --git a/src/Adyen/HttpClient/CurlClient.php b/src/Adyen/HttpClient/CurlClient.php index e992bcfef..cd2a9246c 100644 --- a/src/Adyen/HttpClient/CurlClient.php +++ b/src/Adyen/HttpClient/CurlClient.php @@ -21,7 +21,7 @@ public function requestJson(\Adyen\Service $service, $requestUrl, $params) $logger = $client->getLogger(); $username = $config->getUsername(); $password = $config->getPassword(); - $xapikey = $config->getXApiKey(); + $xApiKey = $config->getXApiKey(); $jsonRequest = json_encode($params); @@ -40,24 +40,20 @@ public function requestJson(\Adyen\Service $service, $requestUrl, $params) //create a custom User-Agent $userAgent = $config->get('applicationName') . " " . \Adyen\Client::USER_AGENT_SUFFIX . $client->getLibraryVersion(); + //Set the content type to application/json and use the defined userAgent + $headers = array( + 'Content-Type: application/json', + 'User-Agent: ' . $userAgent + ); + // set authorisation credentials according to support & availability - if ($service->supportsXAPIKey() && $xapikey != "") { + if ($service->supportsXAPIKey() && !empty($xApiKey)) { //Set the content type to application/json and use the defined userAgent along with the x-api-key - $headers = array( - 'Content-Type: application/json', - 'User-Agent: ' . $userAgent, - 'x-api-key: ' . $xapikey - ); + $headers["x-api-key"] = $xApiKey; } else { //Set the basic auth credentials curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); - - //Set the content type to application/json and use the defined userAgent - $headers = array( - 'Content-Type: application/json', - 'User-Agent: ' . $userAgent - ); } //Set the headers diff --git a/src/Adyen/Util/Util.php b/src/Adyen/Util/Util.php index 9f6195377..6e3860d60 100644 --- a/src/Adyen/Util/Util.php +++ b/src/Adyen/Util/Util.php @@ -32,6 +32,14 @@ public static function calculateSha256Signature($hmacKey, $params) return $merchantSig; } + /** + * @param $POIID + * @param $amountValue + * @param $amountCurrency + * @param $merchantReference + * @param $transactionType + * @return string + */ public static function buildPosPaymentRequest( $POIID, $amountValue, diff --git a/tests/PosPaymentTest.php b/tests/PosPaymentTest.php index a218d6ffb..920471116 100644 --- a/tests/PosPaymentTest.php +++ b/tests/PosPaymentTest.php @@ -19,6 +19,8 @@ public function testCreatePosPaymentSuccess() $transactionType = \Adyen\TransactionType::GOODS_SERVICES; $json = Util::buildPosPaymentRequest($this->getPOIID(), 14.91, "EUR", "POSauth", $transactionType); $params = json_decode($json, true); //Create associative array for passing along + + // Needed for async calls $serviceID = $service->getServiceId($params); try { @@ -44,6 +46,8 @@ public function testCreatePosPaymentDeclined() $transactionType = \Adyen\TransactionType::GOODS_SERVICES; $json = Util::buildPosPaymentRequest($this->getPOIID(), 1.49, "EUR", "POSdeclined", $transactionType); $params = json_decode($json, true); //Create associative array for passing along + + // Needed for async calls $serviceID = $service->getServiceId($params); try { @@ -70,6 +74,7 @@ public function testCreatePosEMVRefundSuccess() $json = Util::buildPosPaymentRequest($this->getPOIID(), 14.91, "EUR", "POSrefund", $transactionType); $params = json_decode($json, true); //Create associative array for passing along + // Needed for async calls $serviceID = $service->getServiceId($params); try { From 140879e0dd5c2d94c3df593bd6e03205a50b84af Mon Sep 17 00:00:00 2001 From: Aleffio Date: Mon, 29 Jan 2018 11:30:17 +0100 Subject: [PATCH 10/31] PW-351: Fix Headers. --- src/Adyen/HttpClient/CurlClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adyen/HttpClient/CurlClient.php b/src/Adyen/HttpClient/CurlClient.php index cd2a9246c..627a4d601 100644 --- a/src/Adyen/HttpClient/CurlClient.php +++ b/src/Adyen/HttpClient/CurlClient.php @@ -49,7 +49,7 @@ public function requestJson(\Adyen\Service $service, $requestUrl, $params) // set authorisation credentials according to support & availability if ($service->supportsXAPIKey() && !empty($xApiKey)) { //Set the content type to application/json and use the defined userAgent along with the x-api-key - $headers["x-api-key"] = $xApiKey; + $headers[] = 'x-api-key: '. $xApiKey; } else { //Set the basic auth credentials curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); From 13dd569570c1f07a4328cb1ee0fcb4836f361bfc Mon Sep 17 00:00:00 2001 From: Aleffio Date: Fri, 2 Feb 2018 14:18:05 +0100 Subject: [PATCH 11/31] PW-351: Minor fixes --- phpunit.xml | 1 - src/Adyen/Config.php | 10 ++++++++++ src/Adyen/HttpClient/CurlClient.php | 6 +++++- src/Adyen/Service/PosPayment.php | 3 +-- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 7d3cb3f58..a27aa3298 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,7 +2,6 @@ tests - tests/PosPaymentTest.php diff --git a/src/Adyen/Config.php b/src/Adyen/Config.php index bf53fce46..d69c6ec9f 100644 --- a/src/Adyen/Config.php +++ b/src/Adyen/Config.php @@ -59,11 +59,21 @@ public function getPassword() return isset($this->data['password']) ? $this->data['password'] : null; } + /** + * Get the Checkout API Key from the Adyen Customer Area + * + * @return mixed|null + */ public function getXApiKey() { return !empty($this->data['x-api-key']) ? $this->data['x-api-key'] : null; } + /** + * Get the Point of Interest Terminal ID, used for POS Transactions with Terminal API + * + * @return mixed|null + */ public function getPOIID() { return !empty($this->data['POIID']) ? $this->data['POIID'] : null; diff --git a/src/Adyen/HttpClient/CurlClient.php b/src/Adyen/HttpClient/CurlClient.php index 627a4d601..f27eb021d 100644 --- a/src/Adyen/HttpClient/CurlClient.php +++ b/src/Adyen/HttpClient/CurlClient.php @@ -49,8 +49,12 @@ public function requestJson(\Adyen\Service $service, $requestUrl, $params) // set authorisation credentials according to support & availability if ($service->supportsXAPIKey() && !empty($xApiKey)) { //Set the content type to application/json and use the defined userAgent along with the x-api-key - $headers[] = 'x-api-key: '. $xApiKey; + $headers[] = 'x-api-key: ' . $xApiKey; + } elseif ($service->supportsXAPIKey() && empty($xApiKey)) { + $msg = "Please insert a valid Checkout API Key in your test.ini file"; + throw new \Adyen\AdyenException($msg); } else { + //Set the basic auth credentials curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); diff --git a/src/Adyen/Service/PosPayment.php b/src/Adyen/Service/PosPayment.php index 8fb07515d..de43b3241 100644 --- a/src/Adyen/Service/PosPayment.php +++ b/src/Adyen/Service/PosPayment.php @@ -7,7 +7,6 @@ class PosPayment extends \Adyen\Service protected $_runTenderSync; protected $_runTenderAsync; - protected $_supportsXAPIKey = true; protected $_txType; public function __construct(\Adyen\Client $client) @@ -16,7 +15,7 @@ public function __construct(\Adyen\Client $client) $this->_runTenderSync = new \Adyen\Service\ResourceModel\Payment\TerminalCloudAPI($this, false); $this->_runTenderAsync = new \Adyen\Service\ResourceModel\Payment\TerminalCloudAPI($this, true); - + $this->_supportsXAPIKey = true; } public function runTenderSync($params) From 83a0c21889ea1ce2719256ec7771d459e7d0b8e6 Mon Sep 17 00:00:00 2001 From: Aleffio Date: Fri, 2 Feb 2018 15:00:25 +0100 Subject: [PATCH 12/31] PW-351: Fixed POS tests if apikey or poiid not provided. --- tests/TestCase.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 120715a3f..936328610 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -137,15 +137,16 @@ protected function createTerminalCloudAPIClient() // load settings from .ini file $settings = $this->_loadConfigIni(); - if(isset($settings['x-api-key']) && isset($settings['POIID'])){ + if(!isset($settings['x-api-key']) || !isset($settings['POIID']) || $settings['x-api-key'] == 'YOUR X-API KEY' || $settings['POIID'] == 'UNIQUETERMINALID'){ + $this->_skipTest("Skipped the test. Configure your x-api-key and POIID in the config"); + }else{ + $client = new \Adyen\Client(); $client->setApplicationName("My Test Terminal API App"); $client->setEnvironment(\Adyen\Environment::TEST); $client->setXApiKey($settings['x-api-key']); return $client; - }else{ - $this->_skipTest("Skipped the test. Configure your x-api-key and POIID in the config"); } } From d12f6a142aaf679905ceb9f84f7f3e984edf08e4 Mon Sep 17 00:00:00 2001 From: George Georgiou Date: Fri, 9 Feb 2018 15:23:44 +0200 Subject: [PATCH 13/31] Add adjustAuthorisation to modification models --- src/Adyen/Service/Modification.php | 8 +++ .../Modification/AdjustAuthorisation.php | 22 +++++++ tests/ModificationTest.php | 63 ++++++++++++++++++- 3 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 src/Adyen/Service/ResourceModel/Modification/AdjustAuthorisation.php diff --git a/src/Adyen/Service/Modification.php b/src/Adyen/Service/Modification.php index c3260053b..f63696e17 100644 --- a/src/Adyen/Service/Modification.php +++ b/src/Adyen/Service/Modification.php @@ -9,6 +9,7 @@ class Modification extends \Adyen\Service protected $_cancelOrRefund; protected $_capture; protected $_refund; + protected $_adjustAthorisation; public function __construct(\Adyen\Client $client) { @@ -18,6 +19,7 @@ public function __construct(\Adyen\Client $client) $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); + $this->_adjustAthorisation = new \Adyen\Service\ResourceModel\Modification\AdjustAuthorisation($this); } public function cancel($params) @@ -44,4 +46,10 @@ public function refund($params) return $result; } + public function adjustAuthorisation($params) + { + $result = $this->_adjustAthorisation->request($params); + return $result; + } + } \ No newline at end of file diff --git a/src/Adyen/Service/ResourceModel/Modification/AdjustAuthorisation.php b/src/Adyen/Service/ResourceModel/Modification/AdjustAuthorisation.php new file mode 100644 index 000000000..a294bef90 --- /dev/null +++ b/src/Adyen/Service/ResourceModel/Modification/AdjustAuthorisation.php @@ -0,0 +1,22 @@ +_endpoint = $service->getClient()->getConfig()->get('endpoint').'/pal/servlet/Payment/'.$service->getClient()->getApiVersion().'/adjustAuthorisation'; + parent::__construct($service, $this->_endpoint, $this->_requiredFields); + } + +} \ No newline at end of file diff --git a/tests/ModificationTest.php b/tests/ModificationTest.php index fa5b54bd7..3e3e55356 100644 --- a/tests/ModificationTest.php +++ b/tests/ModificationTest.php @@ -15,7 +15,7 @@ class ModificationTest extends TestCase public function testCancelModification() { // create a payment - require_once __DIR__ . '/CreatePaymentRequestTest.php'; + require_once __DIR__.'/CreatePaymentRequestTest.php'; $test = new CreatePaymentRequestTest(); $result = $test->testCreatePaymentSuccess(); @@ -36,7 +36,7 @@ public function testCancelModification() public function testRefundModification() { // create a payment - require_once __DIR__ . '/CreatePaymentRequestTest.php'; + require_once __DIR__.'/CreatePaymentRequestTest.php'; $test = new CreatePaymentRequestTest(); $result = $test->testCreatePaymentSuccess(); @@ -53,7 +53,7 @@ public function testRefundModification() $params = array( "merchantAccount" => $this->_merchantAccount, "modificationAmount" => $modificationAmount, - "reference" => $pspReference . '_refund', + "reference" => $pspReference.'_refund', "originalReference" => $pspReference ); @@ -64,4 +64,61 @@ public function testRefundModification() } + public function testAdjustDecreaseModification() + { + // create a payment + require_once __DIR__.'/CreatePaymentRequestTest.php'; + $test = new CreatePaymentRequestTest(); + $result = $test->testCreatePaymentSuccess(); + + $pspReference = $result['pspReference']; + + // create modification + $client = $this->createClient(); + + // initialize service + $service = new Service\Modification($client); + + $params = [ + "merchantAccount" => $this->_merchantAccount, + "modificationAmount" => ['currency' => 'EUR', 'value' => '750'], + "reference" => $pspReference.'_adjustAuthorisation', + "originalReference" => $pspReference + ]; + + $result = $service->adjustAuthorisation($params); + + $this->assertEquals('[adjustAuthorisation-received]', $result['response']); + + } + + public function testAdjustIncreaseModification() + { + // create a payment + require_once __DIR__.'/CreatePaymentRequestTest.php'; + $test = new CreatePaymentRequestTest(); + $result = $test->testCreatePaymentSuccess(); + + $pspReference = $result['pspReference']; + + // create modification + $client = $this->createClient(); + + // initialize service + $service = new Service\Modification($client); + + $params = [ + "merchantAccount" => $this->_merchantAccount, + "modificationAmount" => ['currency' => 'EUR', 'value' => '1600'], + "reference" => $pspReference.'_adjustAuthorisation', + "originalReference" => $pspReference + ]; + + $result = $service->adjustAuthorisation($params); + + $this->assertEquals('[adjustAuthorisation-received]', $result['response']); + + } + + } From e4031da192ebea7a08f111efbc420f71b9186676 Mon Sep 17 00:00:00 2001 From: George Georgiou Date: Fri, 9 Feb 2018 15:38:09 +0200 Subject: [PATCH 14/31] Fix php5.3 compatibility in tests --- tests/ModificationTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/ModificationTest.php b/tests/ModificationTest.php index 3e3e55356..bd4fe0c53 100644 --- a/tests/ModificationTest.php +++ b/tests/ModificationTest.php @@ -79,12 +79,12 @@ public function testAdjustDecreaseModification() // initialize service $service = new Service\Modification($client); - $params = [ + $params = array( "merchantAccount" => $this->_merchantAccount, - "modificationAmount" => ['currency' => 'EUR', 'value' => '750'], + "modificationAmount" => array('currency' => 'EUR', 'value' => '750'), "reference" => $pspReference.'_adjustAuthorisation', "originalReference" => $pspReference - ]; + ); $result = $service->adjustAuthorisation($params); @@ -107,12 +107,12 @@ public function testAdjustIncreaseModification() // initialize service $service = new Service\Modification($client); - $params = [ + $params = array( "merchantAccount" => $this->_merchantAccount, - "modificationAmount" => ['currency' => 'EUR', 'value' => '1600'], + "modificationAmount" => array('currency' => 'EUR', 'value' => '1600'), "reference" => $pspReference.'_adjustAuthorisation', "originalReference" => $pspReference - ]; + ); $result = $service->adjustAuthorisation($params); From 2965e626e98ad88559f2ab5418718b89a5ea9980 Mon Sep 17 00:00:00 2001 From: George Georgiou Date: Wed, 21 Feb 2018 15:33:32 +0200 Subject: [PATCH 15/31] Fix typo --- src/Adyen/Service/Modification.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Adyen/Service/Modification.php b/src/Adyen/Service/Modification.php index f63696e17..edb0cb543 100644 --- a/src/Adyen/Service/Modification.php +++ b/src/Adyen/Service/Modification.php @@ -9,7 +9,7 @@ class Modification extends \Adyen\Service protected $_cancelOrRefund; protected $_capture; protected $_refund; - protected $_adjustAthorisation; + protected $_adjustAuthorisation; public function __construct(\Adyen\Client $client) { @@ -19,7 +19,7 @@ public function __construct(\Adyen\Client $client) $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); - $this->_adjustAthorisation = new \Adyen\Service\ResourceModel\Modification\AdjustAuthorisation($this); + $this->_adjustAuthorisation = new \Adyen\Service\ResourceModel\Modification\AdjustAuthorisation($this); } public function cancel($params) @@ -48,8 +48,7 @@ public function refund($params) public function adjustAuthorisation($params) { - $result = $this->_adjustAthorisation->request($params); + $result = $this->_adjustAuthorisation->request($params); return $result; } - } \ No newline at end of file From e7ca4a5ae5d79ecc7fb59335f381f320d1bbe24f Mon Sep 17 00:00:00 2001 From: Rik ter Beek Date: Wed, 18 Apr 2018 08:53:22 +0200 Subject: [PATCH 16/31] Update LICENSE --- LICENSE | 223 ++++++-------------------------------------------------- 1 file changed, 21 insertions(+), 202 deletions(-) diff --git a/LICENSE b/LICENSE index 8f71f43fe..60eef4615 100644 --- a/LICENSE +++ b/LICENSE @@ -1,202 +1,21 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - +MIT License + +Copyright (c) 2017 Adyen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 30b26da1ffab10c319545ea6ca4c0f41809618da Mon Sep 17 00:00:00 2001 From: Aleffio Date: Mon, 30 Apr 2018 11:17:10 +0200 Subject: [PATCH 17/31] PW-421: minor fixes for terminalCloudApi after review --- .../Payment/TerminalCloudAPI.php | 2 + src/Adyen/TransactionType.php | 2 +- src/Adyen/Util/Util.php | 69 ---------- tests/PosPaymentTest.php | 128 ++++++++++++++++-- tests/TestCase.php | 2 - 5 files changed, 117 insertions(+), 86 deletions(-) diff --git a/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php b/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php index 063572360..0ee1fc9d9 100644 --- a/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php +++ b/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php @@ -8,9 +8,11 @@ class TerminalCloudAPI extends \Adyen\Service\AbstractResource protected $_requiredFields = array( 'SaleToPOIRequest.MessageHeader.POIID', 'SaleToPOIRequest.MessageHeader.ServiceID', + //TODO fix: actually works with only first two levels 'SaleToPOIRequest.PaymentRequest.SaleData.SaleTransactionID.TransactionID', //reference 'SaleToPOIRequest.PaymentRequest.PaymentTransaction.AmountsReq.Currency', 'SaleToPOIRequest.PaymentRequest.PaymentTransaction.AmountsReq.RequestedAmount', + //PaymentData is optional, if not provided it will perform an authorisation(no refunds) 'SaleToPOIRequest.PaymentRequest.PaymentData.PaymentType', ); diff --git a/src/Adyen/TransactionType.php b/src/Adyen/TransactionType.php index 19a2239cd..abd8e1a74 100644 --- a/src/Adyen/TransactionType.php +++ b/src/Adyen/TransactionType.php @@ -6,7 +6,7 @@ class TransactionType { - const GOODS_SERVICES = 'Normal'; + const NORMAL = 'Normal'; const REFUND = 'Refund'; } \ No newline at end of file diff --git a/src/Adyen/Util/Util.php b/src/Adyen/Util/Util.php index 6e3860d60..73508ff79 100644 --- a/src/Adyen/Util/Util.php +++ b/src/Adyen/Util/Util.php @@ -31,73 +31,4 @@ public static function calculateSha256Signature($hmacKey, $params) $merchantSig = base64_encode(hash_hmac('sha256', $signData, pack("H*", $hmacKey), true)); return $merchantSig; } - - /** - * @param $POIID - * @param $amountValue - * @param $amountCurrency - * @param $merchantReference - * @param $transactionType - * @return string - */ - public static function buildPosPaymentRequest( - $POIID, - $amountValue, - $amountCurrency, - $merchantReference, - $transactionType - ) { - //Set specific dynamic parameters - $serviceID = date("dHis"); - $timeStamper = date("Y-m-d") . "T" . date("H:i:s+00:00"); - - - //Convert requested type - switch ($transactionType) { - case "GOODS_SERVICES": - $txType = 'Normal'; - break; - case "REFUND": - $txType = 'Refund'; - break; - default: - $txType = $transactionType; - } - - //Provide json as result - $result = '{ - "SaleToPOIRequest": { - "MessageHeader": { - "MessageType": "Request", - "MessageClass": "Service", - "MessageCategory": "Payment", - "SaleID": "MagentoCloudEMV", - "POIID": "' . $POIID . '", - "ProtocolVersion": "3.0", - "ServiceID": "' . $serviceID . '" - }, - "PaymentRequest": { - "SaleData": { - "SaleTransactionID": { - "TransactionID": "' . $merchantReference . '", - "TimeStamp": "' . $timeStamper . '" - }, - "TokenRequestedType": "Customer", - "SaleReferenceID": "SalesRefABC" - }, - "PaymentTransaction": { - "AmountsReq": { - "Currency": "' . $amountCurrency . '", - "RequestedAmount": ' . $amountValue . ' - } - }, - "PaymentData": { - "PaymentType": "' . $txType . '" - } - } - } - } - '; - return $result; - } } \ No newline at end of file diff --git a/tests/PosPaymentTest.php b/tests/PosPaymentTest.php index 920471116..c241d90e7 100644 --- a/tests/PosPaymentTest.php +++ b/tests/PosPaymentTest.php @@ -16,12 +16,45 @@ public function testCreatePosPaymentSuccess() $service = new Service\PosPayment($client); //Construct request - $transactionType = \Adyen\TransactionType::GOODS_SERVICES; - $json = Util::buildPosPaymentRequest($this->getPOIID(), 14.91, "EUR", "POSauth", $transactionType); - $params = json_decode($json, true); //Create associative array for passing along + $transactionType = \Adyen\TransactionType::NORMAL; + $serviceID = date("dHis"); + $timeStamper = date("Y-m-d") . "T" . date("H:i:s+00:00"); + + $json = '{ + "SaleToPOIRequest": { + "MessageHeader": { + "MessageType": "Request", + "MessageClass": "Service", + "MessageCategory": "Payment", + "SaleID": "PosTestLibrary", + "POIID": "' . $this->getPOIID() . '", + "ProtocolVersion": "3.0", + "ServiceID": "' . $serviceID . '" + }, + "PaymentRequest": { + "SaleData": { + "SaleTransactionID": { + "TransactionID": "POSauth", + "TimeStamp": "' . $timeStamper . '" + }, + "TokenRequestedType": "Customer", + "SaleReferenceID": "SalesRefABC" + }, + "PaymentTransaction": { + "AmountsReq": { + "Currency": "EUR", + "RequestedAmount": ' . 14.91 . ' + } + }, + "PaymentData": { + "PaymentType": "' . $transactionType . '" + } + } + } + } + '; - // Needed for async calls - $serviceID = $service->getServiceId($params); + $params = json_decode($json, true); //Create associative array for passing along try { $result = $service->runTenderSync($params); @@ -29,6 +62,7 @@ public function testCreatePosPaymentSuccess() $this->validateApiPermission($e); } + print $result; $this->assertTrue(isset($result['SaleToPOIResponse'])); $this->assertEquals('Success', $result['SaleToPOIResponse']['PaymentResponse']['Response']['Result']); @@ -43,12 +77,45 @@ public function testCreatePosPaymentDeclined() $service = new Service\PosPayment($client); //Construct request - $transactionType = \Adyen\TransactionType::GOODS_SERVICES; - $json = Util::buildPosPaymentRequest($this->getPOIID(), 1.49, "EUR", "POSdeclined", $transactionType); - $params = json_decode($json, true); //Create associative array for passing along + $transactionType = \Adyen\TransactionType::NORMAL; + $serviceID = date("dHis"); + $timeStamper = date("Y-m-d") . "T" . date("H:i:s+00:00"); + + $json = '{ + "SaleToPOIRequest": { + "MessageHeader": { + "MessageType": "Request", + "MessageClass": "Service", + "MessageCategory": "Payment", + "SaleID": "PosTestLibrary", + "POIID": "' . $this->getPOIID() . '", + "ProtocolVersion": "3.0", + "ServiceID": "' . $serviceID . '" + }, + "PaymentRequest": { + "SaleData": { + "SaleTransactionID": { + "TransactionID": "POSdeclined", + "TimeStamp": "' . $timeStamper . '" + }, + "TokenRequestedType": "Customer", + "SaleReferenceID": "SalesRefABC" + }, + "PaymentTransaction": { + "AmountsReq": { + "Currency": "EUR", + "RequestedAmount": ' . 1.49 . ' + } + }, + "PaymentData": { + "PaymentType": "' . $transactionType . '" + } + } + } + } + '; - // Needed for async calls - $serviceID = $service->getServiceId($params); + $params = json_decode($json, true); //Create associative array for passing along try { $result = $service->runTenderSync($params); @@ -71,11 +138,44 @@ public function testCreatePosEMVRefundSuccess() //Construct request $transactionType = \Adyen\TransactionType::REFUND; - $json = Util::buildPosPaymentRequest($this->getPOIID(), 14.91, "EUR", "POSrefund", $transactionType); - $params = json_decode($json, true); //Create associative array for passing along + $serviceID = date("dHis"); + $timeStamper = date("Y-m-d") . "T" . date("H:i:s+00:00"); + + $json = '{ + "SaleToPOIRequest": { + "MessageHeader": { + "MessageType": "Request", + "MessageClass": "Service", + "MessageCategory": "Payment", + "SaleID": "PosTestLibrary", + "POIID": "' . $this->getPOIID() . '", + "ProtocolVersion": "3.0", + "ServiceID": "' . $serviceID . '" + }, + "PaymentRequest": { + "SaleData": { + "SaleTransactionID": { + "TransactionID": "POSrefund", + "TimeStamp": "' . $timeStamper . '" + }, + "TokenRequestedType": "Customer", + "SaleReferenceID": "SalesRefABC" + }, + "PaymentTransaction": { + "AmountsReq": { + "Currency": "EUR", + "RequestedAmount": ' . 14.91 . ' + } + }, + "PaymentData": { + "PaymentType": "' . $transactionType . '" + } + } + } + } + '; - // Needed for async calls - $serviceID = $service->getServiceId($params); + $params = json_decode($json, true); //Create associative array for passing along try { $result = $service->runTenderSync($params); diff --git a/tests/TestCase.php b/tests/TestCase.php index 936328610..ccfc194d6 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -12,8 +12,6 @@ class TestCase extends \PHPUnit_Framework_TestCase public function __construct() { - date_default_timezone_set('Europe/Amsterdam'); - $this->_merchantAccount = $this->getMerchantAccount(); $this->_skinCode = $this->getSkinCode(); $this->_hmacSignature = $this->getHmacSignature(); From 343733120455a3f872d932b1c6f0ac0d4f4e7974 Mon Sep 17 00:00:00 2001 From: Aleffio Date: Mon, 30 Apr 2018 11:53:29 +0200 Subject: [PATCH 18/31] PW-421: removed print statement --- tests/PosPaymentTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/PosPaymentTest.php b/tests/PosPaymentTest.php index c241d90e7..568b3993b 100644 --- a/tests/PosPaymentTest.php +++ b/tests/PosPaymentTest.php @@ -62,7 +62,6 @@ public function testCreatePosPaymentSuccess() $this->validateApiPermission($e); } - print $result; $this->assertTrue(isset($result['SaleToPOIResponse'])); $this->assertEquals('Success', $result['SaleToPOIResponse']['PaymentResponse']['Response']['Result']); From 444e645490538619e815deff07e30666a31e3383 Mon Sep 17 00:00:00 2001 From: Alessio Zampatti Date: Mon, 14 May 2018 11:26:42 +0200 Subject: [PATCH 19/31] PW-421: Adding Checkout and Checkout Utility support * PW-421: Adding Checkout and Checkout Utility support, modified CurlClient to make it testable * PW-241: fixed failing test * PW-421: removed comment * PW-421: include Checkout unit tests, simplified CheckoutUtility endpoint * PW-421: Added ApiKeyAuthenticatedService and renamed supportsXAPIKey to requiresApiKey * PW-421: removed phpstorm comment * PW-421: fix for Travis * PW-421: fix for PHP <= 5.4 * PW-421: Readded previous tests, changed Checkout API key message if not provided, added fail() call to the failureTests * PW-421: Removed redundant line in xml * PW-421: Simplified ApiKeyAuthenticatedService structure --- src/Adyen/ApiKeyAuthenticatedService.php | 9 + src/Adyen/Client.php | 62 +++- src/Adyen/HttpClient/CurlClient.php | 17 +- src/Adyen/Service.php | 8 +- src/Adyen/Service/Checkout.php | 57 ++++ src/Adyen/Service/CheckoutUtility.php | 24 ++ src/Adyen/Service/PosPayment.php | 3 +- .../ResourceModel/Checkout/PaymentMethods.php | 20 ++ .../ResourceModel/Checkout/Payments.php | 25 ++ .../Checkout/PaymentsDetails.php | 21 ++ .../Service/ResourceModel/Checkout/Setup.php | 23 ++ .../Service/ResourceModel/Checkout/Verify.php | 20 ++ .../CheckoutUtility/OriginKeys.php | 20 ++ tests/ExceptionTest.php | 2 +- tests/MockTest/CheckoutTest.php | 282 +++++++++++++++ tests/MockTest/CheckoutUtilityTest.php | 43 +++ tests/MockTest/TestCaseMock.php | 27 ++ .../Checkout/invalid-merchant-account.json | 6 + .../Checkout/payment-methods-forbidden.json | 7 + .../Checkout/payment-methods-success.json | 278 +++++++++++++++ .../Checkout/payments-details-success.json | 8 + .../Checkout/payments-forbidden.json | 7 + .../Checkout/payments-success-3D.json | 20 ++ .../Resources/Checkout/payments-success.json | 91 +++++ tests/Resources/Checkout/setup-success.json | 323 ++++++++++++++++++ .../Checkout/verify-invalid-payload.json | 6 + tests/Resources/Checkout/verify-success.json | 4 + .../CheckoutUtility/origin-keys-success.json | 7 + tests/bootstrap.php | 3 +- 29 files changed, 1391 insertions(+), 32 deletions(-) create mode 100644 src/Adyen/ApiKeyAuthenticatedService.php create mode 100644 src/Adyen/Service/Checkout.php create mode 100644 src/Adyen/Service/CheckoutUtility.php create mode 100644 src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php create mode 100644 src/Adyen/Service/ResourceModel/Checkout/Payments.php create mode 100644 src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php create mode 100644 src/Adyen/Service/ResourceModel/Checkout/Setup.php create mode 100644 src/Adyen/Service/ResourceModel/Checkout/Verify.php create mode 100644 src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php create mode 100644 tests/MockTest/CheckoutTest.php create mode 100644 tests/MockTest/CheckoutUtilityTest.php create mode 100644 tests/MockTest/TestCaseMock.php create mode 100644 tests/Resources/Checkout/invalid-merchant-account.json create mode 100644 tests/Resources/Checkout/payment-methods-forbidden.json create mode 100644 tests/Resources/Checkout/payment-methods-success.json create mode 100644 tests/Resources/Checkout/payments-details-success.json create mode 100644 tests/Resources/Checkout/payments-forbidden.json create mode 100644 tests/Resources/Checkout/payments-success-3D.json create mode 100644 tests/Resources/Checkout/payments-success.json create mode 100644 tests/Resources/Checkout/setup-success.json create mode 100644 tests/Resources/Checkout/verify-invalid-payload.json create mode 100644 tests/Resources/Checkout/verify-success.json create mode 100644 tests/Resources/CheckoutUtility/origin-keys-success.json diff --git a/src/Adyen/ApiKeyAuthenticatedService.php b/src/Adyen/ApiKeyAuthenticatedService.php new file mode 100644 index 000000000..adc0bcaaf --- /dev/null +++ b/src/Adyen/ApiKeyAuthenticatedService.php @@ -0,0 +1,9 @@ +_config = new \Adyen\Config(); - }elseif ($config instanceof \Adyen\ConfigInterface) { + } 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"); @@ -91,19 +95,21 @@ public function setXApiKey($xApiKey) */ public function setEnvironment($environment) { - if($environment == \Adyen\Environment::TEST) { + if ($environment == \Adyen\Environment::TEST) { $this->_config->set('environment', \Adyen\Environment::TEST); $this->_config->set('endpoint', self::ENDPOINT_TEST); - $this->_config->set('endpointDirectorylookup', self::ENPOINT_TEST_DIRECTORY_LOOKUP); + $this->_config->set('endpointDirectorylookup', self::ENDPOINT_TEST_DIRECTORY_LOOKUP); $this->_config->set('endpointTerminalCloud', self::TERMINAL_CLOUD_TEST); - } elseif($environment == \Adyen\Environment::LIVE) { + $this->_config->set('endpointCheckout', self::ENDPOINT_CHECKOUT_TEST); + } elseif ($environment == \Adyen\Environment::LIVE) { $this->_config->set('environment', \Adyen\Environment::LIVE); $this->_config->set('endpoint', self::ENDPOINT_LIVE); - $this->_config->set('endpointDirectorylookup', self::ENPOINT_LIVE_DIRECTORY_LOOKUP); + $this->_config->set('endpointDirectorylookup', self::ENDPOINT_LIVE_DIRECTORY_LOOKUP); $this->_config->set('endpointTerminalCloud', self::TERMINAL_CLOUD_LIVE); + $this->_config->set('endpointCheckout', self::ENDPOINT_CHECKOUT_LIVE); } else { - // environment does not exists - $msg = "This environment does not exists use " . \Adyen\Environment::TEST . ' or ' . \Adyen\Environment::LIVE; + // environment does not exist + $msg = "This environment does not exist, use " . \Adyen\Environment::TEST . ' or ' . \Adyen\Environment::LIVE; throw new \Adyen\AdyenException($msg); } } @@ -133,7 +139,8 @@ public function setMerchantAccount($merchantAccount) $this->_config->set('merchantAccount', $merchantAccount); } - public function setApplicationName($applicationName) { + public function setApplicationName($applicationName) + { $this->_config->set('applicationName', $applicationName); } @@ -188,6 +195,25 @@ public function getApiRecurringVersion() return self::API_RECURRING_VERSION; } + /** + * Get the version of the Checkout API endpoint + * + * @return string + */ + public function getApiCheckoutVersion() + { + return self::API_CHECKOUT_VERSION; + } + + /** + * Get the version of the Checkout Utility API endpoint + * + * @return string + */ + public function getApiCheckoutUtilityVersion() + { + return self::API_CHECKOUT_UTILITY_VERSION; + } /** * @param HttpClient\ClientInterface $httpClient diff --git a/src/Adyen/HttpClient/CurlClient.php b/src/Adyen/HttpClient/CurlClient.php index 17c5bcb19..ffcd86818 100644 --- a/src/Adyen/HttpClient/CurlClient.php +++ b/src/Adyen/HttpClient/CurlClient.php @@ -47,11 +47,11 @@ public function requestJson(\Adyen\Service $service, $requestUrl, $params) ); // set authorisation credentials according to support & availability - if ($service->supportsXAPIKey() && !empty($xApiKey)) { + if ($service->requiresApiKey() && !empty($xApiKey)) { //Set the content type to application/json and use the defined userAgent along with the x-api-key $headers[] = 'x-api-key: ' . $xApiKey; - } elseif ($service->supportsXAPIKey() && empty($xApiKey)) { - $msg = "Please insert a valid Checkout API Key in your test.ini file"; + } elseif ($service->requiresApiKey() && empty($xApiKey)) { + $msg = "Please provide a valid Checkout API Key"; throw new \Adyen\AdyenException($msg); } else { @@ -67,8 +67,7 @@ public function requestJson(\Adyen\Service $service, $requestUrl, $params) curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Execute the request - $result = curl_exec($ch); - $httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE); + list($result, $httpStatus) = $this->curlRequest($ch); // log the raw response $logger->info("JSON Response is: " . $result); @@ -231,7 +230,6 @@ protected function handleCurlError($url, $errno, $message, $logger) protected function handleResultError($result, $logger) { $decodeResult = json_decode($result, true); - if (isset($decodeResult['message']) && isset($decodeResult['errorCode'])) { $logger->error($decodeResult['errorCode'] . ': ' . $decodeResult['message']); throw new \Adyen\AdyenException($decodeResult['message'], $decodeResult['errorCode'], null, @@ -261,4 +259,11 @@ private function logRequest(\Psr\Log\LoggerInterface $logger, $requestUrl, $para } $logger->info('JSON Request to Adyen:' . json_encode($params)); } + + protected function curlRequest($ch) + { + $result = curl_exec($ch); + $httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE); + return array($result, $httpStatus); + } } diff --git a/src/Adyen/Service.php b/src/Adyen/Service.php index 06b4d50fe..ada85ecea 100644 --- a/src/Adyen/Service.php +++ b/src/Adyen/Service.php @@ -5,7 +5,7 @@ class Service { private $client; - protected $_supportsXAPIKey = false; + protected $_requiresApiKey = false; public function __construct(\Adyen\Client $client) { @@ -14,7 +14,7 @@ public function __construct(\Adyen\Client $client) // validate if client has all the configuration we need if(!$client->getConfig()->get('environment')) { // throw exception - $msg = "The Client does not have a corect environment. use " . \Adyen\Environment::TEST . ' or ' . \Adyen\Environment::LIVE; + $msg = "The Client does not have a correct environment, use " . \Adyen\Environment::TEST . ' or ' . \Adyen\Environment::LIVE; throw new \Adyen\AdyenException($msg); } @@ -26,9 +26,9 @@ public function getClient() return $this->client; } - public function supportsXAPIKey() + public function requiresApiKey() { - return $this->_supportsXAPIKey; + return $this->_requiresApiKey; } } \ No newline at end of file diff --git a/src/Adyen/Service/Checkout.php b/src/Adyen/Service/Checkout.php new file mode 100644 index 000000000..25edaf2bf --- /dev/null +++ b/src/Adyen/Service/Checkout.php @@ -0,0 +1,57 @@ +_setup = new \Adyen\Service\ResourceModel\Checkout\Setup($this); + $this->_verify = new \Adyen\Service\ResourceModel\Checkout\Verify($this); + $this->_paymentMethods = new \Adyen\Service\ResourceModel\Checkout\PaymentMethods($this); + $this->_payments = new \Adyen\Service\ResourceModel\Checkout\Payments($this); + $this->_paymentsDetails = new \Adyen\Service\ResourceModel\Checkout\PaymentsDetails($this); + + } + + public function setup($params) + { + $result = $this->_setup->request($params); + return $result; + } + + public function verify($params) + { + $result = $this->_verify->request($params); + return $result; + } + + public function paymentMethods($params) + { + $result = $this->_paymentMethods->request($params); + return $result; + } + + public function payments($params) + { + $result = $this->_payments->request($params); + return $result; + } + + public function paymentsDetails($params) + { + $result = $this->_paymentsDetails->request($params); + return $result; + } + + +} \ No newline at end of file diff --git a/src/Adyen/Service/CheckoutUtility.php b/src/Adyen/Service/CheckoutUtility.php new file mode 100644 index 000000000..e4b75b783 --- /dev/null +++ b/src/Adyen/Service/CheckoutUtility.php @@ -0,0 +1,24 @@ +_originKeys = new \Adyen\Service\ResourceModel\CheckoutUtility\OriginKeys($this); + + } + + public function originKeys($params) + { + $result = $this->_originKeys->request($params); + return $result; + } + +} \ No newline at end of file diff --git a/src/Adyen/Service/PosPayment.php b/src/Adyen/Service/PosPayment.php index de43b3241..9d3fe9390 100644 --- a/src/Adyen/Service/PosPayment.php +++ b/src/Adyen/Service/PosPayment.php @@ -2,7 +2,7 @@ namespace Adyen\Service; -class PosPayment extends \Adyen\Service +class PosPayment extends \Adyen\ApiKeyAuthenticatedService { protected $_runTenderSync; @@ -15,7 +15,6 @@ public function __construct(\Adyen\Client $client) $this->_runTenderSync = new \Adyen\Service\ResourceModel\Payment\TerminalCloudAPI($this, false); $this->_runTenderAsync = new \Adyen\Service\ResourceModel\Payment\TerminalCloudAPI($this, true); - $this->_supportsXAPIKey = true; } public function runTenderSync($params) diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php new file mode 100644 index 000000000..f7f563d1f --- /dev/null +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php @@ -0,0 +1,20 @@ +_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutVersion() . '/paymentMethods'; + parent::__construct($service, $this->_endpoint, $this->_requiredFields); + } + +} diff --git a/src/Adyen/Service/ResourceModel/Checkout/Payments.php b/src/Adyen/Service/ResourceModel/Checkout/Payments.php new file mode 100644 index 000000000..92ff15b98 --- /dev/null +++ b/src/Adyen/Service/ResourceModel/Checkout/Payments.php @@ -0,0 +1,25 @@ +_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments'; + parent::__construct($service, $this->_endpoint, $this->_requiredFields); + } + +} diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php new file mode 100644 index 000000000..343b3fa54 --- /dev/null +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php @@ -0,0 +1,21 @@ +_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments/details'; + parent::__construct($service, $this->_endpoint, $this->_requiredFields); + } + +} diff --git a/src/Adyen/Service/ResourceModel/Checkout/Setup.php b/src/Adyen/Service/ResourceModel/Checkout/Setup.php new file mode 100644 index 000000000..d595f2a96 --- /dev/null +++ b/src/Adyen/Service/ResourceModel/Checkout/Setup.php @@ -0,0 +1,23 @@ +_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutVersion() . '/setup'; + parent::__construct($service, $this->_endpoint, $this->_requiredFields); + } + +} diff --git a/src/Adyen/Service/ResourceModel/Checkout/Verify.php b/src/Adyen/Service/ResourceModel/Checkout/Verify.php new file mode 100644 index 000000000..8fdc1c5c8 --- /dev/null +++ b/src/Adyen/Service/ResourceModel/Checkout/Verify.php @@ -0,0 +1,20 @@ +_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutVersion() . '/verify'; + parent::__construct($service, $this->_endpoint, $this->_requiredFields); + } + +} diff --git a/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php b/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php new file mode 100644 index 000000000..1d36fe683 --- /dev/null +++ b/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php @@ -0,0 +1,20 @@ +_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutUtilityVersion() . '/originKeys'; + parent::__construct($service, $this->_endpoint, $this->_requiredFields); + } + +} diff --git a/tests/ExceptionTest.php b/tests/ExceptionTest.php index bac76c6a3..0bc86a02b 100644 --- a/tests/ExceptionTest.php +++ b/tests/ExceptionTest.php @@ -65,7 +65,7 @@ public function testExceptionMissingEnvironmentValue() // should have environment exception $this->assertEquals('Adyen\AdyenException', get_class($e)); - $this->assertEquals('The Client does not have a corect environment. use test or live', $e->getMessage()); + $this->assertEquals('The Client does not have a correct environment, use test or live', $e->getMessage()); } diff --git a/tests/MockTest/CheckoutTest.php b/tests/MockTest/CheckoutTest.php new file mode 100644 index 000000000..b500f9388 --- /dev/null +++ b/tests/MockTest/CheckoutTest.php @@ -0,0 +1,282 @@ +createCheckoutMockClient($jsonFile, $httpStatus); + + // initialize service + $service = new \Adyen\Service\Checkout($client); + + $params = array('merchantAccount' => "YourMerchantAccount"); + $result = $service->paymentMethods($params); + + $this->assertArrayHasKey('paymentMethods', $result); + + } + + public static function successPaymentMethodsProvider() + { + return array( + array('tests/Resources/Checkout/payment-methods-success.json', 200), + ); + } + + /** + * @param $jsonFile + * @param $httpStatus + * @param $expectedExceptionMessage + * @dataProvider failurePaymentMethodsProvider + * + */ + public function testPaymentMethodsFailure($jsonFile, $httpStatus, $expectedExceptionMessage) + { + // create Checkout client + $client = $this->createCheckoutMockClient($jsonFile, $httpStatus); + + if ($expectedExceptionMessage == self::NO_CHECKOUT_KEY) { + $client->setXApiKey(""); + } + // initialize service + $service = new \Adyen\Service\Checkout($client); + + $params = array('merchantAccount' => "YourMerchantAccount"); + try { + $result = $service->paymentMethods($params); + $this->fail(); + } catch (\Exception $e) { + $this->assertEquals('Adyen\AdyenException', get_class($e)); + $this->assertContains($expectedExceptionMessage, $e->getMessage()); + if ($httpStatus != null) { + $this->assertEquals($httpStatus, $e->getStatus()); + } + } + + } + + public static function failurePaymentMethodsProvider() + { + return array( + array('tests/Resources/Checkout/invalid-merchant-account.json', 403, "Invalid Merchant Account"), + array('tests/Resources/Checkout/payment-methods-forbidden.json', null, "Forbidden"), + array(null, null, self::NO_CHECKOUT_KEY) + ); + } + + /** + * @param $jsonFile + * @param $httpStatus + * + * @dataProvider successPaymentsProvider + * + */ + public function testPaymentsSuccess($jsonFile, $httpStatus) + { + // create Checkout client + $client = $this->createCheckoutMockClient($jsonFile, $httpStatus); + + // initialize service + $service = new \Adyen\Service\Checkout($client); + + $params = array( + 'merchantAccount' => "YourMerchantAccount", + 'amount' => array('currency' => "EUR", 'value' => 1000), + 'paymentMethod' => array( + 'type' => "scheme", + 'number' => "4111111111111111", + 'expiryMonth' => "08", + 'expiryYear' => "2018", + 'holderName' => "John Smith", + 'cvc' => "737" + ), + 'reference' => "Your order number", + 'returnUrl' => "https://your-company.com/...", + 'additionalData' => array( + 'executeThreeD' => true + ) + ); + $result = $service->payments($params); + + $this->assertContains($result['resultCode'], array('Authorised', 'RedirectShopper')); + + } + + public static function successPaymentsProvider() + { + return array( + array('tests/Resources/Checkout/payments-success.json', 200), + array('tests/Resources/Checkout/payments-success-3D.json', 200) + ); + } + + /** + * @param $jsonFile + * @param $httpStatus + * @param $expectedExceptionMessage + * @dataProvider failurePaymentsProvider + * + */ + public function testPaymentsFailure($jsonFile, $httpStatus, $expectedExceptionMessage) + { + // create Checkout client + $client = $this->createCheckoutMockClient($jsonFile, $httpStatus); + + // initialize service + $service = new \Adyen\Service\Checkout($client); + + $params = array( + 'merchantAccount' => "YourMerchantAccount", + 'amount' => array('currency' => "EUR", 'value' => 1000), + 'paymentMethod' => array( + 'type' => "scheme", + 'number' => "4111111111111111", + 'expiryMonth' => "08", + 'expiryYear' => "2018", + 'holderName' => "John Smith", + 'cvc' => "737" + ), + 'returnUrl' => "https://your-company.com/..." + ); + if ($expectedExceptionMessage != self::MISSING_FIELDS) { + $params['reference'] = 'yourownreference'; + } + + try { + $result = $service->payments($params); + $this->fail(); + } catch (\Exception $e) { + $this->assertEquals('Adyen\AdyenException', get_class($e)); + $this->assertContains($expectedExceptionMessage, $e->getMessage()); + if ($httpStatus != null) { + $this->assertEquals($httpStatus, $e->getStatus()); + } + } + } + + + public static function failurePaymentsProvider() + { + return array( + array('tests/Resources/Checkout/invalid-merchant-account.json', 403, "Invalid Merchant Account"), + array('tests/Resources/Checkout/payments-forbidden.json', null, "Forbidden"), + array(null, null, self::MISSING_FIELDS) + ); + } + + /** + * @param $jsonFile + * @param $httpStatus + * + * @dataProvider successPaymentsDetailsProvider + * + */ + public function testPaymentsDetailsSuccess($jsonFile, $httpStatus) + { + // create Checkout client + $client = $this->createCheckoutMockClient($jsonFile, $httpStatus); + + // initialize service + $service = new \Adyen\Service\Checkout($client); + + $params = array( + 'merchantAccount' => "YourMerchantAccount", + 'paymentData' => 'Ab02b4c0!BQABAgCJN1wRZuGJmq8dMncmypvknj9s7l5Tj...', + 'details' => array( + 'MD' => 'sdfsdfsdf...', + 'PaRes' => 'sdkfhskdjfsdf...' + ), + ); + + $result = $service->paymentsDetails($params); + + $this->assertContains($result['resultCode'], array('Authorised')); + } + + public static function successPaymentsDetailsProvider() + { + return array( + array('tests/Resources/Checkout/payments-details-success.json', 200) + ); + } + + /** + * @param $jsonFile + * @param $httpStatus + * + * @dataProvider successSetupProvider + * + */ + public function testSetupSuccess($jsonFile, $httpStatus) + { + // create Checkout client + $client = $this->createCheckoutMockClient($jsonFile, $httpStatus); + + // initialize service + $service = new \Adyen\Service\Checkout($client); + + $params = array( + 'merchantAccount' => "YourMerchantAccount", + 'amount' => array('currency' => "EUR", 'value' => 1000), + 'countryCode' => "NL", + 'reference' => "Your order number", + 'returnUrl' => "https://your-company.com/" + ); + + $result = $service->setup($params); + + $this->assertArrayHasKey("paymentData", $result); + $this->assertArrayHasKey("paymentMethods", $result); + } + + public static function successSetupProvider() + { + return array( + array('tests/Resources/Checkout/setup-success.json', 200) + ); + } + + /** + * @param $jsonFile + * @param $httpStatus + * + * @dataProvider successVerifyProvider + * + */ + public function testVerifySuccess($jsonFile, $httpStatus) + { + // create Checkout client + $client = $this->createCheckoutMockClient($jsonFile, $httpStatus); + + // initialize service + $service = new \Adyen\Service\Checkout($client); + + $params = array( + 'payload' => "YourPayload" + ); + + $result = $service->verify($params); + + $this->assertContains($result['resultCode'], array('Authorised')); + } + + public static function successVerifyProvider() + { + return array( + array('tests/Resources/Checkout/verify-success.json', 200) + ); + } + +} diff --git a/tests/MockTest/CheckoutUtilityTest.php b/tests/MockTest/CheckoutUtilityTest.php new file mode 100644 index 000000000..477b8c7ef --- /dev/null +++ b/tests/MockTest/CheckoutUtilityTest.php @@ -0,0 +1,43 @@ +createCheckoutMockClient($jsonFile, $httpStatus); + + // initialize service + $service = new \Adyen\Service\CheckoutUtility($client); + + $params = array( + "originDomains" => array( + "https://www.your-domain1.com", + "https://www.your-domain2.com", + "https://www.your-domain3.com" + ) + ); + + $result = $service->originKeys($params); + + $this->assertArrayHasKey('originKeys', $result); + + } + + public static function successOriginKeysProvider() + { + return array( + array('tests/Resources/CheckoutUtility/origin-keys-success.json', 200) + ); + } +} \ No newline at end of file diff --git a/tests/MockTest/TestCaseMock.php b/tests/MockTest/TestCaseMock.php new file mode 100644 index 000000000..657efa33f --- /dev/null +++ b/tests/MockTest/TestCaseMock.php @@ -0,0 +1,27 @@ +getMockBuilder(get_class(new \Adyen\HttpClient\CurlClient)) + ->setMethods(array('curlRequest')) + ->getMock(); + $curlClient->method('curlRequest') + ->willReturn(array($json, $httpStatus)); + + $client = new \Adyen\Client(); + $client->setApplicationName("My Test Application"); + $client->setEnvironment(\Adyen\Environment::TEST); + $client->setXApiKey("MockAPIKey"); + $client->setHttpClient($curlClient); + return $client; + } +} \ No newline at end of file diff --git a/tests/Resources/Checkout/invalid-merchant-account.json b/tests/Resources/Checkout/invalid-merchant-account.json new file mode 100644 index 000000000..28afc9887 --- /dev/null +++ b/tests/Resources/Checkout/invalid-merchant-account.json @@ -0,0 +1,6 @@ +{ + "status": 403, + "errorCode": "901", + "message": "Invalid Merchant Account", + "errorType": "security" +} \ No newline at end of file diff --git a/tests/Resources/Checkout/payment-methods-forbidden.json b/tests/Resources/Checkout/payment-methods-forbidden.json new file mode 100644 index 000000000..e80d3334e --- /dev/null +++ b/tests/Resources/Checkout/payment-methods-forbidden.json @@ -0,0 +1,7 @@ +{ + "error": { + "code": 403, + "message": "Forbidden", + "requested URI": "\/checkout\/\/v32\/paymentMethods" + } +} \ No newline at end of file diff --git a/tests/Resources/Checkout/payment-methods-success.json b/tests/Resources/Checkout/payment-methods-success.json new file mode 100644 index 000000000..4159b2a78 --- /dev/null +++ b/tests/Resources/Checkout/payment-methods-success.json @@ -0,0 +1,278 @@ +{ + "paymentMethods": [{ + "name": "AliPay", + "type": "alipay" + }, { + "details": [{ + "key": "additionalData.card.encrypted.json", + "type": "cardToken" + }], + "name": "Credit Card", + "type": "scheme" + }, { + "name": "Bank Transfer (DE)", + "type": "bankTransfer_DE" + }, { + "name": "Bank Transfer (GB)", + "type": "bankTransfer_GB" + }, { + "name": "SEPA Bank Transfer", + "type": "bankTransfer_IBAN" + }, { + "name": "Bank Transfer (NL)", + "type": "bankTransfer_NL" + }, { + "name": "Bank Transfer (PL)", + "type": "bankTransfer_PL" + }, { + "name": "Bank Transfer (SE)", + "type": "bankTransfer_SE" + }, { + "details": [{ + "key": "additionalData.card.encrypted.json", + "type": "cardToken" + }], + "name": "Bancontact card", + "type": "bcmc" + }, { + "name": "Cash-Ticket", + "type": "cashticket" + }, { + "name": "DineroMail", + "type": "dineromail" + }, { + "name": "Online bank transfer.", + "type": "directEbanking" + }, { + "name": "Eenmalige machtiging", + "type": "directdebit_NL" + }, { + "details": [{ + "items": [{ + "id": "11", + "name": "Bank transfer \/ postal" + }, { + "id": "74", + "name": "Banki Sp\u00f3\u0142dzielcze" + }, { + "id": "73", + "name": "BLIK" + }, { + "id": "32", + "name": "BNP Paribas" + }, { + "id": "16", + "name": "Credit Agricole" + }, { + "id": "83", + "name": "EnveloBank" + }, { + "id": "55", + "name": "erata - dotpay installment" + }, { + "id": "93", + "name": "eSKOK" + }, { + "id": "56", + "name": "eurobank p\u0142atno\u015bci online" + }, { + "id": "76", + "name": "Getin Bank PBL" + }, { + "id": "81", + "name": "Idea Cloud" + }, { + "id": "7", + "name": "ING Corporate customers" + }, { + "id": "35", + "name": "Kantor Polski" + }, { + "id": "44", + "name": "Millennium - P\u0142atno\u015bci Internetowe" + }, { + "id": "10", + "name": "Millennium Corporate customers" + }, { + "id": "68", + "name": "mRaty" + }, { + "id": "1", + "name": "mTransfer" + }, { + "id": "80", + "name": "Noble Pay" + }, { + "id": "50", + "name": "Pay Way Toyota Bank" + }, { + "id": "45", + "name": "Pay with Alior Bank" + }, { + "id": "65", + "name": "Paylink Idea Bank" + }, { + "id": "36", + "name": "Pekao24Przelew" + }, { + "id": "70", + "name": "Pocztowy24" + }, { + "id": "6", + "name": "Przelew24" + }, { + "id": "46", + "name": "P\u0142ac\u0119 z Citi Handlowy" + }, { + "id": "38", + "name": "P\u0142ac\u0119 z ING" + }, { + "id": "2", + "name": "P\u0142ac\u0119 z Inteligo" + }, { + "id": "4", + "name": "P\u0142ac\u0119 z iPKO" + }, { + "id": "72", + "name": "P\u0142ac\u0119 z Orange" + }, { + "id": "66", + "name": "P\u0142ac\u0119 z PBS" + }, { + "id": "75", + "name": "P\u0142ac\u0119 z Plus Bank" + }, { + "id": "51", + "name": "P\u0142a\u0107 z BO\u015a" + }, { + "id": "48", + "name": "R-Przelew" + }, { + "id": "88", + "name": "Raiffeisen" + }, { + "id": "52", + "name": "SkyCash" + }, { + "id": "58", + "name": "Szybkie Platnosci Internetowe z Deutsche Bank PBC" + }, { + "id": "60", + "name": "T-Mobile us\u0142ugi bankowe" + }, { + "id": "21", + "name": "VIA - Moje Rachunki" + }, { + "id": "84", + "name": "Volkswagen Bank direct" + }, { + "id": "31", + "name": "Zaplac w Zabce i we Freshmarket" + }, { + "id": "24", + "name": "mPay" + }], + "key": "issuer", + "type": "select" + }], + "name": "Local Polish Payment Methods", + "type": "dotpay" + }, { + "name": "Finnish E-Banking", + "type": "ebanking_FI" + }, { + "name": "Lastschrift (ELV)", + "type": "elv" + }, { + "name": "Nationale Entertainment Card", + "type": "entertainmentcard" + }, { + "details": [{ + "key": "bic", + "type": "text" + }], + "name": "GiroPay", + "type": "giropay" + }, { + "details": [{ + "items": [{ + "id": "1121", + "name": "Test Issuer" + }, { + "id": "1154", + "name": "Test Issuer 5" + }, { + "id": "1153", + "name": "Test Issuer 4" + }, { + "id": "1152", + "name": "Test Issuer 3" + }, { + "id": "1151", + "name": "Test Issuer 2" + }, { + "id": "1162", + "name": "Test Issuer Cancelled" + }, { + "id": "1161", + "name": "Test Issuer Pending" + }, { + "id": "1160", + "name": "Test Issuer Refused" + }, { + "id": "1159", + "name": "Test Issuer 10" + }, { + "id": "1158", + "name": "Test Issuer 9" + }, { + "id": "1157", + "name": "Test Issuer 8" + }, { + "id": "1156", + "name": "Test Issuer 7" + }, { + "id": "1155", + "name": "Test Issuer 6" + }], + "key": "idealIssuer", + "type": "select" + }], + "name": "iDEAL", + "type": "ideal" + }, { + "name": "Phone Payment", + "type": "ivr" + }, { + "name": "Landline phone", + "type": "ivrLandline" + }, { + "name": "Mobile phone", + "type": "ivrMobile" + }, { + "name": "Moneybookers", + "type": "moneybookers" + }, { + "name": "Invoice", + "type": "openinvoice" + }, { + "name": "Paysafecard", + "type": "paysafecard" + }, { + "details": [{ + "key": "sepa.ownerName", + "type": "text" + }, { + "key": "sepa.ibanNumber", + "type": "text" + }], + "name": "SEPA Direct Debit", + "type": "sepadirectdebit" + }, { + "name": "Premium SMS", + "type": "sms" + }, { + "name": "Your Gift", + "type": "yourgift" + }] +} \ No newline at end of file diff --git a/tests/Resources/Checkout/payments-details-success.json b/tests/Resources/Checkout/payments-details-success.json new file mode 100644 index 000000000..50d146635 --- /dev/null +++ b/tests/Resources/Checkout/payments-details-success.json @@ -0,0 +1,8 @@ +{ + "pspReference":"8515232733321252", + "resultCode":"Authorised", + "additionalData":{ + "liabilityShift":"true", + "refusalReasonRaw":"AUTHORISED" + } +} \ No newline at end of file diff --git a/tests/Resources/Checkout/payments-forbidden.json b/tests/Resources/Checkout/payments-forbidden.json new file mode 100644 index 000000000..d4f790bc7 --- /dev/null +++ b/tests/Resources/Checkout/payments-forbidden.json @@ -0,0 +1,7 @@ +{ + "error": { + "code": 403, + "message": "Forbidden", + "requested URI": "\/checkout\/\/v32\/payments" + } +} \ No newline at end of file diff --git a/tests/Resources/Checkout/payments-success-3D.json b/tests/Resources/Checkout/payments-success-3D.json new file mode 100644 index 000000000..96ee11563 --- /dev/null +++ b/tests/Resources/Checkout/payments-success-3D.json @@ -0,0 +1,20 @@ +{ + "resultCode": "RedirectShopper", + "details": [{ + "key": "MD", + "type": "text" + }, { + "key": "PaRes", + "type": "text" + }], + "paymentData": "Ab02b4c0!BQABAgBnicwOBkouhPP08Qjg5E5clc0bGyemR...", + "redirect": { + "data": { + "PaReq": "eNpVUttygjAU\/BXbDyAXQZE5ZoZKZ+oD1lp97jDhjNKR...", + "TermUrl": "https:\/\/your-company.com\/...", + "MD": "djIhd29JYnByWUlsYkRuWndGakdkd0F5dz09IWSjFITvzeJZYp37u..." + }, + "method": "POST", + "url": "https:\/\/test.adyen.com\/hpp\/3d\/validate.shtml" + } +} \ No newline at end of file diff --git a/tests/Resources/Checkout/payments-success.json b/tests/Resources/Checkout/payments-success.json new file mode 100644 index 000000000..2f5ab1ad8 --- /dev/null +++ b/tests/Resources/Checkout/payments-success.json @@ -0,0 +1,91 @@ +{ + "additionalData": { + "expiryDate": "8\/2018", + "fraudResultType": "GREEN", + "cardBin": "411111", + "cardSummary": "1111", + "fraudManualReview": "false", + "aliasType": "Default", + "alias": "H167852639363479", + "cardPaymentMethod": "visa", + "cardIssuingCountry": "NL" + }, + "fraudResult": { + "accountScore": 50, + "results": [{ + "FraudCheckResult": { + "accountScore": 0, + "checkId": 2, + "name": "CardChunkUsage" + } + }, { + "FraudCheckResult": { + "accountScore": 0, + "checkId": 3, + "name": "PaymentDetailUsage" + } + }, { + "FraudCheckResult": { + "accountScore": 0, + "checkId": 4, + "name": "HolderNameUsage" + } + }, { + "FraudCheckResult": { + "accountScore": 0, + "checkId": 1, + "name": "PaymentDetailRefCheck" + } + }, { + "FraudCheckResult": { + "accountScore": 0, + "checkId": 13, + "name": "IssuerRefCheck" + } + }, { + "FraudCheckResult": { + "accountScore": 0, + "checkId": 15, + "name": "IssuingCountryReferral" + } + }, { + "FraudCheckResult": { + "accountScore": 0, + "checkId": 27, + "name": "PmOwnerRefCheck" + } + }, { + "FraudCheckResult": { + "accountScore": 50, + "checkId": 41, + "name": "PaymentDetailNonFraudRefCheck" + } + }, { + "FraudCheckResult": { + "accountScore": 0, + "checkId": 10, + "name": "HolderNameContainsNumber" + } + }, { + "FraudCheckResult": { + "accountScore": 0, + "checkId": 11, + "name": "HolderNameIsOneWord" + } + }, { + "FraudCheckResult": { + "accountScore": 0, + "checkId": 82, + "name": "CustomFieldCheck" + } + }, { + "FraudCheckResult": { + "accountScore": 0, + "checkId": 25, + "name": "CVCAuthResultCheck" + } + }] + }, + "pspReference": "8535253563623704", + "resultCode": "Authorised" +} \ No newline at end of file diff --git a/tests/Resources/Checkout/setup-success.json b/tests/Resources/Checkout/setup-success.json new file mode 100644 index 000000000..e2499c82e --- /dev/null +++ b/tests/Resources/Checkout/setup-success.json @@ -0,0 +1,323 @@ +{ + "disableRecurringDetailUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/services\/PaymentInitiation\/v1\/disableRecurringDetail", + "generationtime": "2018-05-07T13:58:38Z", + "initiationUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/services\/PaymentInitiation\/v1\/initiate", + "logoBaseUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/", + "origin": "", + "payment": { + "amount": { + "currency": "EUR", + "value": 1000 + }, + "countryCode": "NL", + "reference": "Your order number", + "sessionValidity": "2018-05-07T14:58:38Z" + }, + "paymentData": "Ab02b4c0!BQABAgBA5QoC4k0...", + "paymentMethods": [ + { + "configuration": { + "canIgnoreCookies": "true" + }, + "inputDetails": [ + { + "items": [ + { + "id": "1121", + "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbank1.png", + "name": "Test Issuer" + }, + { + "id": "1154", + "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbank5.png", + "name": "Test Issuer 5" + }, + { + "id": "1153", + "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbank4.png", + "name": "Test Issuer 4" + }, + { + "id": "1152", + "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbank3.png", + "name": "Test Issuer 3" + }, + { + "id": "1151", + "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbank2.png", + "name": "Test Issuer 2" + }, + { + "id": "1162", + "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbankcancelled.png", + "name": "Test Issuer Cancelled" + }, + { + "id": "1161", + "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbankpending.png", + "name": "Test Issuer Pending" + }, + { + "id": "1160", + "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbankrefused.png", + "name": "Test Issuer Refused" + }, + { + "id": "1159", + "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbank10.png", + "name": "Test Issuer 10" + }, + { + "id": "1158", + "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbank9.png", + "name": "Test Issuer 9" + }, + { + "id": "1157", + "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbank8.png", + "name": "Test Issuer 8" + }, + { + "id": "1156", + "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbank7.png", + "name": "Test Issuer 7" + }, + { + "id": "1155", + "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbank6.png", + "name": "Test Issuer 6" + } + ], + "key": "idealIssuer", + "type": "select" + } + ], + "name": "iDEAL", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWlkZWFs", + "type": "ideal" + }, + { + "group": { + "name": "Credit Card", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXNjaGVtZQ==", + "type": "card" + }, + "inputDetails": [ + { + "key": "additionalData.card.encrypted.json", + "type": "cardToken" + } + ], + "name": "MasterCard", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPW1j", + "type": "mc" + }, + { + "name": "PayPal", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXBheXBhbA==", + "type": "paypal" + }, + { + "group": { + "name": "Credit Card", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXNjaGVtZQ==", + "type": "card" + }, + "inputDetails": [ + { + "key": "additionalData.card.encrypted.json", + "type": "cardToken" + } + ], + "name": "VISA", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXZpc2E=", + "type": "visa" + }, + { + "group": { + "name": "Credit Card", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXNjaGVtZQ==", + "type": "card" + }, + "inputDetails": [ + { + "key": "additionalData.card.encrypted.json", + "type": "cardToken" + } + ], + "name": "American Express", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWFtZXg=", + "type": "amex" + }, + { + "name": "SEPA Direct Debit", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXNlcGFkaXJlY3RkZWJpdA==", + "type": "sepadirectdebit" + }, + { + "name": "Paysafecard", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXBheXNhZmVjYXJk", + "type": "paysafecard" + }, + { + "name": "Bank Transfer (NL)", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWJhbmtUcmFuc2Zlcl9OTA==", + "type": "bankTransfer_NL" + }, + { + "group": { + "name": "Credit Card", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXNjaGVtZQ==", + "type": "card" + }, + "inputDetails": [ + { + "configuration": { + "cvcOptional": "true" + }, + "key": "additionalData.card.encrypted.json", + "type": "cardToken" + } + ], + "name": "Maestro", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPW1hZXN0cm8=", + "type": "maestro" + }, + { + "name": "Hunkemoller Lingerie Card", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWhtbGluZ2VyaWU=", + "type": "hmlingerie" + }, + { + "name": "Eenmalige machtiging", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWRpcmVjdGRlYml0X05M", + "type": "directdebit_NL" + }, + { + "name": "SEPA Bank Transfer", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWJhbmtUcmFuc2Zlcl9JQkFO", + "type": "bankTransfer_IBAN" + }, + { + "name": "c_cash", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWNfY2FzaA==", + "type": "c_cash" + }, + { + "group": { + "name": "Credit Card", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXNjaGVtZQ==", + "type": "card" + }, + "inputDetails": [ + { + "key": "additionalData.card.encrypted.json", + "type": "cardToken" + } + ], + "name": "ExpressPay", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWN1cA==", + "type": "cup" + }, + { + "group": { + "name": "Credit Card", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXNjaGVtZQ==", + "type": "card" + }, + "inputDetails": [ + { + "key": "additionalData.card.encrypted.json", + "type": "cardToken" + } + ], + "name": "Diners Club", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWRpbmVycw==", + "type": "diners" + }, + { + "group": { + "name": "Credit Card", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXNjaGVtZQ==", + "type": "card" + }, + "inputDetails": [ + { + "key": "additionalData.card.encrypted.json", + "type": "cardToken" + } + ], + "name": "Discover", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWRpc2NvdmVy", + "type": "discover" + }, + { + "name": "Nationale Entertainment Card", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWVudGVydGFpbm1lbnRjYXJk", + "type": "entertainmentcard" + }, + { + "name": "Gall & Gall", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWdhbGxnYWxs", + "type": "gallgall" + }, + { + "name": "Phone Payment", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWl2cg==", + "type": "ivr" + }, + { + "name": "Landline phone", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWl2ckxhbmRsaW5l", + "type": "ivrLandline" + }, + { + "name": "Mobile phone", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWl2ck1vYmlsZQ==", + "type": "ivrMobile" + }, + { + "group": { + "name": "Credit Card", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXNjaGVtZQ==", + "type": "card" + }, + "inputDetails": [ + { + "key": "additionalData.card.encrypted.json", + "type": "cardToken" + } + ], + "name": "JCB", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWpjYg==", + "type": "jcb" + }, + { + "name": "Onebip", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPW9uZWJpcA==", + "type": "onebip" + }, + { + "name": "Premium SMS", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXNtcw==", + "type": "sms" + }, + { + "name": "UnionPay", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXVuaW9ucGF5", + "type": "unionpay" + }, + { + "name": "Webshop Giftcard", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXdlYnNob3BnaWZ0Y2FyZA==", + "type": "webshopgiftcard" + }, + { + "name": "Your Gift", + "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXlvdXJnaWZ0", + "type": "yourgift" + } + ], + "publicKey": "10001|publickeyexample...", + "publicKeyToken": "811publickeytoken" +} \ No newline at end of file diff --git a/tests/Resources/Checkout/verify-invalid-payload.json b/tests/Resources/Checkout/verify-invalid-payload.json new file mode 100644 index 000000000..aec41bc02 --- /dev/null +++ b/tests/Resources/Checkout/verify-invalid-payload.json @@ -0,0 +1,6 @@ +{ + "status": 422, + "errorCode": "14_018", + "message": "Invalid payload provided", + "errorType": "validation" +} \ No newline at end of file diff --git a/tests/Resources/Checkout/verify-success.json b/tests/Resources/Checkout/verify-success.json new file mode 100644 index 000000000..9ee3775ce --- /dev/null +++ b/tests/Resources/Checkout/verify-success.json @@ -0,0 +1,4 @@ +{ + "pspReference": "8535253563623704", + "resultCode": "Authorised" +} \ No newline at end of file diff --git a/tests/Resources/CheckoutUtility/origin-keys-success.json b/tests/Resources/CheckoutUtility/origin-keys-success.json new file mode 100644 index 000000000..12908762a --- /dev/null +++ b/tests/Resources/CheckoutUtility/origin-keys-success.json @@ -0,0 +1,7 @@ +{ + "originKeys": { + "https://www.your-domain1.com": "pub.v2.7814286629520534.aHR0cHM6Ly93d3cueW91ci1kb21haW4xLmNvbQ.UEwIBmW9-c_uXo5wSEr2w8Hz8hVIpujXPHjpcEse3xI", + "https://www.your-domain3.com": "pub.v2.7814286629520534.aHR0cHM6Ly93d3cueW91ci1kb21haW4zLmNvbQ.fUvflu-YIdZSsLEH8Qqmr7ksE4ag_NYiiMXK0s6aq_4", + "https://www.your-domain2.com": "pub.v2.7814286629520534.aHR0cHM6Ly93d3cueW91ci1kb21haW4yLmNvbQ.EP6eXBJKk0t7-QIUl6e_b1qMuMHGepxG_SlUqxAYrfY" + } +} \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 9a5a40d97..7880d07bb 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,3 +1,4 @@ Date: Mon, 18 Jun 2018 14:41:26 +0200 Subject: [PATCH 20/31] PW-448 Added mocking to Authorise API (#65) * PW-448: Added mocking for Authorise API, refactored CheckoutMockClient * PW-448: added curlError function for easier mocking * PW-448: Added test on happy flow to prevent full card data to be logged * PW-448: Replaced assertEquals with assertInstanceOf for exceptions * PW-448: Treat logger as stub * PW-448: Added check for cse encrypted data --- src/Adyen/HttpClient/CurlClient.php | 12 +- tests/MockTest/CheckoutTest.php | 18 +- tests/MockTest/CheckoutUtilityTest.php | 2 +- tests/MockTest/PaymentTest.php | 176 ++++++++++++++++++ tests/MockTest/TestCaseMock.php | 6 +- .../Resources/Payment/authorise-success.json | 5 + .../Payment/invalid-merchant-account.json | 6 + 7 files changed, 211 insertions(+), 14 deletions(-) create mode 100644 tests/MockTest/PaymentTest.php create mode 100644 tests/Resources/Payment/authorise-success.json create mode 100644 tests/Resources/Payment/invalid-merchant-account.json diff --git a/src/Adyen/HttpClient/CurlClient.php b/src/Adyen/HttpClient/CurlClient.php index ffcd86818..e08d6471d 100644 --- a/src/Adyen/HttpClient/CurlClient.php +++ b/src/Adyen/HttpClient/CurlClient.php @@ -76,8 +76,8 @@ public function requestJson(\Adyen\Service $service, $requestUrl, $params) if ($httpStatus != 200 && $result) { $this->handleResultError($result, $logger); } elseif (!$result) { - $errno = curl_errno($ch); - $message = curl_error($ch); + + list($errno, $message) = $this->curlError($ch); curl_close($ch); $this->handleCurlError($requestUrl, $errno, $message, $logger); @@ -266,4 +266,12 @@ protected function curlRequest($ch) $httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE); return array($result, $httpStatus); } + + protected function curlError($ch) + { + $errno = curl_errno($ch); + $message = curl_error($ch); + return array($errno, $message); + } + } diff --git a/tests/MockTest/CheckoutTest.php b/tests/MockTest/CheckoutTest.php index b500f9388..51040a23f 100644 --- a/tests/MockTest/CheckoutTest.php +++ b/tests/MockTest/CheckoutTest.php @@ -16,7 +16,7 @@ class CheckoutTest extends TestCaseMock public function testPaymentMethodsSuccess($jsonFile, $httpStatus) { // create Checkout client - $client = $this->createCheckoutMockClient($jsonFile, $httpStatus); + $client = $this->createMockClient($jsonFile, $httpStatus); // initialize service $service = new \Adyen\Service\Checkout($client); @@ -45,7 +45,7 @@ public static function successPaymentMethodsProvider() public function testPaymentMethodsFailure($jsonFile, $httpStatus, $expectedExceptionMessage) { // create Checkout client - $client = $this->createCheckoutMockClient($jsonFile, $httpStatus); + $client = $this->createMockClient($jsonFile, $httpStatus); if ($expectedExceptionMessage == self::NO_CHECKOUT_KEY) { $client->setXApiKey(""); @@ -58,7 +58,7 @@ public function testPaymentMethodsFailure($jsonFile, $httpStatus, $expectedExcep $result = $service->paymentMethods($params); $this->fail(); } catch (\Exception $e) { - $this->assertEquals('Adyen\AdyenException', get_class($e)); + $this->assertInstanceOf('Adyen\AdyenException', $e); $this->assertContains($expectedExceptionMessage, $e->getMessage()); if ($httpStatus != null) { $this->assertEquals($httpStatus, $e->getStatus()); @@ -86,7 +86,7 @@ public static function failurePaymentMethodsProvider() public function testPaymentsSuccess($jsonFile, $httpStatus) { // create Checkout client - $client = $this->createCheckoutMockClient($jsonFile, $httpStatus); + $client = $this->createMockClient($jsonFile, $httpStatus); // initialize service $service = new \Adyen\Service\Checkout($client); @@ -132,7 +132,7 @@ public static function successPaymentsProvider() public function testPaymentsFailure($jsonFile, $httpStatus, $expectedExceptionMessage) { // create Checkout client - $client = $this->createCheckoutMockClient($jsonFile, $httpStatus); + $client = $this->createMockClient($jsonFile, $httpStatus); // initialize service $service = new \Adyen\Service\Checkout($client); @@ -158,7 +158,7 @@ public function testPaymentsFailure($jsonFile, $httpStatus, $expectedExceptionMe $result = $service->payments($params); $this->fail(); } catch (\Exception $e) { - $this->assertEquals('Adyen\AdyenException', get_class($e)); + $this->assertInstanceOf('Adyen\AdyenException', $e); $this->assertContains($expectedExceptionMessage, $e->getMessage()); if ($httpStatus != null) { $this->assertEquals($httpStatus, $e->getStatus()); @@ -186,7 +186,7 @@ public static function failurePaymentsProvider() public function testPaymentsDetailsSuccess($jsonFile, $httpStatus) { // create Checkout client - $client = $this->createCheckoutMockClient($jsonFile, $httpStatus); + $client = $this->createMockClient($jsonFile, $httpStatus); // initialize service $service = new \Adyen\Service\Checkout($client); @@ -222,7 +222,7 @@ public static function successPaymentsDetailsProvider() public function testSetupSuccess($jsonFile, $httpStatus) { // create Checkout client - $client = $this->createCheckoutMockClient($jsonFile, $httpStatus); + $client = $this->createMockClient($jsonFile, $httpStatus); // initialize service $service = new \Adyen\Service\Checkout($client); @@ -258,7 +258,7 @@ public static function successSetupProvider() public function testVerifySuccess($jsonFile, $httpStatus) { // create Checkout client - $client = $this->createCheckoutMockClient($jsonFile, $httpStatus); + $client = $this->createMockClient($jsonFile, $httpStatus); // initialize service $service = new \Adyen\Service\Checkout($client); diff --git a/tests/MockTest/CheckoutUtilityTest.php b/tests/MockTest/CheckoutUtilityTest.php index 477b8c7ef..bc1e3a495 100644 --- a/tests/MockTest/CheckoutUtilityTest.php +++ b/tests/MockTest/CheckoutUtilityTest.php @@ -15,7 +15,7 @@ class CheckoutUtilityTest extends TestCaseMock public function testOriginKeysSuccess($jsonFile, $httpStatus) { // create Checkout client - $client = $this->createCheckoutMockClient($jsonFile, $httpStatus); + $client = $this->createMockClient($jsonFile, $httpStatus); // initialize service $service = new \Adyen\Service\CheckoutUtility($client); diff --git a/tests/MockTest/PaymentTest.php b/tests/MockTest/PaymentTest.php new file mode 100644 index 000000000..d771c7d01 --- /dev/null +++ b/tests/MockTest/PaymentTest.php @@ -0,0 +1,176 @@ +createMockClient($jsonFile, $httpStatus); + + // Stub Logger to prevent full card data being logged + $loggerMock = $this->getMockBuilder('\Monolog\Logger')->setMethods(array('info'))->disableOriginalConstructor()->getMock(); + $client->setLogger($loggerMock); + $loggerMock->expects($this->any()) + ->method('info') + ->with( + $this->logicalAnd( + $this->logicalNot($this->stringContains('4111')), + $this->logicalNot($this->stringContains('737')), + $this->logicalNot($this->stringContains('adyenjs....')) + ) + ); + + // initialize service + $service = new \Adyen\Service\Payment($client); + + $json = '{ + "card": { + "number": "4111111111111111", + "expiryMonth": "08", + "expiryYear": "2018", + "cvc": "737", + "holderName": "John Smith" + }, + "amount": { + "value": 1500, + "currency": "EUR" + }, + "reference": "payment-test", + "merchantAccount": "YourMerchantReference", + "additionalData": { + "card.encrypted.json" : "adyenjs...." + } + }'; + + $params = json_decode($json, true); + + $result = $service->authorise($params); + + $this->assertArrayHasKey('resultCode', $result); + $this->assertEquals('Authorised', $result['resultCode']); + } + + public static function successAuthoriseProvider() + { + return array( + array('tests/Resources/Payment/authorise-success.json', 200), + ); + } + + + /** + * @param $jsonFile Json file location + * @param $httpStatus expected http status code + * @param $errno + * @param $expectedExceptionMessage + * @dataProvider connectionFailureAuthoriseProvider + */ + public function testAuthoriseConnectionFailure($jsonFile, $httpStatus, $errno, $expectedExceptionMessage) + { + // create client + $client = $this->createMockClient($jsonFile, $httpStatus, $errno); + + // initialize service + $service = new \Adyen\Service\Payment($client); + + $json = '{ + "card": { + "number": "4111111111111111", + "expiryMonth": "08", + "expiryYear": "2018", + "cvc": "737", + "holderName": "John Smith" + }, + "amount": { + "value": 1500, + "currency": "EUR" + }, + "reference": "payment-test", + "merchantAccount": "YourMerchantReference" + }'; + + $params = json_decode($json, true); + + try { + $result = $service->authorise($params); + $this->fail(); + } catch (\Exception $e) { + $this->assertInstanceOf('Adyen\ConnectionException', $e); + $this->assertContains($expectedExceptionMessage, $e->getMessage()); + if ($httpStatus != null) { + $this->assertEquals($httpStatus, $e->getCode()); + } + } + } + + public static function connectionFailureAuthoriseProvider() + { + return array( + array(null, null, CURLE_OK, "Probably your Web Service username and/or password is incorrect"), + array(null, null, CURLE_OPERATION_TIMEOUTED, "Could not connect to Adyen"), + array(null, null, CURLE_SSL_CACERT, "Could not verify Adyen's SSL certificate"), + array(null, null, 12345, "Unexpected error communicating with Adyen.") + ); + } + + /** + * @param $jsonFile Json file location + * @param $httpStatus expected http status code + * @param $expectedExceptionMessage + * @dataProvider resultFailureAuthoriseProvider + */ + public function testAuthoriseResultFailure($jsonFile, $httpStatus, $expectedExceptionMessage) + { + // create client + $client = $this->createMockClient($jsonFile, $httpStatus); + + // initialize service + $service = new \Adyen\Service\Payment($client); + + $json = '{ + "card": { + "number": "4111111111111111", + "expiryMonth": "08", + "expiryYear": "2018", + "cvc": "737", + "holderName": "John Smith" + }, + "amount": { + "value": 1500, + "currency": "EUR" + }, + "reference": "payment-test", + "merchantAccount": "YourMerchantReference" + }'; + + $params = json_decode($json, true); + + try { + $result = $service->authorise($params); + $this->fail(); + } catch (\Exception $e) { + $this->assertInstanceOf('Adyen\AdyenException', $e); + $this->assertContains($expectedExceptionMessage, $e->getMessage()); + if ($httpStatus != null) { + $this->assertEquals($httpStatus, $e->getStatus()); + } + } + } + + public static function resultFailureAuthoriseProvider() + { + return array( + array('tests/Resources/Payment/invalid-merchant-account.json', 403, "Invalid Merchant Account") + ); + } +} \ No newline at end of file diff --git a/tests/MockTest/TestCaseMock.php b/tests/MockTest/TestCaseMock.php index 657efa33f..40da84c3d 100644 --- a/tests/MockTest/TestCaseMock.php +++ b/tests/MockTest/TestCaseMock.php @@ -5,17 +5,19 @@ class TestCaseMock extends \PHPUnit_Framework_TestCase { - protected function createCheckoutMockClient($jsonFile, $httpStatus) + protected function createMockClient($jsonFile, $httpStatus, $errno = null) { $json = null; if ($jsonFile != null) { $json = file_get_contents($jsonFile, true); } $curlClient = $this->getMockBuilder(get_class(new \Adyen\HttpClient\CurlClient)) - ->setMethods(array('curlRequest')) + ->setMethods(array('curlRequest', 'curlError')) ->getMock(); $curlClient->method('curlRequest') ->willReturn(array($json, $httpStatus)); + $curlClient->method('curlError') + ->willReturn(array($errno, null)); $client = new \Adyen\Client(); $client->setApplicationName("My Test Application"); diff --git a/tests/Resources/Payment/authorise-success.json b/tests/Resources/Payment/authorise-success.json new file mode 100644 index 000000000..bca90b0b0 --- /dev/null +++ b/tests/Resources/Payment/authorise-success.json @@ -0,0 +1,5 @@ +{ + "pspReference": "8815281183344931", + "resultCode": "Authorised", + "authCode": "99310" +} \ No newline at end of file diff --git a/tests/Resources/Payment/invalid-merchant-account.json b/tests/Resources/Payment/invalid-merchant-account.json new file mode 100644 index 000000000..28afc9887 --- /dev/null +++ b/tests/Resources/Payment/invalid-merchant-account.json @@ -0,0 +1,6 @@ +{ + "status": 403, + "errorCode": "901", + "message": "Invalid Merchant Account", + "errorType": "security" +} \ No newline at end of file From 583e00b1c556577458fd25d8c5b5b56a371b3cc2 Mon Sep 17 00:00:00 2001 From: Aleffio Date: Wed, 20 Jun 2018 15:03:32 +0200 Subject: [PATCH 21/31] Version bump 1.5.0 --- src/Adyen/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adyen/Client.php b/src/Adyen/Client.php index 35f2471cb..a61fe0cb6 100644 --- a/src/Adyen/Client.php +++ b/src/Adyen/Client.php @@ -8,7 +8,7 @@ class Client { - const LIB_VERSION = "1.4.2"; + const LIB_VERSION = "1.5.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"; From 6a0cd1e8f06d4e64989efc9e6ed378c0641661e7 Mon Sep 17 00:00:00 2001 From: Aleffio Date: Wed, 20 Jun 2018 15:33:43 +0200 Subject: [PATCH 22/31] Removed getPOIID from config/interface --- src/Adyen/Config.php | 10 ---------- src/Adyen/ConfigInterface.php | 2 -- 2 files changed, 12 deletions(-) diff --git a/src/Adyen/Config.php b/src/Adyen/Config.php index d69c6ec9f..9e3799295 100644 --- a/src/Adyen/Config.php +++ b/src/Adyen/Config.php @@ -69,16 +69,6 @@ public function getXApiKey() return !empty($this->data['x-api-key']) ? $this->data['x-api-key'] : null; } - /** - * Get the Point of Interest Terminal ID, used for POS Transactions with Terminal API - * - * @return mixed|null - */ - public function getPOIID() - { - return !empty($this->data['POIID']) ? $this->data['POIID'] : null; - } - public function getInputType() { if(isset($this->data['inputType']) && in_array($this->data['inputType'], $this->allowedInput)) { diff --git a/src/Adyen/ConfigInterface.php b/src/Adyen/ConfigInterface.php index fb8c22fb9..3eb46eba3 100644 --- a/src/Adyen/ConfigInterface.php +++ b/src/Adyen/ConfigInterface.php @@ -11,6 +11,4 @@ public function get($param); public function getInputType(); public function getOutputType(); public function getMerchantAccount(); - public function getPOIID(); - } \ No newline at end of file From 00a855da9efbf66027061f39826afd292740d1fd Mon Sep 17 00:00:00 2001 From: Alessio Zampatti Date: Fri, 29 Jun 2018 10:11:18 +0200 Subject: [PATCH 23/31] Updated setup/verify endpoints with paymentSession/paymentsResult (#67) * Updated setup/verify endpoints with paymentSession/paymentsResult * added missing requiredfields --- src/Adyen/Service/Checkout.php | 16 +- .../{Setup.php => PaymentSession.php} | 8 +- .../{Verify.php => PaymentsResult.php} | 4 +- tests/MockTest/CheckoutTest.php | 26 +- .../Checkout/payment-session-success.json | 3 + ...cess.json => payments-result-success.json} | 0 tests/Resources/Checkout/setup-success.json | 323 ------------------ .../Checkout/verify-invalid-payload.json | 6 - 8 files changed, 31 insertions(+), 355 deletions(-) rename src/Adyen/Service/ResourceModel/Checkout/{Setup.php => PaymentSession.php} (74%) rename src/Adyen/Service/ResourceModel/Checkout/{Verify.php => PaymentsResult.php} (81%) create mode 100644 tests/Resources/Checkout/payment-session-success.json rename tests/Resources/Checkout/{verify-success.json => payments-result-success.json} (100%) delete mode 100644 tests/Resources/Checkout/setup-success.json delete mode 100644 tests/Resources/Checkout/verify-invalid-payload.json diff --git a/src/Adyen/Service/Checkout.php b/src/Adyen/Service/Checkout.php index 25edaf2bf..a892db61d 100644 --- a/src/Adyen/Service/Checkout.php +++ b/src/Adyen/Service/Checkout.php @@ -5,8 +5,8 @@ class Checkout extends \Adyen\ApiKeyAuthenticatedService { - protected $_setup; - protected $_verify; + protected $_paymentSession; + protected $_paymentsResult; protected $_paymentMethods; protected $_payments; protected $_paymentsDetails; @@ -15,23 +15,23 @@ public function __construct(\Adyen\Client $client) { parent::__construct($client); - $this->_setup = new \Adyen\Service\ResourceModel\Checkout\Setup($this); - $this->_verify = new \Adyen\Service\ResourceModel\Checkout\Verify($this); + $this->_paymentSession = new \Adyen\Service\ResourceModel\Checkout\PaymentSession($this); + $this->_paymentsResult = new \Adyen\Service\ResourceModel\Checkout\PaymentsResult($this); $this->_paymentMethods = new \Adyen\Service\ResourceModel\Checkout\PaymentMethods($this); $this->_payments = new \Adyen\Service\ResourceModel\Checkout\Payments($this); $this->_paymentsDetails = new \Adyen\Service\ResourceModel\Checkout\PaymentsDetails($this); } - public function setup($params) + public function paymentSession($params) { - $result = $this->_setup->request($params); + $result = $this->_paymentSession->request($params); return $result; } - public function verify($params) + public function paymentsResult($params) { - $result = $this->_verify->request($params); + $result = $this->_paymentsResult->request($params); return $result; } diff --git a/src/Adyen/Service/ResourceModel/Checkout/Setup.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php similarity index 74% rename from src/Adyen/Service/ResourceModel/Checkout/Setup.php rename to src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php index d595f2a96..91e8f6837 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/Setup.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php @@ -2,21 +2,23 @@ namespace Adyen\Service\ResourceModel\Checkout; -class Setup extends \Adyen\Service\AbstractResource +class PaymentSession extends \Adyen\Service\AbstractResource { protected $_requiredFields = array( 'amount.value', 'amount.currency', 'countryCode', - 'merchantAccount' + 'merchantAccount', + 'returnUrl', + 'reference' ); protected $_endpoint; public function __construct($service) { - $this->_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutVersion() . '/setup'; + $this->_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutVersion() . '/paymentSession'; parent::__construct($service, $this->_endpoint, $this->_requiredFields); } diff --git a/src/Adyen/Service/ResourceModel/Checkout/Verify.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php similarity index 81% rename from src/Adyen/Service/ResourceModel/Checkout/Verify.php rename to src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php index 8fdc1c5c8..cc8985ea7 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/Verify.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php @@ -2,7 +2,7 @@ namespace Adyen\Service\ResourceModel\Checkout; -class Verify extends \Adyen\Service\AbstractResource +class PaymentsResult extends \Adyen\Service\AbstractResource { protected $_requiredFields = array( @@ -13,7 +13,7 @@ class Verify extends \Adyen\Service\AbstractResource public function __construct($service) { - $this->_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutVersion() . '/verify'; + $this->_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments/result'; parent::__construct($service, $this->_endpoint, $this->_requiredFields); } diff --git a/tests/MockTest/CheckoutTest.php b/tests/MockTest/CheckoutTest.php index 51040a23f..173ec7344 100644 --- a/tests/MockTest/CheckoutTest.php +++ b/tests/MockTest/CheckoutTest.php @@ -216,10 +216,10 @@ public static function successPaymentsDetailsProvider() * @param $jsonFile * @param $httpStatus * - * @dataProvider successSetupProvider + * @dataProvider successPaymentSessionProvider * */ - public function testSetupSuccess($jsonFile, $httpStatus) + public function testPaymentSessionSuccess($jsonFile, $httpStatus) { // create Checkout client $client = $this->createMockClient($jsonFile, $httpStatus); @@ -232,19 +232,19 @@ public function testSetupSuccess($jsonFile, $httpStatus) 'amount' => array('currency' => "EUR", 'value' => 1000), 'countryCode' => "NL", 'reference' => "Your order number", - 'returnUrl' => "https://your-company.com/" + 'returnUrl' => "https://your-company.com/", + "sdkVersion" => "1.3.0" ); - $result = $service->setup($params); + $result = $service->paymentSession($params); - $this->assertArrayHasKey("paymentData", $result); - $this->assertArrayHasKey("paymentMethods", $result); + $this->assertArrayHasKey("paymentSession", $result); } - public static function successSetupProvider() + public static function successPaymentSessionProvider() { return array( - array('tests/Resources/Checkout/setup-success.json', 200) + array('tests/Resources/Checkout/payment-session-success.json', 200) ); } @@ -252,10 +252,10 @@ public static function successSetupProvider() * @param $jsonFile * @param $httpStatus * - * @dataProvider successVerifyProvider + * @dataProvider successPaymentsResultProvider * */ - public function testVerifySuccess($jsonFile, $httpStatus) + public function testPaymentsResultSuccess($jsonFile, $httpStatus) { // create Checkout client $client = $this->createMockClient($jsonFile, $httpStatus); @@ -267,15 +267,15 @@ public function testVerifySuccess($jsonFile, $httpStatus) 'payload' => "YourPayload" ); - $result = $service->verify($params); + $result = $service->paymentsResult($params); $this->assertContains($result['resultCode'], array('Authorised')); } - public static function successVerifyProvider() + public static function successPaymentsResultProvider() { return array( - array('tests/Resources/Checkout/verify-success.json', 200) + array('tests/Resources/Checkout/payments-result-success.json', 200) ); } diff --git a/tests/Resources/Checkout/payment-session-success.json b/tests/Resources/Checkout/payment-session-success.json new file mode 100644 index 000000000..42446ad47 --- /dev/null +++ b/tests/Resources/Checkout/payment-session-success.json @@ -0,0 +1,3 @@ +{ + "paymentSession": "eyJjaGVja291dHNob3BwZXJCYXNlVXJsIjoiaHR0cHM6XC9cL2NoZWNrb3V0c2asdHBlci10ZXN0LmFkeWVuLmNvbVwvY2hlY2tvdXRzaG9wcGVyXC8iLCJkaXNhYmxlUmVjdXJyaW5nRGV0YWlsVXJsIjoiaHR0cHM6XC9cL2NoZWNrb3V0c2hvcHBlci10ZXN0LmFkeWVuLmNvbVwvY2hlY2tvdXRzaG9wcGVyXC9zZXJ2aWNlc1wvUGF5bWVudEluaXRpYXRpb25cL3YxXC9kaXNhYmxlUmVjdXJyaW5nRGV0YWlsIiwiZ2VuZXJhdGlvbnRpbWUiOiIyMDE4LTA2LTIyVDE0OjMxOjI1WiIsImluaXRpYXRpb25VcmwiOiJodHRwczpcL1wvY2hlY2tvdXRzaG9wc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aMCIsInR5cGUiOiJ5b3VyZ2lmdCJ9XSwicHVibGljS2V5IjoiMTAwMDF8QkNBREY4MjU3RTE4QTFBODlBQ0M0MTQ5RDBGQzMyNEU5ODMxNUMyNDA1RDc1NUU1MDRENjY0QjJDMUM3MUE2MzhCOUQxMkZEMjkwRTEyQTA0QkIxRTZCMkRBM0YzN0M1NTJEMDExQ0ZCQUJCQ0M4NDgwNkFCQjc4RUQxNjU3OERFRDk2NDQ4Q0I4QjU0MTM5RkQ3QzcyRjkwQzA4NkMzNkFFNzdFNjlFOTE3MUEzQTBENTIwRDAyMTM2MzcyNjNFMEM1REY5NjREQUQ4RDc5N0VCMURENkU1NEFENjY5RDYwQUFDMjU1NUUwQzhCRTIyNzNGODk4NDQ3M0U3NkVFNzM4N0ZFQzBFNzFCODM2ODQ0Qjg0MDZBQzkwNTk0OUZCODhGQzY4RThGMDE4NjYzMkYxRURCNEM5QjVCODg4RUY1QzU3RERFMTEzN0JCRjM2RjY1NEU0N0U1NzFGQkM4ODgyOENCRTk0MzhENzQyRjNDMDkyQUQ1RkYzRTYyQUNBRDI1MjQ2RUE0M0QyMkNGQzhBRTE0NDE5NzY3ODY3RDJDNjBEQ0JBNkFDOTIwMDhEMEQ4ODM0QkVBMTExN0FFMzQ3RjMxMkQ2QzAxQzU3Q0I0MkFERDNENEQ2MkUzNzI3QTNDRThBQTFGMDlCRjZCNzk2QTBBMzc0MUJDNDgxMTEifQ==" +} \ No newline at end of file diff --git a/tests/Resources/Checkout/verify-success.json b/tests/Resources/Checkout/payments-result-success.json similarity index 100% rename from tests/Resources/Checkout/verify-success.json rename to tests/Resources/Checkout/payments-result-success.json diff --git a/tests/Resources/Checkout/setup-success.json b/tests/Resources/Checkout/setup-success.json deleted file mode 100644 index e2499c82e..000000000 --- a/tests/Resources/Checkout/setup-success.json +++ /dev/null @@ -1,323 +0,0 @@ -{ - "disableRecurringDetailUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/services\/PaymentInitiation\/v1\/disableRecurringDetail", - "generationtime": "2018-05-07T13:58:38Z", - "initiationUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/services\/PaymentInitiation\/v1\/initiate", - "logoBaseUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/", - "origin": "", - "payment": { - "amount": { - "currency": "EUR", - "value": 1000 - }, - "countryCode": "NL", - "reference": "Your order number", - "sessionValidity": "2018-05-07T14:58:38Z" - }, - "paymentData": "Ab02b4c0!BQABAgBA5QoC4k0...", - "paymentMethods": [ - { - "configuration": { - "canIgnoreCookies": "true" - }, - "inputDetails": [ - { - "items": [ - { - "id": "1121", - "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbank1.png", - "name": "Test Issuer" - }, - { - "id": "1154", - "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbank5.png", - "name": "Test Issuer 5" - }, - { - "id": "1153", - "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbank4.png", - "name": "Test Issuer 4" - }, - { - "id": "1152", - "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbank3.png", - "name": "Test Issuer 3" - }, - { - "id": "1151", - "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbank2.png", - "name": "Test Issuer 2" - }, - { - "id": "1162", - "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbankcancelled.png", - "name": "Test Issuer Cancelled" - }, - { - "id": "1161", - "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbankpending.png", - "name": "Test Issuer Pending" - }, - { - "id": "1160", - "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbankrefused.png", - "name": "Test Issuer Refused" - }, - { - "id": "1159", - "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbank10.png", - "name": "Test Issuer 10" - }, - { - "id": "1158", - "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbank9.png", - "name": "Test Issuer 9" - }, - { - "id": "1157", - "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbank8.png", - "name": "Test Issuer 8" - }, - { - "id": "1156", - "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbank7.png", - "name": "Test Issuer 7" - }, - { - "id": "1155", - "imageUrl": "https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/img\/pm\/testbank6.png", - "name": "Test Issuer 6" - } - ], - "key": "idealIssuer", - "type": "select" - } - ], - "name": "iDEAL", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWlkZWFs", - "type": "ideal" - }, - { - "group": { - "name": "Credit Card", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXNjaGVtZQ==", - "type": "card" - }, - "inputDetails": [ - { - "key": "additionalData.card.encrypted.json", - "type": "cardToken" - } - ], - "name": "MasterCard", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPW1j", - "type": "mc" - }, - { - "name": "PayPal", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXBheXBhbA==", - "type": "paypal" - }, - { - "group": { - "name": "Credit Card", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXNjaGVtZQ==", - "type": "card" - }, - "inputDetails": [ - { - "key": "additionalData.card.encrypted.json", - "type": "cardToken" - } - ], - "name": "VISA", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXZpc2E=", - "type": "visa" - }, - { - "group": { - "name": "Credit Card", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXNjaGVtZQ==", - "type": "card" - }, - "inputDetails": [ - { - "key": "additionalData.card.encrypted.json", - "type": "cardToken" - } - ], - "name": "American Express", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWFtZXg=", - "type": "amex" - }, - { - "name": "SEPA Direct Debit", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXNlcGFkaXJlY3RkZWJpdA==", - "type": "sepadirectdebit" - }, - { - "name": "Paysafecard", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXBheXNhZmVjYXJk", - "type": "paysafecard" - }, - { - "name": "Bank Transfer (NL)", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWJhbmtUcmFuc2Zlcl9OTA==", - "type": "bankTransfer_NL" - }, - { - "group": { - "name": "Credit Card", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXNjaGVtZQ==", - "type": "card" - }, - "inputDetails": [ - { - "configuration": { - "cvcOptional": "true" - }, - "key": "additionalData.card.encrypted.json", - "type": "cardToken" - } - ], - "name": "Maestro", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPW1hZXN0cm8=", - "type": "maestro" - }, - { - "name": "Hunkemoller Lingerie Card", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWhtbGluZ2VyaWU=", - "type": "hmlingerie" - }, - { - "name": "Eenmalige machtiging", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWRpcmVjdGRlYml0X05M", - "type": "directdebit_NL" - }, - { - "name": "SEPA Bank Transfer", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWJhbmtUcmFuc2Zlcl9JQkFO", - "type": "bankTransfer_IBAN" - }, - { - "name": "c_cash", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWNfY2FzaA==", - "type": "c_cash" - }, - { - "group": { - "name": "Credit Card", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXNjaGVtZQ==", - "type": "card" - }, - "inputDetails": [ - { - "key": "additionalData.card.encrypted.json", - "type": "cardToken" - } - ], - "name": "ExpressPay", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWN1cA==", - "type": "cup" - }, - { - "group": { - "name": "Credit Card", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXNjaGVtZQ==", - "type": "card" - }, - "inputDetails": [ - { - "key": "additionalData.card.encrypted.json", - "type": "cardToken" - } - ], - "name": "Diners Club", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWRpbmVycw==", - "type": "diners" - }, - { - "group": { - "name": "Credit Card", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXNjaGVtZQ==", - "type": "card" - }, - "inputDetails": [ - { - "key": "additionalData.card.encrypted.json", - "type": "cardToken" - } - ], - "name": "Discover", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWRpc2NvdmVy", - "type": "discover" - }, - { - "name": "Nationale Entertainment Card", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWVudGVydGFpbm1lbnRjYXJk", - "type": "entertainmentcard" - }, - { - "name": "Gall & Gall", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWdhbGxnYWxs", - "type": "gallgall" - }, - { - "name": "Phone Payment", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWl2cg==", - "type": "ivr" - }, - { - "name": "Landline phone", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWl2ckxhbmRsaW5l", - "type": "ivrLandline" - }, - { - "name": "Mobile phone", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWl2ck1vYmlsZQ==", - "type": "ivrMobile" - }, - { - "group": { - "name": "Credit Card", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXNjaGVtZQ==", - "type": "card" - }, - "inputDetails": [ - { - "key": "additionalData.card.encrypted.json", - "type": "cardToken" - } - ], - "name": "JCB", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPWpjYg==", - "type": "jcb" - }, - { - "name": "Onebip", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPW9uZWJpcA==", - "type": "onebip" - }, - { - "name": "Premium SMS", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXNtcw==", - "type": "sms" - }, - { - "name": "UnionPay", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXVuaW9ucGF5", - "type": "unionpay" - }, - { - "name": "Webshop Giftcard", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXdlYnNob3BnaWZ0Y2FyZA==", - "type": "webshopgiftcard" - }, - { - "name": "Your Gift", - "paymentMethodData": "Cf62f1e3!YnJhbmRDb2RlPXlvdXJnaWZ0", - "type": "yourgift" - } - ], - "publicKey": "10001|publickeyexample...", - "publicKeyToken": "811publickeytoken" -} \ No newline at end of file diff --git a/tests/Resources/Checkout/verify-invalid-payload.json b/tests/Resources/Checkout/verify-invalid-payload.json deleted file mode 100644 index aec41bc02..000000000 --- a/tests/Resources/Checkout/verify-invalid-payload.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "status": 422, - "errorCode": "14_018", - "message": "Invalid payload provided", - "errorType": "validation" -} \ No newline at end of file From a22c9aed020b70fd6ed8547fc5fbc0969ac8d1eb Mon Sep 17 00:00:00 2001 From: Alessio Zampatti Date: Wed, 4 Jul 2018 15:42:51 +0200 Subject: [PATCH 24/31] PW-458: Added timeout optional configuration (#68) * PW-458: Added timeout optional configuration * reverted _requiredfields --- src/Adyen/Client.php | 5 +++++ src/Adyen/Config.php | 5 +++++ src/Adyen/ConfigInterface.php | 1 + src/Adyen/HttpClient/CurlClient.php | 5 +++++ 4 files changed, 16 insertions(+) diff --git a/src/Adyen/Client.php b/src/Adyen/Client.php index a61fe0cb6..804bfd38f 100644 --- a/src/Adyen/Client.php +++ b/src/Adyen/Client.php @@ -164,6 +164,11 @@ public function setOutputType($value) $this->_config->set('outputType', $value); } + public function setTimeout($value) + { + $this->_config->set('timeout', $value); + } + /** * Get the library version diff --git a/src/Adyen/Config.php b/src/Adyen/Config.php index 9e3799295..a807cc338 100644 --- a/src/Adyen/Config.php +++ b/src/Adyen/Config.php @@ -88,6 +88,11 @@ public function getOutputType() return $this->defaultOutput; } + public function getTimeout() + { + return !empty($this->data['timeout']) ? $this->data['timeout'] : null; + } + public function getMerchantAccount() { return isset($this->data['merchantAccount']) ? $this->data['merchantAccount'] : null; diff --git a/src/Adyen/ConfigInterface.php b/src/Adyen/ConfigInterface.php index 3eb46eba3..0f0ef66fc 100644 --- a/src/Adyen/ConfigInterface.php +++ b/src/Adyen/ConfigInterface.php @@ -11,4 +11,5 @@ public function get($param); public function getInputType(); public function getOutputType(); public function getMerchantAccount(); + public function getTimeout(); } \ No newline at end of file diff --git a/src/Adyen/HttpClient/CurlClient.php b/src/Adyen/HttpClient/CurlClient.php index e08d6471d..9dc762f9c 100644 --- a/src/Adyen/HttpClient/CurlClient.php +++ b/src/Adyen/HttpClient/CurlClient.php @@ -60,6 +60,11 @@ public function requestJson(\Adyen\Service $service, $requestUrl, $params) curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); } + //Set the timeout + if($config->getTimeout() != null){ + curl_setopt($ch, CURLOPT_TIMEOUT, $config->getTimeout()); + } + //Set the headers curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); From f08e66494521bfbd12ff972d19b49c23911fe4fe Mon Sep 17 00:00:00 2001 From: Alessio Zampatti Date: Thu, 5 Jul 2018 09:10:38 +0200 Subject: [PATCH 25/31] PW-445: Removed required fields, validate function and related tests (#69) * PW-445: Removed required fields, validate function and related tests * Removed MissingFields test --- src/Adyen/Service/AbstractResource.php | 74 +------------------ .../ResourceModel/Checkout/PaymentMethods.php | 7 +- .../ResourceModel/Checkout/PaymentSession.php | 12 +-- .../ResourceModel/Checkout/Payments.php | 11 +-- .../Checkout/PaymentsDetails.php | 8 +- .../ResourceModel/Checkout/PaymentsResult.php | 7 +- .../CheckoutUtility/OriginKeys.php | 7 +- .../DirectoryLookup/Directory.php | 13 +--- .../Modification/AdjustAuthorisation.php | 9 +-- .../ResourceModel/Modification/Cancel.php | 7 +- .../Modification/CancelOrRefund.php | 7 +- .../ResourceModel/Modification/Capture.php | 10 +-- .../ResourceModel/Modification/Refund.php | 10 +-- .../ResourceModel/Payment/Authorise.php | 9 +-- .../ResourceModel/Payment/Authorise3D.php | 9 +-- .../Payment/TerminalCloudAPI.php | 14 +--- .../Service/ResourceModel/Payout/Confirm.php | 7 +- .../Service/ResourceModel/Payout/Decline.php | 7 +- .../Payout/StoreDetailsAndSubmit.php | 12 +-- .../Service/ResourceModel/Payout/Submit.php | 13 +--- .../Payout/ThirdParty/ConfirmThirdParty.php | 7 +- .../Payout/ThirdParty/DeclineThirdParty.php | 7 +- .../Payout/ThirdParty/StoreDetail.php | 9 +-- .../StoreDetailsAndSubmitThirdParty.php | 12 +-- .../Payout/ThirdParty/SubmitThirdParty.php | 13 +--- .../ResourceModel/Recurring/Disable.php | 7 +- .../Recurring/ListRecurringDetails.php | 8 +- tests/CreatePaymentRequestTest.php | 37 ---------- tests/ExceptionTest.php | 38 ---------- tests/MockTest/CheckoutTest.php | 9 +-- 30 files changed, 30 insertions(+), 370 deletions(-) diff --git a/src/Adyen/Service/AbstractResource.php b/src/Adyen/Service/AbstractResource.php index 8fafb2358..9c67a01ac 100644 --- a/src/Adyen/Service/AbstractResource.php +++ b/src/Adyen/Service/AbstractResource.php @@ -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; } /** @@ -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); } @@ -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); - } - } } \ No newline at end of file diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php index f7f563d1f..a9fbd7ecc 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php @@ -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); } } diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php index 91e8f6837..dcae56005 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php @@ -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); } } diff --git a/src/Adyen/Service/ResourceModel/Checkout/Payments.php b/src/Adyen/Service/ResourceModel/Checkout/Payments.php index 92ff15b98..aa4534867 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/Payments.php +++ b/src/Adyen/Service/ResourceModel/Checkout/Payments.php @@ -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); } } diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php index 343b3fa54..77672c447 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php @@ -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); } } diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php index cc8985ea7..09f808088 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php @@ -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); } } diff --git a/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php b/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php index 1d36fe683..f9ce3c607 100644 --- a/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php +++ b/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php @@ -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); } } diff --git a/src/Adyen/Service/ResourceModel/DirectoryLookup/Directory.php b/src/Adyen/Service/ResourceModel/DirectoryLookup/Directory.php index fa6f48c7d..b139b2cf0 100644 --- a/src/Adyen/Service/ResourceModel/DirectoryLookup/Directory.php +++ b/src/Adyen/Service/ResourceModel/DirectoryLookup/Directory.php @@ -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); } } \ No newline at end of file diff --git a/src/Adyen/Service/ResourceModel/Modification/AdjustAuthorisation.php b/src/Adyen/Service/ResourceModel/Modification/AdjustAuthorisation.php index a294bef90..372595153 100644 --- a/src/Adyen/Service/ResourceModel/Modification/AdjustAuthorisation.php +++ b/src/Adyen/Service/ResourceModel/Modification/AdjustAuthorisation.php @@ -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); } } \ No newline at end of file diff --git a/src/Adyen/Service/ResourceModel/Modification/Cancel.php b/src/Adyen/Service/ResourceModel/Modification/Cancel.php index 254da7e80..735444319 100644 --- a/src/Adyen/Service/ResourceModel/Modification/Cancel.php +++ b/src/Adyen/Service/ResourceModel/Modification/Cancel.php @@ -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); } } \ No newline at end of file diff --git a/src/Adyen/Service/ResourceModel/Modification/CancelOrRefund.php b/src/Adyen/Service/ResourceModel/Modification/CancelOrRefund.php index b35681c6f..cf4c550b2 100644 --- a/src/Adyen/Service/ResourceModel/Modification/CancelOrRefund.php +++ b/src/Adyen/Service/ResourceModel/Modification/CancelOrRefund.php @@ -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); } } \ No newline at end of file diff --git a/src/Adyen/Service/ResourceModel/Modification/Capture.php b/src/Adyen/Service/ResourceModel/Modification/Capture.php index 955ff8eba..5287d8906 100644 --- a/src/Adyen/Service/ResourceModel/Modification/Capture.php +++ b/src/Adyen/Service/ResourceModel/Modification/Capture.php @@ -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); } } \ No newline at end of file diff --git a/src/Adyen/Service/ResourceModel/Modification/Refund.php b/src/Adyen/Service/ResourceModel/Modification/Refund.php index 7d47a3aa2..95e91de85 100644 --- a/src/Adyen/Service/ResourceModel/Modification/Refund.php +++ b/src/Adyen/Service/ResourceModel/Modification/Refund.php @@ -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); } } \ No newline at end of file diff --git a/src/Adyen/Service/ResourceModel/Payment/Authorise.php b/src/Adyen/Service/ResourceModel/Payment/Authorise.php index 6c502bd94..09d649eac 100644 --- a/src/Adyen/Service/ResourceModel/Payment/Authorise.php +++ b/src/Adyen/Service/ResourceModel/Payment/Authorise.php @@ -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); } } \ No newline at end of file diff --git a/src/Adyen/Service/ResourceModel/Payment/Authorise3D.php b/src/Adyen/Service/ResourceModel/Payment/Authorise3D.php index 397725fb9..52d9fd103 100644 --- a/src/Adyen/Service/ResourceModel/Payment/Authorise3D.php +++ b/src/Adyen/Service/ResourceModel/Payment/Authorise3D.php @@ -4,19 +4,12 @@ class Authorise3D extends \Adyen\Service\AbstractResource { - protected $_requiredFields = array( - 'merchantAccount', - 'browserInfo', - 'md', - 'paResponse' - ); - protected $_endpoint; public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payment/' . $service->getClient()->getApiVersion() . '/authorise3d'; - parent::__construct($service, $this->_endpoint, $this->_requiredFields); + parent::__construct($service, $this->_endpoint); } } \ No newline at end of file diff --git a/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php b/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php index 0ee1fc9d9..90b6095f9 100644 --- a/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php +++ b/src/Adyen/Service/ResourceModel/Payment/TerminalCloudAPI.php @@ -4,18 +4,6 @@ class TerminalCloudAPI extends \Adyen\Service\AbstractResource { - - protected $_requiredFields = array( - 'SaleToPOIRequest.MessageHeader.POIID', - 'SaleToPOIRequest.MessageHeader.ServiceID', - //TODO fix: actually works with only first two levels - 'SaleToPOIRequest.PaymentRequest.SaleData.SaleTransactionID.TransactionID', //reference - 'SaleToPOIRequest.PaymentRequest.PaymentTransaction.AmountsReq.Currency', - 'SaleToPOIRequest.PaymentRequest.PaymentTransaction.AmountsReq.RequestedAmount', - //PaymentData is optional, if not provided it will perform an authorisation(no refunds) - 'SaleToPOIRequest.PaymentRequest.PaymentData.PaymentType', - ); - protected $_endpoint; public function __construct($service, $asynchronous) @@ -25,7 +13,7 @@ public function __construct($service, $asynchronous) } else { $this->_endpoint = $service->getClient()->getConfig()->get('endpointTerminalCloud') . '/sync'; } - parent::__construct($service, $this->_endpoint, $this->_requiredFields); + parent::__construct($service, $this->_endpoint); } } \ No newline at end of file diff --git a/src/Adyen/Service/ResourceModel/Payout/Confirm.php b/src/Adyen/Service/ResourceModel/Payout/Confirm.php index f1bec89d0..6e3a87aad 100644 --- a/src/Adyen/Service/ResourceModel/Payout/Confirm.php +++ b/src/Adyen/Service/ResourceModel/Payout/Confirm.php @@ -4,17 +4,12 @@ class Confirm extends \Adyen\Service\AbstractResource { - protected $_requiredFields = array( - 'merchantAccount', - 'originalReference' - ); - protected $_endpoint; public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/confirm'; - parent::__construct($service, $this->_endpoint, $this->_requiredFields); + parent::__construct($service, $this->_endpoint); } } \ No newline at end of file diff --git a/src/Adyen/Service/ResourceModel/Payout/Decline.php b/src/Adyen/Service/ResourceModel/Payout/Decline.php index cfb64fb00..1ed095d25 100644 --- a/src/Adyen/Service/ResourceModel/Payout/Decline.php +++ b/src/Adyen/Service/ResourceModel/Payout/Decline.php @@ -4,17 +4,12 @@ class Decline extends \Adyen\Service\AbstractResource { - protected $_requiredFields = array( - 'merchantAccount', - 'originalReference' - ); - protected $_endpoint; public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/decline'; - parent::__construct($service, $this->_endpoint, $this->_requiredFields); + parent::__construct($service, $this->_endpoint); } } \ No newline at end of file diff --git a/src/Adyen/Service/ResourceModel/Payout/StoreDetailsAndSubmit.php b/src/Adyen/Service/ResourceModel/Payout/StoreDetailsAndSubmit.php index 5c777b2de..7d2dcbc30 100644 --- a/src/Adyen/Service/ResourceModel/Payout/StoreDetailsAndSubmit.php +++ b/src/Adyen/Service/ResourceModel/Payout/StoreDetailsAndSubmit.php @@ -4,22 +4,12 @@ class StoreDetailsAndSubmit extends \Adyen\Service\AbstractResource { - protected $_requiredFields = array( - 'amount.currency', - 'amount.value', - 'merchantAccount', - 'recurring.contract', - 'reference', - 'shopperEmail', - 'shopperReference', - ); - protected $_endpoint; public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/storeDetailAndSubmit'; - parent::__construct($service, $this->_endpoint, $this->_requiredFields); + parent::__construct($service, $this->_endpoint); } } \ No newline at end of file diff --git a/src/Adyen/Service/ResourceModel/Payout/Submit.php b/src/Adyen/Service/ResourceModel/Payout/Submit.php index 97a5e6ba6..0d1268292 100644 --- a/src/Adyen/Service/ResourceModel/Payout/Submit.php +++ b/src/Adyen/Service/ResourceModel/Payout/Submit.php @@ -4,23 +4,12 @@ class Submit extends \Adyen\Service\AbstractResource { - protected $_requiredFields = array( - 'amount.currency', - 'amount.value', - 'merchantAccount', - 'recurring.contract', - 'reference', - 'shopperEmail', - 'shopperReference', - 'selectedRecurringDetailReference' - ); - protected $_endpoint; public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/submit'; - parent::__construct($service, $this->_endpoint, $this->_requiredFields); + parent::__construct($service, $this->_endpoint); } } \ No newline at end of file diff --git a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/ConfirmThirdParty.php b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/ConfirmThirdParty.php index 7c37d1ada..37e19251b 100644 --- a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/ConfirmThirdParty.php +++ b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/ConfirmThirdParty.php @@ -4,17 +4,12 @@ class ConfirmThirdParty extends \Adyen\Service\AbstractResource { - protected $_requiredFields = array( - 'merchantAccount', - 'originalReference' - ); - protected $_endpoint; public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/confirmThirdParty'; - parent::__construct($service, $this->_endpoint, $this->_requiredFields); + parent::__construct($service, $this->_endpoint); } } \ No newline at end of file diff --git a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/DeclineThirdParty.php b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/DeclineThirdParty.php index d83c03179..07f681c02 100644 --- a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/DeclineThirdParty.php +++ b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/DeclineThirdParty.php @@ -4,17 +4,12 @@ class DeclineThirdParty extends \Adyen\Service\AbstractResource { - protected $_requiredFields = array( - 'merchantAccount', - 'originalReference' - ); - protected $_endpoint; public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/declineThirdParty'; - parent::__construct($service, $this->_endpoint, $this->_requiredFields); + parent::__construct($service, $this->_endpoint); } } \ No newline at end of file diff --git a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetail.php b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetail.php index 1fd60b92d..aced34bb4 100644 --- a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetail.php +++ b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetail.php @@ -4,19 +4,12 @@ class StoreDetail extends \Adyen\Service\AbstractResource { - protected $_requiredFields = array( - 'merchantAccount', - 'recurring.contract', - 'shopperEmail', - 'shopperReference' - ); - protected $_endpoint; public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/storeDetail'; - parent::__construct($service, $this->_endpoint, $this->_requiredFields); + parent::__construct($service, $this->_endpoint); } } \ No newline at end of file diff --git a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetailsAndSubmitThirdParty.php b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetailsAndSubmitThirdParty.php index f1f4166bd..f7cb4f86f 100644 --- a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetailsAndSubmitThirdParty.php +++ b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/StoreDetailsAndSubmitThirdParty.php @@ -4,22 +4,12 @@ class StoreDetailsAndSubmitThirdParty extends \Adyen\Service\AbstractResource { - protected $_requiredFields = array( - 'merchantAccount', - 'shopperEmail', - 'shopperReference', - 'reference', - 'recurring.contract', - 'amount.currency', - 'amount.value' - ); - protected $_endpoint; public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/storeDetailAndSubmitThirdParty'; - parent::__construct($service, $this->_endpoint, $this->_requiredFields); + parent::__construct($service, $this->_endpoint); } } \ No newline at end of file diff --git a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/SubmitThirdParty.php b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/SubmitThirdParty.php index 6319670ce..a49d5dcc2 100644 --- a/src/Adyen/Service/ResourceModel/Payout/ThirdParty/SubmitThirdParty.php +++ b/src/Adyen/Service/ResourceModel/Payout/ThirdParty/SubmitThirdParty.php @@ -4,23 +4,12 @@ class SubmitThirdParty extends \Adyen\Service\AbstractResource { - protected $_requiredFields = array( - 'amount.currency', - 'amount.value', - 'merchantAccount', - 'recurring.contract', - 'reference', - 'shopperEmail', - 'shopperReference', - 'selectedRecurringDetailReference' - ); - protected $_endpoint; public function __construct($service) { $this->_endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Payout/' . $service->getClient()->getApiVersion() . '/submitThirdParty'; - parent::__construct($service, $this->_endpoint, $this->_requiredFields); + parent::__construct($service, $this->_endpoint); } } \ No newline at end of file diff --git a/src/Adyen/Service/ResourceModel/Recurring/Disable.php b/src/Adyen/Service/ResourceModel/Recurring/Disable.php index 0fe030647..3d86256c6 100644 --- a/src/Adyen/Service/ResourceModel/Recurring/Disable.php +++ b/src/Adyen/Service/ResourceModel/Recurring/Disable.php @@ -4,15 +4,10 @@ class Disable extends \Adyen\Service\AbstractResource { - protected $_requiredFields = array( - 'merchantAccount', - 'shopperReference' - ); - public function __construct($service) { $endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Recurring/' . $service->getClient()->getApiRecurringVersion() . '/disable'; - parent::__construct($service, $endpoint, $this->_requiredFields); + parent::__construct($service, $endpoint); } } \ No newline at end of file diff --git a/src/Adyen/Service/ResourceModel/Recurring/ListRecurringDetails.php b/src/Adyen/Service/ResourceModel/Recurring/ListRecurringDetails.php index 74a0ad6d7..0b2d1910a 100644 --- a/src/Adyen/Service/ResourceModel/Recurring/ListRecurringDetails.php +++ b/src/Adyen/Service/ResourceModel/Recurring/ListRecurringDetails.php @@ -4,16 +4,10 @@ class ListRecurringDetails extends \Adyen\Service\AbstractResource { - - protected $_requiredFields = array( - 'merchantAccount', - 'shopperReference' - ); - public function __construct($service) { $endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/Recurring/' . $service->getClient()->getApiRecurringVersion() . '/listRecurringDetails'; - parent::__construct($service, $endpoint, $this->_requiredFields); + parent::__construct($service, $endpoint); } } \ No newline at end of file diff --git a/tests/CreatePaymentRequestTest.php b/tests/CreatePaymentRequestTest.php index 2e61a9a75..dd52e5765 100644 --- a/tests/CreatePaymentRequestTest.php +++ b/tests/CreatePaymentRequestTest.php @@ -11,43 +11,6 @@ class CreatePaymentRequestTest extends TestCase { - public function testCreatePaymentMissingReference() - { - // initialize client - $client = $this->createClient(); - - // initialize service - $service = new Service\Payment($client); - - $json = '{ - "card": { - "number": "4111111111111111", - "expiryMonth": "08", - "expiryYear": "2018", - "cvc": "737", - "holderName": "John Smith" - }, - "amount": { - "value": 1500, - "currency": "EUR" - }, - "reference": "", - "merchantAccount": "' . $this->_merchantAccount .'" - }'; - - $params = json_decode($json, true); - $e = null; - try { - $result = $service->authorise($params); - } catch (\Exception $e) { - $this->validateApiPermission($e); - } - - // check if exception is correct - $this->assertEquals('Adyen\AdyenException', get_class($e)); - $this->assertEquals('Missing the following values: reference', $e->getMessage()); - } - public function testCreatePaymentSuccess() { // initialize client diff --git a/tests/ExceptionTest.php b/tests/ExceptionTest.php index 0bc86a02b..04f1e0b15 100644 --- a/tests/ExceptionTest.php +++ b/tests/ExceptionTest.php @@ -11,44 +11,6 @@ class ExceptionTest extends \Adyen\TestCase { - public function testExceptionMissingValuesToParams() - { - // initialize client - $client = $this->createClient(); - - // initialize service - $service = new Service\Payment($client); - - $json = '{ - "card": { - "number": "", - "expiryMonth": "", - "expiryYear": "", - "cvc": "", - "holderName": "" - }, - "amount": { - "value": "", - "currency": "" - }, - "reference": "", - "merchantAccount": "" - }'; - - $params = json_decode($json, true); - $e = null; - try { - $result = $service->authorise($params); - } catch (\Exception $e) { - - } - - $this->assertEquals('Adyen\AdyenException', get_class($e)); - $this->assertEquals('Missing the following values: merchantAccount,amount.value,amount.currency,reference', $e->getMessage()); - - - - } public function testExceptionMissingEnvironmentValue() { $client = new \Adyen\Client(); diff --git a/tests/MockTest/CheckoutTest.php b/tests/MockTest/CheckoutTest.php index 173ec7344..72a9e7430 100644 --- a/tests/MockTest/CheckoutTest.php +++ b/tests/MockTest/CheckoutTest.php @@ -5,7 +5,6 @@ class CheckoutTest extends TestCaseMock { const NO_CHECKOUT_KEY = "Please provide a valid Checkout API Key"; - const MISSING_FIELDS = "Missing the following fields:"; /** * @param $jsonFile Json file location @@ -150,9 +149,8 @@ public function testPaymentsFailure($jsonFile, $httpStatus, $expectedExceptionMe ), 'returnUrl' => "https://your-company.com/..." ); - if ($expectedExceptionMessage != self::MISSING_FIELDS) { - $params['reference'] = 'yourownreference'; - } + + $params['reference'] = 'yourownreference'; try { $result = $service->payments($params); @@ -171,8 +169,7 @@ public static function failurePaymentsProvider() { return array( array('tests/Resources/Checkout/invalid-merchant-account.json', 403, "Invalid Merchant Account"), - array('tests/Resources/Checkout/payments-forbidden.json', null, "Forbidden"), - array(null, null, self::MISSING_FIELDS) + array('tests/Resources/Checkout/payments-forbidden.json', null, "Forbidden") ); } From 1bc9c9cf1d8df2d9109f66b8c390b0dc6a2dd30e Mon Sep 17 00:00:00 2001 From: Rik ter Beek Date: Tue, 2 Oct 2018 08:57:24 +0200 Subject: [PATCH 26/31] PW-645 use dynamic identifier for live if provided, not provided throw error for checkout service as this is mandatory --- src/Adyen/Client.php | 28 +++++++++++++++++++--------- src/Adyen/Service/Checkout.php | 13 +++++++++++++ tests/MockTest/CheckoutTest.php | 33 +++++++++++++++++++++++++++++++-- 3 files changed, 63 insertions(+), 11 deletions(-) diff --git a/src/Adyen/Client.php b/src/Adyen/Client.php index 804bfd38f..c3d780da4 100644 --- a/src/Adyen/Client.php +++ b/src/Adyen/Client.php @@ -12,16 +12,18 @@ class Client 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 ENDPOINT_LIVE_SUFFIX = "-pal-live.adyenpayments.com"; const ENDPOINT_TEST_DIRECTORY_LOOKUP = "https://test.adyen.com/hpp/directory/v2.shtml"; const ENDPOINT_LIVE_DIRECTORY_LOOKUP = "https://live.adyen.com/hpp/directory/v2.shtml"; const API_VERSION = "v30"; const API_RECURRING_VERSION = "v25"; const API_CHECKOUT_VERSION = "v32"; const API_CHECKOUT_UTILITY_VERSION = "v1"; - const TERMINAL_CLOUD_TEST = "https://terminal-api-test.adyen.com"; - const TERMINAL_CLOUD_LIVE = "https://terminal-api-live.adyen.com"; - const ENDPOINT_CHECKOUT_TEST = "https://checkout-test.adyen.com"; - const ENDPOINT_CHECKOUT_LIVE = "https://checkout-live.adyen.com"; + 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"; + const ENDPOINT_CHECKOUT_LIVE_SUFFIX = "-checkout-live.adyenpayments.com/checkout"; + const ENDPOINT_PROTOCOL = "https://"; /** * @var Adyen_Config $config @@ -89,24 +91,32 @@ public function setXApiKey($xApiKey) /** * Set environment to connect to test or live platform of Adyen + * For live please specify the unique identifier. * * @param $environment + * @param null $liveEndpointUrlPrefix * @throws AdyenException */ - public function setEnvironment($environment) + public function setEnvironment($environment, $liveEndpointUrlPrefix = null) { if ($environment == \Adyen\Environment::TEST) { $this->_config->set('environment', \Adyen\Environment::TEST); $this->_config->set('endpoint', self::ENDPOINT_TEST); $this->_config->set('endpointDirectorylookup', self::ENDPOINT_TEST_DIRECTORY_LOOKUP); - $this->_config->set('endpointTerminalCloud', self::TERMINAL_CLOUD_TEST); + $this->_config->set('endpointTerminalCloud', self::ENDPOINT_TERMINAL_CLOUD_TEST); $this->_config->set('endpointCheckout', self::ENDPOINT_CHECKOUT_TEST); } elseif ($environment == \Adyen\Environment::LIVE) { $this->_config->set('environment', \Adyen\Environment::LIVE); - $this->_config->set('endpoint', self::ENDPOINT_LIVE); $this->_config->set('endpointDirectorylookup', self::ENDPOINT_LIVE_DIRECTORY_LOOKUP); - $this->_config->set('endpointTerminalCloud', self::TERMINAL_CLOUD_LIVE); - $this->_config->set('endpointCheckout', self::ENDPOINT_CHECKOUT_LIVE); + $this->_config->set('endpointTerminalCloud', self::ENDPOINT_TERMINAL_CLOUD_LIVE); + + if ($liveEndpointUrlPrefix) { + $this->_config->set('endpoint', self::ENDPOINT_PROTOCOL . $liveEndpointUrlPrefix . self::ENDPOINT_LIVE_SUFFIX); + $this->_config->set('endpointCheckout', self::ENDPOINT_PROTOCOL . $liveEndpointUrlPrefix . self::ENDPOINT_CHECKOUT_LIVE_SUFFIX); + } else { + $this->_config->set('endpoint', self::ENDPOINT_LIVE); + $this->_config->set('endpointCheckout', null); // not supported please specify unique identifier + } } else { // environment does not exist $msg = "This environment does not exist, use " . \Adyen\Environment::TEST . ' or ' . \Adyen\Environment::LIVE; diff --git a/src/Adyen/Service/Checkout.php b/src/Adyen/Service/Checkout.php index a892db61d..74b26f974 100644 --- a/src/Adyen/Service/Checkout.php +++ b/src/Adyen/Service/Checkout.php @@ -11,10 +11,23 @@ class Checkout extends \Adyen\ApiKeyAuthenticatedService protected $_payments; protected $_paymentsDetails; + /** + * Checkout constructor. + * @param \Adyen\Client $client + * @throws \Adyen\AdyenException + */ public function __construct(\Adyen\Client $client) { parent::__construct($client); + // check if endpoint is set + if ($client->getConfig()->get('endpointCheckout') == null) { + $logger = $client->getLogger(); + $msg = "You forgot to specify a unique identifier when setting the environment"; + $logger->error($msg); + throw new \Adyen\AdyenException($msg); + } + $this->_paymentSession = new \Adyen\Service\ResourceModel\Checkout\PaymentSession($this); $this->_paymentsResult = new \Adyen\Service\ResourceModel\Checkout\PaymentsResult($this); $this->_paymentMethods = new \Adyen\Service\ResourceModel\Checkout\PaymentMethods($this); diff --git a/tests/MockTest/CheckoutTest.php b/tests/MockTest/CheckoutTest.php index 72a9e7430..304b895d7 100644 --- a/tests/MockTest/CheckoutTest.php +++ b/tests/MockTest/CheckoutTest.php @@ -30,7 +30,37 @@ public function testPaymentMethodsSuccess($jsonFile, $httpStatus) public static function successPaymentMethodsProvider() { return array( - array('tests/Resources/Checkout/payment-methods-success.json', 200), + array('tests/Resources/Checkout/payment-methods-success.json', 200) + ); + } + + /** + * @param $jsonFile + * @param $httpStatus + * @param $expectedExceptionMessage + * @throws \Adyen\AdyenException + * @dataProvider failurePaymentMethodsMissingIdentifierOnLiveProvider + */ + public function testPaymentMethodsFailureMissingIdentifierOnLive($jsonFile, $httpStatus, $expectedExceptionMessage) + { + // create Checkout client + $client = $this->createMockClient($jsonFile, $httpStatus); + $client->setEnvironment(\Adyen\Environment::LIVE); + + try { + $service = new \Adyen\Service\Checkout($client); + $params = array('merchantAccount' => "YourMerchantAccount"); + $service->paymentMethods($params); + } catch (\Exception $e) { + $this->assertInstanceOf('Adyen\AdyenException', $e); + $this->assertContains($expectedExceptionMessage, $e->getMessage()); + } + } + + public static function failurePaymentMethodsMissingIdentifierOnLiveProvider() + { + return array( + array('tests/Resources/Checkout/payment-methods-success.json', null, 'You forgot to specify a unique identifier when setting the environment') ); } @@ -39,7 +69,6 @@ public static function successPaymentMethodsProvider() * @param $httpStatus * @param $expectedExceptionMessage * @dataProvider failurePaymentMethodsProvider - * */ public function testPaymentMethodsFailure($jsonFile, $httpStatus, $expectedExceptionMessage) { From 7142f644217bbd73eddc9ee114f05fd2ff25846b Mon Sep 17 00:00:00 2001 From: Rik ter Beek Date: Tue, 2 Oct 2018 15:29:45 +0200 Subject: [PATCH 27/31] add check for all checkout services (checkout + checkoutUtil) --- .../Service/AbstractCheckoutResource.php | 27 +++++++++++++++++++ src/Adyen/Service/Checkout.php | 10 ------- .../ResourceModel/Checkout/PaymentMethods.php | 4 +-- .../ResourceModel/Checkout/PaymentSession.php | 4 +-- .../ResourceModel/Checkout/Payments.php | 4 +-- .../Checkout/PaymentsDetails.php | 4 +-- .../ResourceModel/Checkout/PaymentsResult.php | 4 +-- .../CheckoutUtility/OriginKeys.php | 4 +-- 8 files changed, 39 insertions(+), 22 deletions(-) create mode 100644 src/Adyen/Service/AbstractCheckoutResource.php diff --git a/src/Adyen/Service/AbstractCheckoutResource.php b/src/Adyen/Service/AbstractCheckoutResource.php new file mode 100644 index 000000000..b323a2d1a --- /dev/null +++ b/src/Adyen/Service/AbstractCheckoutResource.php @@ -0,0 +1,27 @@ +getClient()->getConfig()->get('endpointCheckout') == null) { + $logger = $service->getClient()->getLogger(); + $msg = "You forgot to specify a unique identifier when setting the environment"; + $logger->error($msg); + throw new \Adyen\AdyenException($msg); + } + + return $service->getClient()->getConfig()->get('endpointCheckout'); + } +} \ No newline at end of file diff --git a/src/Adyen/Service/Checkout.php b/src/Adyen/Service/Checkout.php index 74b26f974..9677c94c2 100644 --- a/src/Adyen/Service/Checkout.php +++ b/src/Adyen/Service/Checkout.php @@ -19,21 +19,11 @@ class Checkout extends \Adyen\ApiKeyAuthenticatedService public function __construct(\Adyen\Client $client) { parent::__construct($client); - - // check if endpoint is set - if ($client->getConfig()->get('endpointCheckout') == null) { - $logger = $client->getLogger(); - $msg = "You forgot to specify a unique identifier when setting the environment"; - $logger->error($msg); - throw new \Adyen\AdyenException($msg); - } - $this->_paymentSession = new \Adyen\Service\ResourceModel\Checkout\PaymentSession($this); $this->_paymentsResult = new \Adyen\Service\ResourceModel\Checkout\PaymentsResult($this); $this->_paymentMethods = new \Adyen\Service\ResourceModel\Checkout\PaymentMethods($this); $this->_payments = new \Adyen\Service\ResourceModel\Checkout\Payments($this); $this->_paymentsDetails = new \Adyen\Service\ResourceModel\Checkout\PaymentsDetails($this); - } public function paymentSession($params) diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php index a9fbd7ecc..6e0b8933a 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php @@ -2,13 +2,13 @@ namespace Adyen\Service\ResourceModel\Checkout; -class PaymentMethods extends \Adyen\Service\AbstractResource +class PaymentMethods extends \Adyen\Service\AbstractCheckoutResource { protected $_endpoint; public function __construct($service) { - $this->_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutVersion() . '/paymentMethods'; + $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/paymentMethods'; parent::__construct($service, $this->_endpoint); } diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php index dcae56005..cb8bc2f31 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php @@ -2,13 +2,13 @@ namespace Adyen\Service\ResourceModel\Checkout; -class PaymentSession extends \Adyen\Service\AbstractResource +class PaymentSession extends \Adyen\Service\AbstractCheckoutResource { protected $_endpoint; public function __construct($service) { - $this->_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutVersion() . '/paymentSession'; + $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/paymentSession'; parent::__construct($service, $this->_endpoint); } diff --git a/src/Adyen/Service/ResourceModel/Checkout/Payments.php b/src/Adyen/Service/ResourceModel/Checkout/Payments.php index aa4534867..37912b599 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/Payments.php +++ b/src/Adyen/Service/ResourceModel/Checkout/Payments.php @@ -2,14 +2,14 @@ namespace Adyen\Service\ResourceModel\Checkout; -class Payments extends \Adyen\Service\AbstractResource +class Payments extends \Adyen\Service\AbstractCheckoutResource { protected $_endpoint; public function __construct($service) { - $this->_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments'; + $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments'; parent::__construct($service, $this->_endpoint); } diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php index 77672c447..97354a50b 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php @@ -2,13 +2,13 @@ namespace Adyen\Service\ResourceModel\Checkout; -class PaymentsDetails extends \Adyen\Service\AbstractResource +class PaymentsDetails extends \Adyen\Service\AbstractCheckoutResource { protected $_endpoint; public function __construct($service) { - $this->_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments/details'; + $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments/details'; parent::__construct($service, $this->_endpoint); } diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php index 09f808088..04af85399 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php @@ -2,13 +2,13 @@ namespace Adyen\Service\ResourceModel\Checkout; -class PaymentsResult extends \Adyen\Service\AbstractResource +class PaymentsResult extends \Adyen\Service\AbstractCheckoutResource { protected $_endpoint; public function __construct($service) { - $this->_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments/result'; + $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments/result'; parent::__construct($service, $this->_endpoint); } diff --git a/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php b/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php index f9ce3c607..571244e82 100644 --- a/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php +++ b/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php @@ -2,13 +2,13 @@ namespace Adyen\Service\ResourceModel\CheckoutUtility; -class OriginKeys extends \Adyen\Service\AbstractResource +class OriginKeys extends \Adyen\Service\AbstractCheckoutResource { protected $_endpoint; public function __construct($service) { - $this->_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutUtilityVersion() . '/originKeys'; + $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutUtilityVersion() . '/originKeys'; parent::__construct($service, $this->_endpoint); } From 137eb53f29c079fb627f3d0f6e50da1f07257ef5 Mon Sep 17 00:00:00 2001 From: Rik ter Beek Date: Thu, 4 Oct 2018 13:44:59 +0200 Subject: [PATCH 28/31] change error message and param name --- src/Adyen/Client.php | 4 ++-- src/Adyen/Service/AbstractCheckoutResource.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Adyen/Client.php b/src/Adyen/Client.php index c3d780da4..10b8be1a2 100644 --- a/src/Adyen/Client.php +++ b/src/Adyen/Client.php @@ -93,8 +93,8 @@ public function setXApiKey($xApiKey) * Set environment to connect to test or live platform of Adyen * For live please specify the unique identifier. * - * @param $environment - * @param null $liveEndpointUrlPrefix + * @param $environment test + * @param null $liveEndpointUrlPrefix Provide the unique live url prefix from the "API URLs and Response" menu in the Adyen Customer Area * @throws AdyenException */ public function setEnvironment($environment, $liveEndpointUrlPrefix = null) diff --git a/src/Adyen/Service/AbstractCheckoutResource.php b/src/Adyen/Service/AbstractCheckoutResource.php index b323a2d1a..a90efab17 100644 --- a/src/Adyen/Service/AbstractCheckoutResource.php +++ b/src/Adyen/Service/AbstractCheckoutResource.php @@ -17,7 +17,7 @@ public function getCheckoutEndpoint($service) // check if endpoint is set if ($service->getClient()->getConfig()->get('endpointCheckout') == null) { $logger = $service->getClient()->getLogger(); - $msg = "You forgot to specify a unique identifier when setting the environment"; + $msg = "Please provide your unique live url prefix on the setEnvironment() call on the Client or provide endpointCheckout in your config object."; $logger->error($msg); throw new \Adyen\AdyenException($msg); } From e6af2fd4ddba400046ad88a7407df248688ad92a Mon Sep 17 00:00:00 2001 From: Rik ter Beek Date: Thu, 4 Oct 2018 13:49:18 +0200 Subject: [PATCH 29/31] fix test --- tests/MockTest/CheckoutTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/MockTest/CheckoutTest.php b/tests/MockTest/CheckoutTest.php index 304b895d7..e408ca5ec 100644 --- a/tests/MockTest/CheckoutTest.php +++ b/tests/MockTest/CheckoutTest.php @@ -60,7 +60,7 @@ public function testPaymentMethodsFailureMissingIdentifierOnLive($jsonFile, $htt public static function failurePaymentMethodsMissingIdentifierOnLiveProvider() { return array( - array('tests/Resources/Checkout/payment-methods-success.json', null, 'You forgot to specify a unique identifier when setting the environment') + array('tests/Resources/Checkout/payment-methods-success.json', null, 'Please provide your unique live url prefix on the setEnvironment() call on the Client or provide endpointCheckout in your config object.') ); } From 9fb6ebcf581ff3ad611b79202ced3e1e003b50b6 Mon Sep 17 00:00:00 2001 From: Rik ter Beek Date: Thu, 4 Oct 2018 14:37:10 +0200 Subject: [PATCH 30/31] update version --- src/Adyen/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adyen/Client.php b/src/Adyen/Client.php index 10b8be1a2..4075af53a 100644 --- a/src/Adyen/Client.php +++ b/src/Adyen/Client.php @@ -8,7 +8,7 @@ class Client { - const LIB_VERSION = "1.5.0"; + const LIB_VERSION = "1.5.1"; const USER_AGENT_SUFFIX = "adyen-php-api-library/"; const ENDPOINT_TEST = "https://pal-test.adyen.com"; const ENDPOINT_LIVE = "https://pal-live.adyen.com"; From dc43ff59b5dcf3005f0e84698bcd6adc9a8635f4 Mon Sep 17 00:00:00 2001 From: Rik ter Beek Date: Thu, 4 Oct 2018 15:31:54 +0200 Subject: [PATCH 31/31] fix merge --- src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php index 98a360277..0de8c8885 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php @@ -3,7 +3,7 @@ namespace Adyen\Service\ResourceModel\Checkout; class PaymentSession extends \Adyen\Service\AbstractCheckoutResource - +{ protected $_endpoint; public function __construct($service)