Skip to content

Commit

Permalink
Merge pull request #242 from magento-mpi/MPI-PR
Browse files Browse the repository at this point in the history
Stories:
- MAGETWO-51658 Kount Status
- MAGETWO-54499 PayPal Payments Configuration UX Update
  • Loading branch information
MomotenkoNatalia committed Aug 15, 2016
2 parents 8eb6402 + 5eba3af commit 903dcbb
Show file tree
Hide file tree
Showing 75 changed files with 4,252 additions and 495 deletions.
10 changes: 10 additions & 0 deletions app/code/Magento/Braintree/Gateway/Response/RiskDataHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class RiskDataHandler implements HandlerInterface
*/
const RISK_DATA_DECISION = 'riskDataDecision';

/**
* Risk data Review status
*/
private static $statusReview = 'Review';

/**
* @var SubjectReader
*/
Expand Down Expand Up @@ -62,5 +67,10 @@ public function handle(array $handlingSubject, array $response)

$payment->setAdditionalInformation(self::RISK_DATA_ID, $transaction->riskData->id);
$payment->setAdditionalInformation(self::RISK_DATA_DECISION, $transaction->riskData->decision);

// mark payment as fraud
if ($transaction->riskData->decision === self::$statusReview) {
$payment->setIsFraudDetected(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
*/
namespace Magento\Braintree\Test\Unit\Gateway\Response;

use Braintree\RiskData;
use Braintree\Transaction;
use Magento\Sales\Model\Order\Payment;
use Magento\Braintree\Gateway\Helper\SubjectReader;
use Magento\Braintree\Gateway\Response\RiskDataHandler;
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
use Magento\Sales\Model\Order\Payment;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

/**
* Class RiskDataHandlerTest
Expand All @@ -25,99 +25,95 @@ class RiskDataHandlerTest extends \PHPUnit_Framework_TestCase
private $riskDataHandler;

/**
* @var SubjectReader|\PHPUnit_Framework_MockObject_MockObject
* @var SubjectReader|MockObject
*/
private $subjectReaderMock;
private $subjectReader;

/**
* Set up
*/
protected function setUp()
{
$this->subjectReaderMock = $this->getMockBuilder(SubjectReader::class)
$this->subjectReader = $this->getMockBuilder(SubjectReader::class)
->disableOriginalConstructor()
->setMethods(['readPayment', 'readTransaction'])
->getMock();

$this->riskDataHandler = new RiskDataHandler($this->subjectReaderMock);
$this->riskDataHandler = new RiskDataHandler($this->subjectReader);
}

/**
* Run test for handle method
* Test for handle method
* @covers \Magento\Braintree\Gateway\Response\RiskDataHandler::handle
* @param string $riskDecision
* @param boolean $isFraud
* @dataProvider riskDataProvider
*/
public function testHandle()
public function testHandle($riskDecision, $isFraud)
{
$paymentData = $this->getPaymentDataObjectMock();
$transaction = $this->getBraintreeTransactionMock();
/** @var Payment|MockObject $payment */
$payment = $this->getMockBuilder(Payment::class)
->disableOriginalConstructor()
->setMethods(['setAdditionalInformation', 'setIsFraudDetected'])
->getMock();
/** @var PaymentDataObjectInterface|MockObject $paymentDO */
$paymentDO = $this->getMock(PaymentDataObjectInterface::class);
$paymentDO->expects(self::once())
->method('getPayment')
->willReturn($payment);

$transaction = Transaction::factory([
'riskData' => [
'id' => 'test-id',
'decision' => $riskDecision
]
]);

$response = [
'object' => $transaction
];
$handlingSubject = [
'payment' =>$paymentData,
'payment' => $paymentDO,
];

$this->subjectReaderMock->expects(self::once())
$this->subjectReader->expects(static::once())
->method('readPayment')
->with($handlingSubject)
->willReturn($paymentData);
$this->subjectReaderMock->expects(self::once())
->willReturn($paymentDO);
$this->subjectReader->expects(static::once())
->method('readTransaction')
->with($response)
->willReturn($transaction);

$this->riskDataHandler->handle($handlingSubject, $response);
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject
*/
private function getBraintreeTransactionMock()
{
$transaction = \Braintree\Transaction::factory([]);
$transaction->_set(
'riskData',
RiskData::factory(
[
'id' => 'test-id',
'decision' => 'test-decision',
]
)
);

return $transaction;
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject
*/
private function getPaymentDataObjectMock()
{
$mock = $this->getMockBuilder(PaymentDataObjectInterface::class)
->getMockForAbstractClass();
$payment->expects(static::at(0))
->method('setAdditionalInformation')
->with(RiskDataHandler::RISK_DATA_ID, 'test-id');
$payment->expects(static::at(1))
->method('setAdditionalInformation')
->with(RiskDataHandler::RISK_DATA_DECISION, $riskDecision);

$mock->expects(static::once())
->method('getPayment')
->willReturn($this->getPaymentMock());
if (!$isFraud) {
$payment->expects(static::never())
->method('setIsFraudDetected');
} else {
$payment->expects(static::once())
->method('setIsFraudDetected')
->with(true);
}

return $mock;
$this->riskDataHandler->handle($handlingSubject, $response);
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject
* Get list of variations to test fraud
* @return array
*/
private function getPaymentMock()
public function riskDataProvider()
{
$paymentMock = $this->getMockBuilder(Payment::class)
->disableOriginalConstructor()
->getMock();

$paymentMock->expects(self::at(0))
->method('setAdditionalInformation')
->with(RiskDataHandler::RISK_DATA_ID, 'test-id');
$paymentMock->expects(self::at(1))
->method('setAdditionalInformation')
->with(RiskDataHandler::RISK_DATA_DECISION, 'test-decision');

return $paymentMock;
return [
['decision' => 'Not Evaluated', 'isFraud' => false],
['decision' => 'Approve', 'isFraud' => false],
['decision' => 'Review', 'isFraud' => true],
];
}
}
20 changes: 10 additions & 10 deletions app/code/Magento/Braintree/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="payment">
<group id="braintree_section" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Braintree</label>
<comment><![CDATA[Accept credit/debit cards and PayPal in your Magento store. No setup or monthly fees and your customers never leave your store to complete the purchase.]]></comment>
<attribute type="expanded">1</attribute>
<fieldset_css>complex braintree-section</fieldset_css>
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Group</frontend_model>
<group id="braintree" translate="label" type="text" sortOrder="25" showInDefault="1" showInWebsite="1" showInStore="1">
<label><![CDATA[&nbsp;]]></label>
<group id="braintree_section" sortOrder="6" showInDefault="0" showInWebsite="0" showInStore="0">
<group id="braintree" translate="label comment" type="text" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Braintree</label>
<comment><![CDATA[Accept credit/debit cards and PayPal in your Magento store.<br/>No setup or monthly fees and your customers never leave your store to complete the purchase.]]></comment>
<fieldset_css>complex braintree-section</fieldset_css>
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Payment</frontend_model>
<attribute type="activity_path">payment/braintree/active</attribute>
<more_url>https://articles.braintreepayments.com/guides/magento/configuration</more_url>
<attribute type="displayIn">recommended_solutions</attribute>
<field id="active" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Enable this Solution</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
Expand All @@ -43,8 +40,11 @@
<group id="braintree_required"/>
</requires>
</field>
<group id="configuration_details" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="4">
<comment>http://docs.magento.com/m2/ce/user_guide/payment/braintree.html</comment>
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Hint</frontend_model>
</group>
<group id="braintree_required" translate="label" showInDefault="1" showInWebsite="1" sortOrder="5">
<comment><![CDATA[<a href="https://www.braintreegateway.com/login" target="_blank">Click here to login to your existing Braintree account</a>. Or to setup a new account and accept payments on your website, <a href="https://apply.braintreegateway.com/signup/us" target="_blank">click here to signup for a Braintree account</a>.<br><br>Powered by <a href="https://www.braintreepayments.com/features/hosted-fields" target="_blank">Braintree v.zero with Hosted Fields</a> latest technology. Hosted Fields are small, transparent iframes that replace the sensitive credit card inputs in your checkout flow - helping you meet the latest data security requirements while ensuring your customization doesn't suffer. <a href="https://www.braintreepayments.com/features/hosted-fields" target="_blank">Find out more</a>.]]></comment>
<label>Basic Braintree Settings</label>
<attribute type="expanded">1</attribute>
<frontend_model>Magento\Config\Block\System\Config\Form\Fieldset</frontend_model>
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Braintree/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
<can_void>1</can_void>
<can_cancel>1</can_cancel>
<can_edit>1</can_edit>
<can_review_payment>1</can_review_payment>
<can_deny_payment>1</can_deny_payment>
<cctypes>AE,VI,MC,DI,JCB,CUP,DN,MI</cctypes>
<useccv>1</useccv>
<cctypes_braintree_mapper><![CDATA[{"american-express":"AE","discover":"DI","jcb":"JCB","mastercard":"MC","master-card":"MC","visa":"VI","maestro":"MI","diners-club":"DN","unionpay":"CUP"}]]></cctypes_braintree_mapper>
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Braintree/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
<item name="void" xsi:type="string">BraintreeVoidCommand</item>
<item name="refund" xsi:type="string">BraintreeRefundCommand</item>
<item name="cancel" xsi:type="string">BraintreeVoidCommand</item>
<item name="deny_payment" xsi:type="string">BraintreeVoidCommand</item>
</argument>
</arguments>
</virtualType>
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Braintree/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,5 @@ Debug,Debug
"europe_bank_accout","Europe bank account"
"credit_card","Credit card"
"apple_pay_card","Apple pay card"
"android_pay_card","Android pay card"
"android_pay_card","Android pay card"
"Accept credit/debit cards and PayPal in your Magento store.<br/>No setup or monthly fees and your customers never leave your store to complete the purchase.","Accept credit/debit cards and PayPal in your Magento store.<br/>No setup or monthly fees and your customers never leave your store to complete the purchase."
5 changes: 3 additions & 2 deletions app/code/Magento/Braintree/view/adminhtml/web/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
* See COPYING.txt for license details.
*/

.braintree-section .entry-edit-head > .config-heading .heading strong {padding-left:150px;background:url(images/braintree_logo.png) no-repeat 0 0 / 145px auto;line-height:36px;}
.braintree-section .entry-edit-head > .config-heading:before {background: url("images/braintree_allinone.png") no-repeat 0 0 / 100% auto;content: "";display: inline;float: right;height: 35px;width: 280px;}
.braintree-section .heading {display: inline-block; background: url("images/braintree_logo.png") no-repeat 0 50% / 18rem auto; padding-left: 20rem;}
.braintree-section .button-container {display: inline-block; float: right;}
.braintree-section .config-alt {background: url("images/braintree_allinone.png") no-repeat scroll 0 0 / 100% auto; height: 28px; margin: 0.5rem 0 0; width: 230px;}
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,42 @@
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

namespace Magento\Paypal\Block\Adminhtml\System\Config\Fieldset;

use Magento\Backend\Block\Template;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\Data\Form\Element\Renderer\RendererInterface;

/**
* Renderer for PayPal banner in System Configuration
* @author Magento Core Team <core@magentocommerce.com>
* Class Hint adds "Configuration Details" link to payment configuration.
* `<comment>` node must be defined in `<group>` node and contain some link.
*/
class Hint extends \Magento\Backend\Block\Template implements \Magento\Framework\Data\Form\Element\Renderer\RendererInterface
class Hint extends Template implements RendererInterface
{
/**
* @var string
* @deprecated
*/
protected $_template = 'Magento_Paypal::system/config/fieldset/hint.phtml';

/**
* Render fieldset html
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @param AbstractElement $element
* @return string
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
public function render(AbstractElement $element)
{
$elementOriginalData = $element->getOriginalData();
if (isset($elementOriginalData['help_link'])) {
$this->setHelpLink($elementOriginalData['help_link']);
$html = '';

if ($element->getComment()) {
$html .= sprintf('<tr id="row_%s">', $element->getHtmlId());
$html .= '<td colspan="1"><p class="note"><span>';
$html .= sprintf(
'<a href="%s" target="_blank">Configuration Details</a>',
$element->getComment()
);
$html .= '</span></p></td></tr>';
}
return $this->toHtml();

return $html;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ protected function _getHeaderTitleHtml($element)
if ($element->getComment()) {
$html .= '<span class="heading-intro">' . $element->getComment() . '</span>';
}
$html .= '<div class="config-alt"></div>';
$html .= '</div>';

$disabledAttributeString = $this->_isPaymentEnabled($element) ? '' : ' disabled="disabled"';
Expand Down Expand Up @@ -149,4 +150,33 @@ protected function _isCollapseState($element)
{
return false;
}

/**
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function _getExtraJs($element)
{
$script = "require(['jquery', 'prototype'], function(jQuery){
window.paypalToggleSolution = function (id, url) {
var doScroll = false;
Fieldset.toggleCollapse(id, url);
if ($(this).hasClassName(\"open\")) {
$$(\".with-button button.button\").each(function(anotherButton) {
if (anotherButton != this && $(anotherButton).hasClassName(\"open\")) {
$(anotherButton).click();
doScroll = true;
}
}.bind(this));
}
if (doScroll) {
var pos = Element.cumulativeOffset($(this));
window.scrollTo(pos[0], pos[1] - 45);
}
}
});";

return $this->_jsHelper->getScript($script);
}
}
Loading

0 comments on commit 903dcbb

Please sign in to comment.