diff --git a/src/Adyen/Client.php b/src/Adyen/Client.php index 804bfd38f..4075af53a 100644 --- a/src/Adyen/Client.php +++ b/src/Adyen/Client.php @@ -8,20 +8,22 @@ class Client { - const LIB_VERSION = "1.5.0"; + const LIB_VERSION = "1.5.1"; const USER_AGENT_SUFFIX = "adyen-php-api-library/"; const ENDPOINT_TEST = "https://pal-test.adyen.com"; const ENDPOINT_LIVE = "https://pal-live.adyen.com"; + const ENDPOINT_LIVE_SUFFIX = "-pal-live.adyenpayments.com"; const ENDPOINT_TEST_DIRECTORY_LOOKUP = "https://test.adyen.com/hpp/directory/v2.shtml"; const ENDPOINT_LIVE_DIRECTORY_LOOKUP = "https://live.adyen.com/hpp/directory/v2.shtml"; const API_VERSION = "v30"; const API_RECURRING_VERSION = "v25"; const API_CHECKOUT_VERSION = "v32"; const API_CHECKOUT_UTILITY_VERSION = "v1"; - const TERMINAL_CLOUD_TEST = "https://terminal-api-test.adyen.com"; - const TERMINAL_CLOUD_LIVE = "https://terminal-api-live.adyen.com"; - const ENDPOINT_CHECKOUT_TEST = "https://checkout-test.adyen.com"; - const ENDPOINT_CHECKOUT_LIVE = "https://checkout-live.adyen.com"; + const ENDPOINT_TERMINAL_CLOUD_TEST = "https://terminal-api-test.adyen.com"; + const ENDPOINT_TERMINAL_CLOUD_LIVE = "https://terminal-api-live.adyen.com"; + const ENDPOINT_CHECKOUT_TEST = "https://checkout-test.adyen.com/checkout"; + const ENDPOINT_CHECKOUT_LIVE_SUFFIX = "-checkout-live.adyenpayments.com/checkout"; + const ENDPOINT_PROTOCOL = "https://"; /** * @var Adyen_Config $config @@ -89,24 +91,32 @@ public function setXApiKey($xApiKey) /** * Set environment to connect to test or live platform of Adyen + * For live please specify the unique identifier. * - * @param $environment + * @param $environment test + * @param null $liveEndpointUrlPrefix Provide the unique live url prefix from the "API URLs and Response" menu in the Adyen Customer Area * @throws AdyenException */ - public function setEnvironment($environment) + public function setEnvironment($environment, $liveEndpointUrlPrefix = null) { if ($environment == \Adyen\Environment::TEST) { $this->_config->set('environment', \Adyen\Environment::TEST); $this->_config->set('endpoint', self::ENDPOINT_TEST); $this->_config->set('endpointDirectorylookup', self::ENDPOINT_TEST_DIRECTORY_LOOKUP); - $this->_config->set('endpointTerminalCloud', self::TERMINAL_CLOUD_TEST); + $this->_config->set('endpointTerminalCloud', self::ENDPOINT_TERMINAL_CLOUD_TEST); $this->_config->set('endpointCheckout', self::ENDPOINT_CHECKOUT_TEST); } elseif ($environment == \Adyen\Environment::LIVE) { $this->_config->set('environment', \Adyen\Environment::LIVE); - $this->_config->set('endpoint', self::ENDPOINT_LIVE); $this->_config->set('endpointDirectorylookup', self::ENDPOINT_LIVE_DIRECTORY_LOOKUP); - $this->_config->set('endpointTerminalCloud', self::TERMINAL_CLOUD_LIVE); - $this->_config->set('endpointCheckout', self::ENDPOINT_CHECKOUT_LIVE); + $this->_config->set('endpointTerminalCloud', self::ENDPOINT_TERMINAL_CLOUD_LIVE); + + if ($liveEndpointUrlPrefix) { + $this->_config->set('endpoint', self::ENDPOINT_PROTOCOL . $liveEndpointUrlPrefix . self::ENDPOINT_LIVE_SUFFIX); + $this->_config->set('endpointCheckout', self::ENDPOINT_PROTOCOL . $liveEndpointUrlPrefix . self::ENDPOINT_CHECKOUT_LIVE_SUFFIX); + } else { + $this->_config->set('endpoint', self::ENDPOINT_LIVE); + $this->_config->set('endpointCheckout', null); // not supported please specify unique identifier + } } else { // environment does not exist $msg = "This environment does not exist, use " . \Adyen\Environment::TEST . ' or ' . \Adyen\Environment::LIVE; diff --git a/src/Adyen/Service/AbstractCheckoutResource.php b/src/Adyen/Service/AbstractCheckoutResource.php new file mode 100644 index 000000000..a90efab17 --- /dev/null +++ b/src/Adyen/Service/AbstractCheckoutResource.php @@ -0,0 +1,27 @@ +getClient()->getConfig()->get('endpointCheckout') == null) { + $logger = $service->getClient()->getLogger(); + $msg = "Please provide your unique live url prefix on the setEnvironment() call on the Client or provide endpointCheckout in your config object."; + $logger->error($msg); + throw new \Adyen\AdyenException($msg); + } + + return $service->getClient()->getConfig()->get('endpointCheckout'); + } +} \ No newline at end of file diff --git a/src/Adyen/Service/Checkout.php b/src/Adyen/Service/Checkout.php index a892db61d..9677c94c2 100644 --- a/src/Adyen/Service/Checkout.php +++ b/src/Adyen/Service/Checkout.php @@ -11,16 +11,19 @@ class Checkout extends \Adyen\ApiKeyAuthenticatedService protected $_payments; protected $_paymentsDetails; + /** + * Checkout constructor. + * @param \Adyen\Client $client + * @throws \Adyen\AdyenException + */ public function __construct(\Adyen\Client $client) { parent::__construct($client); - $this->_paymentSession = new \Adyen\Service\ResourceModel\Checkout\PaymentSession($this); $this->_paymentsResult = new \Adyen\Service\ResourceModel\Checkout\PaymentsResult($this); $this->_paymentMethods = new \Adyen\Service\ResourceModel\Checkout\PaymentMethods($this); $this->_payments = new \Adyen\Service\ResourceModel\Checkout\Payments($this); $this->_paymentsDetails = new \Adyen\Service\ResourceModel\Checkout\PaymentsDetails($this); - } public function paymentSession($params) diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php index a9fbd7ecc..6e0b8933a 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentMethods.php @@ -2,13 +2,13 @@ namespace Adyen\Service\ResourceModel\Checkout; -class PaymentMethods extends \Adyen\Service\AbstractResource +class PaymentMethods extends \Adyen\Service\AbstractCheckoutResource { protected $_endpoint; public function __construct($service) { - $this->_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutVersion() . '/paymentMethods'; + $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/paymentMethods'; parent::__construct($service, $this->_endpoint); } diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php index dcae56005..0de8c8885 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentSession.php @@ -2,14 +2,13 @@ namespace Adyen\Service\ResourceModel\Checkout; -class PaymentSession extends \Adyen\Service\AbstractResource +class PaymentSession extends \Adyen\Service\AbstractCheckoutResource { protected $_endpoint; public function __construct($service) { - $this->_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutVersion() . '/paymentSession'; + $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/paymentSession'; parent::__construct($service, $this->_endpoint); } - -} +} \ No newline at end of file diff --git a/src/Adyen/Service/ResourceModel/Checkout/Payments.php b/src/Adyen/Service/ResourceModel/Checkout/Payments.php index aa4534867..b23713b3b 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/Payments.php +++ b/src/Adyen/Service/ResourceModel/Checkout/Payments.php @@ -2,15 +2,14 @@ namespace Adyen\Service\ResourceModel\Checkout; -class Payments extends \Adyen\Service\AbstractResource +class Payments extends \Adyen\Service\AbstractCheckoutResource { protected $_endpoint; public function __construct($service) { - $this->_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments'; + $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments'; parent::__construct($service, $this->_endpoint); } - -} +} \ No newline at end of file diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php index 77672c447..97354a50b 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentsDetails.php @@ -2,13 +2,13 @@ namespace Adyen\Service\ResourceModel\Checkout; -class PaymentsDetails extends \Adyen\Service\AbstractResource +class PaymentsDetails extends \Adyen\Service\AbstractCheckoutResource { protected $_endpoint; public function __construct($service) { - $this->_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments/details'; + $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments/details'; parent::__construct($service, $this->_endpoint); } diff --git a/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php b/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php index 09f808088..04af85399 100644 --- a/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php +++ b/src/Adyen/Service/ResourceModel/Checkout/PaymentsResult.php @@ -2,13 +2,13 @@ namespace Adyen\Service\ResourceModel\Checkout; -class PaymentsResult extends \Adyen\Service\AbstractResource +class PaymentsResult extends \Adyen\Service\AbstractCheckoutResource { protected $_endpoint; public function __construct($service) { - $this->_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments/result'; + $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutVersion() . '/payments/result'; parent::__construct($service, $this->_endpoint); } diff --git a/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php b/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php index f9ce3c607..571244e82 100644 --- a/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php +++ b/src/Adyen/Service/ResourceModel/CheckoutUtility/OriginKeys.php @@ -2,13 +2,13 @@ namespace Adyen\Service\ResourceModel\CheckoutUtility; -class OriginKeys extends \Adyen\Service\AbstractResource +class OriginKeys extends \Adyen\Service\AbstractCheckoutResource { protected $_endpoint; public function __construct($service) { - $this->_endpoint = $service->getClient()->getConfig()->get('endpointCheckout') .'/'. $service->getClient()->getApiCheckoutUtilityVersion() . '/originKeys'; + $this->_endpoint = $this->getCheckoutEndpoint($service) .'/'. $service->getClient()->getApiCheckoutUtilityVersion() . '/originKeys'; parent::__construct($service, $this->_endpoint); } diff --git a/tests/MockTest/CheckoutTest.php b/tests/MockTest/CheckoutTest.php index 72a9e7430..e408ca5ec 100644 --- a/tests/MockTest/CheckoutTest.php +++ b/tests/MockTest/CheckoutTest.php @@ -30,7 +30,37 @@ public function testPaymentMethodsSuccess($jsonFile, $httpStatus) public static function successPaymentMethodsProvider() { return array( - array('tests/Resources/Checkout/payment-methods-success.json', 200), + array('tests/Resources/Checkout/payment-methods-success.json', 200) + ); + } + + /** + * @param $jsonFile + * @param $httpStatus + * @param $expectedExceptionMessage + * @throws \Adyen\AdyenException + * @dataProvider failurePaymentMethodsMissingIdentifierOnLiveProvider + */ + public function testPaymentMethodsFailureMissingIdentifierOnLive($jsonFile, $httpStatus, $expectedExceptionMessage) + { + // create Checkout client + $client = $this->createMockClient($jsonFile, $httpStatus); + $client->setEnvironment(\Adyen\Environment::LIVE); + + try { + $service = new \Adyen\Service\Checkout($client); + $params = array('merchantAccount' => "YourMerchantAccount"); + $service->paymentMethods($params); + } catch (\Exception $e) { + $this->assertInstanceOf('Adyen\AdyenException', $e); + $this->assertContains($expectedExceptionMessage, $e->getMessage()); + } + } + + public static function failurePaymentMethodsMissingIdentifierOnLiveProvider() + { + return array( + array('tests/Resources/Checkout/payment-methods-success.json', null, 'Please provide your unique live url prefix on the setEnvironment() call on the Client or provide endpointCheckout in your config object.') ); } @@ -39,7 +69,6 @@ public static function successPaymentMethodsProvider() * @param $httpStatus * @param $expectedExceptionMessage * @dataProvider failurePaymentMethodsProvider - * */ public function testPaymentMethodsFailure($jsonFile, $httpStatus, $expectedExceptionMessage) {