-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for consignment_status_history in Orders
- Loading branch information
1 parent
36a90f2
commit bd5c906
Showing
10 changed files
with
311 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace MpApiClient\Order\Entity; | ||
|
||
use MpApiClient\Common\Util\AbstractStringEnum; | ||
|
||
/** | ||
* @method static self CREATED() | ||
* @method static self RECEIVED() | ||
* @method static self CANCELLED() | ||
* @method static self DELIVERING() | ||
* @method static self DAMAGED() | ||
* @method static self RETURNING() | ||
* @method static self RETURNED() | ||
* @method static self READY_FOR_PICKUP() | ||
* @method static self DELIVERED() | ||
* @method static self LOST() | ||
*/ | ||
final class ConsignmentStatusEnum extends AbstractStringEnum | ||
{ | ||
|
||
public const CREATED = 'CREATED'; | ||
public const RECEIVED = 'RECEIVED'; | ||
public const CANCELLED = 'CANCELLED'; | ||
public const DELIVERING = 'DELIVERING'; | ||
public const DAMAGED = 'DAMAGED'; | ||
public const RETURNING = 'RETURNING'; | ||
public const RETURNED = 'RETURNED'; | ||
public const READY_FOR_PICKUP = 'READY_FOR_PICKUP'; | ||
public const DELIVERED = 'DELIVERED'; | ||
public const LOST = 'LOST'; | ||
|
||
public const TYPES = [ | ||
self::CREATED, | ||
self::RECEIVED, | ||
self::CANCELLED, | ||
self::DELIVERING, | ||
self::DAMAGED, | ||
self::RETURNING, | ||
self::RETURNED, | ||
self::READY_FOR_PICKUP, | ||
self::DELIVERED, | ||
self::LOST, | ||
]; | ||
|
||
public const KEY_NAME = 'status'; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace MpApiClient\Order\Entity; | ||
|
||
use MpApiClient\Common\Util\AbstractStringEnum; | ||
|
||
/** | ||
* @method static self DAMAGED() | ||
* @method static self LOST() | ||
*/ | ||
final class ConsignmentStatusFlagEnum extends AbstractStringEnum | ||
{ | ||
|
||
public const DAMAGED = 'damaged'; | ||
public const LOST = 'lost'; | ||
|
||
public const TYPES = [ | ||
self::DAMAGED, | ||
self::LOST, | ||
]; | ||
|
||
public const KEY_NAME = 'flags'; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace MpApiClient\Order\Entity; | ||
|
||
use DateTime; | ||
use DateTimeInterface; | ||
use Exception; | ||
use JsonSerializable; | ||
use MpApiClient\Common\Util\JsonSerializeEntityTrait; | ||
|
||
final class ConsignmentStatusHistoryItem implements JsonSerializable | ||
{ | ||
|
||
use JsonSerializeEntityTrait; | ||
|
||
private DateTimeInterface $date; | ||
private ConsignmentStatusEnum $code; | ||
/** | ||
* @var ConsignmentStatusFlagEnum[] | ||
*/ | ||
private array $flags; | ||
|
||
/** | ||
* @param DateTimeInterface $date | ||
* @param ConsignmentStatusEnum $code | ||
* @param ConsignmentStatusFlagEnum[] $flags | ||
*/ | ||
private function __construct(ConsignmentStatusEnum $code, DateTimeInterface $date, array $flags) | ||
{ | ||
$this->code = $code; | ||
$this->date = $date; | ||
$this->flags = $flags; | ||
} | ||
|
||
/** | ||
* @param array<string, mixed> $data | ||
* | ||
* @throws Exception | ||
* @internal | ||
*/ | ||
public static function createFromApi(array $data): self | ||
{ | ||
return new self( | ||
new ConsignmentStatusEnum($data[ConsignmentStatusEnum::KEY_NAME]), | ||
new DateTime($data['date']), | ||
array_map(fn(string $flag): ConsignmentStatusFlagEnum => new ConsignmentStatusFlagEnum($flag), $data[ConsignmentStatusFlagEnum::KEY_NAME]), | ||
); | ||
} | ||
|
||
public function getCode(): ConsignmentStatusEnum | ||
{ | ||
return $this->code; | ||
} | ||
|
||
public function getDate(): DateTimeInterface | ||
{ | ||
return $this->date; | ||
} | ||
|
||
/** | ||
* @return ConsignmentStatusFlagEnum[] | ||
*/ | ||
public function getFlags(): array | ||
{ | ||
return $this->flags; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace MpApiClient\Order\Entity; | ||
|
||
use Exception; | ||
use MpApiClient\Common\Util\AbstractIntKeyIterator; | ||
|
||
/** | ||
* @extends AbstractIntKeyIterator<ConsignmentStatusHistoryItem> | ||
* @property ConsignmentStatusHistoryItem[] $data | ||
*/ | ||
final class ConsignmentStatusHistoryIterator extends AbstractIntKeyIterator | ||
{ | ||
|
||
private function __construct(ConsignmentStatusHistoryItem ...$data) | ||
{ | ||
$this->data = $data; | ||
} | ||
|
||
/** | ||
* @param array<int, array<string, mixed>> $data | ||
* | ||
* @throws Exception | ||
* @internal | ||
*/ | ||
public static function createFromApi(array $data): self | ||
{ | ||
return new self( | ||
...array_map(fn(array $item): ConsignmentStatusHistoryItem => ConsignmentStatusHistoryItem::createFromApi($item), $data) | ||
); | ||
} | ||
|
||
/** | ||
* @return false|ConsignmentStatusHistoryItem | ||
*/ | ||
public function current() | ||
{ | ||
return current($this->data); | ||
} | ||
|
||
public function get(int $key): ?ConsignmentStatusHistoryItem | ||
{ | ||
return $this->data[$key] ?? null; | ||
} | ||
|
||
} |
Oops, something went wrong.