Skip to content

Commit 2da8ca3

Browse files
authored
Merge pull request #18 from mindbox-moscow/MB-750
Mb 750
2 parents 41d8a05 + 9d3c075 commit 2da8ca3

22 files changed

+628
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
vendor/
22
composer.lock
3+
src/Clients/getDeviceUUID

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ install:
2828
# Run scripts
2929
script:
3030
- vendor/bin/phpcs
31-
- vendor/bin/phpunit --coverage-text
31+
- vendor/bin/phpunit

src/Clients/AbstractMindboxClient.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ final protected function parseRawResponse(MindboxRequest $request, HttpClientRaw
270270
throw new \Mindbox\Exceptions\MindboxClientException('Empty response body');
271271
}
272272

273+
//$statusCode = 503;
274+
273275
switch ($statusCode) {
274276
case 200:
275277
$this->logger->info($message, $context);
@@ -280,7 +282,9 @@ final protected function parseRawResponse(MindboxRequest $request, HttpClientRaw
280282
throw new \Mindbox\Exceptions\MindboxUnavailableException('Service unavailable');
281283
case 400:
282284
$this->logger->error($message, $context);
283-
throw new \Mindbox\Exceptions\MindboxBadRequestException('Bad request');
285+
$body = $context['response']['body'];
286+
$arBody = json_decode($body, true);
287+
throw new \Mindbox\Exceptions\MindboxBadRequestException(substr($arBody['errorMessage'], strpos($arBody['errorMessage'], ":") + 1));
284288
case 409:
285289
$this->logger->error($message, $context);
286290
throw new \Mindbox\Exceptions\MindboxConflictException('Conflict');

src/Clients/MindboxClientV3.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
use Mindbox\HttpClients\IHttpClient;
77
use Psr\Log\LoggerInterface;
8-
use Mindbox\Options;
98

109
/**
1110
* Клиент для отправки запросов к v3 API Mindbox.
@@ -122,8 +121,8 @@ protected function prepareQueryParams($operation, array $queryParams, $addDevice
122121
*/
123122
private function getDeviceUUID()
124123
{
125-
if(empty($_COOKIE['mindboxDeviceUUID'])) {
126-
$logger = new \Mindbox\Loggers\MindboxFileLogger(Options::getModuleOption('LOG_PATH'));
124+
if (empty($_COOKIE['mindboxDeviceUUID'])) {
125+
$logger = new \Mindbox\Loggers\MindboxFileLogger(__DIR__ . '/getDeviceUUID/');
127126
$message = date('d.m.Y H:i:s');
128127
$logger->error($message, ['$_COOKIE' => $_COOKIE, '$_REQUEST' => $_REQUEST, '$_SERVER' => $_SERVER]);
129128
}

src/DTO/V2/Requests/OrderRequestDTO.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,12 @@ public function setDeliveryCost($deliveryCost)
124124
{
125125
$this->setField('deliveryCost', $deliveryCost);
126126
}
127+
128+
/**
129+
* @param mixed $order
130+
*/
131+
public function setOrder($order)
132+
{
133+
$this->setField('order', $order);
134+
}
127135
}

src/DTO/V2/Responses/LineResponseDTO.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ public function getGiftCard()
6363
*/
6464
public function getDiscountedPrice()
6565
{
66-
return $this->getField('discountedPrice');
66+
return $this->getField('discountedPriceOfLine');
6767
}
6868
}

src/DTO/V3/DiscountDTO.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
4+
namespace Mindbox\DTO\V3;
5+
6+
use Mindbox\DTO\DTO;
7+
8+
/**
9+
* Class DiscountDTO
10+
*
11+
* @package Mindbox\DTO\V3
12+
* @property string $type
13+
* @property string $amount
14+
* @property string $id
15+
**/
16+
abstract class DiscountDTO extends DTO
17+
{
18+
/**
19+
* @var string Название элемента для корректной генерации xml.
20+
*/
21+
protected static $xmlName = 'discount';
22+
23+
/**
24+
* @return string
25+
*/
26+
public function getType()
27+
{
28+
return $this->getField('type');
29+
}
30+
31+
/**
32+
* @return string
33+
*/
34+
public function getAmount()
35+
{
36+
return $this->getField('amount');
37+
}
38+
39+
/**
40+
* @return string
41+
*/
42+
public function getId()
43+
{
44+
return $this->getField('id');
45+
}
46+
}

src/DTO/V3/OrderDTO.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
4+
namespace Mindbox\DTO\V3;
5+
6+
use Mindbox\DTO\DTO;
7+
8+
/**
9+
* Class OrderDTO
10+
*
11+
* @package Mindbox\DTO\V3
12+
* @property array $ids
13+
* @property string $pointOfContact
14+
* @property string $area
15+
**/
16+
abstract class OrderDTO extends DTO
17+
{
18+
use IdentityDTO;
19+
20+
/**
21+
* @var string Название элемента для корректной генерации xml.
22+
*/
23+
protected static $xmlName = 'order';
24+
25+
/**
26+
* @return string
27+
*/
28+
public function getPointOfContact()
29+
{
30+
return $this->getField('pointOfContact');
31+
}
32+
33+
/**
34+
* @return string
35+
*/
36+
public function getArea()
37+
{
38+
return $this->getField('area');
39+
}
40+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
4+
namespace Mindbox\DTO\V3\Requests;
5+
6+
use Mindbox\DTO\DTOCollection;
7+
8+
/**
9+
* Class DiscountRequestCollection
10+
*
11+
* @package Mindbox\DTO\V3\Requests
12+
*/
13+
class DiscountRequestCollection extends DTOCollection
14+
{
15+
/**
16+
* @var string Название элементов коллекции для корректной генерации xml.
17+
*/
18+
protected static $collectionItemsName = DiscountRequestDTO::class;
19+
20+
/**
21+
* @var string Название элемента для корректной генерации xml.
22+
*/
23+
protected static $xmlName = 'discounts';
24+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
4+
namespace Mindbox\DTO\V3\Requests;
5+
6+
use Mindbox\DTO\V3\DiscountDTO;
7+
8+
/**
9+
* Class DiscountRequestDTO
10+
*
11+
* @package Mindbox\DTO\V2\Requests
12+
**/
13+
class DiscountRequestDTO extends DiscountDTO
14+
{
15+
/**
16+
* @param mixed $type
17+
*/
18+
public function setType($type)
19+
{
20+
$this->setField('type', $type);
21+
}
22+
23+
/**
24+
* @param mixed $amount
25+
*/
26+
public function setAmount($amount)
27+
{
28+
$this->setField('amount', $amount);
29+
}
30+
31+
/**
32+
* @param mixed $id
33+
*/
34+
public function setId($id)
35+
{
36+
$this->setField('id', $id);
37+
}
38+
}

0 commit comments

Comments
 (0)