Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
paymentimport.php
1<?php
3
10use Bitrix\Main;
12
19{
24 public function setEntity(Internals\Entity $entity)
25 {
26 if(!($entity instanceof Payment))
27 throw new Main\ArgumentException("Entity must be instanceof Payment");
28
29 $this->entity = $entity;
30 }
31
36 protected function checkFields(array $fields)
37 {
38 $result = new Sale\Result();
39
40 if(intval($fields['ORDER_ID'])<=0 && !$this->isLoadedParentEntity())
41 {
42 $result->addError(new Error('ORDER_ID is not defined',''));
43 }
44
45 return $result;
46 }
47
51 public function save()
52 {
55 return $parentEntity->save();
56 }
57
62 public function add(array $params)
63 {
64 $result = new Sale\Result();
65
66 if(!$this->isLoadedParentEntity())
67 {
68 $result->addError(new Error(GetMessage('SALE_EXCHANGE_ENTITY_PAYMENT_ORDER_IS_NOT_LOADED_ERROR'),'ENTITY_PAYMENT_ORDER_IS_NOT_LOADED_ERROR'));
69 return $result;
70 }
71
72 $fields = $params['TRAITS'];
73
74 if(($paySystem = Sale\PaySystem\Manager::getObjectById($fields['PAY_SYSTEM_ID'])) == null)
75 {
76 $result->addError(new Error(GetMessage('SALE_EXCHANGE_ENTITY_PAYMENT_PAYMENT_SYSTEM_IS_NOT_AVAILABLE_ERROR'),'PAYMENT_SYSTEM_IS_NOT_AVAILABLE_ERROR'));
77 }
78 else
79 {
81 $paymentCollection = $parentEntity->getPaymentCollection();
82 $payment = $paymentCollection->createItem($paySystem);
83 $result = $payment->setFields($fields);
84
85 if($result->isSuccess())
86 {
87 $this->setEntity($payment);
88 }
89 }
90
91 return $result;
92 }
93
98 public function update(array $params)
99 {
101 $payment = $this->getEntity();
102
103 $criterion = $this->getCurrentCriterion($this->getEntity());
104
105 $fields = $params['TRAITS'];
106 if(!$criterion->equals($fields))
107 {
108 unset(
109 $fields['SUM'],
110 $fields['COMMENTS'],
111 $fields['PAY_VOUCHER_DATE'],
112 $fields['PAY_VOUCHER_NUM']
113 );
114 }
115 $result = $payment->setFields($fields);
116
117 return $result;
118 }
119
124 public function delete(array $params = null)
125 {
127 $entity = $this->getEntity();
128 $result = $entity->delete();
129 if($result->isSuccess())
130 {
131 //$this->setCollisions(Exchange\EntityCollisionType::OrderPaymentDeleted, $this->getParentEntity());
132 }
133 else
134 {
135 $this->setCollisions(Exchange\EntityCollisionType::OrderPaymentDeletedError, $this->getParentEntity(), implode(',', $result->getErrorMessages()));
136 }
137
138 return $result;
139 }
140
144 protected function getExternalFieldName()
145 {
146 return 'EXTERNAL_PAYMENT';
147 }
148
154 public function load(array $fields)
155 {
156 $r = $this->checkFields($fields);
157 if(!$r->isSuccess())
158 {
159 throw new Main\ArgumentException('ORDER_ID is not defined');
160 }
161
162 if(!$this->isLoadedParentEntity() && !empty($fields['ORDER_ID']))
163 {
164 $this->setParentEntity(
165 $this->loadParentEntity(['ID'=>$fields['ORDER_ID']])
166 );
167 }
168
169 if($this->isLoadedParentEntity())
170 {
173
174 if(!empty($fields['ID']))
175 {
176 $payment = $parentEntity->getPaymentCollection()->getItemById($fields['ID']);
177 }
178
180 if(!empty($payment))
181 {
182 $this->setEntity($payment);
183 }
184 else
185 {
186 $this->setExternal();
187 }
188 }
189 return new Sale\Result();
190 }
191
195 public function refreshData(array $fields)
196 {
198 $entity = $this->getEntity();
199 if(!empty($entity) && $entity->isPaid())
200 {
201 if($fields['PAID'] == 'N')
202 $entity->setField('PAID', 'N');
203 }
204 }
205
211 static public function resolveEntityTypeId(Internals\Entity $payment)
212 {
213 if(!($payment instanceof Payment))
214 throw new Main\ArgumentException("Entity must be instanceof Payment");
215
216 $paySystem = $payment->getPaySystem();
217 $type = $paySystem->getField('IS_CASH');
218
219 return static::resolveEntityTypeIdByCodeType($type);
220 }
221
226 static public function resolveEntityTypeIdByCodeType($type)
227 {
228 switch($type)
229 {
230 case 'Y':
231 $resolveType = EntityType::PAYMENT_CASH;
232 break;
233 case 'N':
234 $resolveType = EntityType::PAYMENT_CASH_LESS;
235 break;
236 case 'A':
238 break;
239 default;
240 $resolveType = EntityType::UNDEFINED;
241 }
242 return $resolveType;
243 }
244
245 public function initFields()
246 {
247 $this->setFields(
248 array(
249 'TRAITS'=>$this->getFieldsTraits(),
250 )
251 );
252 }
253
259 {
260 if(!($entity instanceof Payment))
261 throw new Main\ArgumentException("entity must be instanceof Payment");
262
264 $collection = $entity->getCollection();
265
266 return $collection->getOrder();
267 }
268}
269
271{
272 public function __construct($parentEntityContext = null)
273 {
274 parent::__construct($parentEntityContext);
275 }
276
277 public function getOwnerTypeId()
278 {
280 }
281}
282
284{
285 public function __construct($parentEntityContext = null)
286 {
287 parent::__construct($parentEntityContext);
288 }
289
290 public function getOwnerTypeId()
291 {
293 }
294}
295
297{
298 public function __construct($parentEntityContext = null)
299 {
300 parent::__construct($parentEntityContext);
301 }
302
303 public function getOwnerTypeId()
304 {
306 }
307}
setParentEntity(Sale\Order $parentEntity)
setCollisions($tipeId, Sale\Internals\Entity $entity, $message=null)
static resolveEntityTypeId(Internals\Entity $payment)
static getBusinessValueOrderProvider(\Bitrix\Sale\IBusinessValueProvider $entity)