/** * {@inheritdoc} */ public function build($type) { if ($this->isPaymentExists() && $this->transactionId !== null) { $transaction = $this->transactionRepository->getByTransactionId($this->transactionId, $this->payment->getId(), $this->order->getId()); if (!$transaction) { $transaction = $this->transactionRepository->create()->setTxnId($this->transactionId); } $transaction->setPaymentId($this->payment->getId())->setPayment($this->payment)->setOrderId($this->order->getId())->setOrder($this->order)->setTxnType($type)->isFailsafe($this->failSafe); if ($this->payment->hasIsTransactionClosed()) { $transaction->setIsClosed((int) $this->payment->getIsTransactionClosed()); } if ($this->transactionAdditionalInfo) { foreach ($this->transactionAdditionalInfo as $key => $value) { $transaction->setAdditionalInformation($key, $value); } } $this->transactionAdditionalInfo = []; $this->payment->setLastTransId($transaction->getTxnId()); $this->payment->setCreatedTransaction($transaction); $this->order->addRelatedObject($transaction); if ($this->document && $this->document instanceof AbstractModel) { $this->document->setTransactionId($transaction->getTxnId()); } return $this->linkWithParentTransaction($transaction); } return null; }
/** * Get transaction with type order * * @param OrderPaymentInterface $payment * * @return false|\Magento\Sales\Api\Data\TransactionInterface */ protected function getOrderTransaction($payment) { return $this->transactionRepository->getByTransactionType(Transaction::TYPE_ORDER, $payment->getId(), $payment->getOrder()->getId()); }
/** * Check if capture transaction already exists * * @param OrderPaymentInterface $payment * @return bool */ private function isExistsCaptureTransaction(OrderPaymentInterface $payment) { $filters[] = $this->filterBuilder->setField('payment_id')->setValue($payment->getId())->create(); $filters[] = $this->filterBuilder->setField('txn_type')->setValue(TransactionInterface::TYPE_CAPTURE)->create(); $searchCriteria = $this->searchCriteriaBuilder->addFilters($filters)->create(); $count = $this->transactionRepository->getList($searchCriteria)->getTotalCount(); return (bool) $count; }
/** * {@inheritdoc} */ public function setPayment(\Magento\Sales\Api\Data\OrderPaymentInterface $payment = null) { $payment->setOrder($this)->setParentId($this->getId()); if (!$payment->getId()) { $this->setData(OrderInterface::PAYMENT, $payment); $this->setDataChanges(true); } return $payment; }