Skip to content

Commit e8c5529

Browse files
committed
fix
1 parent db20990 commit e8c5529

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/ApiRequest.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,30 @@ class ApiRequest implements ApiRequestInterface
4141
/** @var bool Формат результата в режиме отладки */
4242
private bool $jsonDebugResponse = true;
4343

44+
/** @var string Хост для отправки запросов */
45+
private string $host = self::HOST;
46+
4447
/** @inheritdoc */
4548
public function __construct(MerchantInterface $merchant)
4649
{
4750
$this->merchant = $merchant;
4851
}
4952

53+
/** @inheritdoc */
5054
public function getHost() : string
5155
{
52-
if ($this->localModeIsOn) {
53-
return self::LOCAL_HOST;
56+
return $this->host;
57+
}
58+
59+
/** @inheritdoc */
60+
public function setHost(string $host) : self
61+
{
62+
if (filter_var($host, FILTER_VALIDATE_URL)) {
63+
$this->host = $host;
64+
65+
return $this;
5466
} else {
55-
return ($this->getSandboxMode() ? self::SANDBOX_HOST : self::HOST);
67+
throw new PaymentException('Некорректный URL для отправки запросов');
5668
}
5769
}
5870

@@ -162,6 +174,11 @@ private function buildReportsSourceString($parameters)
162174
return $hashString;
163175
}
164176

177+
/**
178+
* Расчет подписи для API v3
179+
* @param $parameters
180+
* @return string
181+
*/
165182
private function reportsSign($parameters)
166183
{
167184
$sourceString = $this->buildReportsSourceString($parameters);
@@ -471,6 +488,7 @@ public function setSandboxMode(bool $sandboxModeIsOn = true): self
471488
$this->setLocalMode(false);
472489
}
473490
$this->sandboxModeIsOn = $sandboxModeIsOn;
491+
$this->host = self::SANDBOX_HOST;
474492

475493
return $this;
476494
}
@@ -488,6 +506,7 @@ public function setLocalMode(bool $localModeIsOn = true): self
488506
$this->setSandboxMode(false);
489507
}
490508
$this->localModeIsOn = $localModeIsOn;
509+
$this->host = self::LOCAL_HOST;
491510

492511
return $this;
493512
}

src/ApiRequestInterface.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,14 @@ public function sendReportChartUpdateRequest(array $params);
117117
* @param array $params
118118
*/
119119
public function sendReportGeneralRequest(array $params);
120+
121+
/** @return string Хост для отправки запросов */
122+
public function getHost() : string;
123+
124+
/**
125+
* @param string $host Хост для отправки запросов
126+
* @return $this
127+
* @throws PaymentException
128+
*/
129+
public function setHost(string $host) : self;
120130
}

0 commit comments

Comments
 (0)