Skip to content

Commit

Permalink
Merge pull request #559 from magento-folks/terms_and_conditions
Browse files Browse the repository at this point in the history
[Folks] Sprint 74
  • Loading branch information
Akimov, Alexander(aakimov) committed Aug 31, 2015
2 parents 84c18e3 + bb0e260 commit 33b8dff
Show file tree
Hide file tree
Showing 99 changed files with 2,398 additions and 1,019 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ define(
[
'jquery',
'Magento_Payment/js/view/payment/iframe',
'Magento_Checkout/js/action/set-payment-information'
'Magento_Checkout/js/action/set-payment-information',
'Magento_Checkout/js/model/payment/additional-validators'
],
function ($, Component, setPaymentInformationAction) {
function ($, Component, setPaymentInformationAction, additionalValidators) {
'use strict';
return Component.extend({
defaults: {
Expand Down Expand Up @@ -45,7 +46,7 @@ define(

placeOrder: function() {
var self = this;
if (this.validateHandler()) {
if (this.validateHandler() && additionalValidators.validate()) {
this.isPlaceOrderActionAllowed(false);
$.when(setPaymentInformationAction()).done(function() {
self.placeOrderHandler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,29 @@
'cardFieldsMap': getCardFieldsMap(),
'nativeAction': getSaveOrderUrl()
}, 'validation':[]}">

<!-- ko template: 'Magento_Payment/payment/cc-form' --><!-- /ko -->
</form>
<div class="checkout-agreements-block">
<!-- ko foreach: $parent.getRegion('before-place-order') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
</div>

<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 data-role="review-save"
type="submit"
data-bind="
attr: {title: $t('Place Order')},
enable: (getCode() == isChecked()),
click: placeOrder,
css: {disabled: !isPlaceOrderActionAllowed()}
"
class="action primary checkout"
disabled>
<span data-bind="i18n: 'Place Order'"></span>
</button>
</div>
<div class="actions-toolbar">
<div class="primary">
<button data-role="review-save"
type="submit"
data-bind="
attr: {title: $t('Place Order')},
enable: (getCode() == isChecked()),
click: placeOrder,
css: {disabled: !isPlaceOrderActionAllowed()}
"
class="action primary checkout"
disabled>
<span data-bind="i18n: 'Place Order'"></span>
</button>
</div>
</form>
</div>
</div>
</div>
39 changes: 39 additions & 0 deletions app/code/Magento/Braintree/Controller/PayPal/PlaceOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,40 @@

class PlaceOrder extends \Magento\Braintree\Controller\PayPal
{
/**
* @var \Magento\Checkout\Api\AgreementsValidatorInterface
*/
protected $agreementsValidator;

/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Customer\Model\Session $customerSession
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Magento\Braintree\Model\Config\PayPal $braintreePayPalConfig
* @param \Magento\Paypal\Model\Config $paypalConfig
* @param \Magento\Braintree\Model\CheckoutFactory $checkoutFactory
* @param \Magento\Checkout\Api\AgreementsValidatorInterface $agreementsValidator
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Customer\Model\Session $customerSession,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Braintree\Model\Config\PayPal $braintreePayPalConfig,
\Magento\Paypal\Model\Config $paypalConfig,
\Magento\Braintree\Model\CheckoutFactory $checkoutFactory,
\Magento\Checkout\Api\AgreementsValidatorInterface $agreementsValidator
) {
$this->agreementsValidator = $agreementsValidator;
parent::__construct(
$context,
$customerSession,
$checkoutSession,
$braintreePayPalConfig,
$paypalConfig,
$checkoutFactory
);
}

/**
* Submit the order
*
Expand All @@ -17,6 +51,11 @@ class PlaceOrder extends \Magento\Braintree\Controller\PayPal
public function execute()
{
try {
if (!$this->agreementsValidator->isValid(array_keys($this->getRequest()->getPost('agreement', [])))) {
throw new \Magento\Framework\Exception\LocalizedException(
__('Please agree to all the terms and conditions before placing the order.')
);
}
$this->initCheckout();
$this->getCheckout()->place(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class PlaceOrderTest extends \PHPUnit_Framework_TestCase
*/
protected $controller;

/**
* @var \Magento\Checkout\Api\AgreementsValidatorInterface |\PHPUnit_Framework_MockObject_MockObject
*/
protected $validatorMock;

/**
* test setup
*/
Expand Down Expand Up @@ -80,7 +85,7 @@ public function setUp()
->disableOriginalConstructor()
->getMock();

$this->requestMock = $this->getMock('\Magento\Framework\App\RequestInterface');
$this->requestMock = $this->getMock('\Magento\Framework\App\Request\Http', [], [], '', '', false);

$this->resultFactoryMock = $this->getMockBuilder('\Magento\Framework\Controller\ResultFactory')
->disableOriginalConstructor()
Expand All @@ -98,14 +103,15 @@ public function setUp()
$contextMock->expects($this->any())
->method('getMessageManager')
->willReturn($this->messageManager);

$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->validatorMock = $this->getMock('Magento\Checkout\Api\AgreementsValidatorInterface');
$this->controller = $this->objectManagerHelper->getObject(
'\Magento\Braintree\Controller\PayPal\PlaceOrder',
[
'context' => $contextMock,
'checkoutSession' => $this->checkoutSessionMock,
'checkoutFactory' => $this->checkoutFactoryMock,
'agreementsValidator' => $this->validatorMock
]
);
}
Expand All @@ -131,6 +137,7 @@ protected function setupCart()
->method('create')
->willReturn($this->checkoutMock);

$this->requestMock->expects($this->any())->method('getPost')->willReturn([]);
return $quoteMock;
}

Expand All @@ -141,7 +148,7 @@ public function testExecute()
$orderIncrementId = 125;

$quoteMock = $this->setupCart();

$this->validatorMock->expects($this->once())->method('isValid')->willReturn(true);
$this->checkoutMock->expects($this->once())
->method('place')
->with(null);
Expand Down Expand Up @@ -203,7 +210,7 @@ public function testExecute()
public function testExecuteException()
{
$this->setupCart();

$this->validatorMock->expects($this->once())->method('isValid')->willReturn(true);
$exceptionMsg = new \Magento\Framework\Phrase('error');
$exception = new \Magento\Framework\Exception\LocalizedException($exceptionMsg);
$this->checkoutMock->expects($this->once())
Expand Down
Loading

0 comments on commit 33b8dff

Please sign in to comment.