Skip to content

Commit 4b2bbc7

Browse files
authored
Merge pull request magento#4266 from magento-mpi/MAGETWO-99606
[MPI] Braintree SDK V3.0
2 parents 61f4037 + 5771b3e commit 4b2bbc7

File tree

36 files changed

+1054
-1257
lines changed

36 files changed

+1054
-1257
lines changed

app/code/Magento/Braintree/Block/Paypal/Button.php

+28-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Braintree\Block\Paypal;
79

810
use Magento\Braintree\Gateway\Config\PayPal\Config;
@@ -49,8 +51,6 @@ class Button extends Template implements ShortcutInterface
4951
private $payment;
5052

5153
/**
52-
* Constructor
53-
*
5454
* @param Context $context
5555
* @param ResolverInterface $localeResolver
5656
* @param Session $checkoutSession
@@ -98,6 +98,8 @@ public function getAlias()
9898
}
9999

100100
/**
101+
* Returns container id.
102+
*
101103
* @return string
102104
*/
103105
public function getContainerId()
@@ -106,6 +108,8 @@ public function getContainerId()
106108
}
107109

108110
/**
111+
* Returns locale.
112+
*
109113
* @return string
110114
*/
111115
public function getLocale()
@@ -114,6 +118,8 @@ public function getLocale()
114118
}
115119

116120
/**
121+
* Returns currency.
122+
*
117123
* @return string
118124
*/
119125
public function getCurrency()
@@ -122,6 +128,8 @@ public function getCurrency()
122128
}
123129

124130
/**
131+
* Returns amount.
132+
*
125133
* @return float
126134
*/
127135
public function getAmount()
@@ -130,6 +138,8 @@ public function getAmount()
130138
}
131139

132140
/**
141+
* Returns if is active.
142+
*
133143
* @return bool
134144
*/
135145
public function isActive()
@@ -139,6 +149,8 @@ public function isActive()
139149
}
140150

141151
/**
152+
* Returns merchant name.
153+
*
142154
* @return string
143155
*/
144156
public function getMerchantName()
@@ -147,6 +159,8 @@ public function getMerchantName()
147159
}
148160

149161
/**
162+
* Returns client token.
163+
*
150164
* @return string|null
151165
*/
152166
public function getClientToken()
@@ -155,10 +169,22 @@ public function getClientToken()
155169
}
156170

157171
/**
172+
* Returns action success.
173+
*
158174
* @return string
159175
*/
160176
public function getActionSuccess()
161177
{
162178
return $this->getUrl(ConfigProvider::CODE . '/paypal/review', ['_secure' => true]);
163179
}
180+
181+
/**
182+
* Gets environment value.
183+
*
184+
* @return string
185+
*/
186+
public function getEnvironment(): string
187+
{
188+
return $this->configProvider->getConfig()['payment'][ConfigProvider::CODE]['environment'];
189+
}
164190
}

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

+13-12
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class Config extends \Magento\Payment\Gateway\Config\Config
3030
const KEY_VERIFY_SPECIFIC = 'verify_specific_countries';
3131
const VALUE_3DSECURE_ALL = 0;
3232
const CODE_3DSECURE = 'three_d_secure';
33-
const KEY_KOUNT_MERCHANT_ID = 'kount_id';
3433
const FRAUD_PROTECTION = 'fraudprotection';
3534

3635
/**
@@ -173,6 +172,7 @@ public function get3DSecureSpecificCountries($storeId = null)
173172

174173
/**
175174
* Gets value of configured environment.
175+
*
176176
* Possible values: production or sandbox.
177177
*
178178
* @param int|null $storeId
@@ -183,17 +183,6 @@ public function getEnvironment($storeId = null)
183183
return $this->getValue(Config::KEY_ENVIRONMENT, $storeId);
184184
}
185185

186-
/**
187-
* Gets Kount merchant ID.
188-
*
189-
* @param int|null $storeId
190-
* @return string
191-
*/
192-
public function getKountMerchantId($storeId = null)
193-
{
194-
return $this->getValue(Config::KEY_KOUNT_MERCHANT_ID, $storeId);
195-
}
196-
197186
/**
198187
* Gets merchant ID.
199188
*
@@ -217,13 +206,25 @@ public function getMerchantAccountId($storeId = null)
217206
}
218207

219208
/**
209+
* Returns SDK url.
210+
*
220211
* @return string
221212
*/
222213
public function getSdkUrl()
223214
{
224215
return $this->getValue(Config::KEY_SDK_URL);
225216
}
226217

218+
/**
219+
* Gets Hosted Fields SDK Url
220+
*
221+
* @return string
222+
*/
223+
public function getHostedFieldsSdkUrl(): string
224+
{
225+
return $this->getValue('hosted_fields_sdk_url');
226+
}
227+
227228
/**
228229
* Checks if fraud protection is enabled.
229230
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Braintree\Gateway\Request;
7+
8+
use Magento\Braintree\Gateway\SubjectReader;
9+
use Magento\Payment\Gateway\Request\BuilderInterface;
10+
11+
/**
12+
* Since we can't validate 3Dsecure for sequence multishipping orders based on vault tokens,
13+
* we skip 3D secure verification for vault transactions.
14+
* For common vault transaction original 3d secure verification builder is called.
15+
*/
16+
class VaultThreeDSecureDataBuilder implements BuilderInterface
17+
{
18+
/**
19+
* @var ThreeDSecureDataBuilder
20+
*/
21+
private $threeDSecureDataBuilder;
22+
23+
/**
24+
* @var SubjectReader
25+
*/
26+
private $subjectReader;
27+
28+
/**
29+
* Constructor
30+
*
31+
* @param ThreeDSecureDataBuilder $threeDSecureDataBuilder
32+
* @param SubjectReader $subjectReader
33+
*/
34+
public function __construct(
35+
ThreeDSecureDataBuilder $threeDSecureDataBuilder,
36+
SubjectReader $subjectReader
37+
) {
38+
$this->threeDSecureDataBuilder = $threeDSecureDataBuilder;
39+
$this->subjectReader = $subjectReader;
40+
}
41+
42+
/**
43+
* @inheritdoc
44+
*/
45+
public function build(array $buildSubject)
46+
{
47+
$paymentDO = $this->subjectReader->readPayment($buildSubject);
48+
$payment = $paymentDO->getPayment();
49+
if ($payment->getAdditionalInformation('is_multishipping')) {
50+
return [];
51+
}
52+
53+
return $this->threeDSecureDataBuilder->build($buildSubject);
54+
}
55+
}

app/code/Magento/Braintree/Model/Multishipping/PlaceOrder.php

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\Braintree\Model\Multishipping;
99

1010
use Magento\Braintree\Gateway\Command\GetPaymentNonceCommand;
11+
use Magento\Braintree\Gateway\Config\Config;
1112
use Magento\Braintree\Model\Ui\ConfigProvider;
1213
use Magento\Braintree\Observer\DataAssignObserver;
1314
use Magento\Braintree\Model\Ui\PayPal\ConfigProvider as PaypalConfigProvider;
@@ -118,6 +119,10 @@ private function setVaultPayment(OrderPaymentInterface $orderPayment, PaymentTok
118119
PaymentTokenInterface::CUSTOMER_ID,
119120
$customerId
120121
);
122+
$orderPayment->setAdditionalInformation(
123+
'is_multishipping',
124+
1
125+
);
121126
}
122127

123128
/**

app/code/Magento/Braintree/Model/Paypal/Helper/QuoteUpdater.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,14 @@ private function updateBillingAddress(Quote $quote, array $details)
173173
*/
174174
private function updateAddressData(Address $address, array $addressData)
175175
{
176-
$extendedAddress = isset($addressData['extendedAddress'])
177-
? $addressData['extendedAddress']
176+
$extendedAddress = isset($addressData['line2'])
177+
? $addressData['line2']
178178
: null;
179179

180-
$address->setStreet([$addressData['streetAddress'], $extendedAddress]);
181-
$address->setCity($addressData['locality']);
182-
$address->setRegionCode($addressData['region']);
183-
$address->setCountryId($addressData['countryCodeAlpha2']);
180+
$address->setStreet([$addressData['line1'], $extendedAddress]);
181+
$address->setCity($addressData['city']);
182+
$address->setRegionCode($addressData['state']);
183+
$address->setCountryId($addressData['countryCode']);
184184
$address->setPostcode($addressData['postalCode']);
185185

186186
// PayPal's address supposes not saving against customer account

app/code/Magento/Braintree/Model/Ui/ConfigProvider.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
/**
1515
* Class ConfigProvider
16+
*
17+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1618
*/
1719
class ConfigProvider implements ConfigProviderInterface
1820
{
@@ -72,11 +74,11 @@ public function getConfig()
7274
'clientToken' => $this->getClientToken(),
7375
'ccTypesMapper' => $this->config->getCcTypesMapper(),
7476
'sdkUrl' => $this->config->getSdkUrl(),
77+
'hostedFieldsSdkUrl' => $this->config->getHostedFieldsSdkUrl(),
7578
'countrySpecificCardTypes' => $this->config->getCountrySpecificCardTypeConfig($storeId),
7679
'availableCardTypes' => $this->config->getAvailableCardTypes($storeId),
7780
'useCvv' => $this->config->isCvvEnabled($storeId),
7881
'environment' => $this->config->getEnvironment($storeId),
79-
'kountMerchantId' => $this->config->getKountMerchantId($storeId),
8082
'hasFraudProtection' => $this->config->hasFraudProtection($storeId),
8183
'merchantId' => $this->config->getMerchantId($storeId),
8284
'ccVaultCode' => self::CC_VAULT_CODE,
@@ -92,6 +94,7 @@ public function getConfig()
9294

9395
/**
9496
* Generate a new client token if necessary
97+
*
9598
* @return string
9699
*/
97100
public function getClientToken()

app/code/Magento/Braintree/Test/Unit/Model/Paypal/Helper/QuoteUpdaterTest.php

+14-14
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,21 @@ private function getDetails(): array
159159
'phone' => '312-123-4567',
160160
'countryCode' => 'US',
161161
'shippingAddress' => [
162-
'streetAddress' => '123 Division Street',
163-
'extendedAddress' => 'Apt. #1',
164-
'locality' => 'Chicago',
165-
'region' => 'IL',
162+
'line1' => '123 Division Street',
163+
'line2' => 'Apt. #1',
164+
'city' => 'Chicago',
165+
'state' => 'IL',
166166
'postalCode' => '60618',
167-
'countryCodeAlpha2' => 'US',
167+
'countryCode' => 'US',
168168
'recipientName' => 'Jane Smith',
169169
],
170170
'billingAddress' => [
171-
'streetAddress' => '123 Billing Street',
172-
'extendedAddress' => 'Apt. #1',
173-
'locality' => 'Chicago',
174-
'region' => 'IL',
171+
'line1' => '123 Billing Street',
172+
'line2' => 'Apt. #1',
173+
'city' => 'Chicago',
174+
'state' => 'IL',
175175
'postalCode' => '60618',
176-
'countryCodeAlpha2' => 'US',
176+
'countryCode' => 'US',
177177
],
178178
];
179179
}
@@ -206,13 +206,13 @@ private function updateShippingAddressStep(array $details): void
206206
private function updateAddressDataStep(MockObject $address, array $addressData): void
207207
{
208208
$address->method('setStreet')
209-
->with([$addressData['streetAddress'], $addressData['extendedAddress']]);
209+
->with([$addressData['line1'], $addressData['line2']]);
210210
$address->method('setCity')
211-
->with($addressData['locality']);
211+
->with($addressData['city']);
212212
$address->method('setRegionCode')
213-
->with($addressData['region']);
213+
->with($addressData['state']);
214214
$address->method('setCountryId')
215-
->with($addressData['countryCodeAlpha2']);
215+
->with($addressData['countryCode']);
216216
$address->method('setPostcode')
217217
->with($addressData['postalCode']);
218218
}

app/code/Magento/Braintree/Test/Unit/Model/Ui/ConfigProviderTest.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Braintree\Test\Unit\Model\Ui;
79

810
use Magento\Braintree\Gateway\Config\Config;
@@ -124,6 +126,7 @@ public function getConfigDataProvider()
124126
'isActive' => true,
125127
'getCcTypesMapper' => ['visa' => 'VI', 'american-express'=> 'AE'],
126128
'getSdkUrl' => self::SDK_URL,
129+
'getHostedFieldsSdkUrl' => 'https://sdk.com/test.js',
127130
'getCountrySpecificCardTypeConfig' => [
128131
'GB' => ['VI', 'AE'],
129132
'US' => ['DI', 'JCB']
@@ -134,7 +137,6 @@ public function getConfigDataProvider()
134137
'getThresholdAmount' => 20,
135138
'get3DSecureSpecificCountries' => ['GB', 'US', 'CA'],
136139
'getEnvironment' => 'test-environment',
137-
'getKountMerchantId' => 'test-kount-merchant-id',
138140
'getMerchantId' => 'test-merchant-id',
139141
'hasFraudProtection' => true,
140142
],
@@ -145,14 +147,14 @@ public function getConfigDataProvider()
145147
'clientToken' => self::CLIENT_TOKEN,
146148
'ccTypesMapper' => ['visa' => 'VI', 'american-express' => 'AE'],
147149
'sdkUrl' => self::SDK_URL,
150+
'hostedFieldsSdkUrl' => 'https://sdk.com/test.js',
148151
'countrySpecificCardTypes' =>[
149152
'GB' => ['VI', 'AE'],
150153
'US' => ['DI', 'JCB']
151154
],
152155
'availableCardTypes' => ['AE', 'VI', 'MC', 'DI', 'JCB'],
153156
'useCvv' => true,
154157
'environment' => 'test-environment',
155-
'kountMerchantId' => 'test-kount-merchant-id',
156158
'merchantId' => 'test-merchant-id',
157159
'hasFraudProtection' => true,
158160
'ccVaultCode' => ConfigProvider::CC_VAULT_CODE

app/code/Magento/Braintree/etc/adminhtml/system.xml

-8
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,6 @@
9595
<comment>Be sure to Enable Advanced Fraud Protection in Your Braintree Account in Settings/Processing Section</comment>
9696
<config_path>payment/braintree/fraudprotection</config_path>
9797
</field>
98-
<field id="kount_id" translate="label comment" sortOrder="35" showInDefault="1" showInWebsite="1" showInStore="0">
99-
<label>Kount Merchant ID</label>
100-
<comment><![CDATA[Used for direct fraud tool integration. Make sure you also contact <a href="mailto:[email protected]">[email protected]</a> to setup your Kount account.]]></comment>
101-
<depends>
102-
<field id="fraudprotection">1</field>
103-
</depends>
104-
<config_path>payment/braintree/kount_id</config_path>
105-
</field>
10698
<field id="debug" translate="label" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">
10799
<label>Debug</label>
108100
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>

0 commit comments

Comments
 (0)