38 $paymentClassName = static::getItemCollectionClassName();
50 public function addItem(Internals\CollectableEntity
$payment)
65 public function deleteItem($index)
67 $oldItem = parent::deleteItem($index);
84 public function onItemModify(Internals\CollectableEntity $item,
$name =
null, $oldValue =
null, $value =
null)
94 public function isPaid()
96 if (!empty($this->collection) && is_array($this->collection))
99 foreach ($this->collection as
$payment)
117 public function onOrderModify(
$name, $oldValue, $value)
130 foreach ($this->collection as
$payment)
141 $result->addError(
new ResultError(Loc::getMessage(
'SALE_ORDER_CANCEL_PAYMENT_EXIST_ACTIVE'),
'SALE_ORDER_CANCEL_PAYMENT_EXIST_ACTIVE'));
148 $payment = $this->getItemForAutoEdit($oldValue);
151 $r =
$payment->setField(
"SUM", $value);
152 if (!$r->isSuccess())
154 $result->addErrors($r->getErrors());
161 $payment->setField(
'PRICE_COD', $price);
170 public function onBeforeBasketItemDelete(BasketItem $basketItem) : Result
175 foreach ($this->collection as
$payment)
177 $r =
$payment->onBeforeBasketItemDelete($basketItem);
178 if (!$r->isSuccess())
180 $result->addErrors($r->getErrors());
187 protected function isAllowAutoEdit()
198 $isAllowEditPayment =
204 if ($isAllowEditPayment)
208 $isAllowEditPayment =
$service->isAllowEditPayment();
212 return $isAllowEditPayment;
219 private function getItemForAutoEdit($previousOrderSum) :? Payment
221 if ($this->isAllowAutoEdit())
226 if (
$payment->getSum() === $previousOrderSum)
258 $paymentCollectionClassName = $registry->getPaymentCollectionClassName();
260 return new $paymentCollectionClassName();
275 public static function load(Order
$order)
284 $paymentClassName = static::getItemCollectionClassName();
286 $paymentList = $paymentClassName::loadForOrder(
$order->getId());
302 public function getPaidSum()
305 if (!empty($this->collection) && is_array($this->collection))
308 foreach ($this->collection as
$payment)
310 if (
$payment->getField(
'PAID') ==
"Y")
323 public function getSum()
326 if (!empty($this->collection) && is_array($this->collection))
329 foreach ($this->collection as
$payment)
341 public function hasPaidPayment()
344 foreach ($this->collection as
$payment)
346 if (
$payment->getField(
'PAID') ===
"Y")
358 public function hasUnpaidPayment()
361 foreach ($this->collection as
$payment)
363 if (
$payment->getField(
'PAID') ===
"N")
376 public function save()
383 throw new Main\ObjectNotFoundException(
'Entity "Order" not found');
386 $itemsFromDb =
array();
389 $itemsFromDbList = static::getList(
392 "select" =>
array(
"ID",
"PAY_SYSTEM_NAME",
"PAY_SYSTEM_ID")
395 while ($itemsFromDbItem = $itemsFromDbList->fetch())
396 $itemsFromDb[$itemsFromDbItem[
"ID"]] = $itemsFromDbItem;
399 $changeMeaningfulFields =
array(
410 foreach ($this->collection as
$payment)
415 if (
$order->getId() > 0 && $isChanged)
417 $logFields =
array();
420 $originalValues =
$fields->getOriginalValues();
422 foreach($originalValues as $originalFieldName => $originalFieldValue)
424 if (in_array($originalFieldName, $changeMeaningfulFields) &&
$payment->getField($originalFieldName) != $originalFieldValue)
426 $logFields[$originalFieldName] =
$payment->getField($originalFieldName);
428 $logFields[
'OLD_'.$originalFieldName] = $originalFieldValue;
443 $orderHistory = $registry->getOrderHistoryClassName();
444 $orderHistory::addLog(
447 $isNew ?
'PAYMENT_ADD' :
'PAYMENT_UPDATE',
451 $orderHistory::SALE_ORDER_HISTORY_LOG_LEVEL_1
454 $orderHistory::addAction(
469 $result->addErrors($r->getErrors());
472 if (isset($itemsFromDb[
$payment->getId()]))
474 unset($itemsFromDb[
$payment->getId()]);
478 foreach ($itemsFromDb as
$k => $v)
480 $v[
'ENTITY_REGISTRY_TYPE'] = static::getRegistryType();
483 $event =
new Main\Event(
'sale',
"OnBeforeSalePaymentDeleted",
array(
488 static::deleteInternal(
$k);
491 $event =
new Main\Event(
'sale',
"OnSalePaymentDeleted",
array(
501 $orderHistory = $registry->getOrderHistoryClassName();
502 $orderHistory::addAction(
'PAYMENT',
$order->getId(),
'PAYMENT_REMOVE',
$k,
null,
array(
503 "PAY_SYSTEM_NAME" => $v[
"PAY_SYSTEM_NAME"],
504 "PAY_SYSTEM_ID" => $v[
"PAY_SYSTEM_ID"],
510 $entityMarker = $registry->getEntityMarkerClassName();
511 $entityMarker::deleteByFilter([
512 '=ORDER_ID' =>
$order->getId(),
513 '=ENTITY_TYPE' => $entityMarker::ENTITY_TYPE_PAYMENT,
525 $orderHistory = $registry->getOrderHistoryClassName();
526 $orderHistory::collectEntityFields(
'PAYMENT',
$order->getId());
536 public function getInnerPayment()
541 throw new Main\ObjectNotFoundException(
'Entity "Order" not found');
544 if ($paySystemId = PaySystem\Manager::getInnerPaySystemId())
547 foreach ($this->collection as
$payment)
549 if (
$payment->getPaymentSystemId() == $paySystemId)
561 public function createInnerPayment()
563 $payment = $this->getInnerPayment();
569 $paySystemId = PaySystem\Manager::getInnerPaySystemId();
570 if (!empty($paySystemId))
573 $paySystem = Manager::getObjectById($paySystemId);
576 return $this->createItem($paySystem);
586 public function isExistsInnerPayment()
588 if ($paySystemId = PaySystem\Manager::getInnerPaySystemId())
591 foreach ($this->collection as
$payment)
593 if (
$payment->getPaymentSystemId() == $paySystemId)
605 public function verify()
610 foreach ($this->collection as
$payment)
613 if (!$r->isSuccess())
615 $result->addErrors($r->getErrors());
620 throw new Main\ObjectNotFoundException(
'Entity "Order" not found');
626 $entityMarker = $registry->getEntityMarkerClassName();
628 $order->setField(
'MARKED',
'Y');
634 public function getBasketItemQuantity(BasketItem $basketItem) : float
639 foreach ($this->collection as
$payment)
641 $quantity +=
$payment->getBasketItemQuantity($basketItem);
653 public function createClone(\SplObjectStorage $cloneEntity)
655 if ($this->isClone() && $cloneEntity->contains($this))
657 return $cloneEntity[$this];
661 $paymentCollectionClone = parent::createClone($cloneEntity);
665 if ($cloneEntity->contains($this->order))
667 $paymentCollectionClone->order = $cloneEntity[
$this->order];
671 return $paymentCollectionClone;
679 public function isMarked()
681 if (!empty($this->collection) && is_array($this->collection))
684 foreach ($this->collection as
$payment)
706 private static function getItemCollectionClassName()
709 return $registry->getPaymentClassName();
718 return Internals\PaymentTable::getList($parameters);