Skip to content

Commit 8866746

Browse files
committed
local mode added
1 parent 6b4c939 commit 8866746

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

src/ApiRequest.php

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class ApiRequest implements ApiRequestInterface
1919
const PAYOUT_CREATE_API = '/api/v4/payout';
2020
const HOST = 'https://secure.ypmn.ru';
2121
const SANDBOX_HOST = 'https://sandbox.ypmn.ru';
22+
const LOCAL_HOST = 'http://localhost';
2223

2324

2425
/** @var MerchantInterface Мерчант, от имени которого отправляется запрос */
@@ -27,6 +28,9 @@ class ApiRequest implements ApiRequestInterface
2728
/** @var bool Режим Песочницы (тестовая панель Ypmn) */
2829
private bool $sandboxModeIsOn = false;
2930

31+
/** @var bool Режим отправки запросов на локальный хост */
32+
private bool $localModeIsOn = false;
33+
3034
/** @var bool Режим Отладки (вывод системных сообщений) */
3135
private bool $debugModeIsOn = false;
3236

@@ -45,9 +49,14 @@ private function sendGetRequest(string $api): array
4549
{
4650
$curl = curl_init();
4751
$date = (new DateTime())->format(DateTimeInterface::ATOM);
48-
$urlToPostTo = ($this->getSandboxMode() ? self::SANDBOX_HOST : self::HOST) . $api;
4952
$requestHttpVerb = 'GET';
5053

54+
if ($this->localModeIsOn) {
55+
$urlToPostTo = self::LOCAL_HOST;
56+
} else {
57+
$urlToPostTo = ($this->getSandboxMode() ? self::SANDBOX_HOST : self::HOST) . $api;
58+
}
59+
5160
$setopt_array = [
5261
CURLOPT_URL => $urlToPostTo,
5362
CURLOPT_RETURNTRANSFER => true,
@@ -138,9 +147,14 @@ private function sendPostRequest(JsonSerializable $data, string $api): array
138147

139148
$curl = curl_init();
140149
$date = (new DateTime())->format(DateTimeInterface::ATOM);
141-
$urlToPostTo = ($this->getSandboxMode() ? self::SANDBOX_HOST : self::HOST) . $api;
142150
$requestHttpVerb = 'POST';
143151

152+
if ($this->localModeIsOn) {
153+
$urlToPostTo = self::LOCAL_HOST;
154+
} else {
155+
$urlToPostTo = ($this->getSandboxMode() ? self::SANDBOX_HOST : self::HOST) . $api;
156+
}
157+
144158
curl_setopt_array($curl, [
145159
CURLOPT_URL => $urlToPostTo,
146160
CURLOPT_RETURNTRANSFER => true,
@@ -184,8 +198,10 @@ private function sendPostRequest(JsonSerializable $data, string $api): array
184198
echo '<br><a href="https://github.com/yourpayments/php-api-client/issues">Оставить заявку на улучшение</a>';
185199
echo '<br><a href="https://ypmn.ru/ru/contacts/">Контакты</a>';
186200
} else {
201+
187202
$cpanel_url = 'https://' . ($this->getSandboxMode() ? 'sandbox' : 'secure' ). '.ypmn.ru/cpanel/';
188203

204+
189205
if ($this->getSandboxMode()) {
190206
echo Std::alert([
191207
'type' => 'warning',
@@ -290,7 +306,28 @@ public function getSandboxMode(): bool
290306
/** @inheritdoc */
291307
public function setSandboxMode(bool $sandboxModeIsOn = true): self
292308
{
309+
if ($sandboxModeIsOn) {
310+
$this->setLocalMode(false);
311+
}
293312
$this->sandboxModeIsOn = $sandboxModeIsOn;
313+
314+
return $this;
315+
}
316+
317+
/** @inheritdoc */
318+
public function getLocalMode(): bool
319+
{
320+
return $this->localModeIsOn;
321+
}
322+
323+
/** @inheritdoc */
324+
public function setLocalMode(bool $localModeIsOn = true): self
325+
{
326+
if ($localModeIsOn) {
327+
$this->setSandboxMode(false);
328+
}
329+
$this->localModeIsOn = $localModeIsOn;
330+
294331
return $this;
295332
}
296333

0 commit comments

Comments
 (0)