Skip to content

Commit

Permalink
move api url param to constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
AnzePratnemerDSpot committed Jun 19, 2024
1 parent 3018206 commit 3aa36f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
23 changes: 12 additions & 11 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Client {
/**
* @var string
*/
protected static $gatewayUrl = 'https://gateway.bankart.si/';
private $gatewayUrl;

/**
* the api key given by the gateway
Expand Down Expand Up @@ -127,7 +127,8 @@ class Client {
* @param string $language
* @param bool $testMode - DEPRECATED
*/
public function __construct($username, $password, $apiKey, $sharedSecret, $language = null, $testMode = false) {
public function __construct($gatewayUrl, $username, $password, $apiKey, $sharedSecret, $language = null, $testMode = false) {
$this->gatewayUrl = $gatewayUrl;
$this->username = $username;
$this->setPassword($password);
$this->apiKey = $apiKey;
Expand Down Expand Up @@ -191,7 +192,7 @@ public function buildXml($transactionMethod, AbstractTransaction $transaction) {
*/
protected function sendTransaction($transactionMethod, AbstractTransaction $transaction) {
$xml = $this->buildXml($transactionMethod, $transaction);
$httpResponse= $this->sendRequest($xml, self::$gatewayUrl.self::TRANSACTION_ROUTE);
$httpResponse= $this->sendRequest($xml, $this->gatewayUrl.self::TRANSACTION_ROUTE);

return $this->getParser()->parseResult($httpResponse->getBody());
}
Expand Down Expand Up @@ -287,7 +288,7 @@ public function sendScheduleRequest($scheduleAction, ScheduleData $schedule) {

$scheduleXml = $this->getGenerator()->generateScheduleXml($scheduleAction, $schedule, $this->username, $this->password);

$httpResponse = $this->sendRequest($scheduleXml, self::$gatewayUrl.self::SCHEDULE_ROUTE);
$httpResponse = $this->sendRequest($scheduleXml, $this->gatewayUrl.self::SCHEDULE_ROUTE);

return $this->getParser()->parseScheduleResult($httpResponse->getBody());
}
Expand All @@ -307,7 +308,7 @@ public function sendStatusRequest(StatusRequestData $statusRequestData) {

$statusRequestXml = $this->getGenerator()->generateStatusRequestXml($statusRequestData, $this->username, $this->password);

$httpResponse = $this->sendRequest($statusRequestXml, self::$gatewayUrl.self::STATUS_ROUTE);
$httpResponse = $this->sendRequest($statusRequestXml, $this->gatewayUrl.self::STATUS_ROUTE);

return $this->getParser()->parseStatusResult($httpResponse->getBody());
}
Expand Down Expand Up @@ -372,7 +373,7 @@ protected function sendRequest($xml, $url) {
*/
protected function sendJsonApiRequest($dataArray, $path) {

$url = self::$gatewayUrl.$path;
$url = $this->gatewayUrl.$path;
$body = json_encode($dataArray);

$httpResponse = $this->signAndSendJson($body, $url, $this->username, $this->password, $this->apiKey, $this->sharedSecret);
Expand Down Expand Up @@ -1048,7 +1049,7 @@ public function getOptions($identifier, $args = null, $_ = null) {
$domDocument = $this->getGenerator()->generateOptions($this->getUsername(), $this->getPassword(), $identifier, $args);
$xml = $domDocument->saveXML();

$response = $this->signAndSendXml($xml, $this->apiKey, $this->sharedSecret, self::$gatewayUrl.self::OPTIONS_ROUTE);
$response = $this->signAndSendXml($xml, $this->apiKey, $this->sharedSecret, $this->gatewayUrl.self::OPTIONS_ROUTE);

if ($response->getErrorCode() || $response->getErrorMessage()) {
throw new ClientException('Request failed: ' . $response->getErrorCode() . ' ' . $response->getErrorMessage());
Expand Down Expand Up @@ -1111,7 +1112,7 @@ private function hashPassword($password) {
*
* @internal
*/
public static function setApiUrl($url) {
public function setApiUrl($url) {
if (empty($url)) {
throw new InvalidValueException('The URL to the Gateway can not be empty!');
}
Expand All @@ -1120,16 +1121,16 @@ public static function setApiUrl($url) {
throw new InvalidValueException('The URL to the Gateway should be a valid URL!');
}

static::$gatewayUrl = $url;
$this->gatewayUrl = $url;
}

/**
* Retrieves the currently set API URL.
*
* @return string
*/
public static function getApiUrl() {
return static::$gatewayUrl;
public function getApiUrl() {
return $this->gatewayUrl;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Xml/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Generator {
/**
* @var string
*/
protected $namespaceRoot = 'http://gateway.bankart.si';
protected $namespaceRoot = 'https://bankart.paymentsandbox.cloud/';

/**
* @param string $namespaceRoot
Expand Down

0 comments on commit 3aa36f3

Please sign in to comment.