예제 #1
0
 /**
  * Captures specified amount
  *
  * @param InfoInterface $payment
  * @param string $amount
  * @return $this
  * @throws LocalizedException
  */
 public function capture(InfoInterface $payment, $amount)
 {
     try {
         /** @var \Magento\Sales\Model\Order\Payment $payment */
         if ($payment->getCcTransId()) {
             $collection = $this->salesTransactionCollectionFactory->create()->addFieldToFilter('payment_id', $payment->getId())->addFieldToFilter('txn_type', PaymentTransaction::TYPE_CAPTURE);
             if ($collection->getSize() > 0) {
                 $this->partialCapture($payment, $amount);
             } else {
                 $result = $this->braintreeTransaction->submitForSettlement($payment->getCcTransId(), $amount);
                 $this->_debug([$payment->getCcTransId() . ' - ' . $amount]);
                 $this->_debug($this->_convertObjToArray($result));
                 if ($result->success) {
                     $payment->setIsTransactionClosed(false)->setShouldCloseParentTransaction(false);
                     if ($this->isFinalCapture($payment->getParentId(), $amount)) {
                         $payment->setShouldCloseParentTransaction(true);
                     }
                 } else {
                     throw new LocalizedException($this->errorHelper->parseBraintreeError($result));
                 }
             }
         } else {
             $this->braintreeAuthorize($payment, $amount, true);
         }
     } catch (\Exception $e) {
         $this->_logger->critical($e);
         throw new LocalizedException(__('There was an error capturing the transaction: %1.', $e->getMessage()));
     }
     return $this;
 }