Beispiel #1
0
 /**
  * @param Payment $payment
  * @return Result
  */
 protected function syncOrderPaymentPaid(Payment $payment)
 {
     $result = new Result();
     if ($payment->isPaid()) {
         return $result;
     }
     $paymentCollection = $this->getPaymentCollection();
     $sumPaid = $paymentCollection->getPaidSum();
     $userBudget = Internals\UserBudgetPool::getUserBudgetByOrder($this);
     $debitSum = $payment->getSum();
     $maxPaid = $payment->getSum() + $sumPaid - $this->getSumPaid();
     if ($maxPaid >= $payment->getSum()) {
         $finalSumPaid = $this->getSumPaid();
     } else {
         $debitSum = $maxPaid;
         $finalSumPaid = $sumPaid;
     }
     if ($debitSum > 0) {
         if (PriceMaths::roundByFormatCurrency($debitSum, $this->getCurrency()) > PriceMaths::roundByFormatCurrency($userBudget, $this->getCurrency())) {
             $result->addError(new ResultError(Loc::getMessage('SALE_ORDER_PAYMENT_CANCELLED_PAID'), 'SALE_ORDER_PAYMENT_NOT_ENOUGH_USER_BUDGET_SYNCPAID'));
             return $result;
         }
         Internals\UserBudgetPool::addPoolItem($this, $debitSum * -1, Internals\UserBudgetPool::BUDGET_TYPE_ORDER_CANCEL_PART, $payment);
     }
     $result->setData(array('SUM_PAID' => $finalSumPaid));
     return $result;
 }