/** * This function returns full transaction details for a specified transaction ID. * * @param string $transactionId * @return \Magento\Framework\Object * @throws \Magento\Framework\Model\Exception * @link http://www.authorize.net/support/ReportingGuide_XML.pdf * @link http://developer.authorize.net/api/transaction_details/ */ protected function _getTransactionDetails($transactionId) { $requestBody = sprintf('<?xml version="1.0" encoding="utf-8"?>' . '<getTransactionDetailsRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">' . '<merchantAuthentication><name>%s</name><transactionKey>%s</transactionKey></merchantAuthentication>' . '<transId>%s</transId>' . '</getTransactionDetailsRequest>', $this->getConfigData('login'), $this->getConfigData('trans_key'), $transactionId); $client = new \Magento\Framework\HTTP\ZendClient(); $uri = $this->getConfigData('cgi_url_td'); $client->setUri($uri ? $uri : self::CGI_URL_TD); $client->setConfig(array('timeout' => 45)); $client->setHeaders(array('Content-Type: text/xml')); $client->setMethod(\Zend_Http_Client::POST); $client->setRawData($requestBody); $debugData = array('request' => $requestBody); try { $responseBody = $client->request()->getBody(); $debugData['result'] = $responseBody; $this->_debug($debugData); libxml_use_internal_errors(true); $responseXmlDocument = new \Magento\Framework\Simplexml\Element($responseBody); libxml_use_internal_errors(false); } catch (\Exception $e) { throw new \Magento\Framework\Model\Exception(__('Payment updating error.')); } $response = new \Magento\Framework\Object(); $response->setResponseCode((string) $responseXmlDocument->transaction->responseCode)->setResponseReasonCode((string) $responseXmlDocument->transaction->responseReasonCode)->setTransactionStatus((string) $responseXmlDocument->transaction->transactionStatus); return $response; }
/** * Post request to gateway and return response * * @param \Magento\Authorizenet\Model\Request $request * @return \Magento\Authorizenet\Model\Response * @throws \Magento\Framework\Exception\LocalizedException */ protected function postRequest(\Magento\Authorizenet\Model\Request $request) { $result = $this->responseFactory->create(); $client = new \Magento\Framework\HTTP\ZendClient(); $url = $this->getConfigData('cgi_url') ?: self::CGI_URL; $debugData = ['url' => $url, 'request' => $request->getData()]; $client->setUri($url); $client->setConfig(['maxredirects' => 0, 'timeout' => 30]); foreach ($request->getData() as $key => $value) { $request->setData($key, str_replace(self::RESPONSE_DELIM_CHAR, '', $value)); } $request->setXDelimChar(self::RESPONSE_DELIM_CHAR); $client->setParameterPost($request->getData()); $client->setMethod(\Zend_Http_Client::POST); try { $response = $client->request(); $responseBody = $response->getBody(); $debugData['response'] = $responseBody; } catch (\Exception $e) { $result->setXResponseCode(-1)->setXResponseReasonCode($e->getCode())->setXResponseReasonText($e->getMessage()); throw new \Magento\Framework\Exception\LocalizedException($this->dataHelper->wrapGatewayError($e->getMessage())); } finally { $this->_debug($debugData); } $r = explode(self::RESPONSE_DELIM_CHAR, $responseBody); if ($r) { $result->setXResponseCode((int) str_replace('"', '', $r[0]))->setXResponseReasonCode((int) str_replace('"', '', $r[2]))->setXResponseReasonText($r[3])->setXAvsCode($r[5])->setXTransId($r[6])->setXInvoiceNum($r[7])->setXAmount($r[9])->setXMethod($r[10])->setXType($r[11])->setData('x_MD5_Hash', $r[37])->setXAccountNumber($r[50]); } else { throw new \Magento\Framework\Exception\LocalizedException(__('Something went wrong in the payment gateway.')); } return $result; }