Exemplo n.º 1
0
 /**
  * {inheritdoc}
  */
 public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $transferObject)
 {
     /** @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();
         return $this->converter->convert($response->getBody());
     } catch (\Zend_Http_Client_Exception $e) {
         throw new \Magento\Payment\Gateway\Http\ClientException(__($e->getMessage()));
     } catch (\Magento\Payment\Gateway\Http\ConverterException $e) {
         throw $e;
     }
 }
 /**
  * Returns result code
  *
  * @param TransferInterface $transfer
  * @return int
  */
 private function getResultCode(TransferInterface $transfer)
 {
     $headers = $transfer->getHeaders();
     if (isset($headers['force_result'])) {
         return (int) $headers['force_result'];
     }
     return $this->results[mt_rand(0, 1)];
 }
 /**
  * @param \Magento\Payment\Gateway\Http\TransferInterface $transferObject
  * @return mixed
  * @throws ClientException
  */
 public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $transferObject)
 {
     $request = $transferObject->getBody();
     // call lib
     $service = new \Adyen\Service\Payment($this->_client);
     try {
         $response = $service->authorise($request);
     } catch (\Adyen\AdyenException $e) {
         $response['error'] = $e->getMessage();
     }
     return $response;
 }
Exemplo n.º 4
0
 /**
  * @param \Magento\Payment\Gateway\Http\TransferInterface $transferObject
  * @return null
  */
 public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $transferObject)
 {
     $request = $transferObject->getBody();
     // call lib
     $service = new \Adyen\Service\Modification($this->_client);
     try {
         $response = $service->cancelOrRefund($request);
     } catch (\Adyen\AdyenException $e) {
         $response = null;
     }
     return $response;
 }
Exemplo n.º 5
0
 /**
  * @param \Magento\Payment\Gateway\Http\TransferInterface $transferObject
  * @return null
  */
 public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $transferObject)
 {
     $requests = $transferObject->getBody();
     $responses = [];
     foreach ($requests as $request) {
         // call lib
         $service = new \Adyen\Service\Modification($this->_client);
         try {
             $responses[] = $service->refund($request);
         } catch (\Adyen\AdyenException $e) {
             $responses[] = null;
         }
     }
     return $responses;
 }
Exemplo n.º 6
0
 /**
  * @inheritdoc
  */
 public function placeRequest(TransferInterface $transferObject)
 {
     $data = $transferObject->getBody();
     $log = ['request' => $data, 'client' => static::class];
     $response['object'] = [];
     try {
         $response['object'] = $this->process($data);
     } catch (\Exception $e) {
         $message = __($e->getMessage() ?: 'Sorry, but something went wrong');
         $this->logger->critical($message);
         throw new ClientException($message);
     } finally {
         $log['response'] = (array) $response['object'];
         $this->customLogger->debug($log);
     }
     return $response;
 }
Exemplo n.º 7
0
 /**
  * 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;
 }
Exemplo n.º 8
0
 private function setClientTransferObjects()
 {
     $config = ['key1' => 'value1', 'key2' => 'value2'];
     $method = \Zend_Http_Client::POST;
     $headers = ['key1' => 'value1', 'key2' => 'value2'];
     $body = 'Body content';
     $uri = 'https://example.com/listener';
     $shouldEncode = true;
     $this->transferObjectMock->expects($this->once())->method('getClientConfig')->willReturn($config);
     $this->transferObjectMock->expects($this->atLeastOnce())->method('getMethod')->willReturn($method);
     $this->transferObjectMock->expects($this->once())->method('getHeaders')->willReturn($headers);
     $this->transferObjectMock->expects($this->once())->method('getBody')->willReturn($body);
     $this->transferObjectMock->expects($this->once())->method('shouldEncode')->willReturn($shouldEncode);
     $this->transferObjectMock->expects($this->once())->method('getUri')->willReturn($uri);
     $this->clientMock->expects($this->once())->method('setConfig')->with($config)->willReturnSelf();
     $this->clientMock->expects($this->once())->method('setMethod')->with($method)->willReturnSelf();
     $this->clientMock->expects($this->once())->method('setParameterPost')->with($body)->willReturnSelf();
     $this->clientMock->expects($this->once())->method('setHeaders')->with($headers)->willReturnSelf();
     $this->clientMock->expects($this->once())->method('setUrlEncodeBody')->with($shouldEncode)->willReturnSelf();
     $this->clientMock->expects($this->once())->method('setUri')->with($uri)->willReturnSelf();
 }