Passed
Push — master ( 7b0f05...653ecf )
by Andrey
03:25
created

AdditionalService::CheckPossibilityTermExtension()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
namespace Daaner\NovaPoshta\Models;
4
5
use Daaner\NovaPoshta\NovaPoshta;
6
use Daaner\NovaPoshta\Traits\AdditionalServiceProperty;
7
use Daaner\NovaPoshta\Traits\DateTimes;
8
use Daaner\NovaPoshta\Traits\InternetDocumentProperty;
9
use Daaner\NovaPoshta\Traits\Limit;
10
11
class AdditionalService extends NovaPoshta
12
{
13
    protected $model = 'AdditionalService';
14
    protected $calledMethod;
15
    protected $methodProperties = [];
16
17
    use InternetDocumentProperty, AdditionalServiceProperty, Limit, DateTimes;
18
19
    /**
20
     * Проверка возможности создания заявки на возврат.
21
     *
22
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/a778f519-8512-11ec-8ced-005056b2dbe1 Возможность возврата
23
     *
24
     * @param  string  $ttn  Номер ТТН
25
     * @return array
26
     */
27
    public function CheckPossibilityCreateReturn(string $ttn): array
28
    {
29
        $this->calledMethod = 'CheckPossibilityCreateReturn';
30
        $this->methodProperties['Number'] = $ttn;
31
32
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties);
33
    }
34
35
    /**
36
     * Проверка возможности создания заявки на переадресацию отправки.
37
     *
38
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/a8d29fc2-8512-11ec-8ced-005056b2dbe1 Возможность переадресации
39
     *
40
     * @param  string  $ttn  Номер ТТН
41
     * @return array
42
     */
43
    public function checkPossibilityForRedirecting(string $ttn): array
44
    {
45
        $this->calledMethod = 'checkPossibilityForRedirecting';
46
        $this->methodProperties['Number'] = $ttn;
47
48
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties);
49
    }
50
51
    /**
52
     * Получение списка причин возврата.
53
     *
54
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/a7a6bacb-8512-11ec-8ced-005056b2dbe1 Список причин возврата
55
     *
56
     * @return array
57
     */
58
    public function getReturnReasons(): array
59
    {
60
        $this->calledMethod = 'getReturnReasons';
61
        $this->methodProperties = null;
62
63
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties);
64
    }
65
66
    /**
67
     * Получение списка подтипов причины возврата.
68
     *
69
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/a7cb69ee-8512-11ec-8ced-005056b2dbe1 Список подтипов причины возврата
70
     *
71
     * @param  string|null  $ref  Ref причины
72
     * @return array
73
     */
74
    public function getReturnReasonsSubtypes(?string $ref = null): array
75
    {
76
        $this->calledMethod = 'getReturnReasonsSubtypes';
77
        $this->methodProperties['ReasonRef'] = $ref ?: config('novaposhta.ref_return_reasons');
78
79
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties);
80
    }
81
82
    /**
83
     * Получение списка заявок на возврат.
84
     *
85
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/a7cb69ee-8512-11ec-8ced-005056b2dbe1 Список заявок на возврат
86
     *
87
     * @return array
88
     */
89
    public function getReturnOrdersList(): array
90
    {
91
        $this->calledMethod = 'getReturnOrdersList';
92
        $this->methodProperties = null;
93
94
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties);
95
    }
96
97
    /**
98
     * Получение списка заявок на переадресацию отправлений.
99
     *
100
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/a8faa2e6-8512-11ec-8ced-005056b2dbe1 Список заявок на переадресацию
101
     *
102
     * @return array
103
     */
104
    public function getRedirectionOrdersList(): array
105
    {
106
        $this->calledMethod = 'getRedirectionOrdersList';
107
        $this->methodProperties = null;
108
109
        $this->addLimit();
110
        $this->getPage();
111
112
        $this->getNumber();
113
        $this->getDateBeginEnd();
114
115
        if ($this->Ref) {
116
            $this->methodProperties['Ref'] = $this->Ref;
117
        }
118
119
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties);
120
    }
121
122
    /**
123
     * Создание заявки на возврат.
124
     *
125
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/a7fb4a3a-8512-11ec-8ced-005056b2dbe1 Возврат на адрес отправителя
126
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/5a64f960-e7fa-11ec-a60f-48df37b921db Возврат на новый адрес отделения
127
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/175baec3-8f0d-11ec-8ced-005056b2dbe1 Возврат на новый адрес по адресной доставке
128
     *
129
     * @param  string  $ttn  Номер ТТН
130
     * @param  bool|null  $isRedirecting  Флаг, что заявка является переадресацией
131
     * @return array
132
     */
133
    public function save(string $ttn, ?bool $isRedirecting = false): array
134
    {
135
        $this->calledMethod = 'save';
136
137
        $this->methodProperties['IntDocNumber'] = $ttn;
138
139
        $this->getPaymentMethod();
140
        $this->getNote();
141
142
        /**
143
         * Переадресация или возврат
144
         */
145
        if ($isRedirecting) {
146
            $this->methodProperties['OrderType'] = 'orderRedirecting';
147
            $this->getPayerType();
148
            $this->getCustomer();
149
            $this->getServiceType();
150
            $this->getRecipientData();
151
        } else {
152
            $this->methodProperties['OrderType'] = 'orderCargoReturn';
153
154
            // При возврате нужно указать причину и подтип причины
155
            $this->getReason();
156
            $this->getSubtypeReason();
157
158
            /**
159
             * Возврат/переадресация на адрес отправления.
160
             */
161
            $this->getReturnAddressRef();
162
        }
163
164
        if (! $this->Note) {
165
            $this->methodProperties['Note'] = config('novaposhta.return_note');
166
167
            if ($isRedirecting) {
168
                $this->methodProperties['Note'] = config('novaposhta.redirecting_note');
169
            }
170
        }
171
172
        /**
173
         * Возврат/переадресация на новый адрес отделения.
174
         */
175
        $this->getRecipientWarehouse();
176
177
        /**
178
         * Возврат/переадресация на новый адрес по адресной доставке.
179
         */
180
        $this->getRecipientSettlement();
181
182
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties);
183
    }
184
185
    /**
186
     * Создание заявки на переадресацию.
187
     *
188
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/98acb0f6-8f0b-11ec-8ced-005056b2dbe1 Создание заявки на переадресацию
189
     *
190
     * @param  string  $ttn  Номер ТТН
191
     * @return array
192
     */
193
    public function saveRedirecting(string $ttn): array
194
    {
195
        return $this->save($ttn, true);
196
    }
197
198
    /**
199
     * Удаление заявки на возврат, заявку об изменении данных или заявку переадресации.
200
     *
201
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/a85bb34b-8512-11ec-8ced-005056b2dbe1 Удаление заявки
202
     *
203
     * @param  string  $Ref  Ref заявки
204
     * @return array
205
     */
206
    public function delete(string $Ref): array
207
    {
208
        $this->calledMethod = 'delete';
209
210
        $this->methodProperties['Ref'] = $Ref;
211
212
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties);
213
    }
214
215
    /**
216
     * Проверка продления хранения ТТН.
217
     *
218
     * @param string $ttn Номер ТТН
219
     * @return array
220
     */
221
    public function CheckPossibilityTermExtension(string $ttn): array
222
    {
223
        $this->calledMethod = 'CheckPossibilityTermExtension';
224
225
        $this->methodProperties['IntDocNumber'] = $ttn;
226
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties);
227
    }
228
}
229