Ejemplo n.º 1
0
 /**
  * @param Order $order
  * @param Payment $payment
  * @param $operation
  * @return Result
  * @throws \Exception
  */
 public static function createOperation(Order &$order, Payment &$payment, $operation)
 {
     $result = new Result();
     $paymentSum = $payment->getSum();
     if ($operation == self::OPERATION_DEBIT) {
         $userBudget = UserBudgetPool::getUserBudgetByOrder($order);
         if ($userBudget >= $paymentSum) {
             UserBudgetPool::addPoolItem($order, $paymentSum * -1, UserBudgetPool::BUDGET_TYPE_ORDER_PAY, $payment);
             //				$payment->setField('PAID', 'Y');
         } else {
             $result->addError(new EntityError(Loc::getMessage('ORDER_PS_INNER_ERROR_INSUFFICIENT_MONEY')));
         }
     } elseif ($operation == self::OPERATION_CREDIT) {
         UserBudgetPool::addPoolItem($order, $paymentSum, UserBudgetPool::BUDGET_TYPE_ORDER_UNPAY, $payment);
         //			$payment->setField('PAID', 'N');
     } elseif ($operation == self::OPERATION_RETURN) {
         $sumPaid = $order->getSumPaid();
         $sumTrans = UserBudgetPool::getUserBudgetTransForOrder($order);
         $finalSumPaid = $paymentSum + $sumTrans;
         if ($finalSumPaid > 0) {
             $paymentSum = $paymentSum - $finalSumPaid;
         }
         //			Internals\UserBudgetPool::addPoolItem($order->getUserId(), ( $paymentSum ), UserBudgetPool::BUDGET_TYPE_CANCEL_RETURN, $order, $payment);
         //			$payment->setField('PAID', 'N');
         $payment->setField('IS_RETURN', 'Y');
     } else {
         throw new InvalidOperationException('Wrong operation type!');
     }
     return $result;
 }
Ejemplo n.º 2
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->getPrice();
     if ($maxPaid >= $payment->getSum()) {
         $finalSumPaid = $this->getSumPaid();
     } else {
         $debitSum = $maxPaid;
         $finalSumPaid = $this->getSumPaid() - $payment->getSum() + ($maxPaid > 0 ? $maxPaid : 0);
     }
     if ($maxPaid > 0) {
         if ($debitSum > $userBudget) {
             $result->addError(new ResultError('SALE_ORDER_PAYMENT_NOT_ENOUGH_USER_BUDGET', '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;
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
 /**
  * @return array
  */
 protected static function getPaymentAvailableFields()
 {
     return Sale\Payment::getAvailableFields();
 }
Ejemplo n.º 5
0
 /**
  * @param OrderBase $order
  * @return PaymentCollection
  */
 public static function load(OrderBase $order)
 {
     /** @var PaymentCollection $paymentCollection */
     $paymentCollection = new static();
     $paymentCollection->setOrder($order);
     if ($order->getId() > 0) {
         $paymentList = Payment::loadForOrder($order->getId());
         /** @var Payment $payment */
         foreach ($paymentList as $payment) {
             $payment->setCollection($paymentCollection);
             $paymentCollection->addItem($payment);
         }
     }
     return $paymentCollection;
 }