Skip to content

Commit 532dcd5

Browse files
Merge pull request #163 from magento-mpi/MPI-79
[MPI] Sprint 79
2 parents ffd9cc6 + e8ddb1d commit 532dcd5

File tree

157 files changed

+5363
-711
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+5363
-711
lines changed

app/code/Magento/Authorizenet/Model/Source/Cctype.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ class Cctype extends PaymentCctype
1717
*/
1818
public function getAllowedTypes()
1919
{
20-
return ['VI', 'MC', 'AE', 'DI', 'OT'];
20+
return ['VI', 'MC', 'AE', 'DI'];
2121
}
2222
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Braintree\Block\Customer\PayPal;
7+
8+
use Magento\Braintree\Gateway\Config\PayPal\Config;
9+
use Magento\Braintree\Model\Ui\PayPal\ConfigProvider;
10+
use Magento\Framework\View\Element\Template;
11+
use Magento\Vault\Api\Data\PaymentTokenInterface;
12+
use Magento\Vault\Block\AbstractTokenRenderer;
13+
14+
/**
15+
* Class VaultTokenRenderer
16+
*/
17+
class VaultTokenRenderer extends AbstractTokenRenderer
18+
{
19+
/**
20+
* @var Config
21+
*/
22+
private $config;
23+
24+
public function __construct(
25+
Template\Context $context,
26+
Config $config,
27+
array $data = []
28+
) {
29+
parent::__construct($context, $data);
30+
$this->config = $config;
31+
}
32+
33+
/**
34+
* @inheritdoc
35+
*/
36+
public function getIconUrl()
37+
{
38+
return $this->config->getPayPalIcon()['url'];
39+
}
40+
41+
/**
42+
* @inheritdoc
43+
*/
44+
public function getIconHeight()
45+
{
46+
return $this->config->getPayPalIcon()['height'];
47+
}
48+
49+
/**
50+
* @inheritdoc
51+
*/
52+
public function getIconWidth()
53+
{
54+
return $this->config->getPayPalIcon()['width'];
55+
}
56+
57+
/**
58+
* Can render specified token
59+
*
60+
* @param PaymentTokenInterface $token
61+
* @return boolean
62+
*/
63+
public function canRender(PaymentTokenInterface $token)
64+
{
65+
return $token->getPaymentMethodCode() === ConfigProvider::PAYPAL_CODE;
66+
}
67+
68+
/**
69+
* Get email of PayPal payer
70+
* @return string
71+
*/
72+
public function getPayerEmail()
73+
{
74+
return $this->getTokenDetails()['payerEmail'];
75+
}
76+
}

app/code/Magento/Braintree/Gateway/Config/Config.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ class Config extends \Magento\Payment\Gateway\Config\Config
3030
const KEY_KOUNT_MERCHANT_ID = 'kount_id';
3131
const FRAUD_PROTECTION = 'fraudprotection';
3232

33+
/**
34+
* Get list of available dynamic descriptors keys
35+
* @var array
36+
*/
37+
private static $dynamicDescriptorKeys = [
38+
'name', 'phone', 'url'
39+
];
40+
3341
/**
3442
* Return the country specific card type config
3543
*
@@ -169,4 +177,20 @@ public function isActive()
169177
{
170178
return (bool) $this->getValue(self::KEY_ACTIVE);
171179
}
180+
181+
/**
182+
* Get list of configured dynamic descriptors
183+
* @return array
184+
*/
185+
public function getDynamicDescriptors()
186+
{
187+
$values = [];
188+
foreach (self::$dynamicDescriptorKeys as $key) {
189+
$value = $this->getValue('descriptor_' . $key);
190+
if (!empty($value)) {
191+
$values[$key] = $value;
192+
}
193+
}
194+
return $values;
195+
}
172196
}

app/code/Magento/Braintree/Gateway/Config/PayPal/Config.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\Braintree\Gateway\Config\PayPal;
77

8+
use Magento\Framework\App\Config\ScopeConfigInterface;
9+
use Magento\Payment\Model\CcConfig;
10+
811
/**
912
* Class Config
1013
*/
@@ -22,6 +25,26 @@ class Config extends \Magento\Payment\Gateway\Config\Config
2225

2326
const KEY_REQUIRE_BILLING_ADDRESS = 'require_billing_address';
2427

28+
/**
29+
* @var CcConfig
30+
*/
31+
private $ccConfig;
32+
33+
/**
34+
* @var array
35+
*/
36+
private $icon = [];
37+
38+
public function __construct(
39+
ScopeConfigInterface $scopeConfig,
40+
CcConfig $ccConfig,
41+
$methodCode = null,
42+
$pathPattern = self::DEFAULT_PATH_PATTERN
43+
) {
44+
parent::__construct($scopeConfig, $methodCode, $pathPattern);
45+
$this->ccConfig = $ccConfig;
46+
}
47+
2548
/**
2649
* Get Payment configuration status
2750
*
@@ -79,4 +102,32 @@ public function getTitle()
79102
{
80103
return $this->getValue(self::KEY_TITLE);
81104
}
105+
106+
/**
107+
* Is need to skip order review
108+
* @return bool
109+
*/
110+
public function isSkipOrderReview()
111+
{
112+
return (bool) $this->getValue('skip_order_review');
113+
}
114+
115+
/**
116+
* Get PayPal icon
117+
* @return array
118+
*/
119+
public function getPayPalIcon()
120+
{
121+
if (empty($this->icon)) {
122+
$asset = $this->ccConfig->createAsset('Magento_Braintree::images/paypal.png');
123+
list($width, $height) = getimagesize($asset->getSourceFile());
124+
$this->icon = [
125+
'url' => $asset->getUrl(),
126+
'width' => $width,
127+
'height' => $height
128+
];
129+
}
130+
131+
return $this->icon;
132+
}
82133
}

app/code/Magento/Braintree/Gateway/Helper/SubjectReader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function readAmount(array $subject)
8383
*/
8484
public function readCustomerId(array $subject)
8585
{
86-
if (empty($subject['customer_id'])) {
86+
if (!isset($subject['customer_id'])) {
8787
throw new \InvalidArgumentException('The "customerId" field does not exists');
8888
}
8989

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Braintree\Gateway\Request;
7+
8+
use Magento\Payment\Gateway\Request\BuilderInterface;
9+
use Magento\Braintree\Gateway\Config\Config;
10+
11+
/**
12+
* Class DescriptorDataBuilder
13+
*/
14+
class DescriptorDataBuilder implements BuilderInterface
15+
{
16+
/**
17+
* @var string
18+
*/
19+
private static $descriptorKey = 'descriptor';
20+
21+
/**
22+
* @var Config
23+
*/
24+
private $config;
25+
26+
/**
27+
* DescriptorDataBuilder constructor.
28+
* @param Config $config
29+
*/
30+
public function __construct(Config $config)
31+
{
32+
$this->config = $config;
33+
}
34+
35+
/**
36+
* @inheritdoc
37+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
38+
*/
39+
public function build(array $buildSubject)
40+
{
41+
$values = $this->config->getDynamicDescriptors();
42+
return !empty($values) ? [self::$descriptorKey => $values] : [];
43+
}
44+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Braintree\Gateway\Request\PayPal;
7+
8+
use Magento\Braintree\Gateway\Helper\SubjectReader;
9+
use Magento\Braintree\Observer\DataAssignObserver;
10+
use Magento\Payment\Gateway\Request\BuilderInterface;
11+
12+
/**
13+
* Class DeviceDataBuilder
14+
*/
15+
class DeviceDataBuilder implements BuilderInterface
16+
{
17+
/**
18+
* @var string
19+
*/
20+
private static $deviceDataKey = 'deviceData';
21+
22+
/**
23+
* @var SubjectReader
24+
*/
25+
private $subjectReader;
26+
27+
/**
28+
* DeviceDataBuilder constructor.
29+
* @param SubjectReader $subjectReader
30+
*/
31+
public function __construct(SubjectReader $subjectReader)
32+
{
33+
$this->subjectReader = $subjectReader;
34+
}
35+
36+
/**
37+
* @inheritdoc
38+
*/
39+
public function build(array $buildSubject)
40+
{
41+
$result = [];
42+
$paymentDO = $this->subjectReader->readPayment($buildSubject);
43+
44+
$payment = $paymentDO->getPayment();
45+
$data = $payment->getAdditionalInformation();
46+
if (!empty($data[DataAssignObserver::DEVICE_DATA])) {
47+
$result[self::$deviceDataKey] = $data[DataAssignObserver::DEVICE_DATA];
48+
}
49+
50+
return $result;
51+
}
52+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Braintree\Gateway\Request\PayPal;
7+
8+
use Magento\Braintree\Gateway\Helper\SubjectReader;
9+
use Magento\Payment\Gateway\Request\BuilderInterface;
10+
use Magento\Vault\Model\Ui\VaultConfigProvider;
11+
12+
/**
13+
* Vault Data Builder
14+
*/
15+
class VaultDataBuilder implements BuilderInterface
16+
{
17+
/**
18+
* Additional options in request to gateway
19+
*/
20+
private static $optionsKey = 'options';
21+
22+
/**
23+
* The option that determines whether the payment method associated with
24+
* the successful transaction should be stored in the Vault.
25+
*/
26+
private static $storeInVaultOnSuccess = 'storeInVaultOnSuccess';
27+
28+
/**
29+
* @var SubjectReader
30+
*/
31+
private $subjectReader;
32+
33+
/**
34+
* VaultDataBuilder constructor.
35+
* @param SubjectReader $subjectReader
36+
*/
37+
public function __construct(SubjectReader $subjectReader)
38+
{
39+
$this->subjectReader = $subjectReader;
40+
}
41+
42+
/**
43+
* @inheritdoc
44+
*/
45+
public function build(array $buildSubject)
46+
{
47+
$result = [];
48+
$paymentDO = $this->subjectReader->readPayment($buildSubject);
49+
50+
$payment = $paymentDO->getPayment();
51+
$data = $payment->getAdditionalInformation();
52+
if (!empty($data[VaultConfigProvider::IS_ACTIVE_CODE])) {
53+
$result[self::$optionsKey] = [
54+
self::$storeInVaultOnSuccess => true
55+
];
56+
}
57+
58+
return $result;
59+
}
60+
}

app/code/Magento/Braintree/Gateway/Request/VaultDataBuilder.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ class VaultDataBuilder implements BuilderInterface
1818
const OPTIONS = 'options';
1919

2020
/**
21-
* The option that determines whether the shipping address information
22-
* provided with the transaction should be associated with the customer ID specified.
23-
* When passed, the payment method will always be stored in the Vault.
21+
* The option that determines whether the payment method associated with
22+
* the successful transaction should be stored in the Vault.
2423
*/
2524
const STORE_IN_VAULT_ON_SUCCESS = 'storeInVaultOnSuccess';
2625

0 commit comments

Comments
 (0)