Skip to content

Commit

Permalink
Merge pull request #410 from magento-mpi/MAGETWO-49341
Browse files Browse the repository at this point in the history
[MPI] Bug Fixes & Preview Limitations
  • Loading branch information
dkvashninbay committed Mar 9, 2016
2 parents 96d2202 + 340d942 commit b7dbda1
Show file tree
Hide file tree
Showing 69 changed files with 1,312 additions and 853 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
allowtransparency="true"
frameborder="0"
name="iframeTransparent"
style="display:none;width:100%;background-color:transparent">
class="payment-method-iframe">

</iframe>
<form class="form" id="co-transparent-form" action="#" method="post" data-bind="mageInit: {
Expand Down
12 changes: 11 additions & 1 deletion app/code/Magento/BraintreeTwo/Block/Paypal/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Magento\BraintreeTwo\Model\Ui\ConfigProvider;
use Magento\Framework\View\Element\Template\Context;
use Magento\BraintreeTwo\Gateway\Config\PayPal\Config;
use Magento\Payment\Model\MethodInterface;

/**
* Class Button
Expand Down Expand Up @@ -42,6 +43,11 @@ class Button extends Template implements ShortcutInterface
*/
private $configProvider;

/**
* @var MethodInterface
*/
private $payment;

/**
* Constructor
*
Expand All @@ -50,6 +56,7 @@ class Button extends Template implements ShortcutInterface
* @param Session $checkoutSession
* @param Config $config
* @param ConfigProvider $configProvider
* @param MethodInterface $payment
* @param array $data
*/
public function __construct(
Expand All @@ -58,6 +65,7 @@ public function __construct(
Session $checkoutSession,
Config $config,
ConfigProvider $configProvider,
MethodInterface $payment,
array $data = []
) {
parent::__construct($context, $data);
Expand All @@ -66,6 +74,7 @@ public function __construct(
$this->checkoutSession = $checkoutSession;
$this->config = $config;
$this->configProvider = $configProvider;
$this->payment = $payment;
}

/**
Expand Down Expand Up @@ -125,7 +134,8 @@ public function getAmount()
*/
public function isActive()
{
return $this->config->isActive() && $this->config->isDisplayShoppingCart();
return $this->payment->isAvailable($this->checkoutSession->getQuote()) &&
$this->config->isDisplayShoppingCart();
}

/**
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/BraintreeTwo/etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<item name="alias" xsi:type="string">braintree.paypal.mini-cart</item>
<item name="button_id" xsi:type="string">braintree-paypal-mini-cart</item>
</argument>
<argument name="payment" xsi:type="object">BraintreeTwoPayPalFacade</argument>
</arguments>
</type>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ require([
"jquery/jquery.hashchange",
"mage/mage",
"prototype",
"mage/adminhtml/form",
"domReady!"
], function(jQuery, registry){

Expand Down
19 changes: 12 additions & 7 deletions app/code/Magento/Dhl/Model/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ class Carrier extends \Magento\Dhl\Model\AbstractDhl implements \Magento\Shippin
*/
protected $_httpClientFactory;

/**
* @inheritdoc
*/
protected $_debugReplacePrivateDataKeys = [
'SiteID', 'Password'
];

/**
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory
Expand Down Expand Up @@ -904,37 +911,36 @@ protected function _getQuotes()
{
$responseBody = '';
try {
$debugData = [];
for ($offset = 0; $offset <= self::UNAVAILABLE_DATE_LOOK_FORWARD; $offset++) {
$debugData['try-' . $offset] = [];
$debugPoint = &$debugData['try-' . $offset];
$debugPoint = [];

$requestXml = $this->_buildQuotesRequestXml();
$date = date(self::REQUEST_DATE_FORMAT, strtotime($this->_getShipDate() . " +{$offset} days"));
$this->_setQuotesRequestXmlDate($requestXml, $date);

$request = $requestXml->asXML();
$debugPoint['request'] = $request;
$debugPoint['request'] = $this->filterDebugData($request);
$responseBody = $this->_getCachedQuotes($request);
$debugPoint['from_cache'] = $responseBody === null;

if ($debugPoint['from_cache']) {
$responseBody = $this->_getQuotesFromServer($request);
}

$debugPoint['response'] = $responseBody;
$debugPoint['response'] = $this->filterDebugData($responseBody);

$bodyXml = $this->_xmlElFactory->create(['data' => $responseBody]);
$code = $bodyXml->xpath('//GetQuoteResponse/Note/Condition/ConditionCode');
if (isset($code[0]) && (int)$code[0] == self::CONDITION_CODE_SERVICE_DATE_UNAVAILABLE) {
$debugPoint['info'] = sprintf(__("DHL service is not available at %s date"), $date);
} else {
$this->_debug($debugPoint);
break;
}

$this->_setCachedQuotes($request, $responseBody);
$this->_debug($debugPoint);
}
$this->_debug($debugData);
} catch (\Exception $e) {
$this->_errors[$e->getCode()] = $e->getMessage();
}
Expand Down Expand Up @@ -1308,7 +1314,6 @@ public function proccessAdditionalValidation(\Magento\Framework\DataObject $requ
return $this;
}


/**
* Return container types of carrier
*
Expand Down
26 changes: 25 additions & 1 deletion app/code/Magento/Fedex/Model/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ class Carrier extends AbstractCarrierOnline implements \Magento\Shipping\Model\C
*/
protected $_productCollectionFactory;

/**
* @inheritdoc
*/
protected $_debugReplacePrivateDataKeys = [
'Key', 'Password', 'MeterNumber'
];

/**
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory
Expand Down Expand Up @@ -454,7 +461,7 @@ protected function _doRatesRequest($purpose)
$ratesRequest = $this->_formRateRequest($purpose);
$requestString = serialize($ratesRequest);
$response = $this->_getCachedQuotes($requestString);
$debugData = ['request' => $ratesRequest];
$debugData = ['request' => $this->filterDebugData($ratesRequest)];
if ($response === null) {
try {
$client = $this->_createRateSoapClient();
Expand Down Expand Up @@ -1560,4 +1567,21 @@ public function getDeliveryConfirmationTypes(\Magento\Framework\DataObject $para
{
return $this->getCode('delivery_confirmation_types');
}

/**
* Recursive replace sensitive fields in debug data by the mask
* @param string $data
* @return string
*/
protected function filterDebugData($data)
{
foreach (array_keys($data) as $key) {
if (is_array($data[$key])) {
$data[$key] = $this->filterDebugData($data[$key]);
} elseif (in_array($key, $this->_debugReplacePrivateDataKeys)) {
$data[$key] = self::DEBUG_KEYS_MASK;
}
}
return $data;
}
}
58 changes: 57 additions & 1 deletion app/code/Magento/Fedex/Test/Unit/Model/CarrierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
*/
namespace Magento\Fedex\Test\Unit\Model;

use Magento\Quote\Model\Quote\Address\RateRequest;
use Magento\Fedex\Model\Carrier;
use Magento\Framework\DataObject;
use Magento\Framework\Xml\Security;
use Magento\Quote\Model\Quote\Address\RateRequest;

/**
* Class CarrierTest
Expand Down Expand Up @@ -212,4 +213,59 @@ public function testCollectRatesErrorMessage()

$this->assertSame($this->error, $this->_model->collectRates($request));
}

/**
* @param string $data
* @param array $maskFields
* @param string $expected
* @dataProvider logDataProvider
*/
public function testFilterDebugData($data, array $maskFields, $expected)
{
$refClass = new \ReflectionClass(Carrier::class);
$property = $refClass->getProperty('_debugReplacePrivateDataKeys');
$property->setAccessible(true);
$property->setValue($this->_model, $maskFields);

$refMethod = $refClass->getMethod('filterDebugData');
$refMethod->setAccessible(true);
$result = $refMethod->invoke($this->_model, $data);
static::assertEquals($expected, $result);
}

/**
* Get list of variations
*/
public function logDataProvider()
{
return [
[
[
'WebAuthenticationDetail' => [
'UserCredential' => [
'Key' => 'testKey',
'Password' => 'testPassword'
]
],
'ClientDetail' => [
'AccountNumber' => 4121213,
'MeterNumber' => 'testMeterNumber'
]
],
['Key', 'Password', 'MeterNumber'],
[
'WebAuthenticationDetail' => [
'UserCredential' => [
'Key' => '****',
'Password' => '****'
]
],
'ClientDetail' => [
'AccountNumber' => 4121213,
'MeterNumber' => '****'
]
],
],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Paypal\Block\Express\InContext\Minicart;

use Magento\Checkout\Model\Session;
use Magento\Payment\Model\MethodInterface;
use Magento\Paypal\Model\Config;
use Magento\Paypal\Model\ConfigFactory;
use Magento\Paypal\Block\Express\InContext;
Expand Down Expand Up @@ -41,25 +43,40 @@ class Button extends Template implements ShortcutInterface
*/
private $config;

/**
* @var MethodInterface
*/
private $payment;

/**
* @var Session
*/
private $session;

/**
* Constructor
*
* @param Context $context
* @param ResolverInterface $localeResolver
* @param ConfigFactory $configFactory
* @param MethodInterface $payment
* @param Session $session
* @param array $data
*/
public function __construct(
Context $context,
ResolverInterface $localeResolver,
ConfigFactory $configFactory,
Session $session,
MethodInterface $payment,
array $data = []
) {
parent::__construct($context, $data);

$this->localeResolver = $localeResolver;
$this->config = $configFactory->create();
$this->config->setMethod(Config::METHOD_EXPRESS);
$this->payment = $payment;
$this->session = $session;
}

/**
Expand All @@ -75,7 +92,9 @@ private function isInContext()
*/
protected function shouldRender()
{
return $this->isMiniCart && $this->isInContext();
return $this->payment->isAvailable($this->session->getQuote())
&& $this->isMiniCart
&& $this->isInContext();
}

/**
Expand Down
29 changes: 14 additions & 15 deletions app/code/Magento/Paypal/etc/adminhtml/rules/payment_au.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
<rule type="disable" event="activate-rule"/>
</relation>
<relation target=":self">
<rule type="simple/mark-enable" event="activate-rule"/>
<rule type="simple/disable" event="deactivate-rule"/>
<rule type="simpleMarkEnable" event="activate-rule"/>
<rule type="simpleDisable" event="deactivate-rule"/>
<rule type="conflict" event=":load">
<argument name="paypal_payflowpro_au">paypal_payflowpro_au</argument>
<argument name="payments_pro_hosted_solution_au">payments_pro_hosted_solution_au</argument>
Expand Down Expand Up @@ -62,8 +62,8 @@
<rule type="disable" event="activate-rule"/>
</relation>
<relation target=":self">
<rule type="simple/mark-enable" event="activate-rule"/>
<rule type="simple/disable" event="deactivate-rule"/>
<rule type="simpleMarkEnable" event="activate-rule"/>
<rule type="simpleDisable" event="deactivate-rule"/>
<rule type="conflict" event=":load">
<argument name="wps_other">wps_other</argument>
<argument name="payments_pro_hosted_solution_au">payments_pro_hosted_solution_au</argument>
Expand Down Expand Up @@ -91,8 +91,8 @@
<rule type="disable" event="activate-rule"/>
</relation>
<relation target=":self">
<rule type="simple/mark-enable" event="activate-rule"/>
<rule type="simple/disable" event="deactivate-rule"/>
<rule type="simpleMarkEnable" event="activate-rule"/>
<rule type="simpleDisable" event="deactivate-rule"/>
<rule type="conflict" event=":load">
<argument name="wps_other">wps_other</argument>
<argument name="paypal_payflowpro_au">paypal_payflowpro_au</argument>
Expand Down Expand Up @@ -120,15 +120,14 @@
<rule type="disable" event="activate-rule"/>
</relation>
<relation target=":self">
<rule type="simple/mark-enable" event="activate-rule"/>
<rule type="simple/disable" event="deactivate-rule"/>
<rule type="paypal/in-context/enable" event="activate-rule"/>
<rule type="paypal/in-context/disable" event="deactivate-rule"/>
<rule type="paypal/in-context/show-merchant-id" event="activate-rule"/>
<rule type="paypal/in-context/hide-merchant-id" event="deactivate-rule"/>
<rule type="paypal/in-context/activate" event="activate-in-context-api"/>
<rule type="paypal/in-context/deactivate" event="deactivate-in-context-api"/>
<rule type="paypal/in-context/disable-conditional" event=":load"/>
<rule type="simpleMarkEnable" event="activate-rule"/>
<rule type="simpleDisable" event="deactivate-rule"/>
<rule type="inContextDisable" event="deactivate-rule"/>
<rule type="inContextShowMerchantId" event="activate-rule"/>
<rule type="inContextHideMerchantId" event="deactivate-rule"/>
<rule type="inContextActivate" event="activate-in-context-api"/>
<rule type="inContextDeactivate" event="deactivate-in-context-api"/>
<rule type="inContextDisableConditional" event=":load"/>
<rule type="conflict" event=":load">
<argument name="wps_other">wps_other</argument>
</rule>
Expand Down
Loading

0 comments on commit b7dbda1

Please sign in to comment.