/** * {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; }
/** * Returns gateway response data object * * @param array $gatewayTransactionResponse * @return Object */ public function getResponseObject($gatewayTransactionResponse) { $response = new DataObject(); $response = $this->transparent->mapGatewayResponse($gatewayTransactionResponse, $response); $this->logger->debug($gatewayTransactionResponse, (array) $this->transparent->getDebugReplacePrivateDataKeys(), (bool) $this->transparent->getDebugFlag()); return $response; }
/** * Post request into gateway * * @param DataObject $request * @param ConfigInterface $config * * @return DataObject * @throws \Zend_Http_Client_Exception */ public function postRequest(DataObject $request, ConfigInterface $config) { $result = new DataObject(); $clientConfig = ['maxredirects' => 5, 'timeout' => 30, 'verifypeer' => $config->getValue('verify_peer')]; if ($config->getValue('use_proxy')) { $clientConfig['proxy'] = $config->getValue('proxy_host') . ':' . $config->getValue('proxy_port'); $clientConfig['httpproxytunnel'] = true; $clientConfig['proxytype'] = CURLPROXY_HTTP; } /** @var ZendClient $client */ $client = $this->httpClientFactory->create(); $client->setUri((bool) $config->getValue('sandbox_flag') ? $config->getValue('transaction_url_test_mode') : $config->getValue('transaction_url')); $client->setConfig($clientConfig); $client->setMethod(\Zend_Http_Client::POST); $client->setParameterPost($request->getData()); $client->setHeaders(['X-VPS-VIT-CLIENT-CERTIFICATION-ID' => '33baf5893fc2123d8b191d2d011b7fdc', 'X-VPS-Request-ID' => $this->mathRandom->getUniqueHash(), 'X-VPS-CLIENT-TIMEOUT' => 45]); $client->setUrlEncodeBody(false); try { $response = $client->request(); $responseArray = []; parse_str(strstr($response->getBody(), 'RESULT'), $responseArray); $result->setData(array_change_key_case($responseArray, CASE_LOWER)); $result->setData('result_code', $result->getData('result')); } catch (\Zend_Http_Client_Exception $e) { $result->addData(['response_code' => -1, 'response_reason_code' => $e->getCode(), 'response_reason_text' => $e->getMessage()]); throw $e; } finally { $this->logger->debug(['request' => $request->getData(), 'result' => $result->getData()], (array) $config->getValue('getDebugReplacePrivateDataKeys'), (bool) $config->getValue('debug')); } return $result; }
/** * Run test placeRequest method * * @return void */ public function testPlaceRequestSuccess() { $response = $this->getResponseObject(); $this->adapter->expects($this->once())->method('sale')->with($this->getTransferData())->willReturn($response); $this->loggerMock->expects($this->once())->method('debug')->with(['request' => $this->getTransferData(), 'client' => TransactionSale::class, 'response' => ['success' => 1]]); $actualResult = $this->model->placeRequest($this->getTransferObjectMock()); $this->assertTrue(is_object($actualResult['object'])); $this->assertEquals(['object' => $response], $actualResult); }
/** * @param array $expectedRequest * @param array $expectedResponse * @param array $expectedHeaders * * @dataProvider placeRequestDataProvider */ public function testPlaceRequest(array $expectedRequest, array $expectedResponse, array $expectedHeaders) { /** @var TransferInterface|\PHPUnit_Framework_MockObject_MockObject $transferObject */ $transferObject = $this->getMock(TransferInterface::class); $transferObject->expects(static::once())->method('getBody')->willReturn($expectedRequest); $transferObject->expects(static::once())->method('getHeaders')->willReturn($expectedHeaders); $this->clientMock->expects(static::once())->method('generateTxnId')->willReturn(self::TXN_ID); $this->logger->expects(static::once())->method('debug')->with(['request' => $expectedRequest, 'response' => $expectedResponse]); static::assertEquals($expectedResponse, $this->clientMock->placeRequest($transferObject)); }
public function testPostRequestOk() { $configInterfaceMock = $this->getMockBuilder('\\Magento\\Payment\\Model\\Method\\ConfigInterface')->getMockForAbstractClass(); $zendResponseMock = $this->getMockBuilder('\\Zend_Http_Response')->setMethods(['getBody'])->disableOriginalConstructor()->getMock(); $zendResponseMock->expects($this->once())->method('getBody')->willReturn('RESULT=0&RESPMSG=Approved&SECURETOKEN=8ZIaw2&SECURETOKENID=2481d53'); $this->zendClientMock->expects($this->once())->method('request')->willReturn($zendResponseMock); $configMap = [['getDebugReplacePrivateDataKeys', null, ['masked']], ['debug', null, true]]; $configInterfaceMock->expects($this->any())->method('getValue')->will($this->returnValueMap($configMap)); $this->loggerMock->expects($this->once())->method('debug'); $object = new \Magento\Framework\DataObject(); $result = $this->object->postRequest($object, $configInterfaceMock); $this->assertInstanceOf('Magento\\Framework\\DataObject', $result); $this->assertArrayHasKey('result_code', $result->getData()); }
/** * 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; }
public function testPostRequestOk() { $configMap = [['getDebugReplacePrivateDataKeys', null, ['masked']], ['debug', null, true]]; $expectedResponse = 'RESULT=0&RESPMSG=Approved&SECURETOKEN=8ZIaw2&SECURETOKENID=2481d53'; /** @var ConfigInterface|\PHPUnit_Framework_MockObject_MockObject $configInterfaceMock */ $configInterfaceMock = $this->getMockBuilder(ConfigInterface::class)->getMockForAbstractClass(); $zendResponseMock = $this->getMockBuilder(\Zend_Http_Response::class)->setMethods(['getBody'])->disableOriginalConstructor()->getMock(); $zendResponseMock->expects(static::once())->method('getBody')->willReturn($expectedResponse); $this->zendClientMock->expects(static::once())->method('request')->willReturn($zendResponseMock); $configInterfaceMock->expects(static::any())->method('getValue')->willReturnMap($configMap); $this->loggerMock->expects(static::once())->method('debug'); $object = new DataObject(); $result = $this->object->postRequest($object, $configInterfaceMock); static::assertInstanceOf(DataObject::class, $result); static::assertArrayHasKey('result_code', $result->getData()); }
/** * Load transaction details * * @param \Magento\Authorizenet\Model\Authorizenet $context * @param string $transactionId * @return \Magento\Framework\Simplexml\Element * @throws \Magento\Framework\Exception\LocalizedException */ protected function loadTransactionDetails(Authorizenet $context, $transactionId) { $requestBody = $this->getRequestBody($context->getConfigData('login'), $context->getConfigData('trans_key'), $transactionId); /** @var \Magento\Framework\HTTP\ZendClient $client */ $client = $this->httpClientFactory->create(); $url = $context->getConfigData('cgi_url_td') ?: self::CGI_URL_TD; $client->setUri($url); $client->setConfig(['timeout' => self::CONNECTION_TIMEOUT]); $client->setHeaders(['Content-Type: text/xml']); $client->setMethod(\Zend_Http_Client::POST); $client->setRawData($requestBody); $debugData = ['url' => $url, 'request' => $this->removePrivateDataFromXml($requestBody)]; try { $responseBody = $client->request()->getBody(); if (!$this->xmlSecurityHelper->scan($responseBody)) { $this->logger->critical('Attempt loading of external XML entities in response from Authorizenet.'); throw new \Exception(); } $debugData['response'] = $responseBody; libxml_use_internal_errors(true); $responseXmlDocument = new Element($responseBody); libxml_use_internal_errors(false); } catch (\Exception $e) { throw new LocalizedException(__('Unable to get transaction details. Try again later.')); } finally { $context->debugData($debugData); } if (!isset($responseXmlDocument->messages->resultCode) || $responseXmlDocument->messages->resultCode != static::PAYMENT_UPDATE_STATUS_CODE_SUCCESS) { throw new LocalizedException(__('Unable to get transaction details. Try again later.')); } $this->transactionDetails[$transactionId] = $responseXmlDocument; return $responseXmlDocument; }
/** * @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; }
public function testDeleteException() { $exception = new \Braintree_Exception(); $cardToken = 1; $this->braintreeCreditCardMock->expects($this->once())->method('delete')->with($cardToken)->willThrowException($exception); $this->loggerMock->expects($this->once())->method('critical')->with($exception); $return = $this->model->deleteCard($cardToken); $this->assertEquals(false, $return); }
/** * @param string $response * @param array $processableErrors * @param null|string $exception * @param string $exceptionMessage * @param null|int $exceptionCode * @dataProvider callDataProvider */ public function testCall($response, $processableErrors, $exception, $exceptionMessage = '', $exceptionCode = null) { if (isset($exception)) { $this->setExpectedException($exception, $exceptionMessage, $exceptionCode); } $this->curl->expects($this->once())->method('read')->will($this->returnValue($response)); $this->model->setProcessableErrors($processableErrors); $this->customLoggerMock->expects($this->once())->method('debug'); $this->model->call('some method', ['data' => 'some data']); }
/** * Log debug data to file * * @param array $debugData * @return void */ protected function _debug($debugData) { $this->logger->debug($debugData, $this->getDebugReplacePrivateDataKeys(), $this->getDebugFlag()); }
/** * Log debug data to file * * @param mixed $debugData * @return void */ protected function _debug($debugData) { $this->customLogger->debug($debugData, (array) $this->getDebugReplacePrivateDataKeys(), (bool) $this->getDebugFlag()); }
/** * Places request to gateway. Returns result as ENV array * * @param TransferInterface $transferObject * @return array */ public function placeRequest(TransferInterface $transferObject) { $response = $this->generateResponseForCode($this->getResultCode($transferObject)); $this->logger->debug(['request' => $transferObject->getBody(), 'response' => $response]); return $response; }