示例#1
0
 /**
  * {inheritdoc}
  */
 public function placeRequest(TransferInterface $transferObject)
 {
     $log = ['request' => $transferObject->getBody(), 'request_uri' => $transferObject->getUri()];
     $result = [];
     /** @var ZendClient $client */
     $client = $this->clientFactory->create();
     $client->setConfig($transferObject->getClientConfig());
     $client->setMethod($transferObject->getMethod());
     switch ($transferObject->getMethod()) {
         case \Zend_Http_Client::GET:
             $client->setParameterGet($transferObject->getBody());
             break;
         case \Zend_Http_Client::POST:
             $client->setParameterPost($transferObject->getBody());
             break;
         default:
             throw new \LogicException(sprintf('Unsupported HTTP method %s', $transferObject->getMethod()));
     }
     $client->setHeaders($transferObject->getHeaders());
     $client->setUrlEncodeBody($transferObject->shouldEncode());
     $client->setUri($transferObject->getUri());
     try {
         $response = $client->request();
         $result = $this->converter ? $this->converter->convert($response->getBody()) : [$response->getBody()];
         $log['response'] = $result;
     } catch (\Zend_Http_Client_Exception $e) {
         throw new \Magento\Payment\Gateway\Http\ClientException(__($e->getMessage()));
     } catch (\Magento\Payment\Gateway\Http\ConverterException $e) {
         throw $e;
     } finally {
         $this->logger->debug($log);
     }
     return $result;
 }
示例#2
0
文件: Soap.php 项目: uibar/lavinia2
 /**
  * Places request to gateway. Returns result as ENV array
  *
  * @param TransferInterface $transferObject
  * @return array
  * @throws \Magento\Payment\Gateway\Http\ClientException
  * @throws \Magento\Payment\Gateway\Http\ConverterException
  * @throws \Exception
  */
 public function placeRequest(TransferInterface $transferObject)
 {
     $this->logger->debug(['request' => $transferObject->getBody()]);
     $client = $this->clientFactory->create($transferObject->getClientConfig()['wsdl'], ['trace' => true]);
     try {
         $client->__setSoapHeaders($transferObject->getHeaders());
         $response = $client->__soapCall($transferObject->getMethod(), [$transferObject->getBody()]);
         $result = $this->converter ? $this->converter->convert($response) : [$response];
         $this->logger->debug(['response' => $result]);
     } catch (\Exception $e) {
         $this->logger->debug(['trace' => $client->__getLastRequest()]);
         throw $e;
     }
     return $result;
 }