25 if ($payment = self::findPaymentEqualOrderSum($orderId))
36 if (!$service = self::buildPaySystemService($order, $paySystemId))
41 $paymentSum = $order->getPrice();
42 $paymentCollection = $order->getPaymentCollection();
43 $payment = $paymentCollection->createItem($service);
44 $result = $payment->setField(
'SUM', $paymentSum);
46 $result = $result->isSuccess() ? $order->save() : $result;
48 if ($result->isSuccess())
62 private static function findPaymentEqualOrderSum(
int $orderId): ?
Payment
70 $paymentSum = $order->getPrice();
73 'ORDER_ID' => $order->getId(),
79 'select' => [
'ORDER_ID',
'ID'],
82 if ($paymentData = $paymentRow->fetch())
84 $paymentId = (int)$paymentData[
'ID'];
86 $payment = $order->getPaymentCollection()->getItemById($paymentId);
100 private static function buildPaySystemService(
Order $order, ?
int $paySystemId =
null): ?PaySystem\
Service
102 if ($paySystemId ===
null)
104 $paySystemId = self::getDefaultPaySystemId($order);
107 return PaySystem\Manager::getObjectById($paySystemId);
117 private static function getDefaultPaySystemId(Order $order): int
120 $paySystemList = PaySystem\Manager::getListWithRestrictionsByOrder($order);
122 foreach ($paySystemList as $item)
124 if ($item[
'ACTION_FILE'] ===
'cash')
133 $paySystem = current($paySystemList);
136 return (
int)$paySystem[
'ID'];