From a12651295c45b0d112cb588afe9bd1ce3dca6b64 Mon Sep 17 00:00:00 2001 From: Wel Rachid Date: Thu, 3 Nov 2022 14:23:45 +0100 Subject: [PATCH 1/2] Enable dynamic endpoint Invoicing endpoint enabled. Will autoinject header --- QuickPay/API/Client.php | 14 +++++++++++++- QuickPay/API/Constants.php | 5 +++-- QuickPay/API/Request.php | 2 +- QuickPay/QuickPay.php | 4 ++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/QuickPay/API/Client.php b/QuickPay/API/Client.php index cc420e7..379378e 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); } From 189e8805608f0dc6bf453fd919e0bac097b76587 Mon Sep 17 00:00:00 2001 From: Wel Rachid Date: Wed, 9 Nov 2022 16:35:41 +0100 Subject: [PATCH 2/2] initialize as string instead of array --- QuickPay/API/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QuickPay/API/Client.php b/QuickPay/API/Client.php index 379378e..25f5d41 100644 --- a/QuickPay/API/Client.php +++ b/QuickPay/API/Client.php @@ -10,7 +10,7 @@ class Client public CurlHandle $ch; protected ?string $auth_string; protected array $headers = []; - protected string $api_url = []; + protected string $api_url = ""; public function __construct(?string $auth_string = '', array $additional_headers = [], $api_url = Constants::API_URL) {