/**
  * Process capture request
  *
  * @param \Magento\Authorizenet\Model\Directpost\Response $result
  * @param \Magento\Payment\Model\InfoInterface $payment
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function processCapture($result, $payment)
 {
     switch ($result->getXResponseCode()) {
         case self::RESPONSE_CODE_APPROVED:
         case self::RESPONSE_CODE_HELD:
             if (in_array($result->getXResponseReasonCode(), [self::RESPONSE_REASON_CODE_APPROVED, self::RESPONSE_REASON_CODE_PENDING_REVIEW, self::RESPONSE_REASON_CODE_PENDING_REVIEW_AUTHORIZED])) {
                 if (!$payment->getParentTransactionId() || $result->getXTransId() != $payment->getParentTransactionId()) {
                     $payment->setTransactionId($result->getXTransId());
                 }
                 $payment->setIsTransactionClosed(0)->setTransactionAdditionalInfo(self::REAL_TRANSACTION_ID_KEY, $result->getXTransId());
                 return $this;
             }
             throw new \Magento\Framework\Exception\LocalizedException($this->dataHelper->wrapGatewayError($result->getXResponseReasonText()));
         case self::RESPONSE_CODE_DECLINED:
         case self::RESPONSE_CODE_ERROR:
             throw new \Magento\Framework\Exception\LocalizedException($this->dataHelper->wrapGatewayError($result->getXResponseReasonText()));
         default:
             throw new \Magento\Framework\Exception\LocalizedException(__('Payment capturing error.'));
     }
 }