diff --git a/src/Provider/Mollie.php b/src/Provider/Mollie.php index 428bc5a..daf21ab 100644 --- a/src/Provider/Mollie.php +++ b/src/Provider/Mollie.php @@ -66,25 +66,47 @@ class Mollie extends AbstractProvider /** * @var string */ - private $mollieApiUrl; + private $mollieApiUrl = self::MOLLIE_API_URL; /** * @var string */ - private $mollieWebUrl; + private $mollieWebUrl = self::MOLLIE_WEB_URL; public function __construct(array $options = [], array $collaborators = []) { + parent::__construct($options, $collaborators); + if (isset($options["clientId"]) && strpos($options["clientId"], self::CLIENT_ID_PREFIX) !== 0) { throw new \DomainException("Mollie needs the client ID to be prefixed with " . self::CLIENT_ID_PREFIX . "."); } + } - $this->mollieApiUrl = (isset($options['mollieApiUrl']) ? $options['mollieApiUrl'] : null) ?: self::MOLLIE_API_URL; - $this->mollieWebUrl = (isset($options['mollieWebUrl']) ? $options['mollieWebUrl'] : null) ?: self::MOLLIE_WEB_URL; - unset($options['mollieApiUrl'], $options['mollieWebUrl']); + /** + * Define Mollie api URL + * + * @param string $url + * @return Mollie + */ + public function setMollieApiUrl ($url) + { + $this->mollieApiUrl = $url; - parent::__construct($options, $collaborators); - } + return $this; + } + + /** + * Define Mollie web URL + * + * @param string $url + * @return Mollie + */ + public function setMollieWebUrl ($url) + { + $this->mollieWebUrl = $url; + + return $this; + } /** * Returns the base URL for authorizing a client. diff --git a/tests/src/Provider/MollieTest.php b/tests/src/Provider/MollieTest.php index 70471cc..311e2bb 100644 --- a/tests/src/Provider/MollieTest.php +++ b/tests/src/Provider/MollieTest.php @@ -217,20 +217,16 @@ public function testUserData() public function testWhenDefiningADifferentMollieApiUrlThenUseThisOnApiCalls() { - $options = array_merge(['mollieApiUrl' => 'https://api.mollie.nl'], self::OPTIONS); + $this->provider->setMollieApiUrl('https://api.mollie.nl'); - $provider = new Mollie($options); - - $this->assertEquals('https://api.mollie.nl/oauth2/tokens', $provider->getBaseAccessTokenUrl([])); + $this->assertEquals('https://api.mollie.nl/oauth2/tokens', $this->provider->getBaseAccessTokenUrl([])); } public function testWhenDefiningADifferentMollieWebUrlThenUseThisForAuthorize() { - $options = array_merge(['mollieWebUrl' => 'https://www.mollie.nl'], self::OPTIONS); - - $provider = new Mollie($options); + $this->provider->setMollieWebUrl('https://www.mollie.nl'); - list($url) = explode('?', $provider->getAuthorizationUrl()); + list($url) = explode('?', $this->provider->getAuthorizationUrl()); $this->assertEquals('https://www.mollie.nl/oauth2/authorize', $url); } }