diff --git a/QuickPay/API/Client.php b/QuickPay/API/Client.php index cc420e7..25f5d41 100644 --- a/QuickPay/API/Client.php +++ b/QuickPay/API/Client.php @@ -10,13 +10,21 @@ class Client public CurlHandle $ch; protected ?string $auth_string; protected array $headers = []; + protected string $api_url = ""; - public function __construct(?string $auth_string = '', array $additional_headers = []) + public function __construct(?string $auth_string = '', array $additional_headers = [], $api_url = Constants::API_URL) { if (!function_exists('curl_init')) { throw new GenericException('Lib cURL must be enabled on the server'); } + $this->api_url = $api_url; + if($api_url == Constants::INVOICING_API_URL){ + // no idea why, but invoicing requires this header. + $additional_headers = array_merge($additional_headers,['Accept: application/vnd.api+json']); + } + + // Save authentication string $this->auth_string = $auth_string; @@ -40,6 +48,10 @@ public function __construct(?string $auth_string = '', array $additional_headers $this->setHeaders($additional_headers); } + function getApiURL(){ + return $this->api_url; + } + public function shutdown(): void { if (!empty($this->ch)) { diff --git a/QuickPay/API/Constants.php b/QuickPay/API/Constants.php index 4fa5f76..d0b60c2 100644 --- a/QuickPay/API/Constants.php +++ b/QuickPay/API/Constants.php @@ -4,6 +4,7 @@ class Constants { - public const API_URL = 'https://api.quickpay.net/'; - public const API_VERSION = '10'; + public const API_URL = 'https://api.quickpay.net/'; + public const INVOICING_API_URL = 'https://invoicing.quickpay.net/'; + public const API_VERSION = '10'; } diff --git a/QuickPay/API/Request.php b/QuickPay/API/Request.php index 9282a7f..25ce5bc 100644 --- a/QuickPay/API/Request.php +++ b/QuickPay/API/Request.php @@ -60,7 +60,7 @@ public function delete(string $path, array $form = []): Response protected function setUrl(string $url): void { - curl_setopt($this->client->ch, CURLOPT_URL, Constants::API_URL . trim($url, '/')); + curl_setopt($this->client->ch, CURLOPT_URL, $this->client->getApiURL() . trim($url, '/')); } protected function execute(string $request_type, array $form = []): Response diff --git a/QuickPay/QuickPay.php b/QuickPay/QuickPay.php index 208659a..99b4b45 100644 --- a/QuickPay/QuickPay.php +++ b/QuickPay/QuickPay.php @@ -13,9 +13,9 @@ class QuickPay public Request $request; - public function __construct(string $auth_string = '', array $additional_headers = []) + public function __construct(string $auth_string = '', array $additional_headers = [], $api_url = Constants::API_URL) { - $client = new Client($auth_string, $additional_headers); + $client = new Client($auth_string, $additional_headers, $api_url); $this->request = new Request($client); }