/** * Send request for tracking * * @param string[] $trackings * @return void */ protected function _getXMLTracking($trackings) { $xmlStr = '<?xml version="1.0" encoding="UTF-8"?>' . '<req:KnownTrackingRequest' . ' xmlns:req="http://www.dhl.com"' . ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' . ' xsi:schemaLocation="http://www.dhl.com TrackingRequestKnown.xsd" />'; $xml = $this->_xmlElFactory->create(array('data' => $xmlStr)); $requestNode = $xml->addChild('Request', '', ''); $serviceHeaderNode = $requestNode->addChild('ServiceHeader', '', ''); $serviceHeaderNode->addChild('SiteID', (string) $this->getConfigData('id')); $serviceHeaderNode->addChild('Password', (string) $this->getConfigData('password')); $xml->addChild('LanguageCode', 'EN', ''); foreach ($trackings as $tracking) { $xml->addChild('AWBNumber', $tracking, ''); } /** * Checkpoint details selection flag * LAST_CHECK_POINT_ONLY * ALL_CHECK_POINTS */ $xml->addChild('LevelOfDetails', 'ALL_CHECK_POINTS', ''); /** * Value that indicates for getting the tracking details with the additional * piece details and its respective Piece Details, Piece checkpoints along with * Shipment Details if queried. * * S-Only Shipment Details * B-Both Shipment & Piece Details * P-Only Piece Details * Default is ‘S’ */ //$xml->addChild('PiecesEnabled', 'ALL_CHECK_POINTS'); $request = $xml->asXML(); $request = utf8_encode($request); $responseBody = $this->_getCachedQuotes($request); if ($responseBody === null) { $debugData = array('request' => $request); try { $client = new \Magento\Framework\HTTP\ZendClient(); $client->setUri((string) $this->getConfigData('gateway_url')); $client->setConfig(array('maxredirects' => 0, 'timeout' => 30)); $client->setRawData($request); $responseBody = $client->request(\Magento\Framework\HTTP\ZendClient::POST)->getBody(); $debugData['result'] = $responseBody; $this->_setCachedQuotes($request, $responseBody); } catch (\Exception $e) { $this->_errors[$e->getCode()] = $e->getMessage(); $responseBody = ''; } $this->_debug($debugData); } $this->_parseXmlTrackingResponse($trackings, $responseBody); }
/** * Retrieve country name from ip address * * @return string */ public function getCountry() { $clientIp = $this->_request->getClientIp(); $requestUri = 'http://freegeoip.net/json/' . $clientIp; $httpClient = new \Magento\Framework\HTTP\ZendClient($requestUri); $response = $httpClient->request('GET')->getBody(); return json_decode($response, true); }
/** * 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; }
/** * Check validity of a base URL * * @param string $baseUrl * @return void * @throws \Magento\Framework\Model\Exception * @throws \Exception */ protected function _checkUrl($baseUrl) { try { $staticFile = $this->_findFirstFileRelativePath('', '/.+\\.(html?|js|css|gif|jpe?g|png)$/'); $staticUrl = $baseUrl . $this->_filesystem->getUri(\Magento\Framework\App\Filesystem::PUB_DIR) . '/' . $staticFile; $client = new \Magento\Framework\HTTP\ZendClient($staticUrl); $response = $client->request('GET'); } catch (\Exception $e) { $this->messageManager->addError(__('The URL "%1" is not accessible.', $baseUrl)); throw $e; } if ($response->getStatus() != 200) { $this->messageManager->addError(__('The URL "%1" is invalid.', $baseUrl)); throw new \Magento\Framework\Model\Exception(__('Response from the server is invalid.')); } }
/** * 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; }
/** * Post request to gateway and return response * * @param \Magento\Framework\Object $request * @return \Magento\Framework\Object * @throws \Exception */ protected function _postRequest(\Magento\Framework\Object $request) { $debugData = array('request' => $request->getData()); $client = new \Magento\Framework\HTTP\ZendClient(); $result = new \Magento\Framework\Object(); $_config = array('maxredirects' => 5, 'timeout' => 30, 'verifypeer' => $this->getConfigData('verify_peer')); $_isProxy = $this->getConfigData('use_proxy', false); if ($_isProxy) { $_config['proxy'] = $this->getConfigData('proxy_host') . ':' . $this->getConfigData('proxy_port'); //http://proxy.shr.secureserver.net:3128', $_config['httpproxytunnel'] = true; $_config['proxytype'] = CURLPROXY_HTTP; } $client->setUri($this->_getTransactionUrl())->setConfig($_config)->setMethod(\Zend_Http_Client::POST)->setParameterPost($request->getData())->setHeaders('X-VPS-VIT-CLIENT-CERTIFICATION-ID: 33baf5893fc2123d8b191d2d011b7fdc')->setHeaders('X-VPS-Request-ID: ' . $request->getRequestId())->setHeaders('X-VPS-CLIENT-TIMEOUT: ' . $this->_clientTimeout); try { /** * we are sending request to payflow pro without url encoding * so we set up _urlEncodeBody flag to false */ $response = $client->setUrlEncodeBody(false)->request(); } catch (\Exception $e) { $result->setResponseCode(-1)->setResponseReasonCode($e->getCode())->setResponseReasonText($e->getMessage()); $debugData['result'] = $result->getData(); $this->_debug($debugData); throw $e; } $response = strstr($response->getBody(), 'RESULT'); $valArray = explode('&', $response); foreach ($valArray as $val) { $valArray2 = explode('=', $val); $result->setData(strtolower($valArray2[0]), $valArray2[1]); } $result->setResultCode($result->getResult())->setRespmsg($result->getRespmsg()); $debugData['result'] = $result->getData(); $this->_debug($debugData); return $result; }