Passed
Push — master ( 26fc60...fbb013 )
by Andrey
04:05
created

AdditionalService::saveRedirecting()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
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
152
        } else {
153
            $this->methodProperties['OrderType'] = 'orderCargoReturn';
154
155
            // При возврате нужно указать причину и подтип причины
156
            $this->getReason();
157
            $this->getSubtypeReason();
158
159
            /**
160
             * Возврат/переадресация на адрес отправления.
161
             */
162
            $this->getReturnAddressRef();
163
        }
164
165
166
167
        if (! $this->Note) {
168
            $this->methodProperties['Note'] = config('novaposhta.return_note');
169
170
            if ($isRedirecting) {
171
                $this->methodProperties['Note'] = config('novaposhta.redirecting_note');
172
            }
173
        }
174
175
        /**
176
         * Возврат/переадресация на новый адрес отделения.
177
         */
178
        $this->getRecipientWarehouse();
179
180
        /**
181
         * Возврат/переадресация на новый адрес по адресной доставке.
182
         */
183
        $this->getRecipientSettlement();
184
185
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties);
186
    }
187
188
    /**
189
     * Создание заявки на переадресацию.
190
     *
191
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/98acb0f6-8f0b-11ec-8ced-005056b2dbe1 Создание заявки на переадресацию
192
     *
193
     * @param string $ttn Номер ТТН
194
     * @return array
195
     */
196
    public function saveRedirecting(string $ttn): array
197
    {
198
        return $this->save($ttn, true);
199
    }
200
201
    /**
202
     * Удаление заявки на возврат, заявку об изменении данных или заявку переадресации.
203
     *
204
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/a85bb34b-8512-11ec-8ced-005056b2dbe1 Удаление заявки
205
     *
206
     * @param  string  $Ref  Ref заявки
207
     * @return array
208
     */
209
    public function delete(string $Ref): array
210
    {
211
        $this->calledMethod = 'delete';
212
213
        $this->methodProperties['Ref'] = $Ref;
214
215
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties);
216
    }
217
}
218