Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable dynamic endpoint #84

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion QuickPay/API/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)) {
Expand Down
5 changes: 3 additions & 2 deletions QuickPay/API/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
2 changes: 1 addition & 1 deletion QuickPay/API/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions QuickPay/QuickPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down