-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'mainline/develop' into MAGETWO-44074
- Loading branch information
Showing
299 changed files
with
15,508 additions
and
3,481 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
app/code/Magento/BraintreeTwo/Block/Adminhtml/Form/Field/Cctypes.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\BraintreeTwo\Block\Adminhtml\Form\Field; | ||
|
||
use Magento\Framework\View\Element\Context; | ||
use Magento\Framework\View\Element\Html\Select; | ||
use Magento\BraintreeTwo\Helper\CcType; | ||
|
||
/** | ||
* Class Cctypes | ||
* @package Magento\BraintreeTwo\Block\Adminhtml\Form\Field | ||
*/ | ||
class Cctypes extends Select | ||
{ | ||
/** | ||
* @var \ | ||
*/ | ||
private $ccTypeHelper; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param \Magento\Framework\View\Element\Context $context | ||
* @param \Magento\BraintreeTwo\Helper\CcType $ccTypeHelper | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
CcType $ccTypeHelper, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $data); | ||
$this->ccTypeHelper = $ccTypeHelper; | ||
} | ||
|
||
/** | ||
* Render block HTML | ||
* | ||
* @return string | ||
*/ | ||
protected function _toHtml() | ||
{ | ||
if (!$this->getOptions()) { | ||
$this->setOptions($this->ccTypeHelper->getCcTypes()); | ||
} | ||
$this->setClass('cc-type-select'); | ||
$this->setExtraParams('multiple="multiple"'); | ||
return parent::_toHtml(); | ||
} | ||
|
||
/** | ||
* Sets name for input element | ||
* | ||
* @param string $value | ||
* @return $this | ||
*/ | ||
public function setInputName($value) | ||
{ | ||
return $this->setName($value . '[]'); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
app/code/Magento/BraintreeTwo/Block/Adminhtml/Form/Field/Countries.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\BraintreeTwo\Block\Adminhtml\Form\Field; | ||
|
||
use Magento\BraintreeTwo\Helper\Country; | ||
use Magento\Framework\View\Element\Context; | ||
use Magento\Framework\View\Element\Html\Select; | ||
|
||
/** | ||
* Class Countries | ||
* @package Magento\BraintreeTwo\Block\Adminhtml\Form\Field | ||
*/ | ||
class Countries extends Select | ||
{ | ||
/** | ||
* @var \Magento\BraintreeTwo\Helper\Country | ||
*/ | ||
private $countryHelper; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param \Magento\Framework\View\Element\Context $context | ||
* @param \Magento\BraintreeTwo\Helper\Country $countryHelper | ||
* @param array $data | ||
*/ | ||
public function __construct(Context $context, Country $countryHelper, array $data = []) | ||
{ | ||
parent::__construct($context, $data); | ||
$this->countryHelper = $countryHelper; | ||
} | ||
|
||
/** | ||
* Render block HTML | ||
* | ||
* @return string | ||
*/ | ||
protected function _toHtml() | ||
{ | ||
if (!$this->getOptions()) { | ||
$this->setOptions($this->countryHelper->getCountries()); | ||
} | ||
return parent::_toHtml(); | ||
} | ||
|
||
/** | ||
* Sets name for input element | ||
* | ||
* @param string $value | ||
* @return $this | ||
*/ | ||
public function setInputName($value) | ||
{ | ||
return $this->setName($value); | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
app/code/Magento/BraintreeTwo/Block/Adminhtml/Form/Field/CountryCreditCard.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\BraintreeTwo\Block\Adminhtml\Form\Field; | ||
|
||
use Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray; | ||
use Magento\Framework\DataObject; | ||
|
||
/** | ||
* Class CountryCreditCard | ||
* @package Magento\BraintreeTwo\Block\Adminhtml\Form\Field | ||
*/ | ||
class CountryCreditCard extends AbstractFieldArray | ||
{ | ||
/** | ||
* @var \Magento\BraintreeTwo\Block\Adminhtml\Form\Field\Countries | ||
*/ | ||
protected $countryRenderer = null; | ||
|
||
/** | ||
* @var \Magento\BraintreeTwo\Block\Adminhtml\Form\Field\CcTypes | ||
*/ | ||
protected $ccTypesRenderer = null; | ||
|
||
/** | ||
* Returns renderer for country element | ||
* | ||
* @return \Magento\BraintreeTwo\Block\Adminhtml\Form\Field\Countries | ||
*/ | ||
protected function getCountryRenderer() | ||
{ | ||
if (!$this->countryRenderer) { | ||
$this->countryRenderer = $this->getLayout()->createBlock( | ||
Countries::class, | ||
'', | ||
['data' => ['is_render_to_js_template' => true]] | ||
); | ||
} | ||
return $this->countryRenderer; | ||
} | ||
|
||
/** | ||
* Returns renderer for country element | ||
* | ||
* @return \Magento\BraintreeTwo\Block\Adminhtml\Form\Field\Cctypes | ||
*/ | ||
protected function getCcTypesRenderer() | ||
{ | ||
if (!$this->ccTypesRenderer) { | ||
$this->ccTypesRenderer = $this->getLayout()->createBlock( | ||
Cctypes::class, | ||
'', | ||
['data' => ['is_render_to_js_template' => true]] | ||
); | ||
} | ||
return $this->ccTypesRenderer; | ||
} | ||
|
||
/** | ||
* Prepare to render | ||
* @return void | ||
*/ | ||
protected function _prepareToRender() | ||
{ | ||
$this->addColumn( | ||
'country_id', | ||
[ | ||
'label' => __('Country'), | ||
'renderer' => $this->getCountryRenderer(), | ||
] | ||
); | ||
$this->addColumn( | ||
'cc_types', | ||
[ | ||
'label' => __('Allowed Credit Card Types'), | ||
'renderer' => $this->getCcTypesRenderer(), | ||
] | ||
); | ||
$this->_addAfter = false; | ||
$this->_addButtonLabel = __('Add Rule'); | ||
} | ||
|
||
/** | ||
* Prepare existing row data object | ||
* | ||
* @param \Magento\Framework\DataObject $row | ||
* @return void | ||
*/ | ||
protected function _prepareArrayRow(DataObject $row) | ||
{ | ||
$country = $row->getCountryId(); | ||
$options = []; | ||
if ($country) { | ||
$options['option_' . $this->getCountryRenderer()->calcOptionHash($country)] | ||
= 'selected="selected"'; | ||
|
||
$ccTypes = $row->getCcTypes(); | ||
foreach ($ccTypes as $cardType) { | ||
$options['option_' . $this->getCcTypesRenderer()->calcOptionHash($cardType)] | ||
= 'selected="selected"'; | ||
} | ||
} | ||
$row->setData('option_extra_attrs', $options); | ||
return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\BraintreeTwo\Block; | ||
|
||
use Magento\Backend\Model\Session\Quote; | ||
use Magento\Framework\View\Element\Template\Context; | ||
use Magento\Payment\Block\Form\Cc; | ||
use Magento\Payment\Model\Config; | ||
use Magento\BraintreeTwo\Gateway\Config\Config as GatewayConfig; | ||
use Magento\BraintreeTwo\Model\Adminhtml\Source\CcType; | ||
|
||
/** | ||
* Class Form | ||
* @package Magento\BraintreeTwo\Block | ||
*/ | ||
class Form extends Cc | ||
{ | ||
|
||
/** | ||
* @var \Magento\Backend\Model\Session\Quote | ||
*/ | ||
protected $sessionQuote; | ||
|
||
/** | ||
* @var \Magento\BraintreeTwo\Gateway\Config\Config | ||
*/ | ||
protected $gatewayConfig; | ||
|
||
/** | ||
* @var \Magento\BraintreeTwo\Model\Adminhtml\Source\CcType | ||
*/ | ||
protected $ccType; | ||
|
||
/** | ||
* @param \Magento\Framework\View\Element\Template\Context $context | ||
* @param \Magento\Payment\Model\Config $paymentConfig | ||
* @param \Magento\Backend\Model\Session\Quote $sessionQuote | ||
* @param \Magento\BraintreeTwo\Gateway\Config\Config $gatewayConfig | ||
* @param \Magento\BraintreeTwo\Model\Adminhtml\Source\CcType $ccType | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
Config $paymentConfig, | ||
Quote $sessionQuote, | ||
GatewayConfig $gatewayConfig, | ||
CcType $ccType, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $paymentConfig, $data); | ||
$this->sessionQuote = $sessionQuote; | ||
$this->gatewayConfig = $gatewayConfig; | ||
$this->ccType = $ccType; | ||
} | ||
|
||
/** | ||
* Get list of available card types of order billing address country | ||
* @return array | ||
*/ | ||
public function getCcAvailableTypes() | ||
{ | ||
$configuredCardTypes = $this->getConfiguredCardTypes(); | ||
$countryId = $this->sessionQuote->getQuote()->getBillingAddress()->getCountryId(); | ||
return $this->filterCardTypesForCountry($configuredCardTypes, $countryId); | ||
} | ||
|
||
/** | ||
* Check if cvv validation is available | ||
* @return boolean | ||
*/ | ||
public function useCvv() | ||
{ | ||
return $this->gatewayConfig->isCvvEnabled(); | ||
} | ||
|
||
/** | ||
* Get card types available for Braintree | ||
* @return array | ||
*/ | ||
private function getConfiguredCardTypes() | ||
{ | ||
$types = $this->ccType->getCcTypeLabelMap(); | ||
$configCardTypes = array_fill_keys($this->gatewayConfig->getAvailableCardTypes(), ''); | ||
|
||
return array_intersect_key($types, $configCardTypes); | ||
} | ||
|
||
/** | ||
* Filter card types for specific country | ||
* @param array $configCardTypes | ||
* @param string $countryId | ||
* @return array | ||
*/ | ||
private function filterCardTypesForCountry(array $configCardTypes, $countryId) | ||
{ | ||
$filtered = $configCardTypes; | ||
$countryCardTypes = $this->gatewayConfig->getCountryAvailableCardTypes($countryId); | ||
// filter card types only if specific card types are set for country | ||
if (!empty($countryCardTypes)) { | ||
$availableTypes = array_fill_keys($countryCardTypes, ''); | ||
$filtered = array_intersect_key($filtered, $availableTypes); | ||
} | ||
return $filtered; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\BraintreeTwo\Block; | ||
|
||
use Magento\Framework\Phrase; | ||
use Magento\Payment\Block\ConfigurableInfo; | ||
|
||
/** | ||
* Class Info | ||
* @package Magento\BraintreeTwo\Block | ||
*/ | ||
class Info extends ConfigurableInfo | ||
{ | ||
/** | ||
* Returns label | ||
* | ||
* @param string $field | ||
* @return Phrase | ||
*/ | ||
protected function getLabel($field) | ||
{ | ||
return __($field); | ||
} | ||
} |
Oops, something went wrong.