Skip to content

Commit

Permalink
Merge pull request #409 from magento-tango/MAGETWO-38793
Browse files Browse the repository at this point in the history
[Tango] S55 Authorize.net, Bug Fixes
  • Loading branch information
Kovsher, Iurii(ikovsher) committed Jul 6, 2015
2 parents 2a834a3 + f0c363e commit a09b7a1
Show file tree
Hide file tree
Showing 118 changed files with 7,756 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Authorizenet\Block\Adminhtml\Order\View\Info;

use Magento\Authorizenet\Model\Directpost;

class FraudDetails extends \Magento\Backend\Block\Template
{
/**
* @var \Magento\Framework\Registry
*/
protected $registry;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\Registry $registry
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
array $data = []
) {
$this->registry = $registry;
parent::__construct($context, $data);
}

/**
* @return \Magento\Sales\Model\Order\Payment
*/
public function getPayment()
{
$order = $this->registry->registry('current_order');
return $order->getPayment();
}

/**
* @return string
*/
protected function _toHtml()
{
return ($this->getPayment()->getMethod() === Directpost::METHOD_CODE) ? parent::_toHtml() : '';
}
}
48 changes: 48 additions & 0 deletions app/code/Magento/Authorizenet/Block/Transparent/Iframe.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Authorizenet\Block\Transparent;

use Magento\Payment\Block\Transparent\Iframe as TransparentIframe;

/**
* Class Iframe
*/
class Iframe extends TransparentIframe
{
/**
* @var \Magento\Authorizenet\Helper\DataFactory
*/
protected $dataFactory;

/**
* Constructor
*
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Authorizenet\Helper\DataFactory $dataFactory
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Authorizenet\Helper\DataFactory $dataFactory,
array $data = []
) {
$this->dataFactory = $dataFactory;
parent::__construct($context, $registry, $data);
}

/**
* Get helper data
*
* @param string $area
* @return \Magento\Authorizenet\Helper\Backend\Data|\Magento\Authorizenet\Helper\Data
*/
public function getHelper($area)
{
return $this->dataFactory->create($area);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
/**
*
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Authorizenet\Controller\Adminhtml\Authorizenet\Directpost\Payment;

class AddConfigured extends \Magento\Sales\Controller\Adminhtml\Order\Create\AddConfigured
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
/**
*
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Authorizenet\Controller\Adminhtml\Authorizenet\Directpost\Payment;

class Cancel extends \Magento\Sales\Controller\Adminhtml\Order\Create\Cancel
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
/**
*
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Authorizenet\Controller\Adminhtml\Authorizenet\Directpost\Payment;

class ConfigureProductToAdd extends \Magento\Sales\Controller\Adminhtml\Order\Create\ConfigureProductToAdd
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
/**
*
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Authorizenet\Controller\Adminhtml\Authorizenet\Directpost\Payment;

class ConfigureQuoteItems extends \Magento\Sales\Controller\Adminhtml\Order\Create\ConfigureQuoteItems
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
/**
*
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Authorizenet\Controller\Adminhtml\Authorizenet\Directpost\Payment;

class Index extends \Magento\Sales\Controller\Adminhtml\Order\Create\Index
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
/**
*
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Authorizenet\Controller\Adminhtml\Authorizenet\Directpost\Payment;

class LoadBlock extends \Magento\Sales\Controller\Adminhtml\Order\Create\LoadBlock
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Authorizenet\Controller\Adminhtml\Authorizenet\Directpost\Payment;

use Magento\Framework\Escaper;
use Magento\Catalog\Helper\Product;
use Magento\Backend\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
use Magento\Backend\Model\View\Result\ForwardFactory;
use Magento\Authorizenet\Helper\Backend\Data as DataHelper;

/**
* Class Place
*/
class Place extends \Magento\Sales\Controller\Adminhtml\Order\Create
{
/**
* @var DataHelper
*/
protected $helper;

/**
* Constructor
*
* @param Context $context
* @param Product $productHelper
* @param Escaper $escaper
* @param PageFactory $resultPageFactory
* @param ForwardFactory $resultForwardFactory
* @param DataHelper $helper
*/
public function __construct(
Context $context,
Product $productHelper,
Escaper $escaper,
PageFactory $resultPageFactory,
ForwardFactory $resultForwardFactory,
DataHelper $helper
) {
$this->helper = $helper;
parent::__construct($context, $productHelper, $escaper, $resultPageFactory, $resultForwardFactory);
}

/**
* Send request to authorize.net
*
* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
public function execute()
{
$paymentParam = $this->getRequest()->getParam('payment');
$controller = $this->getRequest()->getParam('controller');
$this->getRequest()->setPostValue('collect_shipping_rates', 1);
$this->_processActionData('save');

//get confirmation by email flag
$orderData = $this->getRequest()->getPost('order');
$sendConfirmationFlag = 0;
if ($orderData) {
$sendConfirmationFlag = !empty($orderData['send_confirmation']) ? 1 : 0;
} else {
$orderData = [];
}

if (isset($paymentParam['method'])) {
$result = [];
//create order partially
$this->_getOrderCreateModel()->setPaymentData($paymentParam);
$this->_getOrderCreateModel()->getQuote()->getPayment()->addData($paymentParam);

$orderData['send_confirmation'] = 0;
$this->getRequest()->setPostValue('order', $orderData);

try {
//do not cancel old order.
$oldOrder = $this->_getOrderCreateModel()->getSession()->getOrder();
$oldOrder->setActionFlag(\Magento\Sales\Model\Order::ACTION_FLAG_CANCEL, false);

$order = $this->_getOrderCreateModel()->setIsValidate(
true
)->importPostData(
$this->getRequest()->getPost('order')
)->createOrder();

$payment = $order->getPayment();
if ($payment && $payment->getMethod() == $this->_objectManager->create(
'Magento\Authorizenet\Model\Directpost'
)->getCode()
) {
//return json with data.
$session = $this->_objectManager->get('Magento\Authorizenet\Model\Directpost\Session');
$session->addCheckoutOrderIncrementId($order->getIncrementId());
$session->setLastOrderIncrementId($order->getIncrementId());

/** @var \Magento\Authorizenet\Model\Directpost $method */
$method = $payment->getMethodInstance();
$method->setDataHelper($this->helper);
$requestToAuthorizenet = $method->generateRequestFromOrder($order);
$requestToAuthorizenet->setControllerActionName($controller);
$requestToAuthorizenet->setOrderSendConfirmation($sendConfirmationFlag);
$requestToAuthorizenet->setStoreId($this->_getOrderCreateModel()->getQuote()->getStoreId());

$adminUrl = $this->_objectManager->get('Magento\Backend\Model\UrlInterface');
if ($adminUrl->useSecretKey()) {
$requestToAuthorizenet->setKey(
$adminUrl->getSecretKey('adminhtml', 'authorizenet_directpost_payment', 'redirect')
);
}
$result['directpost'] = ['fields' => $requestToAuthorizenet->getData()];
}

$result['success'] = 1;
$isError = false;
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$message = $e->getMessage();
if (!empty($message)) {
$this->messageManager->addError($message);
}
$isError = true;
} catch (\Exception $e) {
$this->messageManager->addException($e, __('Order saving error: %1', $e->getMessage()));
$isError = true;
}

if ($isError) {
$result['success'] = 0;
$result['error'] = 1;
$result['redirect'] = $this->_objectManager->get(
'Magento\Backend\Model\UrlInterface'
)->getUrl(
'sales/order_create/'
);
}

$this->getResponse()->representJson(
$this->_objectManager->get('Magento\Framework\Json\Helper\Data')->jsonEncode($result)
);
} else {
$result = ['error_messages' => __('Please choose a payment method.')];
$this->getResponse()->representJson(
$this->_objectManager->get('Magento\Framework\Json\Helper\Data')->jsonEncode($result)
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
/**
*
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Authorizenet\Controller\Adminhtml\Authorizenet\Directpost\Payment;

class ProcessData extends \Magento\Sales\Controller\Adminhtml\Order\Create\ProcessData
{
}
Loading

0 comments on commit a09b7a1

Please sign in to comment.