Skip to content

Commit 3dda470

Browse files
🔃 [EngCom] Public Pull Requests - 2.3-develop
Accepted Public Pull Requests: - #13688: #13685 Upgrade jquery.mobile.custom.js to be compatible with jQuery 3.x (by @kirmorozov) - #13527: Removing deprecated dependencies from Braintree module (by @joni-jones) - #13655: [Port 2.3-develop] Update Store getConfig() to respect valid false return value (by @JeroenVanLeusden) Fixed GitHub Issues: - #13685: Incompatibilies with jQuery 3 (reported by @kirmorozov) has been fixed in #13688 by @kirmorozov in 2.3-develop branch Related commits: 1. c36fb76 2. b21f2a6
2 parents 2847ef2 + 7df4647 commit 3dda470

File tree

10 files changed

+1225
-1052
lines changed

10 files changed

+1225
-1052
lines changed

app/code/Magento/Braintree/Gateway/Response/PayPal/VaultDetailsHandler.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
use Magento\Payment\Model\InfoInterface;
1313
use Magento\Sales\Api\Data\OrderPaymentExtensionInterface;
1414
use Magento\Sales\Api\Data\OrderPaymentExtensionInterfaceFactory;
15+
use Magento\Vault\Api\Data\PaymentTokenFactoryInterface;
1516
use Magento\Vault\Api\Data\PaymentTokenInterface;
16-
use Magento\Vault\Api\Data\PaymentTokenInterfaceFactory;
1717

1818
/**
1919
* Vault Details Handler
2020
*/
2121
class VaultDetailsHandler implements HandlerInterface
2222
{
2323
/**
24-
* @var PaymentTokenInterfaceFactory
24+
* @var PaymentTokenFactoryInterface
2525
*/
2626
private $paymentTokenFactory;
2727

@@ -41,15 +41,13 @@ class VaultDetailsHandler implements HandlerInterface
4141
private $dateTimeFactory;
4242

4343
/**
44-
* Constructor
45-
*
46-
* @param PaymentTokenInterfaceFactory $paymentTokenFactory
44+
* @param PaymentTokenFactoryInterface $paymentTokenFactory
4745
* @param OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory
4846
* @param SubjectReader $subjectReader
4947
* @param DateTimeFactory $dateTimeFactory
5048
*/
5149
public function __construct(
52-
PaymentTokenInterfaceFactory $paymentTokenFactory,
50+
PaymentTokenFactoryInterface $paymentTokenFactory,
5351
OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory,
5452
SubjectReader $subjectReader,
5553
DateTimeFactory $dateTimeFactory
@@ -92,7 +90,7 @@ private function getVaultPaymentToken(Transaction $transaction)
9290
}
9391

9492
/** @var PaymentTokenInterface $paymentToken */
95-
$paymentToken = $this->paymentTokenFactory->create();
93+
$paymentToken = $this->paymentTokenFactory->create(PaymentTokenFactoryInterface::TOKEN_TYPE_ACCOUNT);
9694
$paymentToken->setGatewayToken($token);
9795
$paymentToken->setExpiresAt($this->getExpirationDate());
9896
$details = json_encode([

app/code/Magento/Braintree/Gateway/Response/VaultDetailsHandler.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
use Braintree\Transaction;
99
use Magento\Braintree\Gateway\Config\Config;
1010
use Magento\Braintree\Gateway\Helper\SubjectReader;
11+
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\Serialize\Serializer\Json;
1113
use Magento\Payment\Gateway\Response\HandlerInterface;
1214
use Magento\Payment\Model\InfoInterface;
1315
use Magento\Sales\Api\Data\OrderPaymentExtensionInterface;
1416
use Magento\Sales\Api\Data\OrderPaymentExtensionInterfaceFactory;
17+
use Magento\Vault\Api\Data\PaymentTokenFactoryInterface;
1518
use Magento\Vault\Api\Data\PaymentTokenInterface;
16-
use Magento\Vault\Api\Data\PaymentTokenInterfaceFactory;
1719

1820
/**
1921
* Vault Details Handler
@@ -22,7 +24,7 @@
2224
class VaultDetailsHandler implements HandlerInterface
2325
{
2426
/**
25-
* @var PaymentTokenInterfaceFactory
27+
* @var PaymentTokenFactoryInterface
2628
*/
2729
protected $paymentTokenFactory;
2830

@@ -49,26 +51,26 @@ class VaultDetailsHandler implements HandlerInterface
4951
/**
5052
* VaultDetailsHandler constructor.
5153
*
52-
* @param PaymentTokenInterfaceFactory $paymentTokenFactory
54+
* @param PaymentTokenFactoryInterface $paymentTokenFactory
5355
* @param OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory
5456
* @param Config $config
5557
* @param SubjectReader $subjectReader
56-
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
58+
* @param Json|null $serializer
5759
* @throws \RuntimeException
5860
*/
5961
public function __construct(
60-
PaymentTokenInterfaceFactory $paymentTokenFactory,
62+
PaymentTokenFactoryInterface $paymentTokenFactory,
6163
OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory,
6264
Config $config,
6365
SubjectReader $subjectReader,
64-
\Magento\Framework\Serialize\Serializer\Json $serializer = null
66+
Json $serializer = null
6567
) {
6668
$this->paymentTokenFactory = $paymentTokenFactory;
6769
$this->paymentExtensionFactory = $paymentExtensionFactory;
6870
$this->config = $config;
6971
$this->subjectReader = $subjectReader;
70-
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
71-
->get(\Magento\Framework\Serialize\Serializer\Json::class);
72+
$this->serializer = $serializer ?: ObjectManager::getInstance()
73+
->get(Json::class);
7274
}
7375

7476
/**
@@ -103,7 +105,7 @@ protected function getVaultPaymentToken(Transaction $transaction)
103105
}
104106

105107
/** @var PaymentTokenInterface $paymentToken */
106-
$paymentToken = $this->paymentTokenFactory->create();
108+
$paymentToken = $this->paymentTokenFactory->create(PaymentTokenFactoryInterface::TOKEN_TYPE_CREDIT_CARD);
107109
$paymentToken->setGatewayToken($token);
108110
$paymentToken->setExpiresAt($this->getExpirationDate($transaction));
109111

app/code/Magento/Braintree/Model/Adminhtml/Source/PaymentAction.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Magento\Braintree\Model\Adminhtml\Source;
77

88
use Magento\Framework\Option\ArrayInterface;
9-
use Magento\Payment\Model\Method\AbstractMethod;
9+
use Magento\Payment\Model\MethodInterface;
1010

1111
/**
1212
* Class PaymentAction
@@ -22,11 +22,11 @@ public function toOptionArray()
2222
{
2323
return [
2424
[
25-
'value' => AbstractMethod::ACTION_AUTHORIZE,
25+
'value' => MethodInterface::ACTION_AUTHORIZE,
2626
'label' => __('Authorize'),
2727
],
2828
[
29-
'value' => AbstractMethod::ACTION_AUTHORIZE_CAPTURE,
29+
'value' => MethodInterface::ACTION_AUTHORIZE_CAPTURE,
3030
'label' => __('Authorize and Capture'),
3131
]
3232
];

app/code/Magento/Braintree/Test/Unit/Gateway/Response/PayPal/VaultDetailsHandlerTest.php

Lines changed: 38 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Braintree\Test\Unit\Gateway\Response\PayPal;
77

8+
use Braintree\Result\Successful;
89
use Braintree\Transaction;
910
use Braintree\Transaction\PayPalDetails;
1011
use Magento\Braintree\Gateway\Helper\SubjectReader;
@@ -15,24 +16,23 @@
1516
use Magento\Sales\Api\Data\OrderPaymentExtensionInterface;
1617
use Magento\Sales\Api\Data\OrderPaymentExtensionInterfaceFactory;
1718
use Magento\Sales\Model\Order\Payment;
19+
use Magento\Vault\Api\Data\PaymentTokenFactoryInterface;
1820
use Magento\Vault\Api\Data\PaymentTokenInterface;
19-
use Magento\Vault\Api\Data\PaymentTokenInterfaceFactory;
20-
use Magento\Vault\Model\AccountPaymentTokenFactory;
2121
use Magento\Vault\Model\PaymentToken;
22+
use PHPUnit\Framework\TestCase;
2223
use PHPUnit_Framework_MockObject_MockObject as MockObject;
2324

2425
/**
2526
* Class VaultDetailsHandlerTest
2627
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2728
*/
28-
class VaultDetailsHandlerTest extends \PHPUnit\Framework\TestCase
29+
class VaultDetailsHandlerTest extends TestCase
2930
{
3031
private static $transactionId = '1n2suy';
3132

32-
/**
33-
* @var SubjectReader|MockObject
34-
*/
35-
private $subjectReader;
33+
private static $token = 'rc39al';
34+
35+
private static $payerEmail = 'john.doe@example.com';
3636

3737
/**
3838
* @var PaymentDataObjectInterface|MockObject
@@ -45,7 +45,7 @@ class VaultDetailsHandlerTest extends \PHPUnit\Framework\TestCase
4545
private $paymentInfo;
4646

4747
/**
48-
* @var AccountPaymentTokenFactory|MockObject
48+
* @var PaymentTokenFactoryInterface|MockObject
4949
*/
5050
private $paymentTokenFactory;
5151

@@ -92,7 +92,7 @@ protected function setUp()
9292

9393
$this->paymentToken = $objectManager->getObject(PaymentToken::class);
9494

95-
$this->paymentTokenFactory = $this->getMockBuilder(AccountPaymentTokenFactory::class)
95+
$this->paymentTokenFactory = $this->getMockBuilder(PaymentTokenFactoryInterface::class)
9696
->setMethods(['create'])
9797
->disableOriginalConstructor()
9898
->getMock();
@@ -109,14 +109,6 @@ protected function setUp()
109109
$this->subject = [
110110
'payment' => $this->paymentDataObject,
111111
];
112-
$this->subjectReader = $this->getMockBuilder(SubjectReader::class)
113-
->disableOriginalConstructor()
114-
->setMethods(['readPayment', 'readTransaction'])
115-
->getMock();
116-
$this->subjectReader->expects(static::once())
117-
->method('readPayment')
118-
->with($this->subject)
119-
->willReturn($this->paymentDataObject);
120112

121113
$this->dateTimeFactory = $this->getMockBuilder(DateTimeFactory::class)
122114
->disableOriginalConstructor()
@@ -126,123 +118,102 @@ protected function setUp()
126118
$this->handler = new VaultDetailsHandler(
127119
$this->paymentTokenFactory,
128120
$this->paymentExtensionFactory,
129-
$this->subjectReader,
121+
new SubjectReader(),
130122
$this->dateTimeFactory
131123
);
132124
}
133125

134-
/**
135-
* @covers \Magento\Braintree\Gateway\Response\PayPal\VaultDetailsHandler::handle
136-
*/
137126
public function testHandle()
138127
{
139-
/** @var Transaction $transaction */
140128
$transaction = $this->getTransaction();
141129
$response = [
142130
'object' => $transaction
143131
];
144132

145-
$this->paymentExtension->expects(static::once())
146-
->method('setVaultPaymentToken')
133+
$this->paymentExtension->method('setVaultPaymentToken')
147134
->with($this->paymentToken);
148-
$this->paymentExtension->expects(static::once())
149-
->method('getVaultPaymentToken')
135+
$this->paymentExtension->method('getVaultPaymentToken')
150136
->willReturn($this->paymentToken);
151-
152-
$this->subjectReader->expects(static::once())
153-
->method('readTransaction')
154-
->with($response)
155-
->willReturn($transaction);
156137

157-
$this->paymentDataObject->expects(static::once())
158-
->method('getPayment')
138+
$this->paymentDataObject->method('getPayment')
159139
->willReturn($this->paymentInfo);
160140

161-
$this->paymentTokenFactory->expects(static::once())
162-
->method('create')
141+
$this->paymentTokenFactory->method('create')
142+
->with(PaymentTokenFactoryInterface::TOKEN_TYPE_ACCOUNT)
163143
->willReturn($this->paymentToken);
164144

165-
$this->paymentExtensionFactory->expects(static::once())
166-
->method('create')
145+
$this->paymentExtensionFactory->method('create')
167146
->willReturn($this->paymentExtension);
168147

169148
$dateTime = new \DateTime('2016-07-05 00:00:00', new \DateTimeZone('UTC'));
170149
$expirationDate = '2017-07-05 00:00:00';
171-
$this->dateTimeFactory->expects(static::once())
172-
->method('create')
150+
$this->dateTimeFactory->method('create')
173151
->willReturn($dateTime);
174152

175153
$this->handler->handle($this->subject, $response);
176154

177155
$extensionAttributes = $this->paymentInfo->getExtensionAttributes();
178-
/** @var PaymentTokenInterface $paymentToken */
179156
$paymentToken = $extensionAttributes->getVaultPaymentToken();
180-
static::assertNotNull($paymentToken);
157+
self::assertNotNull($paymentToken);
181158

182159
$tokenDetails = json_decode($paymentToken->getTokenDetails(), true);
183160

184-
static::assertSame($this->paymentToken, $paymentToken);
185-
static::assertEquals($transaction->paypalDetails->token, $paymentToken->getGatewayToken());
186-
static::assertEquals($transaction->paypalDetails->payerEmail, $tokenDetails['payerEmail']);
187-
static::assertEquals($expirationDate, $paymentToken->getExpiresAt());
161+
self::assertSame($this->paymentToken, $paymentToken);
162+
self::assertEquals(self::$token, $paymentToken->getGatewayToken());
163+
self::assertEquals(self::$payerEmail, $tokenDetails['payerEmail']);
164+
self::assertEquals($expirationDate, $paymentToken->getExpiresAt());
188165
}
189166

190-
/**
191-
* @covers \Magento\Braintree\Gateway\Response\PayPal\VaultDetailsHandler::handle
192-
*/
193167
public function testHandleWithoutToken()
194168
{
195169
$transaction = $this->getTransaction();
196-
$transaction->paypalDetails->token = null;
170+
$transaction->transaction->paypalDetails->token = null;
197171

198172
$response = [
199173
'object' => $transaction
200174
];
201175

202-
$this->subjectReader->expects(static::once())
203-
->method('readTransaction')
204-
->with($response)
205-
->willReturn($transaction);
206-
207-
$this->paymentDataObject->expects(static::once())
208-
->method('getPayment')
176+
$this->paymentDataObject->method('getPayment')
209177
->willReturn($this->paymentInfo);
210178

211-
$this->paymentTokenFactory->expects(static::never())
179+
$this->paymentTokenFactory->expects(self::never())
212180
->method('create');
213181

214-
$this->dateTimeFactory->expects(static::never())
182+
$this->dateTimeFactory->expects(self::never())
215183
->method('create');
216184

217185
$this->handler->handle($this->subject, $response);
218-
static::assertNull($this->paymentInfo->getExtensionAttributes());
186+
self::assertNull($this->paymentInfo->getExtensionAttributes());
219187
}
220188

221189
/**
222-
* Create Braintree transaction
223-
* @return Transaction
190+
* Creates Braintree transaction.
191+
*
192+
* @return Successful
224193
*/
225-
private function getTransaction()
194+
private function getTransaction(): Successful
226195
{
227196
$attributes = [
228197
'id' => self::$transactionId,
229198
'paypalDetails' => $this->getPayPalDetails()
230199
];
231200

232201
$transaction = Transaction::factory($attributes);
202+
$result = new Successful(['transaction' => $transaction]);
233203

234-
return $transaction;
204+
return $result;
235205
}
236206

237207
/**
238-
* Get PayPal transaction details
208+
* Gets PayPal transaction details.
209+
*
239210
* @return PayPalDetails
240211
*/
241-
private function getPayPalDetails()
212+
private function getPayPalDetails(): PayPalDetails
242213
{
243214
$attributes = [
244-
'token' => 'rc39al',
245-
'payerEmail' => 'john.doe@example.com'
215+
'token' => self::$token,
216+
'payerEmail' => self::$payerEmail
246217
];
247218

248219
$details = new PayPalDetails($attributes);

0 commit comments

Comments
 (0)