Skip to content

Commit

Permalink
Merge pull request #529 from magento-mpi/MPI-bugfixes
Browse files Browse the repository at this point in the history
[MPI] Bugfixes
  • Loading branch information
Momotenko,Natalia(nmomotenko) committed Apr 12, 2016
2 parents 603fcb4 + aea6eee commit 7f2b288
Show file tree
Hide file tree
Showing 33 changed files with 753 additions and 445 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,12 @@

use Magento\Framework\App\ObjectManager;
use Magento\Payment\Block\Transparent\Iframe;
use Magento\Framework\Escaper;

/**
* Class Redirect
*/
class Redirect extends \Magento\Authorizenet\Controller\Directpost\Payment
{
/**
* @var Escaper
*/
private $escaper;

/**
* Retrieve params and put javascript into iframe
*
Expand All @@ -29,7 +23,7 @@ public function execute()
{
$helper = $this->dataFactory->create('frontend');

$redirectParams = $this->filterData($this->getRequest()->getParams());
$redirectParams = $this->getRequest()->getParams();
$params = [];
if (!empty($redirectParams['success'])
&& isset($redirectParams['x_invoice_num'])
Expand All @@ -38,9 +32,11 @@ public function execute()
$this->_getDirectPostSession()->unsetData('quote_id');
$params['redirect_parent'] = $helper->getSuccessOrderUrl([]);
}

if (!empty($redirectParams['error_msg'])) {
$cancelOrder = empty($redirectParams['x_invoice_num']);
$this->_returnCustomerQuote($cancelOrder, $redirectParams['error_msg']);
$params['error_msg'] = $redirectParams['error_msg'];
}

if (isset($redirectParams['controller_action_name'])
Expand All @@ -50,34 +46,8 @@ public function execute()
unset($params['redirect_parent']);
}

$this->_coreRegistry->register(Iframe::REGISTRY_KEY, array_merge($params, $redirectParams));
$this->_coreRegistry->register(Iframe::REGISTRY_KEY, $params);
$this->_view->addPageLayoutHandles();
$this->_view->loadLayout(false)->renderLayout();
}

/**
* Escape xss in request data
* @param array $data
* @return array
*/
private function filterData(array $data)
{
$self = $this;
array_walk($data, function (&$item) use ($self) {
$item = $self->getEscaper()->escapeXssInUrl($item);
});
return $data;
}

/**
* Get Escaper instance
* @return Escaper
*/
private function getEscaper()
{
if (!$this->escaper) {
$this->escaper = ObjectManager::getInstance()->get(Escaper::class);
}
return $this->escaper;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Magento\Authorizenet\Controller\Directpost\Payment\Redirect;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\App\ViewInterface;
use Magento\Framework\Escaper;
use Magento\Framework\Registry;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Payment\Block\Transparent\Iframe;
Expand All @@ -34,11 +33,6 @@ class RedirectTest extends \PHPUnit_Framework_TestCase
*/
private $coreRegistry;

/**
* @var Escaper|MockObject
*/
private $escaper;

/**
* @var Redirect
*/
Expand All @@ -57,21 +51,11 @@ protected function setUp()
->setMethods(['register'])
->getMock();

$this->escaper = static::getMockBuilder(Escaper::class)
->disableOriginalConstructor()
->setMethods(['escapeXssInUrl'])
->getMock();

$this->controller = $objectManager->getObject(Redirect::class, [
'request' => $this->request,
'view' => $this->view,
'coreRegistry' => $this->coreRegistry
]);

$refClass = new \ReflectionClass(Redirect::class);
$refProperty = $refClass->getProperty('escaper');
$refProperty->setAccessible(true);
$refProperty->setValue($this->controller, $this->escaper);
}

/**
Expand All @@ -87,14 +71,9 @@ public function testExecute()
->method('getParams')
->willReturn($params);

$this->escaper->expects(static::once())
->method('escapeXssInUrl')
->with($url)
->willReturn($url);

$this->coreRegistry->expects(static::once())
->method('register')
->with(Iframe::REGISTRY_KEY, $params);
->with(Iframe::REGISTRY_KEY, []);

$this->view->expects(static::once())
->method('addPageLayoutHandles');
Expand Down
4 changes: 1 addition & 3 deletions app/code/Magento/Braintree/Controller/Payment/GetNonce.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Session\SessionManagerInterface;
use Magento\Framework\Webapi\Exception;
use Psr\Log\LoggerInterface;
use Magento\Vault\Model\Ui\TokenUiComponentProviderInterface;
use Magento\CheckoutAgreements;
use Magento\Theme;
use Psr\Log\LoggerInterface;

/**
* Class GetNonce
Expand Down
4 changes: 3 additions & 1 deletion app/code/Magento/Braintree/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
"magento/module-catalog": "*",
"magento/module-quote": "*",
"magento/module-paypal": "*",
"magento/module-checkout-agreements": "*",
"magento/module-theme": "*",
"braintree/braintree_php": "3.7.0"
},
"suggest": {
"magento/module-checkout-agreements": "100.0.*"
},
"type": "magento2-module",
"version": "100.0.2",
"license": [
Expand Down
1 change: 0 additions & 1 deletion app/code/Magento/Braintree/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<module name="Magento_Catalog"/>
<module name="Magento_Quote"/>
<module name="Magento_Paypal"/>
<module name="Magento_CheckoutAgreements"/>
<module name="Magento_Theme"/>
</sequence>
</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ define([
'Magento_Checkout/js/view/payment/default',
'Magento_Braintree/js/view/payment/adapter',
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/model/full-screen-loader'
], function ($, _, Component, Braintree, quote, fullScreenLoader) {
'Magento_Checkout/js/model/full-screen-loader',
'Magento_Checkout/js/model/payment/additional-validators'
], function ($, _, Component, Braintree, quote, fullScreenLoader, additionalValidators) {
'use strict';

var checkout;
Expand Down Expand Up @@ -173,7 +174,9 @@ define([
* Triggers when customer click "Continue to PayPal" button
*/
payWithPayPal: function () {
checkout.paypal.initAuthFlow();
if (additionalValidators.validate()) {
checkout.paypal.initAuthFlow();
}
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@
</fieldset>
<input type="submit" id="braintree_submit" style="display:none" />
</form>
<div class="checkout-agreements-block">
<!-- ko foreach: $parent.getRegion('before-place-order') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
</div>
<div class="actions-toolbar">
<div class="primary">
<button class="action primary checkout"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
name="agreement[<?php /* @escapeNotVerified */ echo $agreement->getAgreementId()?>]"
value="1"
title="<?php echo $block->escapeHtml($agreement->getCheckboxText()) ?>"
class="checkbox""/>
class="checkbox"
data-validate="{required:true}"/>
<label class="label" for="agreement-<?php /* @escapeNotVerified */ echo $agreement->getAgreementId()?>">
<span><?php echo $agreement->getIsHtml() ? $agreement->getCheckboxText() : $block->escapeHtml($agreement->getCheckboxText()) ?></span>
</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

// @codingStandardsIgnoreFile
use Magento\Framework\Json\Helper\Data;

/** @var \Magento\Payment\Block\Transparent\Iframe $block */
$params = $block->getParams();
Expand All @@ -26,6 +27,22 @@ $params = $block->getParams();
parent.location="<?php echo $block->escapeXssInUrl($params['redirect_parent']); ?>";
}
);
<?php elseif (isset($params['error_msg'])): ?>
var require = window.top.require;
require(
[
'jquery',
'Magento_Ui/js/model/messageList',
'mage/translate'
],
function($, globalMessageList, $t) {
var parent = window.top;
$(parent).trigger('clearTimeout');
globalMessageList.addErrorMessage({
message: $t('Unable to place order. Please try again later.')
});
}
);
<?php elseif (isset($params['order_success'])): ?>
window.top.location = "<?php echo $block->escapeXssInUrl($params['order_success']); ?>";
<?php else: ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,20 @@ define(
}
},
{
title: 'Maestro',
title: 'Maestro International',
type: 'MI',
pattern: '^((5((0|[6-9])\\d*)?)|(6|6[37]\\d*))$',
pattern: '^(5(0|[6-9])|63|67(?!59|6770|6774))\\d*$',
gaps: [4, 8, 12],
lengths: [12, 13, 14, 15, 16, 17, 18, 19],
code: {
name: 'CVC',
size: 3
}
},
{
title: 'Maestro Domestic',
type: 'MD',
pattern: '^6759(?!24|38|40|6[3-9]|70|76)|676770|676774\\d*$',
gaps: [4, 8, 12],
lengths: [12, 13, 14, 15, 16, 17, 18, 19],
code: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Paypal\Block\Adminhtml\System\Config\Field\Depends;

use Magento\Paypal\Block\Adminhtml\System\Config\Field\Enable\AbstractEnable;

/**
* Class BmlSortOrderApi
*/
class BmlApiSortOrder extends AbstractEnable
{
/**
* Getting the name of a UI attribute
*
* @return string
*/
protected function getDataAttributeName()
{
return 'bml-api-sort-order';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Paypal\Block\Adminhtml\System\Config\Field\Depends;

use Magento\Paypal\Block\Adminhtml\System\Config\Field\Enable\AbstractEnable;

/**
* Class BmlSortOrder
*/
class BmlSortOrder extends AbstractEnable
{
/**
* Getting the name of a UI attribute
*
* @return string
*/
protected function getDataAttributeName()
{
return 'bml-sort-order';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Paypal\Block\Adminhtml\System\Config\Field\Depends;

use Magento\Paypal\Block\Adminhtml\System\Config\Field\Enable\AbstractEnable;

/**
* Class MerchantId
*/
class MerchantId extends AbstractEnable
{
/**
* Getting the name of a UI attribute
*
* @return string
*/
protected function getDataAttributeName()
{
return 'merchant-id';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public function __construct(
*/
public function getJson()
{
return json_encode($this->rulesReader->read());
return json_encode($this->rulesReader->read(), JSON_FORCE_OBJECT);
}
}
6 changes: 6 additions & 0 deletions app/code/Magento/Paypal/Model/Express/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,12 @@ public function updateShippingMethod($methodCode)
if ($methodCode != $shippingAddress->getShippingMethod()) {
$this->ignoreAddressValidation();
$shippingAddress->setShippingMethod($methodCode)->setCollectShippingRates(true);
$cartExtension = $this->_quote->getExtensionAttributes();
if ($cartExtension && $cartExtension->getShippingAssignments()) {
$cartExtension->getShippingAssignments()[0]
->getShipping()
->setMethod($methodCode);
}
$this->_quote->collectTotals();
$this->quoteRepository->save($this->_quote);
}
Expand Down
Loading

0 comments on commit 7f2b288

Please sign in to comment.