From 553f919edcf49959f21a6e00aa6c2703d3073186 Mon Sep 17 00:00:00 2001 From: aprasker Date: Wed, 3 Jan 2018 10:00:56 +0100 Subject: [PATCH 01/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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 30b26da1ffab10c319545ea6ca4c0f41809618da Mon Sep 17 00:00:00 2001 From: Aleffio Date: Mon, 30 Apr 2018 11:17:10 +0200 Subject: [PATCH 13/14] 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 14/14] 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']);