Test Failed
Pull Request — master (#13)
by Sergey
03:15
created

InternetDocument::getDocumentDeliveryDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * @noinspection PhpUnused
5
 */
6
7
declare(strict_types=1);
8
9
namespace SergeyNezbritskiy\NovaPoshta\Models;
10
11
use SergeyNezbritskiy\NovaPoshta\Connection;
12
use SergeyNezbritskiy\NovaPoshta\ModelInterface;
13
use SergeyNezbritskiy\NovaPoshta\NovaPoshtaApiException;
14
15
class InternetDocument implements ModelInterface
16
{
17
    public const CARGO_TYPE_CARGO = 'Cargo';
18
    public const CARGO_TYPE_DOCUMENTS = 'Documents';
19
    public const CARGO_TYPE_TIRES_WHEELS = 'TiresWheels';
20
    public const CARGO_TYPE_PALLET = 'Pallet';
21
22
    private const MODEL_NAME = 'InternetDocument';
23
    private Connection $connection;
24
25
    /**
26
     * @param Connection $connection
27
     */
28
    public function __construct(Connection $connection)
29
    {
30
        $this->connection = $connection;
31
    }
32
33
    /**
34
     * @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a91f115b-8512-11ec-8ced-005056b2dbe1
35
     * @see \SergeyNezbritskiy\NovaPoshta\Tests\Integration\Models\InternetDocument\GetDocumentPriceTest for more cases
36
     * @param array $params
37
     *    $params = [
38
     *        'CitySender'          => (string) City ref. Required
39
     *        'CityRecipient'       => (string) City ref. Required
40
     *        'Weight'              => (string) Minimal value - 0.1. Required
41
     *        'ServiceTYpe'         => (string) Optional
42
     *        'Cost'                => (float)  Optional, default - 300.00
43
     *        'CargoType'           => (string) Cargo type. see self::CARGO_TYPE_* constants, Optional
44
     *        'CargoDetails'        => [
45
     *            [
46
     *                'CargoDescription' => (string),
47
     *                'Amount' => (float)
48
     *            ],
49
     *            ...
50
     *        ]
51
     *        'RedeliveryCalculate' => [ Back delivery. Optional
52
     *            [
53
     *                'CargoType' => (string), e.g. Money
54
     *                'Amount' => (float)
55
     *            ],
56
     *            ...
57
     *        ],
58
     *        'OptionsSeat' => [
59
     *            'weight' => (float), Required.
60
     *            'volumetricWidth' => (float), Required.
61
     *            'volumetricLength' => (float), Required.
62
     *            'volumetricHeight' => (float), Required.
63
     *            'packRef' => (string), Optional.
64
     *        ],
65
     *        'SeatsAmount'         => (int) Optional
66
     *        'PackCount'           => (int) Optional
67
     *        'CargoDescription'    => (string) Cargo type. see self::CARGO_TYPE_* constants, Optional
68
     *        'PackCount'           => (string) The amount of packing, Optional
69
     *        'PackRef'             => (string) Packing identifier (REF). Optional
70
     *        'Amount'              => (int) Amount of back delivery. Optional
71
     *    ]
72
     * @return array
73
     * @throws NovaPoshtaApiException
74
     */
75
    public function getDocumentPrice(array $params): array
76
    {
77
        $result = $this->connection->post(self::MODEL_NAME, 'getDocumentPrice', $params);
78
        return array_shift($result);
79
    }
80
81
    /**
82
     * @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a941c714-8512-11ec-8ced-005056b2dbe1
83
     * @see \SergeyNezbritskiy\NovaPoshta\Tests\Integration\Models\InternetDocument\GetDocumentDeliveryDateTest
84
     * @param array $params
85
     *         $params = [
86
     *              'DateTime'      => (string), Document creation date, format `d.m.Y`. Optional.
87
     *              'ServiceType'   => (string), Required.
88
     *              'CitySender'    => (string), city ref. Required.
89
     *              'CityRecipient' => (string), city ref. Required.
90
     *          ];
91
     * @return array
92
     * @throws NovaPoshtaApiException
93
     */
94
    public function getDocumentDeliveryDate(array $params): array
95
    {
96
        $result = $this->connection->post(self::MODEL_NAME, 'getDocumentDeliveryDate', $params);
97
        return array_shift($result)['DeliveryDate'];
98
    }
99
100
    /**
101
     * @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a9d22b34-8512-11ec-8ced-005056b2dbe1
102
     * @param array $params
103
     * @param int|null $page
104
     * @return array
105
     * @throws NovaPoshtaApiException
106
     */
107
    public function getDocumentList(array $params, int $page = null): array
108
    {
109
        if ($page !== null) {
110
            $params['Page'] = $page;
111
        }
112
        return $this->connection->post(self::MODEL_NAME, 'getDocumentList', $params);
113
    }
114
115
    /**
116
     * @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a965630e-8512-11ec-8ced-005056b2dbe1
117
     * @param array $params
118
     * @return array
119
     * @throws NovaPoshtaApiException
120
     */
121
    public function save(array $params): array
122
    {
123
        $result = $this->connection->post(self::MODEL_NAME, 'save', $params);
124
        return array_shift($result);
125
    }
126
127
    /**
128
     * @see https://developers.novaposhta.ua/view/model/a90d323c-8512-11ec-8ced-005056b2dbe1/method/a965630e-8512-11ec-8ced-005056b2dbe1
129
     * @param string $documentRef
130
     * @return void
131
     * @throws NovaPoshtaApiException
132
     */
133
    public function delete(string $documentRef): void
134
    {
135
        $this->connection->post(self::MODEL_NAME, 'delete', ['DocumentRefs' => $documentRef]);
136
    }
137
}
138