Skip to content
Merged
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
39 changes: 38 additions & 1 deletion docs/examples/send_request_to_v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* method - HTTP метод запроса: 'POST', 'GET';
* operationName - название операции в Mindbox;
* body - тело запроса в виде DTO, необязательный параметр;
* additionalUrl - дополнительный URL, конкатенируется с базовым URL: https://api.mindbox.ru/v3/operations/{additionalUrl}, необязательный параметр;
* additionalUrl - дополнительный URL, конкатенируется с базовым URL: https://{domain}.{domainZone}/v3/operations/{additionalUrl}, необязательный параметр;
* queryParams - массив дополнительных GET параметров, необязательный параметр;
* isSync - флаг, синхронный или асинхронный запрос, по умолчанию true (синхронный), необязательный параметр;
* addDeviceUUID - флаг, добавлять ли DeviceUUID в запрос, по умолчанию true (добавляет DeviceUUID из куки mindboxDeviceUUID в query-параметры запроса и IP-адрес потребителя в заголовок X-Customer-IP), необязательный параметр.
Expand Down Expand Up @@ -46,4 +46,41 @@ try {
} catch (\Mindbox\Exceptions\MindboxClientException $e) {
echo $e->getMessage();
}
```
Для указания запроса на произвольный url mindbox следует следует использовать \Mindbox\Clients\MindboxClientV3 вместо фабрики

## Пример отправки запроса на произвольны URL к API v3
``` php
$logger = new \Mindbox\Loggers\MindboxFileLogger('{logsDir}');
$httpClient = (new \Mindbox\HttpClients\HttpClientFactory())->createHttpClient('{timeout}', '{handlerName}');

$client = new \Mindbox\Clients\MindboxClientV3(
'{endpointId}',
'{secretKey}',
$httpClient,
$logger,
'{domainZone}'
'{domain}'
);

$customer = new \Mindbox\DTO\V3\Requests\CustomerRequestDTO();
$customer->setEmail('test@test.ru');
$customer->setMobilePhone('79374134389');
$customer->setId('bitrixId', '123456');
$customer->setId('mindboxId', '1028');

$operation = new \Mindbox\DTO\V3\OperationDTO();
$operation->setCustomer($customer);

/* Формирование состава операции */
try {
$response = $client
->prepareRequest('POST', 'Website.AuthorizeCustomer', $operation, '', [], false, false)
->sendRequest();

$requestBody = $response->getRequest()->getBody();
$responseBody = $response->getBody();
} catch (\Mindbox\Exceptions\MindboxClientException $e) {
echo $e->getMessage();
}
```
55 changes: 55 additions & 0 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ require_once __DIR__ . '/path/to/mindboxSDK/vendor/autoload.php';
* endpointId - уникальный идентификатор сайта/мобильного приложения/и т.п. Значение нужно уточнить у менеджера Mindbox.
* secretKey - секретный ключ, соответствующий endpointId. Значение нужно уточнить у менеджера Mindbox.
* domain - домен, на который будут отправляться запросы к v2.1 API Mindbox: https://{domain}/v2.1/orders/.
* domainZone - доменная зона, на которую будут отправляться запросы к v3 API Mindbox: https://api.mindbox.{{domainZone}}/v3/operations/.

Опциональные параметры:
* timeout - таймаут соединения при выполнении HTTP запроса (в секундах). По умолчанию равен 5 секундам.
Expand All @@ -71,6 +72,7 @@ $logger = new \Mindbox\Loggers\MindboxFileLogger('{logsDir}');
$mindbox = new \Mindbox\Mindbox([
'endpointId' => '{endpointId}',
'secretKey' => '{secretKey}',
'domain' => '{domain}',
'domainZone' => '{domainZone}',
//'timeout' => '{timeout}',
//'httpClient' => '{httpClient}',
Expand Down Expand Up @@ -158,4 +160,57 @@ try {
} catch (\Mindbox\Exceptions\MindboxClientException $e) {
echo $e->getMessage();
}
```

## Пример отправки запроса на произвольны URL к API v3
Обязательные параметры конфигурации SDK:
* endpointId - уникальный идентификатор сайта/мобильного приложения/и т.п. Значение нужно уточнить у менеджера Mindbox.
* secretKey - секретный ключ, соответствующий endpointId. Значение нужно уточнить у менеджера Mindbox.
* timeout - таймаут соединения при выполнении HTTP запроса (в секундах). По умолчанию равен 5 секундам.
* httpClient - назвавние клиента для отправки запроса ("curl", "stream"). По умолчанию curl, если установлено расширение ext-curl, иначе stream.
* logger - объект логгера, реализующий интерфейс \Psr\Log\LoggerInterface.
* domainZone - доменная зона ("ru", "api-ru", "cloud", "io")


Опциональные параметры:
* $domain - Домен API URL ("api.mindbox", "api.s.mindbox", "api.maestra")

При передача домена, URL запроса формируется следующим образом:

https://{domain}.{domainZone}/v3/operations/


``` php
$logger = new \Mindbox\Loggers\MindboxFileLogger('{logsDir}');
$httpClient = (new \Mindbox\HttpClients\HttpClientFactory())->createHttpClient('{timeout}', '{handlerName}');

$client = new \Mindbox\Clients\MindboxClientV3(
'{endpointId}',
'{secretKey}',
$httpClient,
$logger,
'{domainZone}'
'{domain}'
);

$customer = new \Mindbox\DTO\V3\Requests\CustomerRequestDTO();
$customer->setEmail('test@test.ru');
$customer->setMobilePhone('79374134389');
$customer->setId('bitrixId', '123456');
$customer->setId('mindboxId', '1028');

$operation = new \Mindbox\DTO\V3\OperationDTO();
$operation->setCustomer($customer);

/* Формирование состава операции */
try {
$response = $client
->prepareRequest('POST', 'Website.AuthorizeCustomer', $operation, '', [], false, false)
->sendRequest();

$requestBody = $response->getRequest()->getBody();
$responseBody = $response->getBody();
} catch (\Mindbox\Exceptions\MindboxClientException $e) {
echo $e->getMessage();
}
```
38 changes: 36 additions & 2 deletions docs/structure/Mindbox-Clients-MindboxClientV3.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Constants

### BASE_V3_URL

const BASE_V3_URL = 'https://api.mindbox.ru/v3/operations/'
const BASE_V3_URL = 'https://{{url}}/v3/operations/'



Expand All @@ -43,6 +43,13 @@ Constants
Properties
----------

### $url

private string $url


* Visibility: **private**


### $endpointId

Expand Down Expand Up @@ -121,13 +128,23 @@ Properties
* Visibility: **protected**


### $headers

protected array $headers





* Visibility: **protected**

Methods
-------


### __construct

mixed Mindbox\Clients\AbstractMindboxClient::__construct(string $secretKey, \Mindbox\HttpClients\IHttpClient $httpClient, \Psr\Log\LoggerInterface $logger)
mixed Mindbox\Clients\AbstractMindboxClient::__construct(string $secretKey, \Mindbox\HttpClients\IHttpClient $httpClient, \Psr\Log\LoggerInterface $logger, string $domainZone, string $domain)

Конструктор AbstractMindboxClient.

Expand All @@ -141,6 +158,8 @@ Methods
* $secretKey **string** - <p>Секретный ключ.</p>
* $httpClient **[Mindbox\HttpClients\IHttpClient](Mindbox-HttpClients-IHttpClient.md)** - <p>Экземпляр HTTP клиента.</p>
* $logger **Psr\Log\LoggerInterface** - <p>Экземпляр логгера.</p>
* $domainZone **string** - <p>Доменная зона URL.</p>
* $domain **string** - <p>API url.</p>



Expand Down Expand Up @@ -277,6 +296,21 @@ Methods
* $rawBody **string** - <p>Сырое тело ответа.</p>


### getApiUrl

string Mindbox\Clients\AbstractMindboxClient::getApiUrl(string $domain, string $domainZone)

Преобразование API URL.



* Visibility: **protected**
*

#### Arguments
* $rawBody **string** - <p>Сырое тело ответа.</p>



### prepareRequest

Expand Down
2 changes: 1 addition & 1 deletion tests/Clients/AbstractMindboxClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function setUp(): void
$this->domainZone = $this->domainZone;
$this->httpClientStub = $this->getHttpClientStub();
$this->loggerStub = $this->getLoggerStub();
$this->client = $this->getClient($this->secret, $this->httpClientStub, $this->loggerStub, $this->domain);
$this->client = $this->getClient($this->secret, $this->httpClientStub, $this->loggerStub);
$this->dtoStub = $this->getDTOStub();
}

Expand Down