Skip to content
Snippets Groups Projects
Commit 02e38fc6 authored by Stanislav Lopukhov's avatar Stanislav Lopukhov
Browse files

Merge branch 'develop' of github.corp.ebay.com:magento2/magento2ce into MAGETWO-37206

parents 194791ea 163044a7
Branches
No related merge requests found
Showing
with 394 additions and 61 deletions
......@@ -15,7 +15,7 @@ class Info extends \Magento\Framework\View\Element\Template
*
* @var \Magento\Framework\Object
*/
protected $_paymentSpecificInformation = null;
protected $_paymentSpecificInformation;
/**
* @var string
......@@ -152,10 +152,6 @@ class Info extends \Magento\Framework\View\Element\Template
} elseif (is_array($transport)) {
$transport = new \Magento\Framework\Object($transport);
}
$this->_eventManager->dispatch(
'payment_info_block_prepare_specific_information',
['transport' => $transport, 'payment' => $this->getInfo(), 'block' => $this]
);
$this->_paymentSpecificInformation = $transport;
}
return $this->_paymentSpecificInformation;
......
......@@ -6,6 +6,7 @@
namespace Magento\Payment\Block\Transparent;
use Magento\Framework\Exception\LocalizedException;
use Magento\Payment\Model\Method\Adapter;
use Magento\Payment\Model\Method\TransparentInterface;
use Magento\Checkout\Model\Session;
use Magento\Payment\Model\Config;
......@@ -168,7 +169,11 @@ class Form extends \Magento\Payment\Block\Form\Cc
*/
public function getMethodConfigData($fieldName)
{
return $this->getMethod()->getConfigInterface()->getValue($fieldName);
$method = $this->getMethod();
if ($method instanceof TransparentInterface) {
return $method->getConfigInterface()->getValue($fieldName);
}
return $method->getConfigData($fieldName);
}
/**
......@@ -181,7 +186,7 @@ class Form extends \Magento\Payment\Block\Form\Cc
{
$method = parent::getMethod();
if (!$method instanceof TransparentInterface) {
if (!$method instanceof TransparentInterface && !$method instanceof Adapter) {
throw new LocalizedException(
__('We cannot retrieve the transparent payment method model object.')
);
......
......@@ -12,6 +12,8 @@ namespace Magento\Payment\Block\Transparent;
*/
class Iframe extends \Magento\Framework\View\Element\Template
{
const REGISTRY_KEY = 'transparent_form_params';
/**
* Core registry
*
......@@ -42,10 +44,8 @@ class Iframe extends \Magento\Framework\View\Element\Template
*/
protected function _prepareLayout()
{
if ($this->hasRegistryKey()) {
$params = $this->coreRegistry->registry($this->getRegistryKey());
$this->setParams($params);
}
$params = $this->coreRegistry->registry(self::REGISTRY_KEY);
$this->setParams($params);
return parent::_prepareLayout();
}
}
......@@ -8,21 +8,29 @@ namespace Magento\Payment\Gateway\Command;
use Magento\Framework\ObjectManager\TMap;
use Magento\Payment\Gateway\CommandInterface;
use Magento\Framework\Exception\NotFoundException;
use Magento\Framework\ObjectManager\TMapFactory;
class CommandPool implements CommandPoolInterface
{
/**
* @var CommandInterface[]
* @var CommandInterface[] | TMap
*/
private $commands;
/**
* @param TMap $commands
* @param array $commands
* @param TMapFactory $tmapFactory
*/
public function __construct(
TMap $commands
array $commands,
TMapFactory $tmapFactory
) {
$this->commands = $commands;
$this->commands = $tmapFactory->create(
[
'array' => $commands,
'type' => 'Magento\Payment\Gateway\CommandInterface'
]
);
}
/**
......
......@@ -7,66 +7,83 @@ namespace Magento\Payment\Gateway\Command;
use Magento\Payment\Gateway\CommandInterface;
use Magento\Payment\Gateway\Http\ClientInterface;
use Magento\Payment\Gateway\Http\TransferFactoryInterface;
use Magento\Payment\Gateway\Request;
use Magento\Payment\Gateway\Request\BuilderInterface;
use Magento\Payment\Gateway\Response;
use Magento\Payment\Gateway\Response\HandlerInterface;
use Magento\Payment\Gateway\Validator\ValidatorInterface;
class GatewayCommand implements CommandInterface
{
/**
* @var \Magento\Payment\Gateway\Request\BuilderInterface
* @var BuilderInterface
*/
private $requestBuilder;
/**
* @var \Magento\Payment\Gateway\Http\TransferBuilderInterface
* @var TransferFactoryInterface
*/
private $transferBuilder;
private $transferFactory;
/**
* @var \Magento\Payment\Gateway\Http\ClientInterface
* @var ClientInterface
*/
private $gateway;
private $client;
/**
* @var \Magento\Payment\Gateway\Response\HandlerInterface
* @var HandlerInterface
*/
private $responseHandler;
private $handler;
/**
* @param \Magento\Payment\Gateway\Request\BuilderInterface $requestBuilder
* @param \Magento\Payment\Gateway\Http\TransferBuilderInterface $transferBuilder
* @param \Magento\Payment\Gateway\Http\ClientInterface $gateway
* @param \Magento\Payment\Gateway\Response\HandlerInterface $responseHandler
* @var ValidatorInterface
*/
private $validator;
/**
* @param BuilderInterface $requestBuilder
* @param TransferFactoryInterface $transferFactory
* @param ClientInterface $client
* @param HandlerInterface $handler
* @param ValidatorInterface $validator
*/
public function __construct(
\Magento\Payment\Gateway\Request\BuilderInterface $requestBuilder,
\Magento\Payment\Gateway\Http\TransferBuilderInterface $transferBuilder,
ClientInterface $gateway,
\Magento\Payment\Gateway\Response\HandlerInterface $responseHandler
BuilderInterface $requestBuilder,
TransferFactoryInterface $transferFactory,
ClientInterface $client,
HandlerInterface $handler,
ValidatorInterface $validator
) {
$this->requestBuilder = $requestBuilder;
$this->transferBuilder = $transferBuilder;
$this->gateway = $gateway;
$this->responseHandler = $responseHandler;
$this->transferFactory = $transferFactory;
$this->client = $client;
$this->handler = $handler;
$this->validator = $validator;
}
/**
* Executes command basing on business object
*
* @param array $commandSubject
* @return void
* @return null
*/
public function execute(array $commandSubject)
{
// @TODO implement exceptions catching
$transferO = $this->transferBuilder->build(
$transferO = $this->transferFactory->create(
$this->requestBuilder->build($commandSubject)
);
$response = $this->gateway->placeRequest($transferO);
$response = $this->client->placeRequest($transferO);
$result = $this->validator->validate(array_merge($commandSubject, ['response' => $response]));
if ($result !== null && !$result->isValid()) {
$commandSubject['payment']->getPayment()->setIsTransactionPending(true);
return;
}
$this->responseHandler->handle(
$this->handler->handle(
$commandSubject,
$response
);
......
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Payment\Gateway\Command\Result;
use Magento\Payment\Gateway\Command\ResultInterface;
class ArrayResult implements ResultInterface
{
/**
* @var array
*/
private $array;
/**
* @param array $array
*/
public function __construct(array $array = [])
{
$this->array = $array;
}
/**
* Returns result interpretation
*
* @return array
*/
public function get()
{
return $this->array;
}
}
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Payment\Gateway\Command;
interface ResultInterface
{
/**
* Returns result interpretation
*
* @return mixed
*/
public function get();
}
......@@ -11,7 +11,7 @@ interface CommandInterface
* Executes command basing on business object
*
* @param array $commandSubject
* @return void
* @return null|Command\ResultInterface
*/
public function execute(array $commandSubject);
}
......@@ -6,6 +6,7 @@
namespace Magento\Payment\Gateway\Config;
use Magento\Framework\ObjectManager\TMap;
use Magento\Framework\ObjectManager\TMapFactory;
class ValueHandlerPool implements \Magento\Payment\Gateway\Config\ValueHandlerPoolInterface
{
......@@ -15,21 +16,28 @@ class ValueHandlerPool implements \Magento\Payment\Gateway\Config\ValueHandlerPo
const DEFAULT_HANDLER = 'default';
/**
* @var ValueHandlerInterface[]
* @var ValueHandlerInterface[] | TMap
*/
private $handlers;
/**
* @param TMap $handlers
* @param array $handlers
* @param TMapFactory $tmapFactory
*/
public function __construct(
TMap $handlers
array $handlers,
TMapFactory $tmapFactory
) {
if (!isset($handlers[self::DEFAULT_HANDLER])) {
throw new \LogicException('Default handler should be provided.');
}
$this->handlers = $handlers;
$this->handlers = $tmapFactory->create(
[
'array' => $handlers,
'type' => 'Magento\Payment\Gateway\Config\ValueHandlerInterface'
]
);
}
/**
......
......@@ -12,7 +12,7 @@ interface AddressAdapterInterface
*
* @return string
*/
public function getRegion();
public function getRegionCode();
/**
* Get country id
......
......@@ -28,9 +28,9 @@ class AddressAdapter implements AddressAdapterInterface
*
* @return string
*/
public function getRegion()
public function getRegionCode()
{
return $this->address->getRegion();
return $this->address->getRegionCode();
}
/**
......
......@@ -86,4 +86,24 @@ class OrderAdapter implements OrderAdapterInterface
['address' => $this->order->getShippingAddress()]
);
}
/**
* Returns order store id
*
* @return int
*/
public function getStoreId()
{
return $this->order->getStoreId();
}
/**
* Returns order id
*
* @return int
*/
public function getId()
{
return $this->order->getEntityId();
}
}
......@@ -41,4 +41,18 @@ interface OrderAdapterInterface
* @return AddressAdapterInterface
*/
public function getShippingAddress();
/**
* Returns order store id
*
* @return int
*/
public function getStoreId();
/**
* Returns order id
*
* @return int
*/
public function getId();
}
......@@ -28,9 +28,9 @@ class AddressAdapter implements AddressAdapterInterface
*
* @return string
*/
public function getRegion()
public function getRegionCode()
{
return $this->address->getRegion();
return $this->address->getRegionCode();
}
/**
......
......@@ -86,4 +86,24 @@ class QuoteAdapter implements OrderAdapterInterface
['address' => $this->quote->getShippingAddress()]
);
}
/**
* Returns order store id
*
* @return int
*/
public function getStoreId()
{
return $this->quote->getStoreId();
}
/**
* Returns order id
*
* @return int
*/
public function getId()
{
return $this->quote->getId();
}
}
......@@ -8,6 +8,8 @@ namespace Magento\Payment\Gateway\Http\Client;
use Magento\Framework\HTTP\ZendClientFactory;
use Magento\Framework\HTTP\ZendClient;
use Magento\Payment\Gateway\Http\ClientInterface;
use Magento\Payment\Gateway\Http\ConverterInterface;
use Magento\Payment\Model\Method\Logger;
class Zend implements ClientInterface
{
......@@ -17,20 +19,28 @@ class Zend implements ClientInterface
private $clientFactory;
/**
* @var \Magento\Payment\Gateway\Http\ConverterInterface
* @var ConverterInterface
*/
private $converter;
/**
* @var Logger
*/
private $logger;
/**
* @param ZendClientFactory $clientFactory
* @param \Magento\Payment\Gateway\Http\ConverterInterface $converter
* @param ConverterInterface $converter
* @param Logger $logger
*/
public function __construct(
ZendClientFactory $clientFactory,
\Magento\Payment\Gateway\Http\ConverterInterface $converter
ConverterInterface $converter,
Logger $logger
) {
$this->clientFactory = $clientFactory;
$this->converter = $converter;
$this->logger = $logger;
}
/**
......@@ -38,6 +48,10 @@ class Zend implements ClientInterface
*/
public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $transferObject)
{
$log = [
'request' => $transferObject->getBody()
];
$result = [];
/** @var ZendClient $client */
$client = $this->clientFactory->create();
......@@ -61,11 +75,17 @@ class Zend implements ClientInterface
try {
$response = $client->request();
return $this->converter->convert($response->getBody());
$result = $this->converter->convert($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;
}
}
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Payment\Gateway\Http\Converter;
use Magento\Payment\Gateway\Http\ConverterException;
use Magento\Payment\Gateway\Http\ConverterInterface;
class HtmlFormConverter implements ConverterInterface
{
/**
* Converts gateway response to ENV structure
*
* @param string $response
* @return array
* @throws ConverterException
*/
public function convert($response)
{
$document = new \DOMDocument();
libxml_use_internal_errors(true);
if (!$document->loadHTML($response)) {
throw new ConverterException(__('Wrong gateway response format.'));
}
libxml_use_internal_errors(false);
$document->getElementsByTagName('input');
$convertedResponse = [];
/** @var \DOMNode $inputNode */
foreach ($document->getElementsByTagName('input') as $inputNode) {
if (!$inputNode->attributes->getNamedItem('value')
|| !$inputNode->attributes->getNamedItem('name')
) {
continue;
}
$convertedResponse[$inputNode->attributes->getNamedItem('name')->nodeValue]
= $inputNode->attributes->getNamedItem('value')->nodeValue;
}
return $convertedResponse;
}
}
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Payment\Gateway\Http;
class Transfer implements TransferInterface
{
/**
* @var array
*/
private $clientConfig;
/**
* @var array
*/
private $headers;
/**
* @var string
*/
private $method;
/**
* @var array
*/
private $body;
/**
* @var string
*/
private $uri;
/**
* @var bool
*/
private $encode;
/**
* @param array $clientConfig
* @param array $headers
* @param array $body
* @param string $method
* @param string $uri
* @param bool $encode
*/
public function __construct(
array $clientConfig,
array $headers,
array $body,
$method,
$uri,
$encode = false
) {
$this->clientConfig = $clientConfig;
$this->headers = $headers;
$this->method = $method;
$this->body = $body;
$this->uri = $uri;
$this->encode = $encode;
}
/**
* Returns gateway client configuration
*
* @return array
*/
public function getClientConfig()
{
return $this->clientConfig;
}
/**
* Returns method used to place request
*
* @return string|int
*/
public function getMethod()
{
return (string)$this->method;
}
/**
* Returns headers
*
* @return array
*/
public function getHeaders()
{
return $this->headers;
}
/**
* Whether body should be encoded before place
*
* @return bool
*/
public function shouldEncode()
{
return (bool)$this->encode;
}
/**
* Returns request body
*
* @return array
*/
public function getBody()
{
return $this->body;
}
/**
* Returns URI
*
* @return string
*/
public function getUri()
{
return (string)$this->uri;
}
}
......@@ -5,15 +5,13 @@
*/
namespace Magento\Payment\Gateway\Http;
use Magento\Payment\Gateway\Http\TransferInterface;
interface TransferBuilderInterface
interface TransferFactoryInterface
{
/**
* Builds gateway transfer object
*
* @param array $requestENV
* @param array $request
* @return TransferInterface
*/
public function build(array $requestENV);
public function create(array $request);
}
......@@ -6,21 +6,29 @@
namespace Magento\Payment\Gateway\Request;
use Magento\Framework\ObjectManager\TMap;
use Magento\Framework\ObjectManager\TMapFactory;
class BuilderComposite implements BuilderInterface
{
/**
* @var BuilderInterface[]
* @var BuilderInterface[] | TMap
*/
private $builders;
/**
* @param TMap $builders
* @param array $builders
* @param TMapFactory $tmapFactory
*/
public function __construct(
TMap $builders
array $builders,
TMapFactory $tmapFactory
) {
$this->builders = $builders;
$this->builders = $tmapFactory->create(
[
'array' => $builders,
'type' => 'Magento\Payment\Gateway\Request\BuilderInterface'
]
);
}
/**
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment