From 1c34f1d8d8a8ca52dc0bb1bc3be91f7af3d31f34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Thing=20Andersen?= Date: Wed, 3 May 2017 11:06:27 +0200 Subject: [PATCH 1/3] Possibility to use the invoicing API for resellers. --- QuickPay/API/Client.php | 35 +++++++++++++++++++++++++++++------ QuickPay/API/Constants.php | 7 ++++++- QuickPay/API/Request.php | 3 ++- QuickPay/QuickPay.php | 23 ++++++++++++----------- 4 files changed, 49 insertions(+), 19 deletions(-) diff --git a/QuickPay/API/Client.php b/QuickPay/API/Client.php index 3cad955..cdd5763 100644 --- a/QuickPay/API/Client.php +++ b/QuickPay/API/Client.php @@ -18,6 +18,13 @@ class Client */ public $ch; + /** + * Base url for the selected API. + * + * @var string + */ + public $base_url; + /** * Contains the authentication string * @@ -31,8 +38,11 @@ class Client * Instantiate object * * @access public - */ - public function __construct($auth_string = '') + * @param string $auth_string Format 'username:password' or ':apiKey' + * @param string $base_url The API to call. Use on of the constants. + * @throws Exception + */ + public function __construct($auth_string = '', $base_url = Constants::API_URL) { // Check if lib cURL is enabled if (!function_exists('curl_init')) { @@ -42,6 +52,9 @@ public function __construct($auth_string = '') // Set auth string property $this->auth_string = $auth_string; + // Set base url of selected API + $this->base_url = $base_url; + // Instantiate cURL object $this->authenticate(); } @@ -71,10 +84,20 @@ protected function authenticate() { $this->ch = curl_init(); - $headers = array( - 'Accept-Version: v10', - 'Accept: application/json', - ); + $headers = array(); + switch ($this->base_url) { + case Constants::API_URL_INVOICING: + $headers[] = 'Accept: application/vnd.api+json'; + break; + + case Constants::API_URL: + $headers[] = 'Accept-Version: v' . Constants::API_VERSION; + $headers[] = 'Accept: application/json'; + break; + + default: + break; + } if (!empty($this->auth_string)) { $headers[] = 'Authorization: Basic ' . base64_encode($this->auth_string); diff --git a/QuickPay/API/Constants.php b/QuickPay/API/Constants.php index ecbe5b2..4c53231 100644 --- a/QuickPay/API/Constants.php +++ b/QuickPay/API/Constants.php @@ -12,8 +12,13 @@ class Constants { /** - * API DEFINITIONS + * Primary API */ const API_URL = 'https://api.quickpay.net/'; const API_VERSION = '10'; + + /** + * Invoicing API + */ + const API_URL_INVOICING = 'https://invoicing.quickpay.net/'; } diff --git a/QuickPay/API/Request.php b/QuickPay/API/Request.php index e3a3f2a..948cc1d 100644 --- a/QuickPay/API/Request.php +++ b/QuickPay/API/Request.php @@ -18,6 +18,7 @@ class Request * Contains QuickPay_Client instance * * @access protected + * @var Client */ protected $client; @@ -139,7 +140,7 @@ public function delete($path, $form = array()) */ protected function setUrl($params) { - curl_setopt($this->client->ch, CURLOPT_URL, Constants::API_URL . trim($params, '/')); + curl_setopt($this->client->ch, CURLOPT_URL, $this->client->base_url . trim($params, '/')); } /** diff --git a/QuickPay/QuickPay.php b/QuickPay/QuickPay.php index 98ba3f3..e1314b3 100644 --- a/QuickPay/QuickPay.php +++ b/QuickPay/QuickPay.php @@ -14,18 +14,19 @@ class QuickPay public $request; /** - * __construct function. - * - * Instantiates the main class. - * Creates a client which is passed to the request construct. - * - * @auth_string string Authentication string for QuickPay - * - * @access public - */ - public function __construct($auth_string = '') + * __construct function. + * + * Instantiates the main class. + * Creates a client which is passed to the request construct. + * + * @param string $auth_string Authentication string for QuickPay. Format 'username:password' or ':apiKey' + * @param string $base_url Optional: Use a secondary API (eg billing) + * + * @access public + */ + public function __construct($auth_string = '', $base_url = \QuickPay\API\Constants::API_URL) { - $client = new Client($auth_string); + $client = new Client($auth_string, $base_url); $this->request = new Request($client); } } From 4ab3cefc85e3180891e74cdcf8f62142fbe138b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Thing=20Andersen?= Date: Wed, 3 May 2017 11:30:28 +0200 Subject: [PATCH 2/3] TAB => Space --- QuickPay/API/Client.php | 44 +++++++++++++++++++------------------- QuickPay/API/Constants.php | 8 +++---- QuickPay/QuickPay.php | 4 ++-- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/QuickPay/API/Client.php b/QuickPay/API/Client.php index cdd5763..9f4d58b 100644 --- a/QuickPay/API/Client.php +++ b/QuickPay/API/Client.php @@ -18,11 +18,11 @@ class Client */ public $ch; - /** - * Base url for the selected API. - * - * @var string - */ + /** + * Base url for the selected API. + * + * @var string + */ public $base_url; /** @@ -38,10 +38,10 @@ class Client * Instantiate object * * @access public - * @param string $auth_string Format 'username:password' or ':apiKey' - * @param string $base_url The API to call. Use on of the constants. - * @throws Exception - */ + * @param string $auth_string Format 'username:password' or ':apiKey' + * @param string $base_url The API to call. Use on of the constants. + * @throws Exception + */ public function __construct($auth_string = '', $base_url = Constants::API_URL) { // Check if lib cURL is enabled @@ -53,7 +53,7 @@ public function __construct($auth_string = '', $base_url = Constants::API_URL) $this->auth_string = $auth_string; // Set base url of selected API - $this->base_url = $base_url; + $this->base_url = $base_url; // Instantiate cURL object $this->authenticate(); @@ -84,20 +84,20 @@ protected function authenticate() { $this->ch = curl_init(); - $headers = array(); - switch ($this->base_url) { - case Constants::API_URL_INVOICING: - $headers[] = 'Accept: application/vnd.api+json'; - break; + $headers = array(); + switch ($this->base_url) { + case Constants::API_URL_INVOICING: + $headers[] = 'Accept: application/vnd.api+json'; + break; - case Constants::API_URL: - $headers[] = 'Accept-Version: v' . Constants::API_VERSION; - $headers[] = 'Accept: application/json'; - break; + case Constants::API_URL: + $headers[] = 'Accept-Version: v' . Constants::API_VERSION; + $headers[] = 'Accept: application/json'; + break; - default: - break; - } + default: + break; + } if (!empty($this->auth_string)) { $headers[] = 'Authorization: Basic ' . base64_encode($this->auth_string); diff --git a/QuickPay/API/Constants.php b/QuickPay/API/Constants.php index 4c53231..4e60325 100644 --- a/QuickPay/API/Constants.php +++ b/QuickPay/API/Constants.php @@ -17,8 +17,8 @@ class Constants const API_URL = 'https://api.quickpay.net/'; const API_VERSION = '10'; - /** - * Invoicing API - */ - const API_URL_INVOICING = 'https://invoicing.quickpay.net/'; + /** + * Invoicing API + */ + const API_URL_INVOICING = 'https://invoicing.quickpay.net/'; } diff --git a/QuickPay/QuickPay.php b/QuickPay/QuickPay.php index e1314b3..8c0f24f 100644 --- a/QuickPay/QuickPay.php +++ b/QuickPay/QuickPay.php @@ -19,8 +19,8 @@ class QuickPay * Instantiates the main class. * Creates a client which is passed to the request construct. * - * @param string $auth_string Authentication string for QuickPay. Format 'username:password' or ':apiKey' - * @param string $base_url Optional: Use a secondary API (eg billing) + * @param string $auth_string Authentication string for QuickPay. Format 'username:password' or ':apiKey' + * @param string $base_url Optional: Use a secondary API (eg billing) * * @access public */ From e74a02f78607e2e378cb4b215f90efa6076e24bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Thing=20Andersen?= Date: Wed, 3 May 2017 11:33:29 +0200 Subject: [PATCH 3/3] Mere TAB => Space --- QuickPay/API/Client.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/QuickPay/API/Client.php b/QuickPay/API/Client.php index 9f4d58b..8a17980 100644 --- a/QuickPay/API/Client.php +++ b/QuickPay/API/Client.php @@ -38,8 +38,8 @@ class Client * Instantiate object * * @access public - * @param string $auth_string Format 'username:password' or ':apiKey' - * @param string $base_url The API to call. Use on of the constants. + * @param string $auth_string Format 'username:password' or ':apiKey' + * @param string $base_url The API to call. Use on of the constants. * @throws Exception */ public function __construct($auth_string = '', $base_url = Constants::API_URL)