From 8eb49cbfe0374dbc17272cd745698ad443f57605 Mon Sep 17 00:00:00 2001 From: Aleffio Date: Fri, 4 May 2018 09:41:21 +0200 Subject: [PATCH 01/11] PW-421: Adding Checkout and Checkout Utility support, modified CurlClient to make it testable --- src/Adyen/Client.php | 64 ++++++++++++++----- src/Adyen/HttpClient/CurlClient.php | 11 +++- src/Adyen/Service.php | 2 +- src/Adyen/Service/AbstractResource.php | 2 +- src/Adyen/Service/Checkout.php | 58 +++++++++++++++++ src/Adyen/Service/CheckoutUtility.php | 25 ++++++++ .../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 ++++++ 12 files changed, 269 insertions(+), 22 deletions(-) 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 diff --git a/src/Adyen/Client.php b/src/Adyen/Client.php index 6a604e91f..651c049b1 100644 --- a/src/Adyen/Client.php +++ b/src/Adyen/Client.php @@ -8,16 +8,22 @@ class Client { - const LIB_VERSION = "1.4.2"; - const USER_AGENT_SUFFIX = "adyen-php-api-library/"; - const ENDPOINT_TEST = "https://pal-test.adyen.com"; - const ENDPOINT_LIVE = "https://pal-live.adyen.com"; - const ENPOINT_TEST_DIRECTORY_LOOKUP = "https://test.adyen.com/hpp/directory/v2.shtml"; - 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"; + const LIB_VERSION = "1.4.2"; + 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_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_CHECKOUT_UTILITY_TEST = "https://checkout-test.adyen.com/checkoutUtility"; + const ENDPOINT_CHECKOUT_UTILITY_LIVE = "https://checkout-live.adyen.com/checkoutUtility"; /** * @var Adyen_Config $config @@ -40,7 +46,7 @@ public function __construct($config = null) if (!$config) { // create config $this->_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 +97,23 @@ 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); + $this->_config->set('endpointCheckoutUtility', self::ENDPOINT_CHECKOUT_UTILITY_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); + $this->_config->set('endpointCheckoutUtility', self::ENDPOINT_CHECKOUT_UTILITY_LIVE); } else { // environment does not exists - $msg = "This environment does not exists use " . \Adyen\Environment::TEST . ' or ' . \Adyen\Environment::LIVE; + $msg = "This environment does not exist, use " . \Adyen\Environment::TEST . ' or ' . \Adyen\Environment::LIVE; throw new \Adyen\AdyenException($msg); } } @@ -133,7 +143,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 +199,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..3e6d8230e 100644 --- a/src/Adyen/HttpClient/CurlClient.php +++ b/src/Adyen/HttpClient/CurlClient.php @@ -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..78fd9ef46 100644 --- a/src/Adyen/Service.php +++ b/src/Adyen/Service.php @@ -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); } diff --git a/src/Adyen/Service/AbstractResource.php b/src/Adyen/Service/AbstractResource.php index 8fafb2358..ed11ebf6b 100644 --- a/src/Adyen/Service/AbstractResource.php +++ b/src/Adyen/Service/AbstractResource.php @@ -38,7 +38,7 @@ public function request($params) // validate the request parameters $this->_validate($params); - $curlClient = $this->_service->getClient()->getHttpClient(); + $curlClient = $this->_service->getClient()->getHttpClient(); //mockthis return $curlClient->requestJson($this->_service, $this->_endpoint, $params); } diff --git a/src/Adyen/Service/Checkout.php b/src/Adyen/Service/Checkout.php new file mode 100644 index 000000000..894f23b0e --- /dev/null +++ b/src/Adyen/Service/Checkout.php @@ -0,0 +1,58 @@ +_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); + $this->_supportsXAPIKey = true; + + } + + 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..cd8210c83 --- /dev/null +++ b/src/Adyen/Service/CheckoutUtility.php @@ -0,0 +1,25 @@ +_originKeys = new \Adyen\Service\ResourceModel\CheckoutUtility\OriginKeys($this); + $this->_supportsXAPIKey = true; + + } + + public function originKeys($params) + { + $result = $this->_originKeys->request($params); + return $result; + } + +} \ No newline at end of file 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..48e015d64 --- /dev/null +++ b/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php @@ -0,0 +1,20 @@ +_endpoint = $service->getClient()->getConfig()->get('endpointCheckoutUtility') .'/'. $service->getClient()->getApiCheckoutUtilityVersion() . '/originKeys'; + parent::__construct($service, $this->_endpoint, $this->_requiredFields); + } + +} From 017db8fd9cb8bdd2aee1b8066d1ef8b0d0baee95 Mon Sep 17 00:00:00 2001 From: Aleffio Date: Fri, 4 May 2018 09:49:20 +0200 Subject: [PATCH 02/11] PW-241: fixed failing test --- tests/ExceptionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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()); } From 27098220996d9ac52e9abf0334ae86445f8972b3 Mon Sep 17 00:00:00 2001 From: Aleffio Date: Fri, 4 May 2018 11:46:21 +0200 Subject: [PATCH 03/11] PW-421: removed comment --- src/Adyen/Service/AbstractResource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adyen/Service/AbstractResource.php b/src/Adyen/Service/AbstractResource.php index ed11ebf6b..8fafb2358 100644 --- a/src/Adyen/Service/AbstractResource.php +++ b/src/Adyen/Service/AbstractResource.php @@ -38,7 +38,7 @@ public function request($params) // validate the request parameters $this->_validate($params); - $curlClient = $this->_service->getClient()->getHttpClient(); //mockthis + $curlClient = $this->_service->getClient()->getHttpClient(); return $curlClient->requestJson($this->_service, $this->_endpoint, $params); } From 694698fb3ea2959554440256a1902061c2b06c62 Mon Sep 17 00:00:00 2001 From: Aleffio Date: Tue, 8 May 2018 10:30:09 +0200 Subject: [PATCH 04/11] PW-421: include Checkout unit tests, simplified CheckoutUtility endpoint --- phpunit.xml | 2 +- src/Adyen/Client.php | 6 +- .../CheckoutUtility/OriginKeys.php | 2 +- tests/MockTest/CheckoutTest.php | 281 +++++++++++++++ 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 | 2 +- 18 files changed, 1112 insertions(+), 8 deletions(-) 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/phpunit.xml b/phpunit.xml index a27aa3298..bd4a46764 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,7 +1,7 @@ - tests + tests/MockTest diff --git a/src/Adyen/Client.php b/src/Adyen/Client.php index 651c049b1..35f2471cb 100644 --- a/src/Adyen/Client.php +++ b/src/Adyen/Client.php @@ -22,8 +22,6 @@ class Client 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_CHECKOUT_UTILITY_TEST = "https://checkout-test.adyen.com/checkoutUtility"; - const ENDPOINT_CHECKOUT_UTILITY_LIVE = "https://checkout-live.adyen.com/checkoutUtility"; /** * @var Adyen_Config $config @@ -103,16 +101,14 @@ public function setEnvironment($environment) $this->_config->set('endpointDirectorylookup', self::ENDPOINT_TEST_DIRECTORY_LOOKUP); $this->_config->set('endpointTerminalCloud', self::TERMINAL_CLOUD_TEST); $this->_config->set('endpointCheckout', self::ENDPOINT_CHECKOUT_TEST); - $this->_config->set('endpointCheckoutUtility', self::ENDPOINT_CHECKOUT_UTILITY_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('endpointCheckoutUtility', self::ENDPOINT_CHECKOUT_UTILITY_LIVE); } else { - // environment does not exists + // environment does not exist $msg = "This environment does not exist, use " . \Adyen\Environment::TEST . ' or ' . \Adyen\Environment::LIVE; throw new \Adyen\AdyenException($msg); } diff --git a/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php b/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php index 48e015d64..1d36fe683 100644 --- a/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php +++ b/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php @@ -13,7 +13,7 @@ class OriginKeys extends \Adyen\Service\AbstractResource public function __construct($service) { - $this->_endpoint = $service->getClient()->getConfig()->get('endpointCheckoutUtility') .'/'. $service->getClient()->getApiCheckoutUtilityVersion() . '/originKeys'; + $this->_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutUtilityVersion() . '/originKeys'; parent::__construct($service, $this->_endpoint, $this->_requiredFields); } diff --git a/tests/MockTest/CheckoutTest.php b/tests/MockTest/CheckoutTest.php new file mode 100644 index 000000000..16bcd1f7e --- /dev/null +++ b/tests/MockTest/CheckoutTest.php @@ -0,0 +1,281 @@ +createCheckoutMockClient($jsonFile, $httpStatus); + + // initialize service + $service = new \Adyen\Service\Checkout($client); + + $params = array('merchantAccount' => $this->_merchantAccount); + $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' => $this->_merchantAccount); + try { + $result = $service->paymentMethods($params); + } 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' => $this->_merchantAccount, + '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' => $this->_merchantAccount, + '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); + } 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' => $this->_merchantAccount, + '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' => $this->_merchantAccount, + '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..ecf3bd909 --- /dev/null +++ b/tests/MockTest/TestCaseMock.php @@ -0,0 +1,27 @@ +getMockBuilder(\Adyen\HttpClient\CurlClient::class) + ->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..5ffaca88b 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,3 +1,3 @@ Date: Tue, 8 May 2018 10:41:48 +0200 Subject: [PATCH 05/11] PW-421: Added ApiKeyAuthenticatedService and renamed supportsXAPIKey to requiresApiKey --- src/Adyen/ApiKeyAuthenticatedService.php | 21 +++++++++++++++++++++ src/Adyen/HttpClient/CurlClient.php | 4 ++-- src/Adyen/Service.php | 6 +++--- src/Adyen/Service/Checkout.php | 3 +-- src/Adyen/Service/CheckoutUtility.php | 3 +-- src/Adyen/Service/PosPayment.php | 3 +-- 6 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 src/Adyen/ApiKeyAuthenticatedService.php diff --git a/src/Adyen/ApiKeyAuthenticatedService.php b/src/Adyen/ApiKeyAuthenticatedService.php new file mode 100644 index 000000000..ee4bb3cbc --- /dev/null +++ b/src/Adyen/ApiKeyAuthenticatedService.php @@ -0,0 +1,21 @@ +_requiresApiKey = true; + } +} \ No newline at end of file diff --git a/src/Adyen/HttpClient/CurlClient.php b/src/Adyen/HttpClient/CurlClient.php index 3e6d8230e..d70fd8a0f 100644 --- a/src/Adyen/HttpClient/CurlClient.php +++ b/src/Adyen/HttpClient/CurlClient.php @@ -47,10 +47,10 @@ 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)) { + } elseif ($service->requiresApiKey() && empty($xApiKey)) { $msg = "Please insert a valid Checkout API Key in your test.ini file"; throw new \Adyen\AdyenException($msg); } else { diff --git a/src/Adyen/Service.php b/src/Adyen/Service.php index 78fd9ef46..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) { @@ -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 index 894f23b0e..25edaf2bf 100644 --- a/src/Adyen/Service/Checkout.php +++ b/src/Adyen/Service/Checkout.php @@ -3,7 +3,7 @@ namespace Adyen\Service; -class Checkout extends \Adyen\Service +class Checkout extends \Adyen\ApiKeyAuthenticatedService { protected $_setup; protected $_verify; @@ -20,7 +20,6 @@ public function __construct(\Adyen\Client $client) $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); - $this->_supportsXAPIKey = true; } diff --git a/src/Adyen/Service/CheckoutUtility.php b/src/Adyen/Service/CheckoutUtility.php index cd8210c83..e4b75b783 100644 --- a/src/Adyen/Service/CheckoutUtility.php +++ b/src/Adyen/Service/CheckoutUtility.php @@ -3,7 +3,7 @@ namespace Adyen\Service; -class CheckoutUtility extends \Adyen\Service +class CheckoutUtility extends \Adyen\ApiKeyAuthenticatedService { protected $_originKeys; @@ -12,7 +12,6 @@ public function __construct(\Adyen\Client $client) parent::__construct($client); $this->_originKeys = new \Adyen\Service\ResourceModel\CheckoutUtility\OriginKeys($this); - $this->_supportsXAPIKey = true; } 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) From 3b5b9c93c33bf715b8f790a38a7e61f5c4b46859 Mon Sep 17 00:00:00 2001 From: Aleffio Date: Tue, 8 May 2018 10:42:45 +0200 Subject: [PATCH 06/11] PW-421: removed phpstorm comment --- src/Adyen/ApiKeyAuthenticatedService.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Adyen/ApiKeyAuthenticatedService.php b/src/Adyen/ApiKeyAuthenticatedService.php index ee4bb3cbc..5c8cf34cb 100644 --- a/src/Adyen/ApiKeyAuthenticatedService.php +++ b/src/Adyen/ApiKeyAuthenticatedService.php @@ -1,10 +1,4 @@ Date: Tue, 8 May 2018 11:01:39 +0200 Subject: [PATCH 07/11] PW-421: fix for Travis --- tests/MockTest/CheckoutTest.php | 12 ++++++------ tests/MockTest/TestCaseMock.php | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/MockTest/CheckoutTest.php b/tests/MockTest/CheckoutTest.php index 16bcd1f7e..f77e10aec 100644 --- a/tests/MockTest/CheckoutTest.php +++ b/tests/MockTest/CheckoutTest.php @@ -21,7 +21,7 @@ public function testPaymentMethodsSuccess($jsonFile, $httpStatus) // initialize service $service = new \Adyen\Service\Checkout($client); - $params = array('merchantAccount' => $this->_merchantAccount); + $params = array('merchantAccount' => "YourMerchantAccount"); $result = $service->paymentMethods($params); $this->assertArrayHasKey('paymentMethods', $result); @@ -53,7 +53,7 @@ public function testPaymentMethodsFailure($jsonFile, $httpStatus, $expectedExcep // initialize service $service = new \Adyen\Service\Checkout($client); - $params = array('merchantAccount' => $this->_merchantAccount); + $params = array('merchantAccount' => "YourMerchantAccount"); try { $result = $service->paymentMethods($params); } catch (\Exception $e) { @@ -92,7 +92,7 @@ public function testPaymentsSuccess($jsonFile, $httpStatus) $service = new \Adyen\Service\Checkout($client); $params = array( - 'merchantAccount' => $this->_merchantAccount, + 'merchantAccount' => "YourMerchantAccount", 'amount' => array('currency' => "EUR", 'value' => 1000), 'paymentMethod' => array( 'type' => "scheme", @@ -138,7 +138,7 @@ public function testPaymentsFailure($jsonFile, $httpStatus, $expectedExceptionMe $service = new \Adyen\Service\Checkout($client); $params = array( - 'merchantAccount' => $this->_merchantAccount, + 'merchantAccount' => "YourMerchantAccount", 'amount' => array('currency' => "EUR", 'value' => 1000), 'paymentMethod' => array( 'type' => "scheme", @@ -191,7 +191,7 @@ public function testPaymentsDetailsSuccess($jsonFile, $httpStatus) $service = new \Adyen\Service\Checkout($client); $params = array( - 'merchantAccount' => $this->_merchantAccount, + 'merchantAccount' => "YourMerchantAccount", 'paymentData' => 'Ab02b4c0!BQABAgCJN1wRZuGJmq8dMncmypvknj9s7l5Tj...', 'details' => array( 'MD' => 'sdfsdfsdf...', @@ -227,7 +227,7 @@ public function testSetupSuccess($jsonFile, $httpStatus) $service = new \Adyen\Service\Checkout($client); $params = array( - 'merchantAccount' => $this->_merchantAccount, + 'merchantAccount' => "YourMerchantAccount", 'amount' => array('currency' => "EUR", 'value' => 1000), 'countryCode' => "NL", 'reference' => "Your order number", diff --git a/tests/MockTest/TestCaseMock.php b/tests/MockTest/TestCaseMock.php index ecf3bd909..77db9a9e8 100644 --- a/tests/MockTest/TestCaseMock.php +++ b/tests/MockTest/TestCaseMock.php @@ -8,6 +8,7 @@ class TestCaseMock extends \PHPUnit_Framework_TestCase protected function createCheckoutMockClient($jsonFile, $httpStatus) { date_default_timezone_set('Europe/Amsterdam'); + $json = null; if ($jsonFile != null) { $json = file_get_contents($jsonFile, true); } From 3198112148f0601e4eab26616634b3451c2febe4 Mon Sep 17 00:00:00 2001 From: Aleffio Date: Tue, 8 May 2018 11:19:57 +0200 Subject: [PATCH 08/11] PW-421: fix for PHP <= 5.4 --- tests/MockTest/TestCaseMock.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/MockTest/TestCaseMock.php b/tests/MockTest/TestCaseMock.php index 77db9a9e8..657efa33f 100644 --- a/tests/MockTest/TestCaseMock.php +++ b/tests/MockTest/TestCaseMock.php @@ -7,12 +7,11 @@ class TestCaseMock extends \PHPUnit_Framework_TestCase protected function createCheckoutMockClient($jsonFile, $httpStatus) { - date_default_timezone_set('Europe/Amsterdam'); $json = null; if ($jsonFile != null) { $json = file_get_contents($jsonFile, true); } - $curlClient = $this->getMockBuilder(\Adyen\HttpClient\CurlClient::class) + $curlClient = $this->getMockBuilder(get_class(new \Adyen\HttpClient\CurlClient)) ->setMethods(array('curlRequest')) ->getMock(); $curlClient->method('curlRequest') From 50af2a84562410a3f67d8a21ee152261dae70050 Mon Sep 17 00:00:00 2001 From: Aleffio Date: Tue, 8 May 2018 15:49:11 +0200 Subject: [PATCH 09/11] PW-421: Readded previous tests, changed Checkout API key message if not provided, added fail() call to the failureTests --- phpunit.xml | 1 + src/Adyen/HttpClient/CurlClient.php | 2 +- tests/MockTest/CheckoutTest.php | 25 +++++++++++++------------ tests/bootstrap.php | 1 + 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index bd4a46764..171379cd0 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,6 +1,7 @@ + tests tests/MockTest diff --git a/src/Adyen/HttpClient/CurlClient.php b/src/Adyen/HttpClient/CurlClient.php index d70fd8a0f..ffcd86818 100644 --- a/src/Adyen/HttpClient/CurlClient.php +++ b/src/Adyen/HttpClient/CurlClient.php @@ -51,7 +51,7 @@ public function requestJson(\Adyen\Service $service, $requestUrl, $params) //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->requiresApiKey() && empty($xApiKey)) { - $msg = "Please insert a valid Checkout API Key in your test.ini file"; + $msg = "Please provide a valid Checkout API Key"; throw new \Adyen\AdyenException($msg); } else { diff --git a/tests/MockTest/CheckoutTest.php b/tests/MockTest/CheckoutTest.php index f77e10aec..b500f9388 100644 --- a/tests/MockTest/CheckoutTest.php +++ b/tests/MockTest/CheckoutTest.php @@ -4,7 +4,7 @@ class CheckoutTest extends TestCaseMock { - const NO_CHECKOUT_KEY = "Please insert a valid Checkout API Key in your test.ini file"; + const NO_CHECKOUT_KEY = "Please provide a valid Checkout API Key"; const MISSING_FIELDS = "Missing the following fields:"; /** @@ -56,13 +56,13 @@ public function testPaymentMethodsFailure($jsonFile, $httpStatus, $expectedExcep $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()); + $this->assertEquals('Adyen\AdyenException', get_class($e)); + $this->assertContains($expectedExceptionMessage, $e->getMessage()); + if ($httpStatus != null) { + $this->assertEquals($httpStatus, $e->getStatus()); + } } } @@ -156,12 +156,13 @@ public function testPaymentsFailure($jsonFile, $httpStatus, $expectedExceptionMe 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()); + $this->assertEquals('Adyen\AdyenException', get_class($e)); + $this->assertContains($expectedExceptionMessage, $e->getMessage()); + if ($httpStatus != null) { + $this->assertEquals($httpStatus, $e->getStatus()); + } } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 5ffaca88b..7880d07bb 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,3 +1,4 @@ Date: Wed, 9 May 2018 11:15:34 +0200 Subject: [PATCH 10/11] PW-421: Removed redundant line in xml --- phpunit.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index 171379cd0..a27aa3298 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,7 +2,6 @@ tests - tests/MockTest From 942c2df9d00a3a0c0f9635916e1a5d1b87795402 Mon Sep 17 00:00:00 2001 From: Aleffio Date: Wed, 9 May 2018 15:06:48 +0200 Subject: [PATCH 11/11] PW-421: Simplified ApiKeyAuthenticatedService structure --- src/Adyen/ApiKeyAuthenticatedService.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Adyen/ApiKeyAuthenticatedService.php b/src/Adyen/ApiKeyAuthenticatedService.php index 5c8cf34cb..adc0bcaaf 100644 --- a/src/Adyen/ApiKeyAuthenticatedService.php +++ b/src/Adyen/ApiKeyAuthenticatedService.php @@ -5,11 +5,5 @@ class ApiKeyAuthenticatedService extends Service { - protected $_requiresApiKey; - - public function __construct(\Adyen\Client $client) - { - parent::__construct($client); - $this->_requiresApiKey = true; - } + protected $_requiresApiKey = true; } \ No newline at end of file