Skip to content

Commit

Permalink
Merge branch '2.1' of https://github.com/magento/magento2ce into MAGE…
Browse files Browse the repository at this point in the history
…TWO-59376

# Conflicts:
#	app/code/Magento/Braintree/etc/di.xml
#	app/code/Magento/Paypal/etc/di.xml
  • Loading branch information
shiftedreality committed Nov 3, 2016
2 parents f535fe1 + 5e86fa1 commit fbd1d3d
Show file tree
Hide file tree
Showing 405 changed files with 13,377 additions and 2,226 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Authorizenet/Model/Source/Cctype.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class Cctype extends PaymentCctype
*/
public function getAllowedTypes()
{
return ['VI', 'MC', 'AE', 'DI', 'OT', 'JCB', 'DN'];
return ['VI', 'MC', 'AE', 'DI', 'JCB', 'DN'];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Braintree\Block\Customer\PayPal;

use Magento\Braintree\Gateway\Config\PayPal\Config;
use Magento\Braintree\Model\Ui\PayPal\ConfigProvider;
use Magento\Framework\View\Element\Template;
use Magento\Vault\Api\Data\PaymentTokenInterface;
use Magento\Vault\Block\AbstractTokenRenderer;

/**
* Class VaultTokenRenderer
*/
class VaultTokenRenderer extends AbstractTokenRenderer
{
/**
* @var Config
*/
private $config;

public function __construct(
Template\Context $context,
Config $config,
array $data = []
) {
parent::__construct($context, $data);
$this->config = $config;
}

/**
* @inheritdoc
*/
public function getIconUrl()
{
return $this->config->getPayPalIcon()['url'];
}

/**
* @inheritdoc
*/
public function getIconHeight()
{
return $this->config->getPayPalIcon()['height'];
}

/**
* @inheritdoc
*/
public function getIconWidth()
{
return $this->config->getPayPalIcon()['width'];
}

/**
* Can render specified token
*
* @param PaymentTokenInterface $token
* @return boolean
*/
public function canRender(PaymentTokenInterface $token)
{
return $token->getPaymentMethodCode() === ConfigProvider::PAYPAL_CODE;
}

/**
* Get email of PayPal payer
* @return string
*/
public function getPayerEmail()
{
return $this->getTokenDetails()['payerEmail'];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,25 @@ private function isExpiredAuthorization(OrderPaymentInterface $payment)
*/
private function isExistsCaptureTransaction(OrderPaymentInterface $payment)
{
$filters[] = $this->filterBuilder->setField('payment_id')
->setValue($payment->getId())
->create();
$this->searchCriteriaBuilder->addFilters(
[
$this->filterBuilder
->setField('payment_id')
->setValue($payment->getId())
->create(),
]
);

$filters[] = $this->filterBuilder->setField('txn_type')
->setValue(TransactionInterface::TYPE_CAPTURE)
->create();
$this->searchCriteriaBuilder->addFilters(
[
$this->filterBuilder
->setField('txn_type')
->setValue(TransactionInterface::TYPE_CAPTURE)
->create(),
]
);

$searchCriteria = $this->searchCriteriaBuilder->addFilters($filters)
->create();
$searchCriteria = $this->searchCriteriaBuilder->create();

$count = $this->transactionRepository->getList($searchCriteria)->getTotalCount();
return (boolean) $count;
Expand Down
24 changes: 24 additions & 0 deletions app/code/Magento/Braintree/Gateway/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ class Config extends \Magento\Payment\Gateway\Config\Config
const KEY_KOUNT_MERCHANT_ID = 'kount_id';
const FRAUD_PROTECTION = 'fraudprotection';

/**
* Get list of available dynamic descriptors keys
* @var array
*/
private static $dynamicDescriptorKeys = [
'name', 'phone', 'url'
];

/**
* Return the country specific card type config
*
Expand Down Expand Up @@ -170,6 +178,22 @@ public function isActive()
return (bool) $this->getValue(self::KEY_ACTIVE);
}

/**
* Get list of configured dynamic descriptors
* @return array
*/
public function getDynamicDescriptors()
{
$values = [];
foreach (self::$dynamicDescriptorKeys as $key) {
$value = $this->getValue('descriptor_' . $key);
if (!empty($value)) {
$values[$key] = $value;
}
}
return $values;
}

/**
* Get Merchant account ID
*
Expand Down
51 changes: 51 additions & 0 deletions app/code/Magento/Braintree/Gateway/Config/PayPal/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
*/
namespace Magento\Braintree\Gateway\Config\PayPal;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Payment\Model\CcConfig;

/**
* Class Config
*/
Expand All @@ -22,6 +25,26 @@ class Config extends \Magento\Payment\Gateway\Config\Config

const KEY_REQUIRE_BILLING_ADDRESS = 'require_billing_address';

/**
* @var CcConfig
*/
private $ccConfig;

/**
* @var array
*/
private $icon = [];

public function __construct(
ScopeConfigInterface $scopeConfig,
CcConfig $ccConfig,
$methodCode = null,
$pathPattern = self::DEFAULT_PATH_PATTERN
) {
parent::__construct($scopeConfig, $methodCode, $pathPattern);
$this->ccConfig = $ccConfig;
}

/**
* Get Payment configuration status
*
Expand Down Expand Up @@ -79,4 +102,32 @@ public function getTitle()
{
return $this->getValue(self::KEY_TITLE);
}

/**
* Is need to skip order review
* @return bool
*/
public function isSkipOrderReview()
{
return (bool) $this->getValue('skip_order_review');
}

/**
* Get PayPal icon
* @return array
*/
public function getPayPalIcon()
{
if (empty($this->icon)) {
$asset = $this->ccConfig->createAsset('Magento_Braintree::images/paypal.png');
list($width, $height) = getimagesize($asset->getSourceFile());
$this->icon = [
'url' => $asset->getUrl(),
'width' => $width,
'height' => $height
];
}

return $this->icon;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function readAmount(array $subject)
*/
public function readCustomerId(array $subject)
{
if (empty($subject['customer_id'])) {
if (!isset($subject['customer_id'])) {
throw new \InvalidArgumentException('The "customerId" field does not exists');
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Braintree\Gateway\Request;

use Magento\Payment\Gateway\Request\BuilderInterface;
use Magento\Braintree\Gateway\Config\Config;

/**
* Class DescriptorDataBuilder
*/
class DescriptorDataBuilder implements BuilderInterface
{
/**
* @var string
*/
private static $descriptorKey = 'descriptor';

/**
* @var Config
*/
private $config;

/**
* DescriptorDataBuilder constructor.
* @param Config $config
*/
public function __construct(Config $config)
{
$this->config = $config;
}

/**
* @inheritdoc
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function build(array $buildSubject)
{
$values = $this->config->getDynamicDescriptors();
return !empty($values) ? [self::$descriptorKey => $values] : [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Braintree\Gateway\Request\PayPal;

use Magento\Braintree\Gateway\Helper\SubjectReader;
use Magento\Braintree\Observer\DataAssignObserver;
use Magento\Payment\Gateway\Request\BuilderInterface;

/**
* Class DeviceDataBuilder
*/
class DeviceDataBuilder implements BuilderInterface
{
/**
* @var string
*/
private static $deviceDataKey = 'deviceData';

/**
* @var SubjectReader
*/
private $subjectReader;

/**
* DeviceDataBuilder constructor.
* @param SubjectReader $subjectReader
*/
public function __construct(SubjectReader $subjectReader)
{
$this->subjectReader = $subjectReader;
}

/**
* @inheritdoc
*/
public function build(array $buildSubject)
{
$result = [];
$paymentDO = $this->subjectReader->readPayment($buildSubject);

$payment = $paymentDO->getPayment();
$data = $payment->getAdditionalInformation();
if (!empty($data[DataAssignObserver::DEVICE_DATA])) {
$result[self::$deviceDataKey] = $data[DataAssignObserver::DEVICE_DATA];
}

return $result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Braintree\Gateway\Request\PayPal;

use Magento\Braintree\Gateway\Helper\SubjectReader;
use Magento\Payment\Gateway\Request\BuilderInterface;
use Magento\Vault\Model\Ui\VaultConfigProvider;

/**
* Vault Data Builder
*/
class VaultDataBuilder implements BuilderInterface
{
/**
* Additional options in request to gateway
*/
private static $optionsKey = 'options';

/**
* The option that determines whether the payment method associated with
* the successful transaction should be stored in the Vault.
*/
private static $storeInVaultOnSuccess = 'storeInVaultOnSuccess';

/**
* @var SubjectReader
*/
private $subjectReader;

/**
* VaultDataBuilder constructor.
* @param SubjectReader $subjectReader
*/
public function __construct(SubjectReader $subjectReader)
{
$this->subjectReader = $subjectReader;
}

/**
* @inheritdoc
*/
public function build(array $buildSubject)
{
$result = [];
$paymentDO = $this->subjectReader->readPayment($buildSubject);

$payment = $paymentDO->getPayment();
$data = $payment->getAdditionalInformation();
if (!empty($data[VaultConfigProvider::IS_ACTIVE_CODE])) {
$result[self::$optionsKey] = [
self::$storeInVaultOnSuccess => true
];
}

return $result;
}
}
Loading

0 comments on commit fbd1d3d

Please sign in to comment.