Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
payment.php
1<?php
2
3
5
6
11
12class Payment extends Base
13{
14 public function getFields()
15 {
16 return [
17 'PAY_SYSTEM_XML_ID'=>[
18 'TYPE'=>self::TYPE_STRING,
19 'ATTRIBUTES'=>[Attributes::ReadOnly]
20 ],
21 'PAY_SYSTEM_IS_CASH'=>[
22 'TYPE'=>self::TYPE_CHAR,
23 'ATTRIBUTES'=>[Attributes::ReadOnly]
24 ],
25 'ACCOUNT_NUMBER'=>[
26 'TYPE'=>self::TYPE_STRING,
27 'ATTRIBUTES'=>[Attributes::ReadOnly]
28 ],
29 'ID'=>[
30 'TYPE'=>self::TYPE_INT,
31 'ATTRIBUTES'=>[Attributes::ReadOnly]
32 ],
33 'ORDER_ID'=>[
34 'TYPE'=>self::TYPE_INT,
35 'ATTRIBUTES'=>[
38 ]
39 ],
40 'PAID'=>[
41 'TYPE'=>self::TYPE_CHAR
42 ],
43 'DATE_PAID'=>[
45 ],
46 'EMP_PAID_ID'=>[
47 'TYPE'=>self::TYPE_INT
48 ],
49 'PAY_SYSTEM_ID'=>[
50 'TYPE'=>self::TYPE_INT,
51 'ATTRIBUTES'=>[Attributes::Required]//for builder
52 ],
53 'PS_STATUS'=>[
54 'TYPE'=>self::TYPE_CHAR
55 ],
56 'PS_STATUS_CODE'=>[
57 'TYPE'=>self::TYPE_STRING
58 ],
59 'PS_STATUS_DESCRIPTION'=>[
60 'TYPE'=>self::TYPE_STRING
61 ],
62 'PS_STATUS_MESSAGE'=>[
63 'TYPE'=>self::TYPE_STRING
64 ],
65 'PS_SUM'=>[
66 'TYPE'=>self::TYPE_FLOAT
67 ],
68 'PS_CURRENCY'=>[
69 'TYPE'=>self::TYPE_STRING
70 ],
71 'PS_RESPONSE_DATE'=>[
73 ],
74 'PAY_VOUCHER_NUM'=>[
75 'TYPE'=>self::TYPE_STRING
76 ],
77 'PAY_VOUCHER_DATE'=>[
79 ],
80 'DATE_PAY_BEFORE'=>[
82 ],
83 'DATE_BILL'=>[
85 ],
86 'XML_ID'=>[
87 'TYPE'=>self::TYPE_STRING
88 ],
89 'SUM'=>[
90 'TYPE'=>self::TYPE_FLOAT
91 ],
92 'CURRENCY'=>[
93 'TYPE'=>self::TYPE_STRING,
94 'ATTRIBUTES'=>[Attributes::ReadOnly]
95 ],
96 'PAY_SYSTEM_NAME'=>[
97 'TYPE'=>self::TYPE_STRING,
98 'ATTRIBUTES'=>[Attributes::ReadOnly]
99 ],
100 'COMPANY_ID'=>[
101 'TYPE'=>self::TYPE_INT
102 ],
103 'PAY_RETURN_NUM'=>[
104 'TYPE'=>self::TYPE_STRING
105 ],
106 'PRICE_COD'=>[
107 'TYPE'=>self::TYPE_STRING
108 ],
109 'PAY_RETURN_DATE'=>[
110 'TYPE'=>self::TYPE_DATETIME
111 ],
112 'EMP_RETURN_ID'=>[
113 'TYPE'=>self::TYPE_INT
114 ],
115 'PAY_RETURN_COMMENT'=>[
116 'TYPE'=>self::TYPE_STRING
117 ],
118 'RESPONSIBLE_ID'=>[
119 'TYPE'=>self::TYPE_INT
120 ],
121 'EMP_RESPONSIBLE_ID'=>[
122 'TYPE'=>self::TYPE_INT
123 ],
124 'DATE_RESPONSIBLE_ID'=>[
125 'TYPE'=>self::TYPE_DATETIME,
126 'ATTRIBUTES'=>[Attributes::ReadOnly]
127 ],
128 'IS_RETURN'=>[
129 'TYPE'=>self::TYPE_CHAR
130 ],
131 'COMMENTS'=>[
132 'TYPE'=>self::TYPE_STRING
133 ],
134 'UPDATED_1C'=>[
135 'TYPE'=>self::TYPE_CHAR
136 ],
137 'ID_1C'=>[
138 'TYPE'=>self::TYPE_STRING
139 ],
140 'VERSION_1C'=>[
141 'TYPE'=>self::TYPE_STRING
142 ],
143 'EXTERNAL_PAYMENT'=>[
144 'TYPE'=>self::TYPE_CHAR
145 ],
146 'PS_INVOICE_ID'=>[
147 'TYPE'=>self::TYPE_INT
148 ],
149 'MARKED'=>[
150 'TYPE'=>self::TYPE_CHAR
151 ],
152 'REASON_MARKED'=>[
153 'TYPE'=>self::TYPE_STRING
154 ],
155 'DATE_MARKED'=>[
156 'TYPE'=>self::TYPE_DATETIME,
157 'ATTRIBUTES'=>[Attributes::ReadOnly]
158 ],
159 'EMP_MARKED_ID'=>[
160 'TYPE'=>self::TYPE_INT
161 ]
162 ];
163 }
164
165 public function internalizeFieldsModify($fields, $fieldsInfo=[])
166 {
167 $result = [];
168
169 $fieldsInfo = empty($fieldsInfo)? $this->getFields():$fieldsInfo;
170 $listFieldsInfoAdd = $this->getListFieldInfo($fieldsInfo, ['filter'=>['ignoredAttributes'=>[Attributes::Hidden, Attributes::ReadOnly], 'ignoredFields'=>['ORDER_ID']]]);
171 $listFieldsInfoUpdate = $this->getListFieldInfo($fieldsInfo, ['filter'=>['ignoredAttributes'=>[Attributes::Hidden, Attributes::ReadOnly, Attributes::Immutable], 'skipFields'=>['ID']]]);
172
173 if(isset($fields['ORDER']['ID']))
174 $result['ORDER']['ID'] = (int)$fields['ORDER']['ID'];
175
176 if(isset($fields['ORDER']['PAYMENTS']))
177 {
178 foreach ($fields['ORDER']['PAYMENTS'] as $k=>$item)
179 {
180 $result['ORDER']['PAYMENTS'][$k] = $this->internalizeFields($item,
181 $this->isNewItem($item)? $listFieldsInfoAdd:$listFieldsInfoUpdate
182 );
183 }
184 }
185
186 return $result;
187 }
188
189 protected function getRewritedFields()
190 {
191 return [
192 'PAY_SYSTEM_IS_CASH'=>[
193 'REFERENCE_FIELD'=>'PAY_SYSTEM.IS_CASH'
194 ],
195 'PAY_SYSTEM_XML_ID'=>[
196 'REFERENCE_FIELD'=>'PAY_SYSTEM.XML_ID'
197 ]
198 ];
199 }
200
201 public function internalizeArguments($name, $arguments)
202 {
203 if($name == 'getorderid'
204 || $name == 'getpaymentsystemid'
205 || $name == 'getpaymentsystemname'
206 || $name == 'getpersontypeid'
207 || $name == 'getsum'
208 || $name == 'getsumpaid'
209 || $name == 'isinner'
210 || $name == 'ismarked'
211 || $name == 'isnarked'
212 || $name == 'ispaid'
213 || $name == 'isreturn'
214 || $name == 'setpaid'
215 || $name == 'setreturn'
216 || $name == 'setavailablepaysystems'
217 || $name == 'clearavailablepaysystems'
218 ){}
219 else
220 {
221 parent::internalizeArguments($name, $arguments);
222 }
223
224 return $arguments;
225 }
226
227 public function externalizeFieldsModify($fields)
228 {
229 return $this->externalizeListFields($fields);
230 }
231
232 public function checkFieldsModify($fields)
233 {
234 $r = new Result();
235
236 $emptyFields = [];
237 if(!isset($fields['ORDER']['ID']))
238 {
239 $emptyFields[] = '[order][id]';
240 }
241 if(!isset($fields['ORDER']['PAYMENTS']) || !is_array($fields['ORDER']['PAYMENTS']))
242 {
243 $emptyFields[] = '[order][payments][]';
244 }
245
246 if(count($emptyFields)>0)
247 {
248 $r->addError(new Error('Required fields: '.implode(', ', $emptyFields)));
249 }
250 else
251 {
252 $r = parent::checkFieldsModify($fields);
253 }
254
255 return $r;
256 }
257
258 public function checkRequiredFieldsModify($fields)
259 {
260 $r = new Result();
261
262 $listFieldsInfoAdd = $this->getListFieldInfo($this->getFields(), ['filter'=>['ignoredAttributes'=>[Attributes::Hidden, Attributes::ReadOnly], 'ignoredFields'=>['ORDER_ID']]]);
263 $listFieldsInfoUpdate = $this->getListFieldInfo($this->getFields(), ['filter'=>['ignoredAttributes'=>[Attributes::Hidden, Attributes::ReadOnly, Attributes::Immutable]]]);
264
265 foreach ($fields['ORDER']['PAYMENTS'] as $k=>$item)
266 {
267 $required = $this->checkRequiredFields($item,
268 $this->isNewItem($item)? $listFieldsInfoAdd:$listFieldsInfoUpdate
269 );
270 if(!$required->isSuccess())
271 {
272 $r->addError(new Error('[payments]['.$k.'] - '.implode(', ', $required->getErrorMessages()).'.'));
273 }
274 }
275 return $r;
276 }
277}
getListFieldInfo(array $fieldsInfo, $params=[])
Definition base.php:62
internalizeFields($fields, array $fieldsInfo)
Definition base.php:281
checkRequiredFields($fields, array $fieldsInfo, $params=[])
Definition base.php:676
internalizeArguments($name, $arguments)
Definition payment.php:201
internalizeFieldsModify($fields, $fieldsInfo=[])
Definition payment.php:165