Esempio n. 1
0
 /**
  * Void the payment through gateway
  *
  * @param \Magento\Framework\DataObject|\Magento\Payment\Model\InfoInterface $payment
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function void(\Magento\Payment\Model\InfoInterface $payment)
 {
     if (!$payment->getParentTransactionId()) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Invalid transaction ID.'));
     }
     $payment->setAnetTransType(self::REQUEST_TYPE_VOID);
     $payment->setXTransId($this->getRealParentTransactionId($payment));
     $request = $this->buildRequest($payment);
     $result = $this->postRequest($request);
     switch ($result->getXResponseCode()) {
         case self::RESPONSE_CODE_APPROVED:
             if ($result->getXResponseReasonCode() == self::RESPONSE_REASON_CODE_APPROVED) {
                 if ($result->getXTransId() != $payment->getParentTransactionId()) {
                     $payment->setTransactionId($result->getXTransId());
                 }
                 $payment->setIsTransactionClosed(1)->setShouldCloseParentTransaction(1)->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 voiding error.'));
     }
 }